From 5dea906103fd7661d7560b5461d0bd2f3dfd8a4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=B9=E6=9E=9C=E7=94=B5=E8=84=91?= Date: Fri, 1 Aug 2025 09:02:38 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=86=E9=A6=96=E9=A1=B5?= =?UTF-8?q?=E7=BC=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/index/dialog.vue | 12 +- src/pages/index/index.vue | 86 +-- src/pages/me/index.vue | 1156 ++++++++++++++++++------------------ 3 files changed, 646 insertions(+), 608 deletions(-) diff --git a/src/pages/index/dialog.vue b/src/pages/index/dialog.vue index 8e7adda2..3b194e87 100644 --- a/src/pages/index/dialog.vue +++ b/src/pages/index/dialog.vue @@ -17,9 +17,9 @@ - + - Hi,我是{{ userInfo.mascotInfo?.mascotName || ''}} + {{ userInfo?'Hi,我是'+userInfo?.mascotInfo?.mascotName : 'Hi'}} 工作学习,我都能帮你! 试试他的能力 @@ -93,7 +93,8 @@ onMounted, watch, nextTick, - computed + computed, + onActivated } from 'vue' import common from '@/common/common'; import TouchBtn from '@/pages/course/components/touchBtn.vue' @@ -481,8 +482,7 @@ const pageTopPadding = computed(() => statusBarHeight + 'px') const pages = getCurrentPages(); if (pages && pages.length > 1) { const page = pages[pages.length - 2]; - if (page.route === 'pages/login/login') { - console.log('进来了'); + if (page.route === 'pages/login/login') {ß if (pages.length == 2) { common.switchTab('/pages/index/index'); } else { @@ -502,9 +502,11 @@ const pageTopPadding = computed(() => statusBarHeight + 'px') }) } onMounted(() => { + console.log('onMounted'); getQuestionList() initsocketTask() }) + onHide(() => { // if(watchFlag.value === 1) return // // 停止获取 diff --git a/src/pages/index/index.vue b/src/pages/index/index.vue index f68a2b2b..34978e9f 100644 --- a/src/pages/index/index.vue +++ b/src/pages/index/index.vue @@ -305,54 +305,67 @@ const recommend_class_list = ref([...init_class_data]) const mascotInfo = ref({}) const statistics_data = reactive({ - 'stdtTmLen': 0, // 学习 - 'accmPracticeCnt': 0, // 训练 - 'accmExamCnt': 0, // 考试 - 'startStdtTmLen': 0, // 起始学习 - 'startAccmPracticeCnt': 0, // 起始训练 - 'startAccmExamCnt': 0, // 起始考试 - 'request_time': 0, // 上次请求时间 - "init": function() { // 初始化统计数据 - const index_statistics_data = common.getValue('index_statistics_data') // 获取缓存 + stdtTmLen: 0, // 学习 + accmPracticeCnt: 0, // 训练 + accmExamCnt: 0, // 考试 + startStdtTmLen: 0, // 起始学习 + startAccmPracticeCnt: 0, // 起始训练 + startAccmExamCnt: 0, // 起始考试 + request_time: 0, // 上次请求时间 + init: function() { // 初始化统计数据 + const index_statistics_data = common.getValue('statistics_data') // 获取缓存 if (index_statistics_data) { this.stdtTmLen = index_statistics_data.stdtTmLen; this.accmPracticeCnt = index_statistics_data.accmPracticeCnt; this.accmExamCnt = index_statistics_data.accmExamCnt; } }, - "get_statistics_data": async function() { + get_statistics_data: async function() { try { const time_now = Date.now(); - if (time_now - this.request_time > 300 * 1000) { + let statistics_data = common.getValue('statistics_data') || {}; + if (time_now - this.request_time > 300) { this.request_time = time_now; // 获取最新数据 const res = await getStatisticsData(); - common.setValue('index_statistics_data', res.body) - const stdtTmLen = res.body.stdtTmLen - const accmPracticeCnt = res.body.accmPracticeCnt - const accmExamCnt = res.body.accmExamCnt - if (stdtTmLen != this.stdtTmLen) { - this.startStdtTmLen = this.stdtTmLen - this.stdtTmLen = stdtTmLen - stdtTmLenRef.value.start() + if (res && res.body) { + // 合并新数据与缓存数据,确保只更新有效字段 + statistics_data = { + ...statistics_data, + stdtTmLen: res.body.stdtTmLen || 0, + accmPracticeCnt: res.body.accmPracticeCnt || 0, + accmExamCnt: res.body.accmExamCnt || 0 + }; + + common.setValue('statistics_data', statistics_data); } - if (accmPracticeCnt != this.accmPracticeCnt) { - this.startAccmPracticeCnt = this.accmPracticeCnt - this.accmPracticeCnt = accmPracticeCnt - accmPracticeCntRef.value.start() - } - if (accmExamCnt != this.accmExamCnt) { - this.startAccmExamCnt = this.accmExamCnt - this.accmExamCnt = accmExamCnt - accmExamCntRef.value.start() - } - - console.log('统计数据已更新'); - } else { - console.log('时间没到无需更新'); } + + // 解构赋值获取最新值 + const { + accmExamCnt = 0, accmPracticeCnt = 0, stdtTmLen = 0 + } = statistics_data; + + // 更新数据并触发动画 + if (stdtTmLen !== this.stdtTmLen) { + this.startStdtTmLen = this.stdtTmLen + this.stdtTmLen = stdtTmLen + stdtTmLenRef.value.start() + } + if (accmPracticeCnt !== this.accmPracticeCnt) { + this.startAccmPracticeCnt = this.accmPracticeCnt + this.accmPracticeCnt = accmPracticeCnt + accmPracticeCntRef.value.start() + } + if (accmExamCnt !== this.accmExamCnt) { + this.startAccmExamCnt = this.accmExamCnt + this.accmExamCnt = accmExamCnt + accmExamCntRef.value.start() + } + } catch (error) { - console.log('获取统计数据失败:', error); + console.error('获取统计数据失败:', error); + // 可以在这里添加更多的错误处理逻辑,比如显示错误提示 } } }); @@ -386,6 +399,11 @@ animationType: 'slide-in-bottom' }) } + onLoad(() => { + statistics_data['init'](); // 初始化数据 + // 检测如果没设置吉祥物,跳转到吉祥物界面 + + }) onShow(() => { if (!common.isLogin()) { common.navigateTo('/pages/login/login') diff --git a/src/pages/me/index.vue b/src/pages/me/index.vue index 8c59eaaf..cbde97b9 100644 --- a/src/pages/me/index.vue +++ b/src/pages/me/index.vue @@ -1,570 +1,588 @@ - - - - - \ No newline at end of file