From 1e8e10976478648f6cad594b62a8a6e2c93f3238 Mon Sep 17 00:00:00 2001 From: zyronon Date: Mon, 28 Jul 2025 03:08:58 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E4=BF=AE=E6=94=B9=E5=AD=A6=E4=B9=A0?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/hooks/dict.ts | 74 ++++++++++++++++-------------- src/pages/pc/word/Statistics.vue | 10 ++-- src/pages/pc/word/StudyWord.vue | 9 ++-- src/pages/pc/word/WordHomePage.vue | 6 ++- 4 files changed, 57 insertions(+), 42 deletions(-) diff --git a/src/hooks/dict.ts b/src/hooks/dict.ts index 9645d855..66b8a776 100644 --- a/src/hooks/dict.ts +++ b/src/hooks/dict.ts @@ -103,12 +103,12 @@ export function getCurrentStudyWord() { }) const getList = (startIndex: number, endIndex: number) => { - if (startIndex < 0) startIndex = 0 return dict.words.slice(startIndex, endIndex) } end = start start = start - dict.perDayStudyNumber + if (start < 0) start = 0 //取上一次学习的单词用于复习 let list = getList(start, end) list.map(item => { @@ -117,6 +117,8 @@ export function getCurrentStudyWord() { } }) + console.log(start,end) + // end = start // start = start - dict.perDayStudyNumber * 3 // //在上次学习再往前取前3次学习的单词用于默写 @@ -129,44 +131,46 @@ export function getCurrentStudyWord() { //write数组放的是上上次之前的单词,总的数量为perDayStudyNumber * 3,取单词的规则为:从后往前取6个perDayStudyNumber的,越靠前的取的单词越多。 end = start - const totalNeed = perDay * 3; - const allWords = dict.words; // 上上次更早的单词 - const candidateWords = allWords.slice(0, end).filter(w => !store.knownWords.includes(w.word)); + if (end>0){ + const totalNeed = perDay * 3; + const allWords = dict.words; + const candidateWords = allWords.slice(0, end).filter(w => !store.knownWords.includes(w.word)); - // 分6组,每组 perDay 个 - const groupCount = 6; - const groupSize = perDay; - const groups: Word[][] = []; - for (let i = 0; i < groupCount; i++) { - const start = candidateWords.length - (i + 1) * groupSize; - const end = candidateWords.length - i * groupSize; - if (start < 0 && end <= 0) break; - groups.unshift(candidateWords.slice(Math.max(0, start), Math.max(0, end))); + // 分6组,每组 perDay 个 + const groupCount = 6; + const groupSize = perDay; + const groups: Word[][] = []; + for (let i = 0; i < groupCount; i++) { + const start = candidateWords.length - (i + 1) * groupSize; + const end = candidateWords.length - i * groupSize; + if (start < 0 && end <= 0) break; + groups.unshift(candidateWords.slice(Math.max(0, start), Math.max(0, end))); + } + + // 分配数量,靠前组多,靠后组少 + // 例如分配比例 [1,2,3,4,5,6] + const ratio = [1, 2, 3, 4, 5, 6]; + const ratioSum = ratio.reduce((a, b) => a + b, 0); + const realRatio = ratio.map(r => Math.round(r * totalNeed / ratioSum)); + + // 按比例从每组取单词 + let writeWords: Word[] = []; + for (let i = 0; i < groups.length; i++) { + writeWords = writeWords.concat(groups[i].slice(-realRatio[i])); + } + // 如果数量不够,补足 + if (writeWords.length < totalNeed) { + const extra = candidateWords.filter(w => !writeWords.includes(w)).slice(-(totalNeed - writeWords.length)); + writeWords = writeWords.concat(extra); + } + // 最终数量截断 + writeWords = writeWords.slice(-totalNeed); + + //这里需要反转一下,越靠近今天的单词,越先练习 + data.write = writeWords.reverse(); } - - // 分配数量,靠前组多,靠后组少 - // 例如分配比例 [1,2,3,4,5,6] - const ratio = [1, 2, 3, 4, 5, 6]; - const ratioSum = ratio.reduce((a, b) => a + b, 0); - const realRatio = ratio.map(r => Math.round(r * totalNeed / ratioSum)); - - // 按比例从每组取单词 - let writeWords: Word[] = []; - for (let i = 0; i < groups.length; i++) { - writeWords = writeWords.concat(groups[i].slice(-realRatio[i])); - } - // 如果数量不够,补足 - if (writeWords.length < totalNeed) { - const extra = candidateWords.filter(w => !writeWords.includes(w)).slice(-(totalNeed - writeWords.length)); - writeWords = writeWords.concat(extra); - } - // 最终数量截断 - writeWords = writeWords.slice(-totalNeed); - - //这里需要反转一下,越靠近今天的单词,越先练习 - data.write = writeWords.reverse(); } // console.timeEnd() diff --git a/src/pages/pc/word/Statistics.vue b/src/pages/pc/word/Statistics.vue index 1340c343..ad76e472 100644 --- a/src/pages/pc/word/Statistics.vue +++ b/src/pages/pc/word/Statistics.vue @@ -13,7 +13,6 @@ import {inject, watch} from "vue"; dayjs.extend(isBetween); -let dictIsEnd = inject('dictIsEnd') const store = useBaseStore() const settingStore = useSettingStore() @@ -21,6 +20,9 @@ const statStore = usePracticeStore() const model = defineModel({default: false}) let list = $ref([]) +defineProps<{ + dictIsEnd: boolean; +}>() function calcWeekList() { // 获取本周的起止时间 @@ -61,7 +63,6 @@ watch(model, (newVal) => { requestIdleCallback(() => { store.sdict.lastLearnIndex = store.sdict.lastLearnIndex + statStore.newWordNumber store.sdict.statistics.push(data as any) - store.sdict.statistics.sort((a, b) => a.startDate - b.startDate) calcWeekList(); // 新增:计算本周学习记录 }) } @@ -89,7 +90,7 @@ function options(emitType: string) { :keyboard="false" :show-close="false" v-model="model"> -
+
已完成今日任务
@@ -160,6 +161,9 @@ function options(emitType: string) { @click="options(EventKey.continueStudy)"> {{ dictIsEnd ? '重新练习' : '再来一组' }} + + 返回主页 + 分享 diff --git a/src/pages/pc/word/StudyWord.vue b/src/pages/pc/word/StudyWord.vue index 8386134e..cc03d098 100644 --- a/src/pages/pc/word/StudyWord.vue +++ b/src/pages/pc/word/StudyWord.vue @@ -71,6 +71,7 @@ watch(() => studyData, () => { data.wrongWords = [] allWrongWords = new Set() + settingStore.dictation = false statStore.step = 0 statStore.startDate = Date.now() statStore.inputWordNumber = 0 @@ -86,7 +87,6 @@ const dictIsEnd = $computed(() => { }) provide('studyData', data) -provide('dictIsEnd', dictIsEnd) const word = $computed(() => { return data.words[data.index] ?? getDefaultWord() @@ -287,7 +287,10 @@ function togglePanel() { function continueStudy() { if (dictIsEnd) { - + //todo 不知这样处理是否不妥? + store.sdict.lastLearnIndex = 0 + settingStore.dictation = false + studyData = getCurrentStudyWord() } else { settingStore.dictation = false studyData = getCurrentStudyWord() @@ -406,7 +409,7 @@ useEvents([
- +