Skip to content

Commit

Permalink
fix: 在切换词典源时,任何学习模式下必须重新获取能够学习的单词 = 范围 in 词典
Browse files Browse the repository at this point in the history
范围中,学习模式不一样,范围也是不一样的
  • Loading branch information
simply-none committed Jan 20, 2024
1 parent 5ca9119 commit 4ec135d
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 19 deletions.
27 changes: 12 additions & 15 deletions src/hooks/useWordItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,19 @@ 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";

export function useWordItem() {
let useBook = useBookStore();
let useWord = useWordStore();
let useWordOrigin = useWordOriginStore()

const fullscreenLoading = ref(true);

Expand All @@ -42,6 +44,7 @@ export function useWordItem() {
bulkPutDataToTable,
delWordInWillStudyWords,
} = useWord;
let {wordOriginLink } = storeToRefs(useWordOrigin)

const drawer = ref(false);

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down
24 changes: 22 additions & 2 deletions src/stores/wordOrigin.js
Original file line number Diff line number Diff line change
@@ -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([
Expand All @@ -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 {
Expand Down
12 changes: 10 additions & 2 deletions src/stores/words.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

// 设置将要学习的单词:在学习模式
Expand Down Expand Up @@ -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;
}

// 总数据表
Expand Down

0 comments on commit 4ec135d

Please sign in to comment.