From 4ec135d900dd9412eaa19d62a4ab2586c743d211 Mon Sep 17 00:00:00 2001 From: jousindea Date: Sat, 20 Jan 2024 17:43:26 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=9C=A8=E5=88=87=E6=8D=A2=E8=AF=8D?= =?UTF-8?q?=E5=85=B8=E6=BA=90=E6=97=B6=EF=BC=8C=E4=BB=BB=E4=BD=95=E5=AD=A6?= =?UTF-8?q?=E4=B9=A0=E6=A8=A1=E5=BC=8F=E4=B8=8B=E5=BF=85=E9=A1=BB=E9=87=8D?= =?UTF-8?q?=E6=96=B0=E8=8E=B7=E5=8F=96=E8=83=BD=E5=A4=9F=E5=AD=A6=E4=B9=A0?= =?UTF-8?q?=E7=9A=84=E5=8D=95=E8=AF=8D=20=3D=20=E8=8C=83=E5=9B=B4=20in=20?= =?UTF-8?q?=E8=AF=8D=E5=85=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 范围中,学习模式不一样,范围也是不一样的 --- src/hooks/useWordItem.js | 27 ++++++++++++--------------- src/stores/wordOrigin.js | 24 ++++++++++++++++++++++-- src/stores/words.js | 12 ++++++++++-- 3 files changed, 44 insertions(+), 19 deletions(-) diff --git a/src/hooks/useWordItem.js b/src/hooks/useWordItem.js index 094cf14..bbdaffc 100644 --- a/src/hooks/useWordItem.js +++ b/src/hooks/useWordItem.js @@ -9,10 +9,11 @@ import { watchEffect, unref, } from "vue"; +import { storeToRefs } from "pinia"; import { useBookStore } from "../stores/books"; import { useWordStore } from "../stores/words"; -import { storeToRefs } from "pinia"; +import { useWordOriginStore } from "../stores/wordOrigin"; import { clearNotify, setNotify } from "../utils/element-plus"; import { getTodayDate, isValueInRequiredFields } from "../utils/common"; @@ -20,6 +21,7 @@ import { getTodayDate, isValueInRequiredFields } from "../utils/common"; export function useWordItem() { let useBook = useBookStore(); let useWord = useWordStore(); + let useWordOrigin = useWordOriginStore() const fullscreenLoading = ref(true); @@ -42,6 +44,7 @@ export function useWordItem() { bulkPutDataToTable, delWordInWillStudyWords, } = useWord; + let {wordOriginLink } = storeToRefs(useWordOrigin) const drawer = ref(false); @@ -138,17 +141,6 @@ export function useWordItem() { "】在词典中找不到,将跳转到下一个单词...", "warning" ); - let d = dictWords; - d = d.map((dn) => dn.n); - willStudyWords.value = willStudyWords.value.filter((c) => { - return d.includes(c); - }); - isWordNotInDict.value = true; - console.log(willStudyWords.value.length); - - clearNotify(); - - return await showVocabularyCard(isForward); } return vocabularycard; } @@ -211,16 +203,21 @@ export function useWordItem() { } async function getSearchText(e, lastVal) { + let searchText = e.target.innerText.trim() // 防止重复请求 - if (lastVal.n.trim() === e.target.innerText.trim()) { + if (lastVal.n.trim() === searchText) { return false; } let vocabularycard = await getDataFromTable("dict", { - n: e.target.innerText.trim(), + n: searchText, }); if (!vocabularycard) { - setNotify("未查询到相关内容"); + setNotify("未查询到相关内容,2s后将跳转到外部网站查询"); + setTimeout(() => { + open(wordOriginLink.value + searchText, '_blank') + }, 1000); + // 复原之前的单词拼写 bookItem.value = { ...toRaw(lastVal), n: lastVal.n + " " }; return false; diff --git a/src/stores/wordOrigin.js b/src/stores/wordOrigin.js index 114eade..0aaf12b 100644 --- a/src/stores/wordOrigin.js +++ b/src/stores/wordOrigin.js @@ -1,6 +1,24 @@ import { ref, computed, watch, reactive, unref, toRaw, toRefs, watchEffect } from "vue"; import { defineStore, storeToRefs } from "pinia"; +let originInfoKey = 'redict:word-origin-list' + +function getoriginInfo(val) { + let originInfoInStorage = localStorage.getItem(originInfoKey); + if (!originInfoInStorage) { + originInfoInStorage = val; + } else { + originInfoInStorage = JSON.parse(originInfoInStorage); + } + return originInfoInStorage; +} + +function setoriginInfo(val) { + let originInfo = unref(val); + localStorage.setItem(originInfoKey, JSON.stringify(originInfo)); + return originInfo; +} + // 本store,用处在于获取、设置基础信息数据 export const useWordOriginStore = defineStore("wordOrigin", () => { let wordOriginList = reactive([ @@ -22,10 +40,12 @@ export const useWordOriginStore = defineStore("wordOrigin", () => { } ]) - let wordOriginLink = ref(wordOriginList[0].link) + let wordOriginLink = ref(getoriginInfo(wordOriginList[0].link)) + + wordOriginLink.value = setoriginInfo(wordOriginLink) async function updateWordOriginLink(link) { - wordOriginLink.value = link + wordOriginLink.value = setoriginInfo(link) } return { diff --git a/src/stores/words.js b/src/stores/words.js index 433afac..823373b 100644 --- a/src/stores/words.js +++ b/src/stores/words.js @@ -152,7 +152,11 @@ export const useWordStore = defineStore("word", () => { // 设置将要学习的单词:在复习模式 function setWillStudyWordsInReviewPastMode() { - willStudyWords.value = toRaw(historyWords.value); + console.time("xuex1"); + let studyWordsData = filterBFromA(historyWords.value, dictWords.value); + console.timeEnd("xuex1"); + + willStudyWords.value = studyWordsData; } // 设置将要学习的单词:在学习模式 @@ -182,7 +186,11 @@ export const useWordStore = defineStore("word", () => { // 设置将要学习的单词:在复习今日单词模式 function setWillStudyWordsInReviewTodayMode() { - willStudyWords.value = toRaw(todayWords.value); + console.time("xuex1"); + let studyWordsData = filterBFromA(todayWords.value, dictWords.value); + console.timeEnd("xuex1"); + + willStudyWords.value = studyWordsData; } // 总数据表