|
1 | 1 | <template> |
2 | 2 | <div> |
3 | | - <el-select |
4 | | - v-model="mode" |
5 | | - placeholder="Select Mode" |
6 | | - style="margin-bottom: 10px;" |
7 | | - > |
8 | | - <el-option |
9 | | - v-for="item in langTable" |
10 | | - :key="item.value" |
11 | | - :label="item.label" |
12 | | - :value="item.value" |
13 | | - /> |
14 | | - </el-select> |
15 | | - <el-select |
16 | | - v-model="theme" |
17 | | - placeholder="Select Theme" |
18 | | - style="margin-bottom: 10px; margin-left: 20px;" |
19 | | - > |
20 | | - <el-option-group |
21 | | - v-for="group in themeTable" |
22 | | - :key="group.label" |
23 | | - :label="group.label" |
24 | | - > |
25 | | - <el-option |
26 | | - v-for="item in group.themes" |
27 | | - :key="item.value" |
28 | | - :label="item.label" |
29 | | - :value="item.value" |
30 | | - /> |
31 | | - </el-option-group> |
32 | | - </el-select> |
33 | 3 | <textarea ref="editor" v-model="source" /> |
34 | 4 | </div> |
35 | 5 | </template> |
36 | 6 |
|
37 | 7 | <script> |
38 | | -import apiurl from './../../apiurl'; |
39 | 8 | import sfconfig from './../../sfconfig'; |
40 | 9 |
|
41 | 10 | import * as CodeMirror from 'codemirror/lib/codemirror'; |
@@ -91,30 +60,32 @@ export default { |
91 | 60 | return { |
92 | 61 | source: null, |
93 | 62 | langTable: sfconfig.codeMirrorModeTable, |
94 | | - editor: null, |
95 | | - mode: '-', |
96 | | - theme: '-', |
97 | | - themeTable: sfconfig.CodeMirrorThemeTableOptions, |
98 | 63 | CodeMirrorThemeTable: sfconfig.CodeMirrorThemeTable |
99 | 64 | }; |
100 | 65 | }, |
| 66 | + props: { |
| 67 | + mode: { |
| 68 | + type: String, |
| 69 | + default: 'text/x-c++src' |
| 70 | + }, |
| 71 | + theme: { |
| 72 | + type: String, |
| 73 | + default: '3024-day' |
| 74 | + } |
| 75 | + }, |
101 | 76 | watch: { |
102 | 77 | mode(val) { |
103 | 78 | editor.setOption('mode', this.langTable[val].mode); |
104 | 79 | }, |
105 | 80 | theme(val) { |
106 | 81 | editor.setOption('theme', this.CodeMirrorThemeTable[val].theme); |
107 | | - this.$axios |
108 | | - .patch(apiurl('/account/' + this.$store.state.user.userid), { |
109 | | - editor_theme: this.theme |
110 | | - }); |
111 | 82 | } |
112 | 83 | }, |
113 | 84 | methods: { |
114 | 85 | loadEditor() { |
115 | 86 | editor = CodeMirror.fromTextArea(this.$refs.editor, { |
116 | 87 | theme: '3024-day', |
117 | | - mode: 'text/x-markdown', |
| 88 | + mode: 'text/x-c++src', |
118 | 89 | indentUnit: 4, |
119 | 90 | smartIndent: true, |
120 | 91 | indentWithTabs: false, |
@@ -143,22 +114,11 @@ export default { |
143 | 114 | editor.showHint(); |
144 | 115 | }); |
145 | 116 | }, |
146 | | - loadUserLangMode() { |
147 | | - this.mode = this.langTable[sfconfig.langTable[this.$store.state.user.userlang].codeMirror].label; |
148 | | - editor.setOption('mode', this.langTable[this.langTable[sfconfig.langTable[this.$store.state.user.userlang].codeMirror].value].mode); |
149 | | - }, |
150 | | - loadUserTheme() { |
151 | | - this.$axios |
152 | | - .get(apiurl('/account/' + this.$store.state.user.userid)) |
153 | | - .then(res => { |
154 | | - this.theme = String(res.data.res.editor_theme); |
155 | | - }); |
156 | | - } |
157 | 117 | }, |
158 | 118 | mounted() { |
159 | 119 | this.loadEditor(); |
160 | | - this.loadUserLangMode(); |
161 | | - this.loadUserTheme(); |
| 120 | + editor.setOption('mode', this.langTable[this.mode].mode); |
| 121 | + editor.setOption('theme', this.langTable[this.theme].mode); |
162 | 122 | } |
163 | 123 | }; |
164 | 124 | </script> |
0 commit comments