diff --git a/src/App.vue b/src/App.vue index 8038c879..1da9d0ad 100644 --- a/src/App.vue +++ b/src/App.vue @@ -20,6 +20,9 @@ import {usePlayWordAudio} from "@/hooks/usePlayWordAudio.ts" import DictModal from "@/components/DictModal.vue" import Backgorund from "@/components/Backgorund.vue" import Statistics from "@/components/Statistics.vue"; +import {ArrowLeft, ArrowRight, MenuFold} from '@icon-park/vue-next' +import useThemeColor from "@/hooks/useThemeColor"; +import Tooltip from "@/components/Tooltip.vue"; let input = $ref('') let wrong = $ref('') @@ -158,46 +161,63 @@ onMounted(() => { }) const show = $ref(false) +const {appearance, toggle} = useThemeColor() diff --git a/src/components/WordList.vue b/src/components/WordList.vue index 847713dc..8b5ead92 100644 --- a/src/components/WordList.vue +++ b/src/components/WordList.vue @@ -77,8 +77,7 @@ watch(() => props.list, () => { box-sizing: border-box; .item { - background: $dark-main-bg; - //background: $item-hover; + background: var(--color-header-bg); border-radius: 6rem; padding: 12rem; //border: 1px solid gray; diff --git a/src/hooks/useThemeColor.ts b/src/hooks/useThemeColor.ts new file mode 100644 index 00000000..6cda94de --- /dev/null +++ b/src/hooks/useThemeColor.ts @@ -0,0 +1,39 @@ +// 获取主题变量 +import {ref, watchEffect} from "vue"; + +let appearance = ref(localStorage.getItem('appearance') || 'auto') +// 查询当前系统主题颜色 +const match: MediaQueryList = window.matchMedia("(prefers-color-scheme: dark)") +// 监听系统主题变化 +match.addEventListener('change', followSystem) + +function followSystem() { + const theme = match.matches ? 'dark' : 'light' + document.documentElement.setAttribute('data-theme', theme) + // document.documentElement.setAttribute('data-theme', 'dark') +} + +watchEffect(() => { +// 如果主题变量为 auto, 则跟随系统主题 + if (appearance.value === 'auto') { + followSystem() + } else { + document.documentElement.setAttribute('data-theme', appearance.value) + } +}) + +function toggle() { + if (appearance.value === 'auto') { + appearance.value = match.matches ? 'light' : 'dark' + } else { + appearance.value = appearance.value === 'light' ? 'dark' : 'light' + } +} + +export default function useThemeColor() { + + return { + appearance, + toggle + } +}