Skip to content

Commit 2c8fc5a

Browse files
committed
add theme setting
1 parent f046271 commit 2c8fc5a

File tree

6 files changed

+43
-6
lines changed

6 files changed

+43
-6
lines changed

src/components/RightPanel/index.vue

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
<div ref="rightPanel" :class="{show:show}" class="rightPanel-container">
33
<div class="rightPanel-background" />
44
<div class="rightPanel">
5-
<el-button class="handle-button" :style="{'top':buttonTop+'px'}" type="primary" circle :icon="show?'el-icon-close':'el-icon-setting'" @click="show=!show" />
5+
<div class="handle-button" :style="{'top':buttonTop+'px','background-color':theme}" @click="show=!show">
6+
<i :class="show?'el-icon-close':'el-icon-setting'" />
7+
</div>
68
<div class="rightPanel-items">
79
<slot />
810
</div>
@@ -30,6 +32,11 @@ export default {
3032
show: false
3133
}
3234
},
35+
computed: {
36+
theme() {
37+
return this.$store.state.settings.theme
38+
}
39+
},
3340
watch: {
3441
show(value) {
3542
if (value && !this.clickNotClose) {
@@ -130,7 +137,16 @@ export default {
130137
height: 48px;
131138
pointer-events: auto;
132139
z-index: 0;
140+
cursor: pointer;
141+
pointer-events: auto;
133142
font-size: 24px;
134143
text-align: center;
144+
color: #fff;
145+
line-height: 48px;
146+
147+
i {
148+
font-size: 24px;
149+
line-height: 48px;
150+
}
135151
}
136152
</style>

src/components/ThemePicker/index.vue

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<template>
22
<el-color-picker
33
v-model="theme"
4-
:predefine="['#409EFF', '#11a983', '#13c2c2', '#6959CD', '#f5222d', '#eb2f96', '#DB7093', '#e6a23c', '#8B8989', '#212121']"
4+
:predefine="['#409EFF', '#1890ff', '#304156','#212121','#11a983', '#13c2c2', '#6959CD', '#f5222d', ]"
55
class="theme-picker"
66
popper-class="theme-picker-dropdown"
77
/>
@@ -11,17 +11,18 @@
1111
1212
const version = require('element-ui/package.json').version // element-ui version from node_modules
1313
const ORIGINAL_THEME = '#409EFF' // default color
14+
import defaultSettings from '@/settings'
1415
1516
export default {
1617
data() {
1718
return {
1819
chalk: '', // content of theme-chalk css
19-
theme: ORIGINAL_THEME
20+
theme: defaultSettings.theme
2021
}
2122
},
2223
watch: {
2324
async theme(val) {
24-
const oldVal = this.theme
25+
const oldVal = this.chalk ? this.theme : ORIGINAL_THEME
2526
if (typeof val !== 'string') return
2627
const themeCluster = this.getThemeCluster(val.replace('#', ''))
2728
const originalCluster = this.getThemeCluster(oldVal.replace('#', ''))
@@ -70,6 +71,8 @@ export default {
7071
style.innerText = this.updateStyle(innerText, originalCluster, themeCluster)
7172
})
7273
74+
this.$emit('change', val)
75+
7376
$message.close()
7477
}
7578
},

src/layout/components/Settings/index.vue

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<div class="drawer-item">
77
<span>{{ $t('settings.theme') }}</span>
8-
<theme-picker style="float: right;height: 26px;margin: -3px 8px 0 0;" />
8+
<theme-picker style="float: right;height: 26px;margin: -3px 8px 0 0;" @change="themeChange" />
99
</div>
1010

1111
<div class="drawer-item">
@@ -69,6 +69,14 @@ export default {
6969
})
7070
}
7171
}
72+
},
73+
methods: {
74+
themeChange(val) {
75+
this.$store.dispatch('settings/changeSetting', {
76+
key: 'theme',
77+
value: val
78+
})
79+
}
7280
}
7381
}
7482
</script>

src/settings.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
import variables from '@/styles/element-variables.scss'
2+
13
export default {
4+
theme: variables.theme,
25
/**
36
* @type {boolean} true | false
47
* @description Whether show the settings right-panel

src/store/modules/settings.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import defaultSettings from '@/settings'
2-
const { showSettings, tagsView, fixedHeader, sidebarLogo } = defaultSettings
2+
const { showSettings, tagsView, fixedHeader, sidebarLogo, theme } = defaultSettings
33

44
const state = {
5+
theme: theme,
56
showSettings: showSettings,
67
tagsView: tagsView,
78
fixedHeader: fixedHeader,

src/styles/element-variables.scss

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,9 @@ $--table-border:1px solid#dfe6ec;
2323
$--font-path: '~element-ui/lib/theme-chalk/fonts';
2424

2525
@import "~element-ui/packages/theme-chalk/src/index";
26+
27+
// the :export directive is the magic sauce for webpack
28+
// https://www.bluematador.com/blog/how-to-share-variables-between-js-and-sass
29+
:export {
30+
theme: $--color-primary;
31+
}

0 commit comments

Comments
 (0)