增加数据缓存,去除部分请求的重复/

This commit is contained in:
2024-12-30 16:31:01 +08:00
parent cbcd1c857c
commit 6fb98974d6
15 changed files with 697 additions and 320 deletions

View File

@@ -210,6 +210,8 @@
import activityComp from '../../components/activityComp/activityComp.vue'
import dragButton from "@/components/drag-button/drag-button.vue";
import httpsRequest from '../../common/httpRequest.js'
import {$cache_index} from '@/store/cashe.js'
console.log($cache_index)
export default {
components: {
videoList,
@@ -291,10 +293,7 @@
//获取小程序胶囊的宽度
this.barWidth = menuButtonInfo.width
this.barHeight = menuButtonInfo.height
// #endif
console.log(options, '22222222222222222')
if (uni.getStorageSync('qdCode')) {
this.qdCode = uni.getStorageSync('qdCode')
}
@@ -365,9 +364,13 @@
//本周热门
this.getrecomVideo('2')
//本周排行榜
this.getrecomVideo('1')
setTimeout(()=>{
this.getrecomVideo('1')
},100)
//最新
this.getrecomVideo('')
setTimeout(()=>{
this.getrecomVideo('')
},200)
this.getBannerList()
this.getMsg()
this.getGardList()
@@ -460,6 +463,7 @@
},
onPullDownRefresh() {
this.page = 1
$cache_index.clear()
this.getCourseList()
},
methods: {
@@ -616,30 +620,54 @@
// #ifdef MP-TOUTIAO
data.dyShow = 1
// #endif
if(sort==2&&$cache_index.rmVideList){
this.rmVideList = $cache_index.rmVideList
return
}
if(sort==1&&$cache_index.phbVideoList){
this.phbVideoList = $cache_index.phbVideoList
return
}
if(!sort&&$cache_index.newVideList){
this.newVideList = $cache_index.newVideList
return
}
console.log('请求服务器 获取推荐视频')
this.$Request.getT('/app/course/selectCourse', data).then(res => {
if (res.code == 0) {
if (Number(sort) == 2) { //本周热门
this.rmVideList = res.data.list
$cache_index.set('rmVideList',this.rmVideList)
} else if (Number(sort) == 1) { //本周排行榜
this.phbVideoList = res.data.list
$cache_index.set('phbVideoList',this.phbVideoList)
} else { //最新热播
this.newVideList = res.data.list
$cache_index.set('newVideList',this.newVideList)
}
}
})
},
getTypeList() {
if($cache_index.typeList){
this.typeList=$cache_index.typeList
return
}
console.log('请求服务器 getTypeList')
this.$Request.getT('/app/courseClassification/queryClassification').then(res => {
if (res.code == 0) {
let fenlei = {
classificationId: 0,
classificationName: "热门"
}
this.typeList = [];
this.typeList.push(fenlei);
res.data.forEach(d => {
this.typeList.push(d);
});
// this.typeList = [];
// this.typeList.push(fenlei);
// res.data.forEach(d => {
// this.typeList.push(d);
// });
this.typeList=[fenlei,...res.data]
$cache_index.set('typeList',this.typeList)
// console.log(JSON.stringify(this.typeList))
}
});
@@ -706,10 +734,19 @@
},
//获取背景图
getBgImg() {
const bgImg=$cache_index.bgImg
const tuiguang=$cache_index.tuiguang
if(bgImg&&tuiguang){
this.bgImg = bgImg
this.tuiguang = tuiguang
return
}
this.$u.get('app/banner/selectBannerList?classify=5').then(res => {
if (res.code == 0) {
this.bgImg = res.data[0].imageUrl
this.tuiguang = res.data[0].describes
$cache_index.set('bgImg',res.data[0].imageUrl)
$cache_index.set('tuiguang',res.data[0].describes)
} else {
uni.showToast({
title: res.msg,
@@ -738,8 +775,14 @@
// #ifdef MP-TOUTIAO
data.dyShow = 1
// #endif
this.$Request.getT('/app/course/selectCourse', data).then(res => {
if($cache_index.courseList&&this.page==1){
this.courseList=$cache_index.courseList
uni.stopPullDownRefresh()
return
}
this.$Request.getT('/app/course/selectCourse', data).then(res => {
if (res.code == 0) {
this.pages = res.data.totalPage
if (this.page < this.pages) {
@@ -749,6 +792,7 @@
}
if (this.page == 1) {
this.courseList = res.data.list
$cache_index.set('courseList',res.data.list)
} else {
this.courseList = [...this.courseList, ...res.data.list]
}
@@ -801,6 +845,10 @@
},
// 获取金刚区列表
getGardList() {
if($cache_index.gridList){
this.gridList=$cache_index.gridList
return
}
this.$u.api.bannerList({
classify: '2',
}).then(res => {
@@ -812,6 +860,7 @@
}
})
this.gridList = this.processArray(arr)
$cache_index.set('gridList',this.gridList)
} else {
uni.showToast({
title: res.msg,
@@ -907,6 +956,10 @@
},
// 获取轮播图列表
getBannerList() {
if($cache_index.swiperList){
this.swiperList=$cache_index.swiperList
return
}
this.$u.api.bannerList({
classify: '1'
}).then(res => {
@@ -916,7 +969,7 @@
this.swiperList.push(d)
}
})
$cache_index.set('swiperList',this.swiperList)
} else {
uni.showToast({
title: res.msg,