From 769815020f34b9b3193abb90c4a2df32f010cdbb Mon Sep 17 00:00:00 2001 From: Doyoung Date: Fri, 24 Oct 2025 11:00:28 +0800 Subject: [PATCH 1/7] fix: search input no focus when it displayed --- src/components/BaseTable.vue | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/components/BaseTable.vue b/src/components/BaseTable.vue index 15b77136..eebc72aa 100644 --- a/src/components/BaseTable.vue +++ b/src/components/BaseTable.vue @@ -150,7 +150,8 @@ defineRender( clearable modelValue={searchKey} onUpdate:modelValue={debounce(e => searchKey = e)} - class="flex-1"> + class="flex-1" + autofocus> {{ subfix: () => Date: Fri, 24 Oct 2025 19:01:01 +0800 Subject: [PATCH 2/7] fix: two clicks are needed to chenge the theme for the first time --- src/hooks/theme.ts | 74 ++++++++++++++++++++++++++++++++++----------- src/pages/index.vue | 4 +-- 2 files changed, 58 insertions(+), 20 deletions(-) diff --git a/src/hooks/theme.ts b/src/hooks/theme.ts index 25330796..8a7cace5 100644 --- a/src/hooks/theme.ts +++ b/src/hooks/theme.ts @@ -1,33 +1,71 @@ import {useSettingStore} from "@/stores/setting.ts"; +type Theme = "light" | "dark"; +// 获取系统主题 +function getSystemTheme(): Theme { + if (window.matchMedia('(prefers-color-scheme: dark)').matches) { + return 'dark'; + } else if (window.matchMedia('(prefers-color-scheme: light)').matches) { + return 'light'; + } + return 'light'; // 默认浅色模式 +} + +// 交换主题名称 +function swapTheme(theme: Theme): Theme { + return theme === 'light' ? 'dark' : 'light' +} + +// 监听系统主题变化 +function listenToSystemThemeChange(call: (theme: Theme) => void) { + window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', e => { + if (e.matches) { + // console.log('系统已切换到深色模式'); + call('dark'); + } + }); + window.matchMedia('(prefers-color-scheme: light)').addEventListener('change', e => { + if (e.matches) { + // console.log('系统已切换到浅色模式'); + call('light'); + } + }); +} + export default function useTheme() { const settingStore = useSettingStore() -// // 查询当前系统主题颜色 -// const match: MediaQueryList = window.matchMedia("(prefers-color-scheme: dark)") -// // 监听系统主题变化 -// match.addEventListener('change', followSystem) -// -// function followSystem() { -// document.documentElement.className = match.matches ? 'dark' : 'light' -// } - + // 开启监听系统主题变更,后期可以通过用户配置来决定是否开启 + listenToSystemThemeChange((theme: Theme) => { + // 如果系统主题变更后和当前的主题一致,则不需要再重新切换 + if(settingStore.theme === theme){ + return; + } + + settingStore.theme = theme; + setTheme(theme); + }) function toggleTheme() { - if (settingStore.theme === 'auto') { - settingStore.theme = 'light' - } else { - settingStore.theme = settingStore.theme === 'light' ? 'dark' : 'light' - } - setTheme(settingStore.theme) + // auto模式下,默认是使用系统主题,切换时应该使用当前系统主题为基础进行切换 + settingStore.theme = swapTheme(settingStore.theme === 'auto' ? getSystemTheme() : settingStore.theme as Theme); + setTheme(settingStore.theme); } - function setTheme(val) { - document.documentElement.className = val + function setTheme(val:string) { + // auto模式下,则通过查询系统主题来设置主题名称 + document.documentElement.className = val === 'auto' ? getSystemTheme() : val; + } + + // 获取当前具体的主题名称 + function getTheme():Theme{ + // auto模式下,则通过查询系统主题来获取当前具体的主题名称 + return settingStore.theme === 'auto' ? getSystemTheme() : settingStore.theme as Theme; } return { toggleTheme, - setTheme + setTheme, + getTheme } } diff --git a/src/pages/index.vue b/src/pages/index.vue index 5a7d8562..245a887a 100644 --- a/src/pages/index.vue +++ b/src/pages/index.vue @@ -12,7 +12,7 @@ import {useRuntimeStore} from "@/stores/runtime.ts"; const settingStore = useSettingStore() const runtimeStore = useRuntimeStore() const router = useRouter() -const {toggleTheme} = useTheme() +const {toggleTheme,getTheme} = useTheme() @@ -58,7 +58,7 @@ const {toggleTheme} = useTheme() :title="`切换主题(${settingStore.shortcutKeyMap[ShortcutKey.ToggleTheme]})`" @click="toggleTheme" > - + From b5fdd71194e82f802fc56b6d03bfd458a3659fba Mon Sep 17 00:00:00 2001 From: Zyronon Date: Tue, 28 Oct 2025 12:54:59 +0800 Subject: [PATCH 3/7] Update PracticeWords.vue --- src/pages/word/PracticeWords.vue | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pages/word/PracticeWords.vue b/src/pages/word/PracticeWords.vue index 33b94479..27838a52 100644 --- a/src/pages/word/PracticeWords.vue +++ b/src/pages/word/PracticeWords.vue @@ -272,8 +272,8 @@ async function next(isTyping: boolean = true) { } else { isTypingWrongWord.value = false console.log('当前学完了,没错词', statStore.total, statStore.step, data.index) - //学完了 - if (statStore.step === 8) { + //学完了,这里第 7 步如果无单词,加 3 就是 9 了 + if (statStore.step >= 8) { statStore.spend = Date.now() - statStore.startDate console.log('全完学完了') showStatDialog = true From b2e11a194eb7bb3682329c0ffb32d36d1bef8272 Mon Sep 17 00:00:00 2001 From: Zyronon Date: Tue, 28 Oct 2025 15:53:45 +0800 Subject: [PATCH 4/7] Update TypeWord.vue --- src/pages/word/components/TypeWord.vue | 113 +++++++++++-------------- 1 file changed, 50 insertions(+), 63 deletions(-) diff --git a/src/pages/word/components/TypeWord.vue b/src/pages/word/components/TypeWord.vue index d5ae4abf..793175fe 100644 --- a/src/pages/word/components/TypeWord.vue +++ b/src/pages/word/components/TypeWord.vue @@ -1,14 +1,14 @@