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

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

@@ -113,15 +113,16 @@
</template>
<script>
import { $cache_chasingDrama} from '@/store/cashe.js'
export default {
data() {
return {
isErQd: false, //昨天是否签到
isQd: false, //今日是否已签到
day: 0, //签到天数
isErQd: $cache_chasingDrama.isErQd|| false, //昨天是否签到
isQd: $cache_chasingDrama.isQd||false, //今日是否已签到
day: $cache_chasingDrama.day|| 0, //签到天数
numList: this.getThisWeekDates(),
list: [],
zhuiju: [],
list: $cache_chasingDrama.list||[],
zhuiju: $cache_chasingDrama.zhuiju|| [],
};
},
onLoad() {
@@ -171,6 +172,9 @@
this.isQd = false
this.isErQd = false
}
$cache_chasingDrama.set('day',this.day)
$cache_chasingDrama.set('isQd',this.isQd)
$cache_chasingDrama.set('isErQd',this.isErQd)
} else {
uni.showToast({
title: res.msg,
@@ -201,6 +205,7 @@
this.$Request.getT('/app/courseCollect/selectByUserId', data).then(res => {
if (res.code == 0) {
this.zhuiju = res.data.records
$cache_chasingDrama.set('zhuiju',this.zhuiju)
}
})
},
@@ -217,6 +222,7 @@
this.$nextTick(() => {
this.videPage = 1
})
$cache_chasingDrama.set('list',this.list)
}
})
},

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,

View File

@@ -262,8 +262,8 @@
import ttMsg from '../../components/ttMsg/ttMsg.vue'
import httpsRequest from '../../common/httpRequest.js'
import otherXuanfu from '@/components/other-xuafu.vue'
import {$cache_user} from '@/store/cashe.js'
console.log($cache_user);
export default {
components: {
ttMsg,
@@ -289,8 +289,8 @@
invitationCode: '',
token: '',
endTime: '', //会员到期时间
moneyNum: 0, //余额
jifen: 0, //积分
moneyNum:$cache_user.moneyNum|| 0, //余额
jifen:$cache_user.jifen|| 0, //积分
isVips: '否', //是否显示会员
myLoveNum: 0, //我的喜欢个数
myZhui: 0, //我的追剧数量
@@ -300,13 +300,18 @@
twoRate: 0,
kmPaySel: '否',
isWxIosPay: true, //微信下是否显示支付功能
userInfo: {},
userInfo:$cache_user.userInfo|| {},
isShowMoneyPay: true,
}
},
onLoad() {
this.getBannerList()
},
onPullDownRefresh() {
$cache_user.clear()
this.getMyMoney()
this.getPoints()
},
onShow() {
const systemInfo = uni.getSystemInfoSync();
@@ -333,6 +338,11 @@
this.invitationCode = res.data.invitationCode
this.rate = res.data.rate || 0
this.twoRate = res.data.twoRate || 0
$cache_user.set('userName',this.userName)
$cache_user.set('avatar',this.avatar)
$cache_user.set('invitationCode',this.invitationCode)
$cache_user.set('rate',this.rate)
$cache_user.set('twoRate',this.twoRate)
}
})
@@ -473,6 +483,7 @@
} else {
this.jifen = 0
}
$cache_user.set('jifen',this.jifen)
})
},
/**
@@ -495,6 +506,8 @@
if (res.code === 0) {
this.moneyNum = res.data.money
this.userInfo = res.data
$cache_user.set('userInfo',res.data)
$cache_user.set('moneyNum',res.data.money)
// this.$Request.getT('/app/invite/selectInviteMoney').then(ret => {
// if (ret.code == 0) {
// if (ret.data.inviteMoney && ret.data.inviteMoney.money) {

View File

@@ -6,6 +6,7 @@
<script>
import httpsRequest from '@/common/httpRequest.js'
import {cacheClear} from '@/store/cashe.js'
export default {
data() {
return {
@@ -22,45 +23,50 @@
}
},
methods:{
getOrder(){
httpsRequest.getT("/app/wuyou/queryOrder/" + this.ordersId, {}).then(res => {
console.log(res.data);
if (res.data == 1) {
uni.hideLoading()
const sysInfo = uni.getSystemInfoSync();
let isIos = sysInfo.platform == 'ios'
console.log("is ios ", isIos);
if (isIos) {
uni.navigateBack()
uni.showToast({
title: '支付成功',
icon: 'none'
})
cacheClear(['renwu','user'])
setTimeout(() => {
uni.navigateBack()
}, 1500)
} else {
uni.showToast({
title: '支付成功',
icon: 'none'
})
this.timer = setTimeout(() => {
clearTimeout(this.timer)
uni.navigateBack()
}, 500)
}
} else {
// #ifdef APP
uni.showLoading({
title: '支付中'
})
// #endif
}
});
}
},
onReady() {},
onShow() {
console.log(this.ordersId);
httpsRequest.getT("/app/wuyou/queryOrder/" + this.ordersId, {}).then(res => {
console.log(res.data);
if (res.data == 1) {
uni.hideLoading()
const sysInfo = uni.getSystemInfoSync();
let isIos = sysInfo.platform == 'ios'
console.log("is ios ", isIos);
if (isIos) {
uni.navigateBack()
uni.showToast({
title: '支付成功',
icon: 'none'
})
setTimeout(() => {
uni.navigateBack()
}, 1500)
} else {
uni.showToast({
title: '支付成功',
icon: 'none'
})
this.timer = setTimeout(() => {
clearTimeout(this.timer)
uni.navigateBack()
}, 500)
}
} else {
// #ifdef APP
uni.showLoading({
title: '支付中'
})
// #endif
}
});
this.getOrder()
},
onHide() {
clearInterval(this.timer)

View File

@@ -98,6 +98,7 @@
</template>
<script>
import {$cache_renwu} from '@/store/cashe.js'
export default {
data() {
@@ -114,7 +115,6 @@
recordList: [
],
signInBtn: '点击签到',
isShowMoneyPay: true,
isIos: false,
isAndroid: false,
adRewardedVideo: true,
@@ -128,18 +128,6 @@
this.signInList = []
this.getTaskdata()
this.getsignIn()
this.$Request.getT("app/common/type/919", {}).then(res => {
if (res.code == 0) {
const sysInfo = uni.getSystemInfoSync();
let isIos = sysInfo.platform == 'ios'
this.isIos = /iOS/.test(sysInfo.platform);
// 判断是否是安卓设备
this.isShowMoneyPay = !(res.data.value == '1' && isIos)
}
});
this.$nextTick(()=>{
this.adRewardedVideoloadNum = 0
this.$refs.adRewardedVideo.load();
@@ -214,6 +202,12 @@
* 获取签到数据
*/
getsignIn() {
if($cache_renwu.signInList&&$cache_renwu.signDays&&$cache_renwu.enable){
this.signInList =$cache_renwu.signInList
this.signDays =$cache_renwu.signDays
this.enable =$cache_renwu.enable
return
}
this.$Request.getT('app/userSignRecord/getUserSignData', {}).then(res => {
if (res.code == 0) {
this.signInList = res.data.recordList
@@ -228,6 +222,9 @@
this.signInBtn = '已签到'
}
})
$cache_renwu.set('signInList',this.signInList)
$cache_renwu.set('signDays',this.signDays)
$cache_renwu.set('enable',this.enable)
} else {
// uni.showToast({
// title: res.msg,
@@ -318,6 +315,7 @@
icon: 'none'
})
setTimeout(() => {
$cache_renwu.clear()
this.getTaskdata()
this.getsignIn()
}, 1000)
@@ -333,6 +331,12 @@
* 获取任务列表
*/
getTaskdata() {
if($cache_renwu.list){
this.list= $cache_renwu.list
uni.stopPullDownRefresh();
return
}
console.log('获取服务器 任务列表')
this.list= [];
this.$Request.getT('app/taskCenter/selectTaskCenter', {}).then(res => {
if (res.code == 0) {
@@ -350,8 +354,7 @@
}
// #endif
})
$cache_renwu.set('list',this.list)
}
uni.stopPullDownRefresh();
})
@@ -362,6 +365,7 @@
*/
onPullDownRefresh: function() {
console.log(2)
$cache_renwu.clear()
this.getTaskdata();
},

View File

@@ -150,6 +150,7 @@
<script>
import config from '../../common/config.js'
import tkiQrcode from '../../components/tki-qrcode/tki-qrcode.vue';
import {$cache_video} from '@/store/cashe.js'
export default {
components: {
tkiQrcode
@@ -665,6 +666,30 @@
}
},
//首页视频初始化
videoInit(){
if(this.page==1){
let numIdCurr = this.videoList[0].courseDetailsId;
this.courseId = this.videoList[0].courseId
this.courseDetailsId = this.videoList[0].courseDetailsId;
this.videoContextId = 'myVideo' + numIdCurr;
this.$nextTick(() => {
this.videoContext = uni.createVideoContext(this.videoContextId, this);
this.videoContext.play();
})
if (uni.getStorageSync('token')) { //如果有token则插入
//插入历史记录
this.setHistor(this.videoList[this.current].courseId, this.videoList[this
.current]
.courseDetailsId)
}
}
this.getsrc(this.videoList[this.current].videoUrl, this.videoList[this.current]
.wxCourseDetailsId)
this.$forceUpdate()
},
// 资源详情
getDataList() {
let data = {
@@ -679,6 +704,11 @@
// #ifdef MP-TOUTIAO
data.dyShow = 1
// #endif
if(this.page==1&&$cache_video.videoList){
this.videoList=$cache_video.videoList
return
}
this.$Request.getT('/app/course/selectCourseDetailsList', data).then(res => {
if (res.code == 0) {
this.pages = res.data.totalPage
@@ -691,30 +721,11 @@
//菜单数组
if (this.page == 1) {
this.videoList = arr
$cache_video.set('videoList',arr)
} else {
this.videoList = [...this.videoList, ...arr]
}
if (this.page == 1) {
let numIdCurr = this.videoList[0].courseDetailsId;
this.courseId = this.videoList[0].courseId
this.courseDetailsId = this.videoList[0].courseDetailsId;
this.videoContextId = 'myVideo' + numIdCurr;
this.$nextTick(() => {
this.videoContext = uni.createVideoContext(this.videoContextId, this);
this.videoContext.play();
})
if (uni.getStorageSync('token')) { //如果有token则插入
//插入历史记录
this.setHistor(this.videoList[this.current].courseId, this.videoList[this
.current]
.courseDetailsId)
}
}
this.getsrc(this.videoList[this.current].videoUrl, this.videoList[this.current]
.wxCourseDetailsId)
this.$forceUpdate()
this.videoInit()
}
} else {
uni.showToast({