From b9a35f5c6d329cc9e0113a0b4556949359648586 Mon Sep 17 00:00:00 2001 From: zyronon Date: Thu, 30 May 2024 18:53:26 +0800 Subject: [PATCH] save --- auto-imports.d.ts | 2 +- src/hooks/dict.ts | 23 ++++ .../pc/practice/practice-word/TypingWord.vue | 13 +- src/pages/pc/word/StudyWord.vue | 76 ++--------- src/pages/pc/word/WordHome.vue | 122 ++++++++++-------- src/stores/base.ts | 6 +- src/stores/runtime.ts | 2 + src/utils/index.ts | 8 +- 8 files changed, 118 insertions(+), 134 deletions(-) diff --git a/auto-imports.d.ts b/auto-imports.d.ts index 1d89ee8c..78813d8f 100644 --- a/auto-imports.d.ts +++ b/auto-imports.d.ts @@ -5,5 +5,5 @@ // Generated by unplugin-auto-import export {} declare global { - + const ElMessage: typeof import('element-plus/es')['ElMessage'] } diff --git a/src/hooks/dict.ts b/src/hooks/dict.ts index efe3df57..8df26057 100644 --- a/src/hooks/dict.ts +++ b/src/hooks/dict.ts @@ -106,4 +106,27 @@ export function syncMyDictList(dict: Dict, isCustom = true) { } else { store.myDictList.push(cloneDeep(dict)) } +} + +export function getCurrentStudyWord() { + const store = useBaseStore() + let data = {new: [], review: []} + let c = store.currentStudy.word + let dict = store.currentStudyWordDict; + if (dict.words?.length) { + for (let i = c.lastLearnIndex; i < dict.words.length; i++) { + if (data.new.length >= c.perDayStudyNumber) break + let item = dict.words[i] + if (!store.skipWordNames.includes(item.word.toLowerCase())) { + data.new.push(item) + } + } + if (dict.statistics.length) { + let stat = dict.statistics.reverse() + stat.slice(0, 1).map(({startIndex, endIndex}) => { + let list = dict.words.splice(startIndex, endIndex) + }) + } + } + return data } \ No newline at end of file diff --git a/src/pages/pc/practice/practice-word/TypingWord.vue b/src/pages/pc/practice/practice-word/TypingWord.vue index a9463c2d..dc26fe84 100644 --- a/src/pages/pc/practice/practice-word/TypingWord.vue +++ b/src/pages/pc/practice/practice-word/TypingWord.vue @@ -106,15 +106,10 @@ function next(isTyping: boolean = true) { emitter.emit(EventKey.openStatModal, {}) // emit('complete', {}) } else { - if (props.data.review.length) { - settingStore.dictation = true - statisticsStore.step++ - current.words = shuffle(props.data.review.concat(props.data.new)) - current.index = 0 - } else { - emitter.emit(EventKey.openStatModal, {}) - // emit('complete', {}) - } + settingStore.dictation = true + statisticsStore.step++ + current.words = shuffle(props.data.review.concat(props.data.new)) + current.index = 0 } } } else { diff --git a/src/pages/pc/word/StudyWord.vue b/src/pages/pc/word/StudyWord.vue index ff7b245c..3fa8a006 100644 --- a/src/pages/pc/word/StudyWord.vue +++ b/src/pages/pc/word/StudyWord.vue @@ -15,7 +15,7 @@ import DictModal from "@/pages/pc/components/dialog/DictDiglog.vue"; import {useStartKeyboardEventListener} from "@/hooks/event.ts"; import useTheme from "@/hooks/theme.ts"; import TypingWord from "@/pages/pc/practice/practice-word/TypingWord.vue"; -import {syncMyDictList} from "@/hooks/dict.ts"; +import {getCurrentStudyWord, syncMyDictList} from "@/hooks/dict.ts"; import {cloneDeep, shuffle} from "lodash-es"; const statisticsStore = usePracticeStore() @@ -36,33 +36,20 @@ watch(statisticsStore, () => { function next() { store.currentStudy.word.lastLearnIndex = store.currentStudy.word.lastLearnIndex + store.currentStudy.word.perDayStudyNumber - repeat() -} - -function write() { - // console.log('write') - settingStore.dictation = true - repeat() + emitter.emit(EventKey.resetWord) + getCurrentPractice() } //TODO 需要判断是否已忽略 function repeat() { // console.log('repeat') + settingStore.dictation = false emitter.emit(EventKey.resetWord) - getCurrentPractice() + data = cloneDeep(data) } -function prev() { - // console.log('next') - if (store.currentDict.chapterIndex === 0) { - ElMessage.warning('已经在第一章了~') - } else { - store.currentDict.chapterIndex-- - repeat() - } -} -function toggleShowTranslate() { +function toggleTranslate() { settingStore.translate = !settingStore.translate } @@ -87,21 +74,12 @@ function togglePanel() { settingStore.showPanel = !settingStore.showPanel } -function jumpSpecifiedChapter(val: number) { - store.currentDict.chapterIndex = val - repeat() -} - onMounted(() => { - emitter.on(EventKey.write, write) emitter.on(EventKey.repeat, repeat) emitter.on(EventKey.next, next) - emitter.on(EventKey.jumpSpecifiedChapter, jumpSpecifiedChapter) - emitter.on(ShortcutKey.PreviousChapter, prev) emitter.on(ShortcutKey.RepeatChapter, repeat) - emitter.on(ShortcutKey.DictationChapter, write) - emitter.on(ShortcutKey.ToggleShowTranslate, toggleShowTranslate) + emitter.on(ShortcutKey.ToggleShowTranslate, toggleTranslate) emitter.on(ShortcutKey.ToggleDictation, toggleDictation) emitter.on(ShortcutKey.OpenSetting, openSetting) emitter.on(ShortcutKey.OpenDictDetail, openDictDetail) @@ -111,15 +89,11 @@ onMounted(() => { }) onUnmounted(() => { - emitter.off(EventKey.write, write) emitter.off(EventKey.repeat, repeat) emitter.off(EventKey.next, next) - emitter.off(EventKey.jumpSpecifiedChapter, jumpSpecifiedChapter) - emitter.off(ShortcutKey.PreviousChapter, prev) emitter.off(ShortcutKey.RepeatChapter, repeat) - emitter.off(ShortcutKey.DictationChapter, write) - emitter.off(ShortcutKey.ToggleShowTranslate, toggleShowTranslate) + emitter.off(ShortcutKey.ToggleShowTranslate, toggleTranslate) emitter.off(ShortcutKey.ToggleDictation, toggleDictation) emitter.off(ShortcutKey.OpenSetting, openSetting) emitter.off(ShortcutKey.OpenDictDetail, openDictDetail) @@ -129,7 +103,8 @@ onUnmounted(() => { }) onMounted(() => { - getCurrentPractice() + settingStore.dictation = false + data = runtimeStore.routeData emitter.on(EventKey.changeDict, getCurrentPractice) }) @@ -137,42 +112,18 @@ onUnmounted(() => { emitter.off(EventKey.changeDict, getCurrentPractice) }) -let wordData = $ref({ - words: [], - index: -1 -}) let data = $ref({ new: [], review: [] }) function getCurrentPractice() { - let c = store.currentStudy.word - let wordDict = store.currentStudyWordDict; - if (wordDict.words?.length) { - wordData.index = 0 - wordData.words = [] - statisticsStore.step = 0 - for (let i = c.lastLearnIndex; i < wordDict.words.length; i++) { - if (data.new.length >= c.perDayStudyNumber) break - let item = wordDict.words[i] - if (!store.skipWordNames.includes(item.word.toLowerCase())) { - data.new.push(item) - } - } - - emitter.emit(EventKey.resetWord) - } -} - -//TODO wait -function sort(list: Word[]) { - store.currentDict.chapterWords[store.currentDict.chapterIndex] = wordData.words = list - wordData.index = 0 - syncMyDictList(store.currentDict) + settingStore.dictation = false + data = getCurrentStudyWord() } function complete() { + // store.currentStudyWordDict.statistics.push() } @@ -184,7 +135,6 @@ useStartKeyboardEventListener()
diff --git a/src/pages/pc/word/WordHome.vue b/src/pages/pc/word/WordHome.vue index f6c9190e..0567a224 100644 --- a/src/pages/pc/word/WordHome.vue +++ b/src/pages/pc/word/WordHome.vue @@ -7,10 +7,11 @@ import {useRouter} from "vue-router"; import BaseIcon from "@/components/BaseIcon.vue"; import {useNav} from "@/utils"; import BasePage from "@/pages/pc/components/BasePage.vue"; -import {watch} from "vue"; import {getDefaultDict} from "@/types.ts"; +import {onMounted} from "vue"; +import {getCurrentStudyWord} from "@/hooks/dict.ts"; -const base = useBaseStore() +const store = useBaseStore() const router = useRouter() const {nav} = useNav() @@ -20,71 +21,82 @@ function clickEvent(e) { let showMore = $ref(false) const otherWordDictList = $computed(() => { - if (showMore) return base.otherWordDictList - else return base.otherWordDictList.slice(0, 4) + if (showMore) return store.otherWordDictList + else return store.otherWordDictList.slice(0, 4) }) + + +let currentStudy = $ref({ + new: [], + review: [] +}) + +onMounted(() => { + currentStudy = getCurrentStudyWord() +}) +