From a0e89f4b4006e87c49d928ebcd9636959ffe6155 Mon Sep 17 00:00:00 2001 From: Zyronon Date: Mon, 15 Dec 2025 02:28:34 +0800 Subject: [PATCH] fix: correct translation color in dark mode and enable Chinese punctuation input - Fix incorrect text color of translations in dark mode - Resolve issue where Chinese punctuation could not be input --- scripts/deploy-oss.js | 4 +-- src/App.vue | 7 ++++ .../article/components/TypingArticle.vue | 4 +-- src/pages/word/WordsPage.vue | 3 +- src/pages/word/components/TypeWord.vue | 33 +++++++++++++++++++ src/stores/base.ts | 1 - src/utils/index.ts | 33 ++++++++++++++++--- 7 files changed, 74 insertions(+), 11 deletions(-) diff --git a/scripts/deploy-oss.js b/scripts/deploy-oss.js index f86749ef..e5483f35 100644 --- a/scripts/deploy-oss.js +++ b/scripts/deploy-oss.js @@ -129,8 +129,8 @@ async function refreshCDN(domain) { async function main() { const files = getAllFiles('./dist') console.log(`📁 共找到 ${files.length} 个文件,开始上传...`) - // await uploadFilesWithClean(files, './dist', ['dicts', 'sound', 'libs','imgs]) - await uploadFilesWithClean(files, './dist', ['sound','libs','imgs']) + await uploadFilesWithClean(files, './dist', ['dicts', 'sound', 'libs','imgs']) + // await uploadFilesWithClean(files, './dist', ['sound','libs','imgs']) await refreshCDN('2study.top') await refreshCDN('typewords.cc') } diff --git a/src/App.vue b/src/App.vue index d12c7147..d12256d3 100644 --- a/src/App.vue +++ b/src/App.vue @@ -21,7 +21,11 @@ const userStore = useUserStore() const {setTheme} = useTheme() let lastAudioFileIdList = [] +let isInitializing = true // 标记是否正在初始化 watch(store.$state, (n: BaseState) => { + // 如果正在初始化,不保存数据,避免覆盖 + if (isInitializing) return + console.log('watch') let data = shakeCommonDict(n) set(SAVE_DICT_KEY.key, JSON.stringify({val: data, version: SAVE_DICT_KEY.version})) @@ -52,6 +56,7 @@ watch(store.$state, (n: BaseState) => { }) watch(() => settingStore.$state, (n) => { + if (isInitializing) return set(SAVE_SETTING_KEY.key, JSON.stringify({val: n, version: SAVE_SETTING_KEY.version})) if (AppEnv.CAN_REQUEST) { syncSetting(null, settingStore.$state) @@ -59,10 +64,12 @@ watch(() => settingStore.$state, (n) => { }, {deep: true}) async function init() { + isInitializing = true // 开始初始化 await userStore.init() await store.init() await settingStore.init() store.load = true + isInitializing = false // 初始化完成,允许保存数据 setTheme(settingStore.theme) diff --git a/src/pages/article/components/TypingArticle.vue b/src/pages/article/components/TypingArticle.vue index 00cf5993..e465b7d9 100644 --- a/src/pages/article/components/TypingArticle.vue +++ b/src/pages/article/components/TypingArticle.vue @@ -648,7 +648,7 @@ const currentPractice = inject('currentPractice', []) @input="handleMobileInput" />
-
{{ +
{{ store.sbook.lastLearnIndex + 1 }}.{{ props.article.title }}
@@ -826,7 +826,7 @@ $article-lh: 2.4; display: inline-block !important; } .translate{ - color:black; + color: var(--color-reverse-black); } } diff --git a/src/pages/word/WordsPage.vue b/src/pages/word/WordsPage.vue index 1c11f11f..d6348fc1 100644 --- a/src/pages/word/WordsPage.vue +++ b/src/pages/word/WordsPage.vue @@ -245,8 +245,7 @@ let isNewHost = $ref(window.location.host === Host) 2study.top 域名将在不久后停止使用
- -
+
diff --git a/src/pages/word/components/TypeWord.vue b/src/pages/word/components/TypeWord.vue index 44f91773..ea747bf4 100644 --- a/src/pages/word/components/TypeWord.vue +++ b/src/pages/word/components/TypeWord.vue @@ -245,6 +245,38 @@ async function onTyping(e: KeyboardEvent) { } else { right = letter === word[input.length] } + //针对中文的特殊判断 + if (e.shiftKey && ( + '!' === word[input.length] && e.code === 'Digit1' || + '¥' === word[input.length] && e.code === 'Digit4' || + '…' === word[input.length] && e.code === 'Digit6' || + '(' === word[input.length] && e.code === 'Digit9' || + '—' === word[input.length] && e.code === 'Minus' || + '?' === word[input.length] && e.code === 'Slash' || + '》' === word[input.length] && e.code === 'Period' || + '《' === word[input.length] && e.code === 'Comma' || + '“' === word[input.length] && e.code === 'Quote' || + ':' === word[input.length] && e.code === 'Semicolon' || + ')' === word[input.length] && e.code === 'Digit0') + ) { + right = true + letter = word[input.length] + } + if (!e.shiftKey && ( + '【' === word[input.length] && e.code === 'BracketLeft' || + '、' === word[input.length] && e.code === 'Slash' || + '。' === word[input.length] && e.code === 'Period' || + ',' === word[input.length] && e.code === 'Comma' || + '‘' === word[input.length] && e.code === 'Quote' || + ';' === word[input.length] && e.code === 'Semicolon' || + '【' === word[input.length] && e.code === 'BracketLeft' || + '】' === word[input.length] && e.code === 'BracketRight' + )) { + right = true + letter = word[input.length] + } + console.log('e', e, e.code, e.shiftKey, word[input.length]) + if (right) { input += letter wrong = '' @@ -386,6 +418,7 @@ function checkCursorPosition() { // 选中目标元素 const cursorEl = document.querySelector(`.cursor`); const inputList = document.querySelectorAll(`.l`); + if (!typingWordRef) return; const typingWordRect = typingWordRef.getBoundingClientRect(); if (inputList.length) { diff --git a/src/stores/base.ts b/src/stores/base.ts index 273cac37..a2b31414 100644 --- a/src/stores/base.ts +++ b/src/stores/base.ts @@ -129,7 +129,6 @@ export const useBaseStore = defineStore('base', { } } this.setState(data) - set(SAVE_DICT_KEY.key, JSON.stringify({ val: shakeCommonDict(this.$state), version: SAVE_DICT_KEY.version })) } catch (e) { console.error('读取本地dict数据失败', e) } diff --git a/src/utils/index.ts b/src/utils/index.ts index dd10c2c7..1151ac26 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -37,9 +37,15 @@ export function checkAndUpgradeSaveDict(val: any) { } else { data = val } - if (!data.version) return defaultState + if (!data.version) { + console.warn('数据缺少版本号,返回默认状态') + return defaultState + } let state: any = data.val - if (typeof state !== 'object') return defaultState + if (typeof state !== 'object') { + console.warn('数据格式无效,返回默认状态') + return defaultState + } state.load = false let version = Number(data.version) // console.log('state', state) @@ -53,10 +59,29 @@ export function checkAndUpgradeSaveDict(val: any) { }) return defaultState } else { - checkRiskKey(defaultState, state) - return defaultState + // 版本不匹配时,尽量保留数据而不是直接返回默认状态 + console.warn(`数据版本不匹配: 当前版本 ${version}, 期望版本 ${SAVE_DICT_KEY.version},尝试保留数据`) + try { + checkRiskKey(defaultState, state) + // 尝试保留 bookList 数据 + if (state.word && state.word.bookList && Array.isArray(state.word.bookList)) { + defaultState.word.bookList = state.word.bookList.map((v: any) => { + return getDefaultDict(checkRiskKey(getDefaultDict(), v)) + }) + } + if (state.article && state.article.bookList && Array.isArray(state.article.bookList)) { + defaultState.article.bookList = state.article.bookList.map((v: any) => { + return getDefaultDict(checkRiskKey(getDefaultDict(), v)) + }) + } + return defaultState + } catch (upgradeError) { + console.error('数据升级失败,返回默认状态', upgradeError) + return defaultState + } } } catch (e) { + console.error('数据解析异常,返回默认状态', e) return defaultState } }