diff --git a/src/App.vue b/src/App.vue index 9dcdc931..64b6bd2b 100644 --- a/src/App.vue +++ b/src/App.vue @@ -5,11 +5,32 @@ import Type from "@/components/Type.vue"; import Side from "@/components/Side.vue"; import Statistics from "@/components/Modal/Statistics.vue"; import Backgorund from "@/components/Backgorund.vue"; +import {onMounted} from "vue"; +import {useBaseStore} from "@/stores/base.ts"; +const store = useBaseStore() +// 查询当前系统主题颜色 +const match: MediaQueryList = window.matchMedia("(prefers-color-scheme: dark)") +// 监听系统主题变化 +match.addEventListener('change', followSystem) + +function followSystem() { + if (store.theme === 'auto') { + const theme = match.matches ? 'dark' : 'light' + document.documentElement.setAttribute('data-theme', theme) + // document.documentElement.setAttribute('data-theme', 'dark') + localStorage.setItem('appearance', theme) + } +} + +onMounted(() => { + store.init() + followSystem() +})