From a4b466eafff1f3e3ee58d087a0fd7349ffe7cddb Mon Sep 17 00:00:00 2001 From: zyronon Date: Thu, 9 Nov 2023 18:57:34 +0800 Subject: [PATCH] save --- components.d.ts | 3 ++ src/App.vue | 2 +- src/components/Modal/AddWordDialog.vue | 75 ++++++++++++-------------- src/components/Practice/Practice.vue | 2 +- src/components/list/DictList.vue | 18 +++---- src/components/list/WordItem.vue | 12 ----- src/components/list/WordList2.vue | 75 +++++++++++++++++--------- src/stores/base.ts | 17 ++++++ 8 files changed, 115 insertions(+), 89 deletions(-) diff --git a/components.d.ts b/components.d.ts index 4071719a..2b805ad6 100644 --- a/components.d.ts +++ b/components.d.ts @@ -24,6 +24,9 @@ declare module 'vue' { EditArticle: typeof import('./src/components/Article/EditArticle.vue')['default'] EditBatchArticleModal: typeof import('./src/components/Article/EditBatchArticleModal.vue')['default'] EditSingleArticleModal: typeof import('./src/components/Article/EditSingleArticleModal.vue')['default'] + ElButton: typeof import('element-plus/es')['ElButton'] + ElForm: typeof import('element-plus/es')['ElForm'] + ElFormItem: typeof import('element-plus/es')['ElFormItem'] ElInput: typeof import('element-plus/es')['ElInput'] ElInputNumber: typeof import('element-plus/es')['ElInputNumber'] ElOption: typeof import('element-plus/es')['ElOption'] diff --git a/src/App.vue b/src/App.vue index f784acde..5a75d09c 100644 --- a/src/App.vue +++ b/src/App.vue @@ -38,7 +38,7 @@ watch(store.wrong.originWords, (n) => { store.wrong.chapterWords = [store.wrong.words] }) -useStartKeyboardEventListener() +// useStartKeyboardEventListener() async function init() { console.time() diff --git a/src/components/Modal/AddWordDialog.vue b/src/components/Modal/AddWordDialog.vue index 5517d82e..c1e7d22a 100644 --- a/src/components/Modal/AddWordDialog.vue +++ b/src/components/Modal/AddWordDialog.vue @@ -9,7 +9,7 @@ import {useBaseStore} from "@/stores/base.ts"; import {useSettingStore} from "@/stores/setting.ts"; import {useRuntimeStore} from "@/stores/runtime.ts"; import {useDisableEventListener} from "@/hooks/event.ts"; -import {Dict, DictType, languageCategoryOptions, Sort, Word} from "@/types.ts"; +import {DefaultDict, Dict, DictType, languageCategoryOptions, Sort, Word} from "@/types.ts"; import {onMounted, reactive, watch} from "vue"; import {FormInstance, FormRules} from "element-plus"; import {dictionaryResources} from "@/assets/dictionary.ts"; @@ -39,12 +39,11 @@ let step = $ref(1) let isAddDict = $ref(false) let list = $computed(() => { - return store.myDicts.filter(v => v.type === DictType.customArticle) - .concat([ - store.simple, - store.wrong, - store.collect - ]) + return [ + store.collect, + store.simple, + store.wrong + ].concat(store.myDicts.filter(v => v.type === DictType.customArticle)) .concat([{name: '',} as any]) }) @@ -99,9 +98,11 @@ onMounted(() => { console.log('tagList', tagList) }) -function selectDict(dict: Dict) { - // runtimeStore.editDict = cloneDeep(dict) - runtimeStore.editDict = dict +function selectDict(val: { + dict: Dict, + index: number +}) { + store.current.editIndex = val.index isAddDict = false step = 1 } @@ -109,31 +110,20 @@ function selectDict(dict: Dict) { async function onSubmit() { await dictFormRef.validate((valid, fields) => { if (valid) { - let data = { - sort: Sort.normal, - type: DictType.customArticle, - originWords: [], - words: [], - chapterWordNumber: 30, - chapterWords: [], - chapterIndex: 0, - chapterWordIndex: 0, - statistics: [], - articles: [], - url: '', + let data: Dict = { + ...DefaultDict, ...dictForm, } if (dictForm.id) { let rIndex = store.myDicts.findIndex(v => v.id === dictForm.id) - runtimeStore.editDict = data store.myDicts[rIndex] = cloneDeep(data) isAddDict = false } else { if (store.myDicts.find(v => v.name === dictForm.name)) { return ElMessage.warning('已有相同名称词典!') } else { - runtimeStore.editDict = data store.myDicts.push(cloneDeep(data)) + store.current.editIndex = store.myDicts.length - 1 isAddDict = false console.log('submit!', data) } @@ -145,8 +135,8 @@ async function onSubmit() { } function editDict() { - dictForm.name = runtimeStore.editDict.name - dictForm.description = runtimeStore.editDict.description + dictForm.name = store.editDict.name + dictForm.description = store.editDict.description wordFormMode = FormMode.None; isAddDict = true } @@ -171,23 +161,30 @@ const wordRules = reactive({ {max: 30, message: '名称不能超过30个字符', trigger: 'blur'}, ], }) +let wordListRef: any = $ref() async function onSubmitWord() { await wordFormRef.validate((valid, fields) => { if (valid) { if (wordFormMode === FormMode.Add) { - if (runtimeStore.editDict.originWords.find(v => v.name === wordForm.name)) { + if (store.editDict.originWords.find(v => v.name === wordForm.name)) { return ElMessage.warning('已有相同名称单词!') } else { + // let list = cloneDeep(store.editDict.originWords) let data: any = cloneDeep(wordForm) if (data.trans) { data.trans = data.trans.split('\n'); } else { data.trans = [] } - runtimeStore.editDict.originWords.push(data) + store.editDict.originWords.push(data) + console.log('wordListRef',wordListRef) + wordListRef?.reset() + // store.editDict.originWords = list + //因为虚拟列表,必须重新赋值才能检测到更新 + // store.editDict.originWords = cloneDeep(store.editDict.originWords) } - console.log('runtimeStore.editDict', runtimeStore.editDict) + console.log('store.editDict', store.editDict) } } else { ElMessage.warning('请填写完整') @@ -245,10 +242,10 @@ const {
-
{{ runtimeStore.editDict.name }}
-
{{ runtimeStore.editDict.description }}
+
{{ store.editDict.name }}
+
{{ store.editDict.description }}
-
词汇量:{{ runtimeStore.editDict.originWords.length }}词
+
词汇量:{{ store.editDict.originWords.length }}词
创建日期:-
花费时间:-
累积错误:-
@@ -293,25 +290,19 @@ const {
单词列表
-
{{ store.currentDict.originWords.length }}个单词
+
{{ store.editDict.originWords.length }}个单词
- - - - - - -