修改了首页缓存

This commit is contained in:
2025-08-01 09:02:38 +08:00
parent cbe8b835d1
commit 5dea906103
3 changed files with 646 additions and 608 deletions
+7 -5
View File
@@ -17,9 +17,9 @@
<view class="ai-info">
<!-- <image src="@/static/images/dialog/pet-3.png" alt="" class="image-pet-bg"></image> -->
<image src="@/static/images/dialog/pet-bg-base.png" alt="" class="image-pet-bg"></image>
<image :src="userInfo.mascotInfo?.imgAddr ||''" alt="" class="image-pet" mode="widthFix"></image>
<image :src="userInfo?.mascotInfo?.imgAddr ||''" alt="" class="image-pet" mode="widthFix"></image>
<view class="ai-info-bg-box">
<view class="hello-text">Hi我是{{ userInfo.mascotInfo?.mascotName || ''}}</view>
<view class="hello-text">{{ userInfo?'Hi,我是'+userInfo?.mascotInfo?.mascotName : 'Hi'}}</view>
<view class="info-text">工作学习我都能帮你</view>
<view class="info-btn">试试他的能力</view>
</view>
@@ -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
// // 停止获取
+52 -34
View File
@@ -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')
+587 -569
View File
File diff suppressed because it is too large Load Diff