4
4
round
5
5
type =" primary"
6
6
size =" mini"
7
+ style =" background : #66b1ff ;border-color : #66b1ff "
7
8
@click.stop =" showConfigurator"
8
9
>{{getActionDisplayName("theme-editor")}}</el-button >
9
10
<transition name =" fade" >
23
24
</div >
24
25
<div v-if =" init && !currentConfig" class =" no-config" >
25
26
<img src =" ../../assets/images/theme-no-config.png" alt >
26
- <span >{{getActionDisplayName("no-config")}}</span >
27
+ <span v-if =" pageCouldEdit" >{{getActionDisplayName("no-config")}}</span >
28
+ <span v-else >{{getActionDisplayName("no-need-config")}}</span >
27
29
</div >
28
30
<download-area ></download-area >
29
31
</div >
@@ -100,8 +102,16 @@ import {
100
102
} from ' ./utils/utils.js' ;
101
103
import DocStyle from ' ./docStyle' ;
102
104
import Loading from ' ./loading' ;
105
+ import Shortcut from ' ./shortcut' ;
103
106
import DownloadArea from ' ./download' ;
104
107
108
+ const ELEMENT_THEME_USER_CONFIG = ' ELEMENT_THEME_USER_CONFIG' ;
109
+
110
+ const DEFAULT_USER_CONFIG = {
111
+ global: {},
112
+ local: {}
113
+ };
114
+
105
115
export default {
106
116
components: {
107
117
mainPanel,
@@ -117,21 +127,33 @@ export default {
117
127
global: {},
118
128
local: {}
119
129
},
120
- lastApply: 0
130
+ lastApply: 0 ,
131
+ userConfigHistory: [],
132
+ userConfigRedoHistory: [],
133
+ hasLocalConfig: false
121
134
};
122
135
},
123
- mixins: [DocStyle, Loading],
136
+ mixins: [DocStyle, Loading, Shortcut ],
124
137
computed: {
125
138
globalValue () {
126
139
return filterGlobalValue (this .defaultConfig , this .userConfig );
140
+ },
141
+ pageCouldEdit () {
142
+ const noNeedEdit = [' installation' , ' quickstart' , ' i18n' , ' custom-theme' , ' transition' ];
143
+ const lastPath = this .$route .path .split (' /' ).slice (- 1 ).pop ();
144
+ return noNeedEdit .indexOf (lastPath) < 0 ;
127
145
}
128
146
},
147
+ mounted () {
148
+ this .checkLocalThemeConfig ();
149
+ },
129
150
methods: {
130
151
getActionDisplayName (key ) {
131
152
return getActionDisplayName (key);
132
153
},
133
154
showConfigurator () {
134
155
this .visible = ! this .visible ;
156
+ this .visible ? this .enableShortcut () : this .disableShortcut ();
135
157
bus .$emit (' user-theme-config-visible' , this .visible );
136
158
window .userThemeConfigVisible = Boolean (this .visible );
137
159
if (this .init ) return ;
@@ -154,25 +176,46 @@ export default {
154
176
this .defaultConfig = defaultConfig;
155
177
this .filterCurrentConfig ();
156
178
this .init = true ;
179
+ this .checkLocalThemeConfig ();
157
180
}
158
181
loading .close ();
159
182
}, 300 ); // action after transition
160
183
});
161
184
});
162
185
},
186
+ checkLocalThemeConfig () {
187
+ try {
188
+ if (this .hasLocalConfig ) {
189
+ this .$message (getActionDisplayName (' load-local-theme-config' ));
190
+ this .onAction ();
191
+ return ;
192
+ }
193
+ const config = JSON .parse (localStorage .getItem (ELEMENT_THEME_USER_CONFIG ));
194
+ if (config && config .global ) {
195
+ this .userConfig = config;
196
+ this .hasLocalConfig = true ;
197
+ this .showConfigurator ();
198
+ }
199
+ } catch (e) {
200
+ // bad local config
201
+ }
202
+ },
163
203
filterCurrentConfig () {
164
204
this .currentConfig = this .defaultConfig .find ((config ) => {
165
- return config .name === this .$route .path .split (' /' ).pop ().toLowerCase ();
205
+ return config .name === this .$route .path .split (' /' ).pop ().toLowerCase (). replace ( ' - ' , ' ' ) ;
166
206
});
167
207
},
168
208
userConfigChange (e ) {
209
+ this .userConfigHistory .push (JSON .stringify (this .userConfig ));
210
+ this .userConfigRedoHistory = [];
169
211
this .$set (this .userConfig [filterConfigType (this .currentConfig .name )], e .key , e .value );
170
212
this .onAction ();
171
213
},
172
214
applyStyle (res , time ) {
173
215
if (time < this .lastApply ) return ;
174
- this .updateDocs ();
175
- updateDomHeadStyle (' chalk-style' , res);
216
+ this .updateDocs (() => {
217
+ updateDomHeadStyle (' chalk-style' , res);
218
+ });
176
219
this .lastApply = time;
177
220
},
178
221
onDownload () {
@@ -190,6 +233,12 @@ export default {
190
233
onAction () {
191
234
this .triggerComponentLoading (true );
192
235
const time = + new Date ();
236
+ const currentConfigString = JSON .stringify (this .userConfig );
237
+ if (JSON .stringify (DEFAULT_USER_CONFIG ) === currentConfigString) {
238
+ localStorage .removeItem (ELEMENT_THEME_USER_CONFIG );
239
+ } else {
240
+ localStorage .setItem (ELEMENT_THEME_USER_CONFIG , currentConfigString);
241
+ }
193
242
updateVars (this .userConfig )
194
243
.then ((res ) => {
195
244
this .applyStyle (res, time);
@@ -213,10 +262,24 @@ export default {
213
262
triggerComponentLoading (val ) {
214
263
bus .$emit (' user-theme-config-loading' , val);
215
264
},
216
- updateDocs () {
265
+ updateDocs (cb ) {
217
266
window .userThemeConfig = JSON .parse (JSON .stringify (this .userConfig ));
218
267
bus .$emit (' user-theme-config-update' , this .userConfig );
219
- this .updateDocStyle (this .userConfig );
268
+ this .updateDocStyle (this .userConfig , cb);
269
+ },
270
+ undo () {
271
+ if (this .userConfigHistory .length > 0 ) {
272
+ this .userConfigRedoHistory .push (JSON .stringify (this .userConfig ));
273
+ this .userConfig = JSON .parse (this .userConfigHistory .pop ());
274
+ this .onAction ();
275
+ }
276
+ },
277
+ redo () {
278
+ if (this .userConfigRedoHistory .length > 0 ) {
279
+ this .userConfigHistory .push (JSON .stringify (this .userConfig ));
280
+ this .userConfig = JSON .parse (this .userConfigRedoHistory .shift ());
281
+ this .onAction ();
282
+ }
220
283
}
221
284
},
222
285
watch: {
0 commit comments