This commit is contained in:
邹方成 2025-11-19 19:36:12 +08:00
commit c905d2492b
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> <script setup>
import { useAppStore } from '@/store' import { useAppStore } from '@/store'
import { useDark, useToggle } from '@vueuse/core' import { useToggle } from '@vueuse/core'
import { useAppDark } from '@/composables/useAppDark'
const appStore = useAppStore() const appStore = useAppStore()
const isDark = useDark() const isDark = useAppDark()
const toggleDark = () => { const toggleDark = () => {
appStore.toggleDark() appStore.toggleDark()
useToggle(isDark)() useToggle(isDark)()

View File

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