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) {