refactor: 使用自定义useAppDark替代vueuse的useDark

将ThemeMode组件和app store中的useDark替换为自定义的useAppDark composable,统一暗色模式管理逻辑
This commit is contained in:
Wei_佳 2025-11-18 15:17:55 +08:00
parent 2b4b9a2e9c
commit 2ec91a6085
3 changed files with 19 additions and 4 deletions

View File

@ -0,0 +1,14 @@
import { useDark } from '@vueuse/core'
const darkOptions = {
selector: 'html',
attribute: 'class',
valueDark: 'dark',
valueLight: '',
storageKey: 'guzhi-color-scheme',
initialValue: 'light',
}
export function useAppDark() {
return useDark(darkOptions)
}

View File

@ -1,9 +1,10 @@
<script setup>
import { useAppStore } from '@/store'
import { useDark, useToggle } from '@vueuse/core'
import { useToggle } from '@vueuse/core'
import { useAppDark } from '@/composables/useAppDark'
const appStore = useAppStore()
const isDark = useDark()
const isDark = useAppDark()
const toggleDark = () => {
appStore.toggleDark()
useToggle(isDark)()

View File

@ -1,12 +1,12 @@
import { defineStore } from 'pinia'
import { useDark } from '@vueuse/core'
import { lStorage } from '@/utils'
import i18n from '~/i18n'
import { useAppDark } from '@/composables/useAppDark'
const currentLocale = lStorage.get('locale')
const { locale } = i18n.global
const isDark = useDark()
const isDark = useAppDark()
export const useAppStore = defineStore('app', {
state() {
return {