From b651a509074e90dbd2d93490607dfd88bd217674 Mon Sep 17 00:00:00 2001 From: zyronon Date: Mon, 9 Oct 2023 18:57:50 +0800 Subject: [PATCH] save --- src/components/Toolbar/DictModal.vue | 106 ++++++++++++++------------- 1 file changed, 57 insertions(+), 49 deletions(-) diff --git a/src/components/Toolbar/DictModal.vue b/src/components/Toolbar/DictModal.vue index 68d12640..28f857ea 100644 --- a/src/components/Toolbar/DictModal.vue +++ b/src/components/Toolbar/DictModal.vue @@ -51,47 +51,55 @@ let currentLanguage = $ref('en') let currentSelectDict: Dict = $ref(cloneDeep(store.currentDict)) let step = $ref(1) -const currentSelectChapter: Word[] = $computed(() => { - return currentSelectDict.chapterWords?.[currentSelectDict.chapterIndex] ?? [] -}) - watch(() => props.modelValue, (n: boolean) => { - currentSelectDict = store.currentDict + let rIndex = base.myDicts.findIndex((v: Dict) => v.name === store.currentDict.name) + if (rIndex > -1) { + base.current.editIndex = rIndex + } }) async function selectDict(item: DictionaryResource) { step = 1 - if (item.name === currentSelectDict.name) return - currentSelectDict = { - ...item, - sort: Sort.normal, - type: DictType.publicDict, - originWords: [], - words: [], - chapterWordNumber: 30, - chapterWords: [], - chapterIndex: 0, - chapterWordIndex: 0, - statistics: [], - articles: [] - } - if (item.languageCategory === 'article') { - currentSelectDict.type = DictType.publicArticle - let r = await fetch(`${item.url}`) - r.json().then(v => { - currentSelectDict.articles = cloneDeep(v.map(v => { - v.id = uuidv4() - return v - })) - }) + let rIndex = base.myDicts.findIndex((v: Dict) => v.name === item.name) + if (rIndex > -1) { + base.current.editIndex = rIndex } else { - currentSelectDict.type = DictType.publicDict - let r = await fetch(`${item.url}`) - r.json().then(v => { - currentSelectDict.originWords = v - currentSelectDict.words = v - currentSelectDict.chapterWords = chunk(v, currentSelectDict.chapterWordNumber) - }) + let data = { + ...item, + sort: Sort.normal, + type: DictType.publicDict, + originWords: [], + words: [], + chapterWordNumber: 30, + chapterWords: [], + chapterIndex: 0, + chapterWordIndex: 0, + statistics: [], + articles: [] + } + + if (item.languageCategory === 'article') { + data.type = DictType.publicArticle + let r = await fetch(`${item.url}`) + r.json().then(v => { + data.articles = cloneDeep(v.map(v => { + v.id = uuidv4() + return v + })) + base.myDicts.push(data) + base.current.editIndex = base.myDicts.length - 1 + }) + } else { + data.type = DictType.publicDict + let r = await fetch(`${item.url}`) + r.json().then(v => { + data.originWords = v + data.words = v + data.chapterWords = chunk(v, currentSelectDict.chapterWordNumber) + base.myDicts.push(data) + base.current.editIndex = base.myDicts.length - 1 + }) + } } } @@ -154,7 +162,7 @@ function showWord(list: Word[]) { } const dictIsArticle = $computed(() => { - return isArticle(currentSelectDict.type) + return isArticle(base.currentEditDict.type) }) @@ -208,16 +216,16 @@ const dictIsArticle = $computed(() => {
-
{{ currentSelectDict.name }}
-
{{ currentSelectDict.description }}
+
{{ base.currentEditDict.name }}
+
{{ base.currentEditDict.description }}
总文章:{{ currentSelectDict.articles.length }}篇 + >总文章:{{ base.currentEditDict.articles.length }}篇
- 总词汇:{{ currentSelectDict.length }}词 + @click="emitter.emit(EventKey.openWordListModal,{title:'所有单词',list:base.currentEditDict.words})"> + 总词汇:{{ base.currentEditDict.length }}词
开始日期:-
花费时间:-
@@ -230,16 +238,16 @@ const dictIsArticle = $computed(() => {
学习设置
-
+
每章单词数
- {{ currentSelectDict.chapterWordNumber }} + {{ base.currentEditDict.chapterWordNumber }}
@@ -303,19 +311,19 @@ const dictIsArticle = $computed(() => {
+ v-model:active-index="base.currentEditDict.chapterIndex" + :dict="base.currentEditDict"/>