44
55<template >
66 <Panel >
7- <template #title >{{ $t("fileManagerEditor.title") }} {{ target }}</template >
7+ <template #title >
8+ {{ $t("fileManagerEditor.title") }}
9+ {{ target }}
10+ <el-tag type =" warning" effect =" plain" size =" small" v-if =" editStatus === 'edit'" >编辑中</el-tag >
11+ <el-tag type =" success" effect =" plain" size =" small" v-if =" editStatus === 'success'" >已保存</el-tag >
12+ </template >
813 <template #default >
914 <div class =" instance-table-wrapper" >
1015 <div >
1116 <ItemGroup >
1217 <el-button size =" small" type =" success" @click =" saveFile" >
13- <i class =" el-icon-refresh" ></i > {{ $t("fileManagerEditor.updateFile") }}
18+ <i class =" el-icon-refresh" ></i >
19+ {{ $t("fileManagerEditor.updateFile") }}
1420 </el-button >
1521 <el-button size =" small" @click =" refresh" >
16- <i class =" el-icon-refresh" ></i > {{ $t("general.refresh") }}
22+ <i class =" el-icon-refresh" ></i >
23+ {{ $t("general.refresh") }}
24+ </el-button >
25+ <el-button size =" small" @click =" jumpToLine" >
26+ <i class =" el-icon-sort-down" ></i >
27+ 跳转行
28+ </el-button >
29+ <el-dropdown :hide-on-click =" false" >
30+ <el-button type =" default" size =" small" >
31+ <i class =" el-icon-setting" ></i >
32+ 编辑器设置
33+ <i class =" el-icon-arrow-down el-icon--right" ></i >
34+ </el-button >
35+ <template #dropdown >
36+ <el-dropdown-menu >
37+ <el-dropdown-item >
38+ <el-switch
39+ v-model =" editorSettings.wrapMode"
40+ @change =" setWrapMode($event)"
41+ active-color =" #13ce66"
42+ inactive-color =" #ff4949"
43+ active-text =" 自动换行"
44+ />
45+ </el-dropdown-item >
46+ <el-dropdown-item >
47+ <el-switch
48+ v-model =" editorSettings.behavioursEnabled"
49+ @change =" setBehavioursEnabled($event)"
50+ active-color =" #13ce66"
51+ inactive-color =" #ff4949"
52+ active-text =" 自动补全"
53+ />
54+ </el-dropdown-item >
55+ <el-dropdown-item >
56+ <el-switch
57+ v-model =" editorSettings.highlightActiveLine"
58+ @change =" setHighlightActiveLine($event)"
59+ active-color =" #13ce66"
60+ inactive-color =" #ff4949"
61+ active-text =" 高亮当前行"
62+ />
63+ </el-dropdown-item >
64+ <el-dropdown-item >
65+ <el-switch
66+ v-model =" editorSettings.readOnly"
67+ @change =" setReadOnly($event)"
68+ active-color =" #13ce66"
69+ inactive-color =" #ff4949"
70+ active-text =" 只读模式"
71+ />
72+ </el-dropdown-item >
73+ <el-dropdown-item >
74+ <el-switch
75+ v-model =" editorSettings.showInvisibles"
76+ @change =" setShowInvisibles($event)"
77+ active-color =" #13ce66"
78+ inactive-color =" #ff4949"
79+ active-text =" 显示隐藏字符"
80+ />
81+ </el-dropdown-item >
82+ <el-dropdown-item >
83+ <el-switch
84+ v-model =" editorSettings.enableMultiselect"
85+ @change =" setEnableMultiselect($event)"
86+ active-color =" #13ce66"
87+ inactive-color =" #ff4949"
88+ active-text =" 选中多行"
89+ />
90+ </el-dropdown-item >
91+ <el-dropdown-item >
92+ <el-switch
93+ v-model =" editorSettings.showLineNumbers"
94+ @change =" setShowLineNumbers($event)"
95+ active-color =" #13ce66"
96+ inactive-color =" #ff4949"
97+ active-text =" 显示行号"
98+ />
99+ </el-dropdown-item >
100+ </el-dropdown-menu >
101+ </template >
102+ </el-dropdown >
103+ <el-select
104+ v-model =" editorSettings.theme"
105+ filterable
106+ size =" small"
107+ placeholder =" 编辑器主题"
108+ @change =" changeEditorTheme($event)"
109+ >
110+ <el-option v-for =" item in editorThemes" :key =" item" :label =" item" :value =" item" ></el-option >
111+ </el-select >
112+ <el-input-number v-model =" editorSettings.fontSize" @change =" changeEditorFontsize($event)" :min =" 1" :max =" 114.514" size =" small" ></el-input-number >
113+ <el-button type =" default" size =" small" @click =" toHotKey" >
114+ <i class =" el-icon-sort-down" ></i >
115+ 快捷键提示
17116 </el-button >
18117 <el-button size =" small" @click =" back" v-if =" !backType" >
19- <i class =" el-icon-pie-chart" ></i > {{ $t("fileManagerEditor.backToFileManager") }}
118+ <i class =" el-icon-pie-chart" ></i >
119+ {{ $t("fileManagerEditor.backToFileManager") }}
20120 </el-button >
21121 </ItemGroup >
22122 </div >
23123 <div >
24- <el-button size =" small" @click =" backViaHistory" type =" primary" plain v-if =" backType == 1" >
25- {{ $t("fileManagerEditor.backViaHistory") }}
26- </el-button >
124+ <el-button
125+ size =" small"
126+ @click =" backViaHistory"
127+ type =" primary"
128+ plain
129+ v-if =" backType == 1"
130+ >{{ $t("fileManagerEditor.backViaHistory") }}</el-button >
27131 </div >
28132 </div >
29133 <div v-show =" !error" style =" overflow : auto " >
30- <div id =" editor" style =" height : 70vh " class =" editor-code-font" ></div >
134+ <div
135+ id =" editor"
136+ style =" height : 70vh "
137+ class =" editor-code-font"
138+ @keyup.ctrl.S =" this.onkeydown"
139+ ></div >
31140 </div >
32141 <div v-show =" error" style =" padding : 16px 0px " >
33142 <el-alert
@@ -59,15 +168,88 @@ export default {
59168 text: " " ,
60169 fileName: this .$route .query .target
61170 },
62- editor: null
171+ editor: null ,
172+ editorSettings: {
173+ highlightActiveLine: true ,
174+ readOnly: false ,
175+ showInvisibles: true ,
176+ wrapMode: true ,
177+ enableMultiselect: true ,
178+ showLineNumbers: true ,
179+ behavioursEnabled: true ,
180+ fontSize: parseInt (localStorage .getItem (" editorFontSize" ) || 16 ),
181+ theme: localStorage .getItem (" editorTheme" ) || " monokai"
182+ },
183+ editorThemes: [
184+ " ambiance" ,
185+ " chaos" ,
186+ " chrome" ,
187+ " clouds_midnight" ,
188+ " clouds" ,
189+ " cobalt" ,
190+ " crimson_editor" ,
191+ " dawn" ,
192+ " dracula" ,
193+ " dreamweaver" ,
194+ " eclipse" ,
195+ " github" ,
196+ " gob" ,
197+ " gruvbox" ,
198+ " idle_fingers" ,
199+ " iplastic" ,
200+ " katzenmilch" ,
201+ " kr_theme" ,
202+ " kuroir" ,
203+ " merbivore_soft" ,
204+ " merbivore" ,
205+ " mono_industrial" ,
206+ " monokai" ,
207+ " nord_dark" ,
208+ " pastel_on_dark" ,
209+ " solarized_dark" ,
210+ " solarized_light" ,
211+ " sqlserver" ,
212+ " terminal" ,
213+ " textmate" ,
214+ " tomorrow_night" ,
215+ " tomorrow_night_blue" ,
216+ " tomorrow_night_bright" ,
217+ " tomorrow_night_eighties" ,
218+ " tomorrow" ,
219+ " twilight" ,
220+ " vibrant_ink" ,
221+ " xcode"
222+ ],
223+ editStatus: null ,
224+ editorHotKey: false
63225 };
64226 },
227+
65228 async mounted () {
66229 await this .render ();
67230 this .editor = window .ace .edit (" editor" );
68- this .editor .setTheme (" ace/theme/monokai" );
69- this .editor .setShowPrintMargin (false );
70- this .editor .setFontSize (16 );
231+ this .editor .setTheme (" ace/theme/" + this .editorSettings .theme );
232+ this .editor .setOptions ({
233+ highlightActiveLine: this .editorSettings .highlightActiveLine ,
234+ readOnly: this .editorSettings .readOnly ,
235+ showInvisibles: this .editorSettings .showInvisibles ,
236+ wrap: this .editorSettings .wrapMode ,
237+ enableMultiselect: this .editorSettings .enableMultiselect ,
238+ showPrintMargin: false ,
239+ showLineNumbers: this .editorSettings .showLineNumbers ,
240+ fontSize: this .editorSettings .fontSize
241+ });
242+ this .editor .session .on (" change" , () => {
243+ this .editStatus = " edit" ;
244+ });
245+ this .editor .commands .addCommand ({
246+ name: " saveFile" ,
247+ bindKey: { win: " Ctrl-S" , mac: " Command-S" },
248+ exec : () => {
249+ this .saveFile ();
250+ this .editStatus = " success" ;
251+ }
252+ });
71253 const extName = path .extname (this .target );
72254 if (extName === " .js" ) this .editor .session .setMode (" ace/mode/javascript" );
73255 if (extName === " .json" ) this .editor .session .setMode (" ace/mode/json" );
@@ -88,6 +270,53 @@ export default {
88270 this .editor .setValue (this .edit .text );
89271 },
90272 methods: {
273+ changeEditorFontsize (val ) {
274+ this .editor .setFontSize (val);
275+ localStorage .setItem (" editorFontSize" , val);
276+ },
277+ jumpToLine () {
278+ this .editor .find ();
279+ this .$prompt (" 跳转到指定行" , " 提示" , {
280+ confirmButtonText: " 确定" ,
281+ cancelButtonText: " 取消" ,
282+ inputPattern: / ^ [0-9 ] * $ / ,
283+ inputErrorMessage: " 格式不正确"
284+ }).then (({ value }) => {
285+ this .$message ({
286+ type: " success" ,
287+ message: " 已跳转到第 " + value + " 行"
288+ });
289+ this .editor .gotoLine (value);
290+ });
291+ },
292+ setWrapMode (val ) {
293+ this .editor .getSession ().setUseWrapMode (val);
294+ },
295+ setHighlightActiveLine (val ) {
296+ this .editor .setOption (" highlightActiveLine" , val);
297+ },
298+ setReadOnly (val ) {
299+ this .editor .setOption (" readOnly" , val);
300+ },
301+ setShowInvisibles (val ) {
302+ this .editor .setOption (" showInvisibles" , val);
303+ },
304+ setEnableMultiselect (val ) {
305+ this .editor .setOption (" enableMultiselect" , val);
306+ },
307+ setShowLineNumbers (val ) {
308+ this .editor .setOption (" showLineNumbers" , val);
309+ },
310+ setBehavioursEnabled (val ) {
311+ this .editor .setOption (" behavioursEnabled" , val);
312+ },
313+ changeEditorTheme (val ) {
314+ this .editor .setTheme (" ace/theme/" + val);
315+ localStorage .setItem (" editorTheme" , val);
316+ },
317+ toHotKey () {
318+ window .open (' https://github.com/ajaxorg/ace/wiki/Default-Keyboard-Shortcuts' )
319+ },
91320 async refresh () {
92321 await this .render ();
93322 this .$message ({ message: this .$t (" general.refreshFinish" ), type: " success" });
@@ -98,12 +327,28 @@ export default {
98327 });
99328 },
100329 async back () {
101- this .$router .push ({
102- path: ` /file/${ this .serviceUuid } /${ this .instanceUuid } /` ,
103- query: {
104- path: path .dirname (this .target )
105- }
106- });
330+ if (this .editStatus === " edit" ) {
331+ this .$confirm (" 你还未保存文件, 是否继续返回?" , " 提示" , {
332+ confirmButtonText: " 确定" ,
333+ cancelButtonText: " 取消" ,
334+ type: " warning"
335+ })
336+ .then (() => {
337+ this .$router .push ({
338+ path: ` /file/${ this .serviceUuid } /${ this .instanceUuid } /` ,
339+ query: {
340+ path: path .dirname (this .target )
341+ }
342+ });
343+ })
344+ } else {
345+ this .$router .push ({
346+ path: ` /file/${ this .serviceUuid } /${ this .instanceUuid } /` ,
347+ query: {
348+ path: path .dirname (this .target )
349+ }
350+ });
351+ }
107352 },
108353 backViaHistory () {
109354 this .$router .go (- 1 );
@@ -155,7 +400,7 @@ export default {
155400.editor-code-font {
156401 font-family : " Monaco" , " Menlo" , " Ubuntu Mono" , " Consolas" , " source-code-pro" , " Droid Sans Mono" ,
157402 monospace ;
158- font-size : 12 px ;
403+ font-size : 16 px ;
159404 white-space : pre-wrap ;
160405}
161406 </style >
0 commit comments