修改了首页缓存
This commit is contained in:
@@ -17,9 +17,9 @@
|
|||||||
<view class="ai-info">
|
<view class="ai-info">
|
||||||
<!-- <image src="@/static/images/dialog/pet-3.png" alt="" class="image-pet-bg"></image> -->
|
<!-- <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="@/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="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-text">工作学习,我都能帮你!</view>
|
||||||
<view class="info-btn">试试他的能力</view>
|
<view class="info-btn">试试他的能力</view>
|
||||||
</view>
|
</view>
|
||||||
@@ -93,7 +93,8 @@
|
|||||||
onMounted,
|
onMounted,
|
||||||
watch,
|
watch,
|
||||||
nextTick,
|
nextTick,
|
||||||
computed
|
computed,
|
||||||
|
onActivated
|
||||||
} from 'vue'
|
} from 'vue'
|
||||||
import common from '@/common/common';
|
import common from '@/common/common';
|
||||||
import TouchBtn from '@/pages/course/components/touchBtn.vue'
|
import TouchBtn from '@/pages/course/components/touchBtn.vue'
|
||||||
@@ -481,8 +482,7 @@ const pageTopPadding = computed(() => statusBarHeight + 'px')
|
|||||||
const pages = getCurrentPages();
|
const pages = getCurrentPages();
|
||||||
if (pages && pages.length > 1) {
|
if (pages && pages.length > 1) {
|
||||||
const page = pages[pages.length - 2];
|
const page = pages[pages.length - 2];
|
||||||
if (page.route === 'pages/login/login') {
|
if (page.route === 'pages/login/login') {ß
|
||||||
console.log('进来了');
|
|
||||||
if (pages.length == 2) {
|
if (pages.length == 2) {
|
||||||
common.switchTab('/pages/index/index');
|
common.switchTab('/pages/index/index');
|
||||||
} else {
|
} else {
|
||||||
@@ -502,9 +502,11 @@ const pageTopPadding = computed(() => statusBarHeight + 'px')
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
|
console.log('onMounted');
|
||||||
getQuestionList()
|
getQuestionList()
|
||||||
initsocketTask()
|
initsocketTask()
|
||||||
})
|
})
|
||||||
|
|
||||||
onHide(() => {
|
onHide(() => {
|
||||||
// if(watchFlag.value === 1) return
|
// if(watchFlag.value === 1) return
|
||||||
// // 停止获取
|
// // 停止获取
|
||||||
|
|||||||
+52
-34
@@ -305,54 +305,67 @@
|
|||||||
const recommend_class_list = ref([...init_class_data])
|
const recommend_class_list = ref([...init_class_data])
|
||||||
const mascotInfo = ref({})
|
const mascotInfo = ref({})
|
||||||
const statistics_data = reactive({
|
const statistics_data = reactive({
|
||||||
'stdtTmLen': 0, // 学习
|
stdtTmLen: 0, // 学习
|
||||||
'accmPracticeCnt': 0, // 训练
|
accmPracticeCnt: 0, // 训练
|
||||||
'accmExamCnt': 0, // 考试
|
accmExamCnt: 0, // 考试
|
||||||
'startStdtTmLen': 0, // 起始学习
|
startStdtTmLen: 0, // 起始学习
|
||||||
'startAccmPracticeCnt': 0, // 起始训练
|
startAccmPracticeCnt: 0, // 起始训练
|
||||||
'startAccmExamCnt': 0, // 起始考试
|
startAccmExamCnt: 0, // 起始考试
|
||||||
'request_time': 0, // 上次请求时间
|
request_time: 0, // 上次请求时间
|
||||||
"init": function() { // 初始化统计数据
|
init: function() { // 初始化统计数据
|
||||||
const index_statistics_data = common.getValue('index_statistics_data') // 获取缓存
|
const index_statistics_data = common.getValue('statistics_data') // 获取缓存
|
||||||
if (index_statistics_data) {
|
if (index_statistics_data) {
|
||||||
this.stdtTmLen = index_statistics_data.stdtTmLen;
|
this.stdtTmLen = index_statistics_data.stdtTmLen;
|
||||||
this.accmPracticeCnt = index_statistics_data.accmPracticeCnt;
|
this.accmPracticeCnt = index_statistics_data.accmPracticeCnt;
|
||||||
this.accmExamCnt = index_statistics_data.accmExamCnt;
|
this.accmExamCnt = index_statistics_data.accmExamCnt;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"get_statistics_data": async function() {
|
get_statistics_data: async function() {
|
||||||
try {
|
try {
|
||||||
const time_now = Date.now();
|
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;
|
this.request_time = time_now;
|
||||||
// 获取最新数据
|
// 获取最新数据
|
||||||
const res = await getStatisticsData();
|
const res = await getStatisticsData();
|
||||||
common.setValue('index_statistics_data', res.body)
|
if (res && res.body) {
|
||||||
const stdtTmLen = res.body.stdtTmLen
|
// 合并新数据与缓存数据,确保只更新有效字段
|
||||||
const accmPracticeCnt = res.body.accmPracticeCnt
|
statistics_data = {
|
||||||
const accmExamCnt = res.body.accmExamCnt
|
...statistics_data,
|
||||||
if (stdtTmLen != this.stdtTmLen) {
|
stdtTmLen: res.body.stdtTmLen || 0,
|
||||||
this.startStdtTmLen = this.stdtTmLen
|
accmPracticeCnt: res.body.accmPracticeCnt || 0,
|
||||||
this.stdtTmLen = stdtTmLen
|
accmExamCnt: res.body.accmExamCnt || 0
|
||||||
stdtTmLenRef.value.start()
|
};
|
||||||
|
|
||||||
|
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) {
|
} catch (error) {
|
||||||
console.log('获取统计数据失败:', error);
|
console.error('获取统计数据失败:', error);
|
||||||
|
// 可以在这里添加更多的错误处理逻辑,比如显示错误提示
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -386,6 +399,11 @@
|
|||||||
animationType: 'slide-in-bottom'
|
animationType: 'slide-in-bottom'
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
onLoad(() => {
|
||||||
|
statistics_data['init'](); // 初始化数据
|
||||||
|
// 检测如果没设置吉祥物,跳转到吉祥物界面
|
||||||
|
|
||||||
|
})
|
||||||
onShow(() => {
|
onShow(() => {
|
||||||
if (!common.isLogin()) {
|
if (!common.isLogin()) {
|
||||||
common.navigateTo('/pages/login/login')
|
common.navigateTo('/pages/login/login')
|
||||||
|
|||||||
+587
-569
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user