Skip to content

Commit 27322ac

Browse files
committed
add ThemePicker to setting
1 parent 6c6f03f commit 27322ac

File tree

4 files changed

+49
-55
lines changed

4 files changed

+49
-55
lines changed

src/components/RightPanel/index.vue

+3-13
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22
<div ref="rightPanel" :class="{show:show}" class="rightPanel-container">
33
<div class="rightPanel-background" />
44
<div class="rightPanel">
5-
<div class="handle-button" :style="{'top':buttonTop+'px'}" type="primary" circle @click="show=!show">
6-
<i :class="show?'el-icon-close':'el-icon-setting'" />
7-
</div>
5+
<el-button class="handle-button" :style="{'top':buttonTop+'px'}" type="primary" circle :icon="show?'el-icon-close':'el-icon-setting'" @click="show=!show" />
86
<div class="rightPanel-items">
97
<slot />
108
</div>
@@ -121,20 +119,12 @@ export default {
121119
.handle-button {
122120
position: absolute;
123121
left: -48px;
124-
border-radius: 4px 0 0 4px !important;
122+
border-radius: 6px 0 0 6px !important;
125123
width: 48px;
126124
height: 48px;
127-
background: #1890ff;
128-
cursor: pointer;
129125
pointer-events: auto;
130126
z-index: 0;
127+
font-size: 24px;
131128
text-align: center;
132-
color: #fff;
133-
line-height: 48px;
134-
135-
i {
136-
font-size: 24px;
137-
line-height: 48px;
138-
}
139129
}
140130
</style>

src/components/ThemePicker/index.vue

+38-32
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,21 @@ export default {
1919
}
2020
},
2121
watch: {
22-
theme(val) {
22+
async theme(val) {
2323
const oldVal = this.theme
2424
if (typeof val !== 'string') return
2525
const themeCluster = this.getThemeCluster(val.replace('#', ''))
2626
const originalCluster = this.getThemeCluster(oldVal.replace('#', ''))
2727
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+
2837
const getHandler = (variable, id) => {
2938
return () => {
3039
const originalCluster = this.getThemeCluster(ORIGINAL_THEME.replace('#', ''))
@@ -40,15 +49,15 @@ export default {
4049
}
4150
}
4251
43-
const chalkHandler = getHandler('chalk', 'chalk-style')
44-
4552
if (!this.chalk) {
4653
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')
5055
}
5156
57+
const chalkHandler = getHandler('chalk', 'chalk-style')
58+
59+
chalkHandler()
60+
5261
const styles = [].slice.call(document.querySelectorAll('style'))
5362
.filter(style => {
5463
const text = style.innerText
@@ -59,39 +68,32 @@ export default {
5968
if (typeof innerText !== 'string') return
6069
style.innerText = this.updateStyle(innerText, originalCluster, themeCluster)
6170
})
62-
this.$message({
63-
message: '换肤成功',
64-
type: 'success'
65-
})
71+
72+
$message.close()
6673
}
6774
},
6875
6976
methods: {
7077
updateStyle(style, oldCluster, newCluster) {
71-
const colorOverrides = [] // only capture color overides
78+
let newStyle = style
7279
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])
8181
})
82-
return colorOverrides.join('')
82+
return newStyle
8383
},
8484
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+
}
9193
}
92-
}
93-
xhr.open('GET', url)
94-
xhr.send()
94+
xhr.open('GET', url)
95+
xhr.send()
96+
})
9597
},
9698
9799
getThemeCluster(theme) {
@@ -143,10 +145,14 @@ export default {
143145
</script>
144146

145147
<style>
148+
.theme-message,
149+
.theme-picker-dropdown {
150+
z-index: 99999 !important;
151+
}
152+
146153
.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;
150156
padding: 2px;
151157
}
152158

src/layout/components/Navbar.vue

-5
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@
1818

1919
<lang-select class="right-menu-item hover-effect" />
2020

21-
<el-tooltip :content="$t('navbar.theme')" effect="dark" placement="bottom">
22-
<theme-picker class="right-menu-item hover-effect" />
23-
</el-tooltip>
2421
</template>
2522

2623
<el-dropdown class="avatar-container right-menu-item hover-effect" trigger="click">
@@ -56,7 +53,6 @@ import ErrorLog from '@/components/ErrorLog'
5653
import Screenfull from '@/components/Screenfull'
5754
import SizeSelect from '@/components/SizeSelect'
5855
import LangSelect from '@/components/LangSelect'
59-
import ThemePicker from '@/components/ThemePicker'
6056
import Search from '@/components/HeaderSearch'
6157
6258
export default {
@@ -67,7 +63,6 @@ export default {
6763
Screenfull,
6864
SizeSelect,
6965
LangSelect,
70-
ThemePicker,
7166
Search
7267
},
7368
computed: {

src/layout/components/Settings/index.vue

+8-5
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,23 @@
66
</h3>
77

88
<div class="drawer-item">
9-
<span>开启 Tags-View</span>
9+
<span>开启 Tags-View</span>
1010
<el-switch v-model="tagsView" class="drawer-switch" />
1111
</div>
1212

13-
<!-- <div class="drawer-item">
14-
<span>显示 Logo</span>
15-
<el-switch v-model="sidebarLogo" class="drawer-switch" />
16-
</div> -->
13+
<div class="drawer-item">
14+
<span>主题色</span>
15+
<theme-picker style="float: right;height: 26px;margin: -3px 5px 0 0;" />
16+
</div>
1717
</div>
1818
</div>
1919
</template>
2020

2121
<script>
22+
import ThemePicker from '@/components/ThemePicker'
23+
2224
export default {
25+
components: { ThemePicker },
2326
data() {
2427
return {
2528
sidebarLogo: true

0 commit comments

Comments
 (0)