@@ -19,12 +19,21 @@ export default {
19
19
}
20
20
},
21
21
watch: {
22
- theme (val ) {
22
+ async theme (val ) {
23
23
const oldVal = this .theme
24
24
if (typeof val !== ' string' ) return
25
25
const themeCluster = this .getThemeCluster (val .replace (' #' , ' ' ))
26
26
const originalCluster = this .getThemeCluster (oldVal .replace (' #' , ' ' ))
27
27
console .log (themeCluster, originalCluster)
28
+
29
+ const $message = this .$message ({
30
+ message: ' Compiling the theme' ,
31
+ customClass: ' theme-message' ,
32
+ type: ' success' ,
33
+ duration: 0 ,
34
+ iconClass: ' el-icon-loading'
35
+ })
36
+
28
37
const getHandler = (variable , id ) => {
29
38
return () => {
30
39
const originalCluster = this .getThemeCluster (ORIGINAL_THEME .replace (' #' , ' ' ))
@@ -40,15 +49,15 @@ export default {
40
49
}
41
50
}
42
51
43
- const chalkHandler = getHandler (' chalk' , ' chalk-style' )
44
-
45
52
if (! this .chalk ) {
46
53
const url = ` https://unpkg.com/element-ui@${ version} /lib/theme-chalk/index.css`
47
- this .getCSSString (url, chalkHandler, ' chalk' )
48
- } else {
49
- chalkHandler ()
54
+ await this .getCSSString (url, ' chalk' )
50
55
}
51
56
57
+ const chalkHandler = getHandler (' chalk' , ' chalk-style' )
58
+
59
+ chalkHandler ()
60
+
52
61
const styles = [].slice .call (document .querySelectorAll (' style' ))
53
62
.filter (style => {
54
63
const text = style .innerText
@@ -59,39 +68,32 @@ export default {
59
68
if (typeof innerText !== ' string' ) return
60
69
style .innerText = this .updateStyle (innerText, originalCluster, themeCluster)
61
70
})
62
- this .$message ({
63
- message: ' 换肤成功' ,
64
- type: ' success'
65
- })
71
+
72
+ $message .close ()
66
73
}
67
74
},
68
75
69
76
methods: {
70
77
updateStyle (style , oldCluster , newCluster ) {
71
- const colorOverrides = [] // only capture color overides
78
+ let newStyle = style
72
79
oldCluster .forEach ((color , index ) => {
73
- const value = newCluster[index]
74
- const color_plain = color .replace (/ ([()] )/ g , ' \\ $1' )
75
- const repl = new RegExp (` (^|})([^{]+{[^{}]+)${ color_plain} \\ b([^}]*)(?=})` , ' gi' )
76
- const nestRepl = new RegExp (color_plain, ' ig' ) // for greed matching before the 'color'
77
- let v
78
- while ((v = repl .exec (style))) {
79
- colorOverrides .push (v[2 ].replace (nestRepl, value) + value + v[3 ] + ' }' ) // '}' not captured in the regexp repl to reserve it as locator-boundary
80
- }
80
+ newStyle = newStyle .replace (new RegExp (color, ' ig' ), newCluster[index])
81
81
})
82
- return colorOverrides . join ( ' ' )
82
+ return newStyle
83
83
},
84
84
85
- getCSSString (url , callback , variable ) {
86
- const xhr = new XMLHttpRequest ()
87
- xhr .onreadystatechange = () => {
88
- if (xhr .readyState === 4 && xhr .status === 200 ) {
89
- this [variable] = xhr .responseText .replace (/ @font-face{[^ }] + }/ , ' ' )
90
- callback ()
85
+ getCSSString (url , variable ) {
86
+ return new Promise (resolve => {
87
+ const xhr = new XMLHttpRequest ()
88
+ xhr .onreadystatechange = () => {
89
+ if (xhr .readyState === 4 && xhr .status === 200 ) {
90
+ this [variable] = xhr .responseText .replace (/ @font-face{[^ }] + }/ , ' ' )
91
+ resolve ()
92
+ }
91
93
}
92
- }
93
- xhr .open ( ' GET ' , url )
94
- xhr . send ( )
94
+ xhr . open ( ' GET ' , url)
95
+ xhr .send ( )
96
+ } )
95
97
},
96
98
97
99
getThemeCluster (theme ) {
@@ -143,10 +145,14 @@ export default {
143
145
</script >
144
146
145
147
<style >
148
+ .theme-message ,
149
+ .theme-picker-dropdown {
150
+ z-index : 99999 !important ;
151
+ }
152
+
146
153
.theme-picker .el-color-picker__trigger {
147
- margin-top : 12px ;
148
- height : 26px !important ;
149
- width : 26px !important ;
154
+ height : 26px !important ;
155
+ width : 26px !important ;
150
156
padding : 2px ;
151
157
}
152
158
0 commit comments