2021-12-17 11:55:42 +08:00
|
|
|
import { defineStore } from 'pinia'
|
|
|
|
import { store } from '@/store'
|
|
|
|
import { theme } from '@/settings/designSetting'
|
2021-12-10 14:11:49 +08:00
|
|
|
import { DesignStateType } from './designStore.d'
|
2021-12-20 14:29:29 +08:00
|
|
|
import { setLocalStorage, getLocalStorage } from '@/utils'
|
2021-12-17 11:55:42 +08:00
|
|
|
import { GO_Theme_SELECT } from '@/settings/storageConst'
|
|
|
|
import { ThemeEnum } from '@/enums/styleEnum'
|
|
|
|
|
|
|
|
const { darkTheme, appTheme, appThemeList } = theme
|
|
|
|
const storageThemeName = getLocalStorage(GO_Theme_SELECT)
|
2021-12-10 14:11:49 +08:00
|
|
|
|
|
|
|
export const useDesignStore = defineStore({
|
|
|
|
id: 'useDesignStore',
|
|
|
|
state: (): DesignStateType => ({
|
2021-12-17 11:55:42 +08:00
|
|
|
// 是否暗黑
|
|
|
|
darkTheme: storageThemeName === ThemeEnum.dark,
|
|
|
|
// 主题名称
|
|
|
|
themeName:
|
|
|
|
storageThemeName || (darkTheme && ThemeEnum.dark) || ThemeEnum.light,
|
|
|
|
// 颜色色号
|
2021-12-10 14:11:49 +08:00
|
|
|
appTheme,
|
2021-12-17 11:55:42 +08:00
|
|
|
// 颜色列表
|
|
|
|
appThemeList
|
2021-12-10 14:11:49 +08:00
|
|
|
}),
|
|
|
|
getters: {
|
2021-12-17 11:55:42 +08:00
|
|
|
getDarkTheme(e): boolean {
|
|
|
|
return this.darkTheme
|
2021-12-10 14:11:49 +08:00
|
|
|
},
|
|
|
|
getAppTheme(): string {
|
2021-12-17 11:55:42 +08:00
|
|
|
return this.appTheme
|
2021-12-10 14:11:49 +08:00
|
|
|
},
|
|
|
|
getAppThemeList(): string[] {
|
2021-12-17 11:55:42 +08:00
|
|
|
return this.appThemeList
|
|
|
|
}
|
2021-12-10 14:11:49 +08:00
|
|
|
},
|
2021-12-15 22:16:16 +08:00
|
|
|
actions: {
|
2021-12-17 11:55:42 +08:00
|
|
|
changeTheme(): void {
|
2021-12-15 22:16:16 +08:00
|
|
|
this.darkTheme = !this.darkTheme
|
2021-12-17 11:55:42 +08:00
|
|
|
this.themeName = this.darkTheme ? ThemeEnum.dark : ThemeEnum.light
|
|
|
|
setLocalStorage(GO_Theme_SELECT, this.themeName)
|
2021-12-15 22:16:16 +08:00
|
|
|
}
|
|
|
|
}
|
2021-12-17 11:55:42 +08:00
|
|
|
})
|
2021-12-10 14:11:49 +08:00
|
|
|
|
|
|
|
export function useDesignSettingWithOut() {
|
2021-12-17 11:55:42 +08:00
|
|
|
return useDesignStore(store)
|
2021-12-10 14:11:49 +08:00
|
|
|
}
|