From b713e0e5e815ca7f9803c6a608c791bba038e38b Mon Sep 17 00:00:00 2001 From: zyronon Date: Mon, 28 Jul 2025 01:16:32 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E6=B7=BB=E5=8A=A0=E5=8E=86=E5=8F=B2?= =?UTF-8?q?=E7=BB=9F=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vercel/project.json | 1 + src/pages/pc/components/Book.vue | 4 +- src/pages/pc/word/Statistics.vue | 7 +- src/pages/pc/word/StudyWord.vue | 2 +- src/pages/pc/word/WordHomePage.vue | 148 ++++++++++++++------------ src/pages/pc/word/components/Type.vue | 6 +- src/stores/practice.ts | 3 + src/types.ts | 5 + 8 files changed, 98 insertions(+), 78 deletions(-) create mode 100644 .vercel/project.json diff --git a/.vercel/project.json b/.vercel/project.json new file mode 100644 index 00000000..57427865 --- /dev/null +++ b/.vercel/project.json @@ -0,0 +1 @@ +{"projectName":"trae_typing-word_c29f"} \ No newline at end of file diff --git a/src/pages/pc/components/Book.vue b/src/pages/pc/components/Book.vue index c5120a36..dad8491c 100644 --- a/src/pages/pc/components/Book.vue +++ b/src/pages/pc/components/Book.vue @@ -23,7 +23,9 @@ defineEmits<{
{{ item?.name }}
{{ item?.description }}
-
{{ item?.length }}{{ quantifier }}
+
+ {{ item?.lastLearnIndex ? item?.lastLearnIndex + '/' : '' }}{{ item?.length }}{{ quantifier }} +
{ if (newVal) { - let data = { - speed: statStore.speed, + let data: Statistics = { + spend: statStore.spend, startDate: statStore.startDate, total: statStore.total, wrong: statStore.wrong, + new: statStore.newWordNumber, } //这里不知为啥会卡,打开有延迟 requestIdleCallback(() => { diff --git a/src/pages/pc/word/StudyWord.vue b/src/pages/pc/word/StudyWord.vue index 2a37f030..e7d42052 100644 --- a/src/pages/pc/word/StudyWord.vue +++ b/src/pages/pc/word/StudyWord.vue @@ -108,7 +108,7 @@ function next(isTyping: boolean = true) { //学完了 if (statStore.step === 2) { - statStore.speed = Date.now() - statStore.startDate + statStore.spend = Date.now() - statStore.startDate console.log('全完学完了') emitter.emit(EventKey.openStatModal, {}) // emit('complete', {}) diff --git a/src/pages/pc/word/WordHomePage.vue b/src/pages/pc/word/WordHomePage.vue index 76e98a72..dafd517b 100644 --- a/src/pages/pc/word/WordHomePage.vue +++ b/src/pages/pc/word/WordHomePage.vue @@ -6,7 +6,7 @@ import "vue-activity-calendar/style.css"; import {useRouter} from "vue-router"; import BaseIcon from "@/components/BaseIcon.vue"; import Dialog from "@/pages/pc/components/dialog/Dialog.vue"; -import {_getAccomplishDate, _getAccomplishDays, _getDictDataByUrl, useNav} from "@/utils"; +import {_getAccomplishDate, _getAccomplishDays, _getDictDataByUrl, useNav, _dateFormat} from "@/utils"; import BasePage from "@/pages/pc/components/BasePage.vue"; import {DictResource, getDefaultDict} from "@/types.ts"; import {onMounted, watch} from "vue"; @@ -15,16 +15,13 @@ import DictListPanel from "@/pages/pc/components/DictListPanel.vue"; import {useRuntimeStore} from "@/stores/runtime.ts"; import Book from "@/pages/pc/components/Book.vue"; import PopConfirm from "@/pages/pc/components/PopConfirm.vue"; +import {ElMessage} from 'element-plus'; const store = useBaseStore() const router = useRouter() const {nav} = useNav() const runtimeStore = useRuntimeStore() -function clickEvent(e) { - console.log('e', e) -} - let currentStudy = $ref({ new: [], review: [], @@ -49,6 +46,7 @@ async function init() { if (!currentStudy.new.length && store.sdict.words.length) { currentStudy = getCurrentStudyWord() } + } function study() { @@ -120,6 +118,51 @@ function toggleSelect(item) { } } +// 统计所有词典的学习日期 +const allStudyDays = $computed(() => { + const dateCountMap = new Map(); + store.word.bookList.forEach(dict => { + if (Array.isArray(dict.statistics)) { + dict.statistics.forEach(stat => { + // 格式化为 'YYYY-MM-DD' + const date = _dateFormat(stat.startDate, 'YYYY-MM-DD'); + if (!date) return; + // spend 直接累加原始毫秒数 + const spend = Number(stat.spend || stat.speed) || 0; + if (!dateCountMap.has(date)) { + dateCountMap.set(date, {count: 1, spend}); + } else { + const v = dateCountMap.get(date)!; + v.count += 1; + v.spend += spend; + } + }); + } + }); + // 转为 [{ date, count, spend }] + return Array.from(dateCountMap.entries()).map(([date, {count, spend}]) => ({date, count, spend})); +}); + +function clickActivityEvent(e) { + // e.date 是 'YYYY-MM-DD' + const day = allStudyDays.find(item => item.date === e.date); + if (day) { + // 这里将毫秒转为分钟和小时 + const min = Math.round(day.spend / 1000 / 60); + let msg = ''; + if (min < 60) { + msg = ` 学习了${min}分钟`; + } else { + const hour = (min / 60).toFixed(1); + msg = ` 学习了${min}分钟(约${hour}小时)`; + } + ElMessage.success(e.date + msg); + } else { + ElMessage.info('当天无学习记录'); + } +} + +