From a14af056f7610b7c75d3bce5140706f38a88efb8 Mon Sep 17 00:00:00 2001 From: zyronon Date: Wed, 23 Jul 2025 00:53:33 +0800 Subject: [PATCH] feat:save --- src/pages/pc/components/Panel.vue | 19 +++++++++---------- src/pages/pc/word/DictDetail.vue | 21 +-------------------- src/pages/pc/word/StudyWord.vue | 13 ++++++++----- src/stores/base.ts | 21 ++++++++++++++++++++- 4 files changed, 38 insertions(+), 36 deletions(-) diff --git a/src/pages/pc/components/Panel.vue b/src/pages/pc/components/Panel.vue index 6c3ab5f7..01287944 100644 --- a/src/pages/pc/components/Panel.vue +++ b/src/pages/pc/components/Panel.vue @@ -40,10 +40,9 @@ watch(() => settingStore.showPanel, n => { } }) -let practiceType = $ref(DictType.word) - function changeIndex(dict: Dict) { - store.changeDict(dict, practiceType) + store.changeDict(dict) + emitter.emit(EventKey.changeDict) } useEvent(EventKey.changeDict, () => { @@ -69,7 +68,7 @@ const showCollectToggleButton = $computed(() => { function changeCollect() { if (props.type === DictType.word) { - store.currentStudy.word.dictIndex = -store.collectWord.index + changeIndex(store.collectWord) } else { } @@ -125,7 +124,7 @@ function changeCollect() { @@ -139,7 +138,7 @@ function changeCollect() { @@ -166,12 +165,12 @@ function changeCollect() { @@ -191,12 +190,12 @@ function changeCollect() { diff --git a/src/pages/pc/word/DictDetail.vue b/src/pages/pc/word/DictDetail.vue index f2269ad0..379a1cf1 100644 --- a/src/pages/pc/word/DictDetail.vue +++ b/src/pages/pc/word/DictDetail.vue @@ -293,26 +293,7 @@ function formClose() { } async function addMyStudyList() { - - //把其他的词典的单词数据都删掉,全保存在内存里太卡了 - base.word.bookList.slice(3).map(v => { - if (!v.custom) { - v.words = [] - } - }) - let rIndex = base.word.bookList.findIndex(v => v.name === runtimeStore.editDict.name) - if (runtimeStore.editDict.words.length < runtimeStore.editDict.perDayStudyNumber) { - runtimeStore.editDict.perDayStudyNumber = runtimeStore.editDict.words.length - } - if (rIndex > -1) { - base.word.studyIndex = rIndex - base.word.bookList[base.word.studyIndex].words = runtimeStore.editDict.words - base.word.bookList[base.word.studyIndex].perDayStudyNumber = runtimeStore.editDict.perDayStudyNumber - } else { - base.word.bookList.push(runtimeStore.editDict) - base.word.studyIndex = base.word.bookList.length - 1 - } - + base.changeDict(runtimeStore.editDict) router.back() } diff --git a/src/pages/pc/word/StudyWord.vue b/src/pages/pc/word/StudyWord.vue index 19840b28..15107adf 100644 --- a/src/pages/pc/word/StudyWord.vue +++ b/src/pages/pc/word/StudyWord.vue @@ -9,7 +9,7 @@ import {useRuntimeStore} from "@/stores/runtime.ts"; import {getDefaultWord, ShortcutKey, StudyData, Word} from "@/types.ts"; import {useOnKeyboardEventListener, useStartKeyboardEventListener} from "@/hooks/event.ts"; import useTheme from "@/hooks/theme.ts"; -import {useWordOptions} from "@/hooks/dict.ts"; +import {getCurrentStudyWord, useWordOptions} from "@/hooks/dict.ts"; import {cloneDeep, shuffle} from "lodash-es"; import {useRouter} from "vue-router"; import {Icon} from "@iconify/vue"; @@ -245,6 +245,9 @@ function togglePanel() { useEvents([ [EventKey.repeat, repeat], [EventKey.next, next], + [EventKey.changeDict, () => { + studyData = getCurrentStudyWord() + }], [ShortcutKey.ShowWord, show], [ShortcutKey.Previous, prev], @@ -324,23 +327,23 @@ useEvents([ diff --git a/src/stores/base.ts b/src/stores/base.ts index 505fac46..e96cc1cd 100644 --- a/src/stores/base.ts +++ b/src/stores/base.ts @@ -183,7 +183,26 @@ export const useBaseStore = defineStore('base', { resolve(true) }) }, - async changeDict() { + //TODO + changeDict(val: Dict) { + //把其他的词典的单词数据都删掉,全保存在内存里太卡了 + this.word.bookList.slice(3).map(v => { + if (!v.custom) { + v.words = [] + } + }) + let rIndex = this.word.bookList.findIndex(v => v.id === val.id) + if (val.words.length < val.perDayStudyNumber) { + val.perDayStudyNumber = val.words.length + } + if (rIndex > -1) { + this.word.studyIndex = rIndex + this.word.bookList[this.word.studyIndex].words = val.words + this.word.bookList[this.word.studyIndex].perDayStudyNumber = val.perDayStudyNumber + } else { + this.word.bookList.push(cloneDeep(val)) + this.word.studyIndex = this.word.bookList.length - 1 + } }, }, })