|
@@ -1,26 +1,27 @@
|
|
|
import config from '@/config/defaultSetting'
|
|
import config from '@/config/defaultSetting'
|
|
|
import colorUtil from '@/utils/color'
|
|
import colorUtil from '@/utils/color'
|
|
|
|
|
|
|
|
-export const useThemeStore = defineStore({
|
|
|
|
|
- id: 'theme',
|
|
|
|
|
- state: () => ({
|
|
|
|
|
- themeColor: localStorage.getItem('themeColor') || config.themeColor
|
|
|
|
|
- }),
|
|
|
|
|
- actions: {
|
|
|
|
|
- setThemeColor(themeColor: string) {
|
|
|
|
|
- this.themeColor = themeColor
|
|
|
|
|
- localStorage.setItem('themeColor', themeColor)
|
|
|
|
|
- this.initThemeColor()
|
|
|
|
|
- },
|
|
|
|
|
- initThemeColor() {
|
|
|
|
|
- const primary = this.themeColor
|
|
|
|
|
- document.documentElement.style.setProperty('--el-color-primary', primary)
|
|
|
|
|
- for (let i = 1; i <= 9; i++) {
|
|
|
|
|
- document.documentElement.style.setProperty(`--el-color-primary-light-${i}`, colorUtil.lighten(primary, i / 10))
|
|
|
|
|
- }
|
|
|
|
|
- for (let i = 1; i <= 9; i++) {
|
|
|
|
|
- document.documentElement.style.setProperty(`--el-color-primary-dark-${i}`, colorUtil.darken(primary, i / 10))
|
|
|
|
|
- }
|
|
|
|
|
|
|
+export const useThemeStore = defineStore('theme', () => {
|
|
|
|
|
+ const themeColor = useStorage('themeColor', config.themeColor)
|
|
|
|
|
+
|
|
|
|
|
+ const setThemeColor = (color: string) => {
|
|
|
|
|
+ themeColor.value = color
|
|
|
|
|
+ initThemeColor()
|
|
|
|
|
+ }
|
|
|
|
|
+ const initThemeColor = () => {
|
|
|
|
|
+ const primary = themeColor.value
|
|
|
|
|
+ document.documentElement.style.setProperty('--el-color-primary', primary)
|
|
|
|
|
+ for (let i = 1; i <= 9; i++) {
|
|
|
|
|
+ document.documentElement.style.setProperty(`--el-color-primary-light-${i}`, colorUtil.lighten(primary, i / 10))
|
|
|
|
|
+ }
|
|
|
|
|
+ for (let i = 1; i <= 9; i++) {
|
|
|
|
|
+ document.documentElement.style.setProperty(`--el-color-primary-dark-${i}`, colorUtil.darken(primary, i / 10))
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ return {
|
|
|
|
|
+ themeColor,
|
|
|
|
|
+ setThemeColor,
|
|
|
|
|
+ initThemeColor
|
|
|
|
|
+ }
|
|
|
})
|
|
})
|