首页增加缓存

This commit is contained in:
YeMingfei666 2024-12-30 18:29:38 +08:00
parent 78f071dfda
commit 4bedd70016
1 changed files with 143 additions and 99 deletions

View File

@ -210,7 +210,12 @@
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'
import {
$cache_index
} from '@/store/cashe.js'
import {
$cache_config
} from '@/store/cashe.js'
console.log($cache_index)
export default {
components: {
@ -339,13 +344,8 @@
uni.setStorageSync('qdCodeion', options.qdCode)
}
if (uni.getStorageSync('token')) {
this.$u.get('/app/common/type/813').then(res => {
if (res.code == 0 && res.data.value) {
if (res.data.value == '是') {
this.getActivity()
}
}
})
this.zhuliInit()
}
let u = navigator ? navigator.userAgent : '';
@ -364,13 +364,13 @@
//
this.getrecomVideo('2')
//
setTimeout(()=>{
setTimeout(() => {
this.getrecomVideo('1')
},100)
}, 100)
//
setTimeout(()=>{
setTimeout(() => {
this.getrecomVideo('')
},200)
}, 200)
this.getBannerList()
this.getMsg()
this.getGardList()
@ -378,63 +378,29 @@
this.getCourseList()
this.homeTypeSel = uni.getStorageSync('homeTypeSel') ? uni.getStorageSync('homeTypeSel') : '否'
//#ifdef H5
let that = this
this.$u.get('/app/common/type/108').then(res => { //// 108
if (res.code == 0 && res.data) {
if (res.data.value == '是') {
let ua = navigator.userAgent.toLowerCase();
if (ua.indexOf('micromessenger') !== -1) {
let openid = uni.getStorageSync('openId');
let userId = uni.getStorageSync('userId');
if (userId) {
if (!openid) {
if (window.location.href.indexOf('?code=') !== -1 || window.location.href
.indexOf(
'&code=') !==
-1) {
let code;
if (window.location.href.indexOf('?code=') !== -1) {
code = window.location.href.split('?code=')[1].split('&')[0];
} else {
code = window.location.href.split('&code=')[1].split('&')[0];
}
if (userId) {
that.$u.get('/app/user/openId/' + code + '/' + userId).then(
res => {
uni.setStorageSync('openId', res.data)
});
}
} else {
window.location.href =
'https://open.weixin.qq.com/connect/oauth2/authorize?appid=' +
that.$queue.getWxAppid() +
'&redirect_uri=' +
window.location.href.split('#')[0] +
'&response_type=code&scope=snsapi_userinfo#wechat_redirect';
}
}
}
let that=this;
if($cache_config.isGongZhongHaoAutoLogin!==null&&$cache_config.isGongZhongHaoAutoLogin!==undefined){
if($cache_config.isGongZhongHaoAutoLogin=='是'){
that.wxWebInit()
}
}else{
this.$u.get('/app/common/type/108').then(res => { //// 108
if (res.code == 0 && res.data) {
$cache_config.set('isGongZhongHaoAutoLogin',res.data)
if (res.data.value == '是') {
that.wxWebInit()
}
}
}
});
});
}
//#endif
if (uni.getStorageSync('token')) {
this.getMyLoveVideo()
this.$u.get('/app/common/type/813').then(res => {
if (res.code == 0 && res.data.value) {
if (res.data.value == '是') {
this.getActivitys()
}
}
})
// 837
this.$u.get('/app/common/type/837').then(res => {
if (res.code == 0 && res.data.value) {
this.xxJDNum = res.data.value;
this.checkNewUser()
}
})
this.newUserRedInit()
} else { //
this.showzl = false
this.shodrag = false
@ -450,7 +416,7 @@
}
});
// #endif
},
onReachBottom() {
if (this.page < this.pages) {
@ -467,6 +433,78 @@
this.getCourseList()
},
methods: {
// 837
newUserRedInit(){
if($cache_config.isNewUserRedPack!==null&&$cache_config.isNewUserRedPack!==undefined){
if($cache_config.isNewUserRedPack){
this.xxJDNum = $cache_config.isNewUserRedPack;
this.checkNewUser()
}
return
}
this.$u.get('/app/common/type/837').then(res => {
$cache_config.set('isNewUserRedPack',res.data.value)
if (res.code == 0 && res.data.value) {
this.xxJDNum = res.data.value;
this.checkNewUser()
}
})
},
zhuliInit(){
if($cache_config.isOpenZhuLi!==null&&$cache_config.isOpenZhuLi!==undefined){
if($cache_config.isOpenZhuLi=='是'){
this.getActivity()
}
}else{
this.$u.get('/app/common/type/813').then(res => {
if (res.code == 0 && res.data.value) {
$cache_config.set('isOpenZhuLi',res.data.value)
if (res.data.value == '是') {
this.getActivity()
}
}
})
}
},
//
wxWebInit() {
let that = this;
let ua = navigator.userAgent.toLowerCase();
if (ua.indexOf('micromessenger') !== -1) {
let openid = uni.getStorageSync('openId');
let userId = uni.getStorageSync('userId');
if (userId) {
if (!openid) {
if (window.location.href.indexOf('?code=') !== -1 || window.location.href
.indexOf(
'&code=') !==
-1) {
let code;
if (window.location.href.indexOf('?code=') !== -1) {
code = window.location.href.split('?code=')[1].split('&')[0];
} else {
code = window.location.href.split('&code=')[1].split('&')[0];
}
if (userId) {
that.$u.get('/app/user/openId/' + code + '/' + userId).then(
res => {
uni.setStorageSync('openId', res.data)
});
}
} else {
window.location.href =
'https://open.weixin.qq.com/connect/oauth2/authorize?appid=' +
that.$queue.getWxAppid() +
'&redirect_uri=' +
window.location.href.split('#')[0] +
'&response_type=code&scope=snsapi_userinfo#wechat_redirect';
}
}
}
}
},
//
getActivitys() {
this.$Request.getT('/app/invite/selectInviteAwardByUserId').then(res => {
@ -502,9 +540,15 @@
limit: 1,
classify: 1
}
if($cache_index.videoInfo){
this.videoInfo = $cache_index.videoInfo||[]
this.shodrag = this.videoInfo.length>0
return
}
this.$Request.getT('/app/courseCollect/selectByUserId', data).then(res => {
if (res.code == 0) {
this.videoInfo = res.data.records
$cache_index.set('videoInfo',this.videoInfo)
if (this.videoInfo.length > 0) {
this.shodrag = true
}
@ -620,38 +664,38 @@
// #ifdef MP-TOUTIAO
data.dyShow = 1
// #endif
if(sort==2&&$cache_index.rmVideList){
if (sort == 2 && $cache_index.rmVideList) {
this.rmVideList = $cache_index.rmVideList
return
return
}
if(sort==1&&$cache_index.phbVideoList){
if (sort == 1 && $cache_index.phbVideoList) {
this.phbVideoList = $cache_index.phbVideoList
return
return
}
if(!sort&&$cache_index.newVideList){
if (!sort && $cache_index.newVideList) {
this.newVideList = $cache_index.newVideList
return
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)
$cache_index.set('rmVideList', this.rmVideList)
} else if (Number(sort) == 1) { //
this.phbVideoList = res.data.list
$cache_index.set('phbVideoList',this.phbVideoList)
$cache_index.set('phbVideoList', this.phbVideoList)
} else { //
this.newVideList = res.data.list
$cache_index.set('newVideList',this.newVideList)
$cache_index.set('newVideList', this.newVideList)
}
}
})
},
getTypeList() {
if($cache_index.typeList){
this.typeList=$cache_index.typeList
return
if ($cache_index.typeList) {
this.typeList = $cache_index.typeList
return
}
console.log('请求服务器 getTypeList')
this.$Request.getT('/app/courseClassification/queryClassification').then(res => {
@ -665,9 +709,9 @@
// res.data.forEach(d => {
// this.typeList.push(d);
// });
this.typeList=[fenlei,...res.data]
$cache_index.set('typeList',this.typeList)
this.typeList = [fenlei, ...res.data]
$cache_index.set('typeList', this.typeList)
// console.log(JSON.stringify(this.typeList))
}
});
@ -734,19 +778,19 @@
},
//
getBgImg() {
const bgImg=$cache_index.bgImg
const tuiguang=$cache_index.tuiguang
if(bgImg&&tuiguang){
const bgImg = $cache_index.bgImg
const tuiguang = $cache_index.tuiguang
if (bgImg && tuiguang) {
this.bgImg = bgImg
this.tuiguang = tuiguang
return
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)
$cache_index.set('bgImg', res.data[0].imageUrl)
$cache_index.set('tuiguang', res.data[0].describes)
} else {
uni.showToast({
title: res.msg,
@ -775,13 +819,13 @@
// #ifdef MP-TOUTIAO
data.dyShow = 1
// #endif
if($cache_index.courseList&&this.page==1){
this.courseList=$cache_index.courseList
if ($cache_index.courseList && this.page == 1) {
this.courseList = $cache_index.courseList
uni.stopPullDownRefresh()
return
return
}
this.$Request.getT('/app/course/selectCourse', data).then(res => {
if (res.code == 0) {
this.pages = res.data.totalPage
@ -792,7 +836,7 @@
}
if (this.page == 1) {
this.courseList = res.data.list
$cache_index.set('courseList',res.data.list)
$cache_index.set('courseList', res.data.list)
} else {
this.courseList = [...this.courseList, ...res.data.list]
}
@ -845,9 +889,9 @@
},
//
getGardList() {
if($cache_index.gridList){
this.gridList=$cache_index.gridList
return
if ($cache_index.gridList) {
this.gridList = $cache_index.gridList
return
}
this.$u.api.bannerList({
classify: '2',
@ -860,7 +904,7 @@
}
})
this.gridList = this.processArray(arr)
$cache_index.set('gridList',this.gridList)
$cache_index.set('gridList', this.gridList)
} else {
uni.showToast({
title: res.msg,
@ -956,9 +1000,9 @@
},
//
getBannerList() {
if($cache_index.swiperList){
this.swiperList=$cache_index.swiperList
return
if ($cache_index.swiperList) {
this.swiperList = $cache_index.swiperList
return
}
this.$u.api.bannerList({
classify: '1'
@ -969,7 +1013,7 @@
this.swiperList.push(d)
}
})
$cache_index.set('swiperList',this.swiperList)
$cache_index.set('swiperList', this.swiperList)
} else {
uni.showToast({
title: res.msg,