diff --git a/src/components/Practice/Panel.vue b/src/components/Practice/Panel.vue index c5b82204..10f835ea 100644 --- a/src/components/Practice/Panel.vue +++ b/src/components/Practice/Panel.vue @@ -2,10 +2,10 @@ import {useBaseStore} from "@/stores/base.ts" import WordList from "@/components/WordList.vue" -import {$ref} from "vue/macros" +import {$computed, $ref} from "vue/macros" import {computed, provide, watch} from "vue" import 'swiper/css'; -import {DictType, Word} from "@/types.ts" +import {Dict, DictType, Word} from "@/types.ts" import PopConfirm from "@/components/PopConfirm.vue" import BaseButton from "@/components/BaseButton.vue"; import {useSettingStore} from "@/stores/setting.ts"; @@ -14,6 +14,9 @@ const props = defineProps<{ list?: Word[], index: number }>() +const emit = defineEmits<{ + 'update:index': [i: number] +}>() const store = useBaseStore() const settingStore = useSettingStore() let tabIndex = $ref(0) @@ -22,11 +25,11 @@ provide('tabIndex', computed(() => tabIndex)) watch(() => settingStore.showPanel, n => { if (n) { switch (store.current.dictType) { - case DictType.newDict: + case DictType.newWordDict: return tabIndex = 1; - case DictType.skipDict: + case DictType.skipWordDict: return tabIndex = 3; - case DictType.wrongDict: + case DictType.wrongWordDict: return tabIndex = 2; case DictType.publicDict: case DictType.customDict: @@ -34,23 +37,39 @@ watch(() => settingStore.showPanel, n => { } } }) -const newWordDictActiveIndex = computed(() => { - if (store.current.dictType !== DictType.newDict) return -1 - else return props.index + +const currentDict: Dict = $computed(() => { + return store.myDicts[store.current.index] }) -const wrongWordDictActiveIndex = computed(() => { - if (store.current.dictType !== DictType.wrongDict) return -1 - else return props.index +const currentData = $computed(() => { + if (store.current.dictType !== currentDict.type) return {list: currentDict.chapterWords[currentDict.chapterIndex] ?? [], index: -1} + else return props }) -const skipWordDictActiveIndex = computed(() => { - if (store.current.dictType !== DictType.skipDict) return -1 - else return props.index +const newWordDictData = $computed(() => { + if (store.current.dictType !== DictType.newWordDict) return {list: store.newWordDict.words ?? [], index: -1} + else return props }) -function changeIndex(i: number) { +const wrongWordDictData = $computed(() => { + if (store.current.dictType !== DictType.wrongWordDict) return {list: store.wrongWordDict.words ?? [], index: -1} + else return props +}) +const skipWordDictData = $computed(() => { + if (store.current.dictType !== DictType.skipWordDict) return {list: store.skipWordDict.words ?? [], index: -1} + else return props +}) + +function changeIndex(i: number, dict: Dict) { + dict.chapterWordIndex = i + console.log('i', i, dict.type) + if (store.current.dictType === dict.type) { + emit('update:index', i) + } else { + store.changeDict(dict, dict.chapterIndex, i) + } } @@ -59,11 +78,12 @@ function changeIndex(i: number) {
-
{{ store.dictTitle }}
+
+ {{ currentDict.name + ` 第${currentDict.chapterIndex + 1}章` }} +
{{ store.newWordDict.name }}
-
{{ - store.wrongWordDict.name - }} +
+ {{ store.wrongWordDict.name }}
{{ store.skipWordDict.name }}
@@ -72,20 +92,20 @@ function changeIndex(i: number) {
-
词数:{{ props.list.length }}
+
词数:{{ currentData.list.length }}
+ :list="currentData.list" + :activeIndex="currentData.index"/>
切换 @@ -93,20 +113,20 @@ function changeIndex(i: number) {
-
总词数:{{ store.newWordDict.originWords.length }}
+
总词数:{{ newWordDictData.list.length }}
+ :list="newWordDictData.list" + :activeIndex="newWordDictData.index"/>
-
+
切换 @@ -115,21 +135,21 @@ function changeIndex(i: number) {
-
总词数:{{ store.wrongWordDict.originWords.length }}
+
总词数:{{ wrongWordDictData.list.length }}
+ :list="wrongWordDictData.list" + :activeIndex="wrongWordDictData.index"/>
+ v-if="store.current.dictType !== DictType.wrongWordDict && wrongWordDictData.list.length"> 切换 @@ -137,20 +157,20 @@ function changeIndex(i: number) {
-
总词数:{{ store.skipWordDict.originWords.length }}
+
总词数:{{ skipWordDictData.list.length }}
+ :list="skipWordDictData.list" + :activeIndex="skipWordDictData.index"/>
-
+
切换 diff --git a/src/components/Practice/Practice.vue b/src/components/Practice/Practice.vue index 007c7e8c..24a15380 100644 --- a/src/components/Practice/Practice.vue +++ b/src/components/Practice/Practice.vue @@ -130,7 +130,8 @@ function getCurrentPractice() { } } else { wordData.words = cloneDeep(store.chapter) - wordData.index = 0 + wordData.index = store.currentDict.chapterWordIndex + console.log('wordData', wordData) } } diff --git a/src/components/Practice/Statistics.vue b/src/components/Practice/Statistics.vue index 722a3ef8..c815d1fa 100644 --- a/src/components/Practice/Statistics.vue +++ b/src/components/Practice/Statistics.vue @@ -26,6 +26,7 @@ onMounted(() => { emitter.on(EventKey.openStatModal, (stat: DisplayStatistics) => { currentStat = {...DefaultDisplayStatistics, ...stat} statModalIsOpen = true + store.saveStatistics(stat) }) }) diff --git a/src/components/Practice/TypeWord.vue b/src/components/Practice/TypeWord.vue index a53657a8..4ad41907 100644 --- a/src/components/Practice/TypeWord.vue +++ b/src/components/Practice/TypeWord.vue @@ -48,7 +48,7 @@ const volumeIconRef: any = $ref() watch(() => props.words, () => { data.words = props.words - data.index = props.words.length ? 0 : -1 + data.index = props.index practiceStore.wrongWords = [] practiceStore.repeatNumber = 0 @@ -59,6 +59,13 @@ watch(() => props.words, () => { practiceStore.wrongWordNumber = 0 }, {immediate: true}) +watch(() => data.index, (n) => { + wrong = input = '' + practiceStore.index = n + playWordAudio(word.name) + volumeIconRef?.play() +}) + const word = $computed(() => { return data.words[data.index] ?? { trans: [], @@ -119,15 +126,11 @@ function next(isTyping: boolean = true) { } } else { data.index++ - practiceStore.index++ isTyping && practiceStore.inputWordNumber++ console.log('这个词完了') if ([DictType.customDict, DictType.publicDict].includes(store.current.dictType) && store.skipWordNames.includes(word.name.toLowerCase())) { next() - } else { - playWordAudio(word.name) - volumeIconRef?.play() } } wrong = input = '' @@ -312,7 +315,7 @@ useOnKeyboardEventListener(onKeyDown, onKeyUp) 跳过
- +
diff --git a/src/components/Tooltip.vue b/src/components/Tooltip.vue index 8513b9f3..87359138 100644 --- a/src/components/Tooltip.vue +++ b/src/components/Tooltip.vue @@ -47,17 +47,18 @@ export default { render() { let Vnode = this.$slots.default()[0] return <> - - - { - this.show && this.title && ( -
+ { + this.show && this.title && ( + + + +
{this.title}
- ) - } -
-
+ + + ) + } this.show = false} onmouseenter={(e) => this.showPop(e)} diff --git a/src/components/WordItem.vue b/src/components/WordItem.vue index b779dd06..2dff613b 100644 --- a/src/components/WordItem.vue +++ b/src/components/WordItem.vue @@ -29,7 +29,7 @@ const emit = defineEmits<{
1000 * 10) { + delete statistics.wrongWords this.currentDict.statistics.push(statistics) } }, @@ -252,13 +253,13 @@ export const useBaseStore = defineStore('base', { // this.saveStatistics() console.log('changeDict', cloneDeep(dict), chapterIndex, chapterWordIndex) this.current.dictType = dict.type - if ([DictType.newDict, - DictType.skipDict, - DictType.wrongDict].includes(dict.type)) { + if ([DictType.newWordDict, + DictType.skipWordDict, + DictType.wrongWordDict].includes(dict.type)) { this[dict.type].chapterIndex = chapterIndex this[dict.type].chapterWordIndex = chapterWordIndex } else { - let rIndex = this.myDicts.findIndex(v => v.name === dict.name) + let rIndex = this.myDicts.findIndex((v: Dict) => v.name === dict.name) if (rIndex > -1) { this.current.index = rIndex } else { diff --git a/src/types.ts b/src/types.ts index 17e4734e..9b3e3b81 100644 --- a/src/types.ts +++ b/src/types.ts @@ -49,9 +49,9 @@ export interface Dict { } export enum DictType { - newDict = 'newDict', - skipDict = 'skipDict', - wrongDict = 'wrongDict', + newWordDict = 'newWordDict', + skipWordDict = 'skipWordDict', + wrongWordDict = 'wrongWordDict', publicDict = 'publicDict', customDict = 'customDict', publicArticle = 'publicArticle',