mirror of
https://github.com/XiaoDaiGua-Ray/ray-template.git
synced 2025-04-06 03:57:49 +08:00
50 lines
1.2 KiB
TypeScript
50 lines
1.2 KiB
TypeScript
import { setCache, getCache } from '@/utils/cache'
|
|
|
|
export const useSetting = defineStore('setting', () => {
|
|
const cachePrimaryColor: string =
|
|
getCache('primaryColor', 'localStorage') === 'no'
|
|
? '#18A058'
|
|
: getCache('primaryColor', 'localStorage')
|
|
const cacheTheme =
|
|
getCache('theme', 'localStorage') === 'no'
|
|
? false
|
|
: getCache('theme', 'localStorage')
|
|
|
|
const settingState = reactive({
|
|
drawerPlacement: 'right' as NaiveDrawerPlacement,
|
|
primaryColorOverride: {
|
|
common: {
|
|
primaryColor: cachePrimaryColor, // 主题色
|
|
},
|
|
},
|
|
themeValue: cacheTheme, // `true` 为黑夜主题, `false` 为白色主题
|
|
})
|
|
const { locale } = useI18n()
|
|
|
|
const updateLocale = (key: string) => {
|
|
// TODO: 修改语言
|
|
locale.value = key
|
|
|
|
setCache('localeLanguage', key, 'localStorage')
|
|
}
|
|
|
|
const changeTheme = (bool: boolean) => {
|
|
settingState.themeValue = bool
|
|
|
|
setCache('theme', bool, 'localStorage')
|
|
}
|
|
|
|
const changePrimaryColor = (value: string) => {
|
|
settingState.primaryColorOverride.common.primaryColor = value
|
|
|
|
setCache('primaryColor', value, 'localStorage')
|
|
}
|
|
|
|
return {
|
|
...toRefs(settingState),
|
|
updateLocale,
|
|
changeTheme,
|
|
changePrimaryColor,
|
|
}
|
|
})
|