Wei_佳 26701c25cf refactor: 使用自定义useAppDark替代vueuse的useDark
将ThemeMode组件和app store中的useDark替换为自定义的useAppDark composable,统一暗色模式管理逻辑

(cherry picked from commit 2ec91a6085a7df2432bbe2d242daa2d018c1c64c)
2025-11-18 15:39:34 +08:00

61 lines
1.4 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { defineStore } from 'pinia'
import { lStorage } from '@/utils'
import i18n from '~/i18n'
import { useAppDark } from '@/composables/useAppDark'
const currentLocale = lStorage.get('locale')
const { locale } = i18n.global
const isDark = useAppDark()
export const useAppStore = defineStore('app', {
state() {
return {
reloadFlag: true,
collapsed: false,
fullScreen: true,
/** keepAlive路由的key重新赋值可重置keepAlive */
aliveKeys: {},
isDark,
locale: currentLocale || 'en',
}
},
actions: {
async reloadPage() {
$loadingBar.start()
this.reloadFlag = false
await nextTick()
this.reloadFlag = true
setTimeout(() => {
document.documentElement.scrollTo({ left: 0, top: 0 })
$loadingBar.finish()
}, 100)
},
switchCollapsed() {
this.collapsed = !this.collapsed
},
setCollapsed(collapsed) {
this.collapsed = collapsed
},
setFullScreen(fullScreen) {
this.fullScreen = fullScreen
},
setAliveKeys(key, val) {
this.aliveKeys[key] = val
},
/** 设置暗黑模式 */
setDark(isDark) {
this.isDark = isDark
},
/** 切换/关闭 暗黑模式 */
toggleDark() {
this.isDark = !this.isDark
},
setLocale(newLocale) {
this.locale = newLocale
locale.value = newLocale
lStorage.set('locale', newLocale)
},
},
})