Commit 56d68f35 by 李嘉林

商品列表组件缓存问题

parent d2523711
...@@ -71,7 +71,7 @@ ...@@ -71,7 +71,7 @@
<div v-else-if="item1.componentCode=='goods-list' && item1.componentInfo.visible == 1" style="height:100%;"> <div v-else-if="item1.componentCode=='goods-list' && item1.componentInfo.visible == 1" style="height:100%;">
<!-- <goods-list class="goodsListItem" :datas="item1"></goods-list> --> <!-- <goods-list class="goodsListItem" :datas="item1"></goods-list> -->
<goods-list :class="['goodsListItemIndex'+index,'transverse-label-goodsListItem']" :datas="item1" :datasIndex="active" :goodsListIndex="index"></goods-list> <goods-list :storageKey="'transverseLabel'+componentIndex" :class="['goodsListItemIndex'+index,'transverse-label-goodsListItem']" :datas="item1" :datasIndex="active" :goodsListIndex="index"></goods-list>
</div> </div>
<div v-else-if="item1.componentCode == 'area-navigation' && item1.componentInfo.visible == 1"> <div v-else-if="item1.componentCode == 'area-navigation' && item1.componentInfo.visible == 1">
...@@ -235,11 +235,16 @@ export default { ...@@ -235,11 +235,16 @@ export default {
}) })
}) })
console.log(pageGoodsList,storageDatasList,ids,loadingFlag,pageNumList,'newVal'); console.log(pageGoodsList,storageDatasList,ids,loadingFlag,pageNumList,'newVal');
wx.setStorageSync("pageGoodsList",pageGoodsList) let pageGoodsListKey = `transverseLabel${this.componentIndex}_pageGoodsList`;
wx.setStorageSync("storageDatasList",storageDatasList) let storageDatasListKey = `transverseLabel${this.componentIndex}_storageDatasList`;
wx.setStorageSync("ids",ids) let idsKey = `transverseLabel${this.componentIndex}_ids`;
wx.setStorageSync("loadingFlag",loadingFlag) let loadingFlagKey = `transverseLabel${this.componentIndex}_loadingFlag`;
wx.setStorageSync("pageNumList",pageNumList) let pageNumListKey = `transverseLabel${this.componentIndex}_pageNumList`;
wx.setStorageSync(pageGoodsListKey,pageGoodsList)
wx.setStorageSync(storageDatasListKey,storageDatasList)
wx.setStorageSync(idsKey,ids)
wx.setStorageSync(loadingFlagKey,loadingFlag)
wx.setStorageSync(pageNumListKey,pageNumList)
return this.datas.componentData.tabList.filter( return this.datas.componentData.tabList.filter(
(item) => item.visible == undefined || item.visible == 1 (item) => item.visible == undefined || item.visible == 1
); );
......
...@@ -13,7 +13,10 @@ ...@@ -13,7 +13,10 @@
<banner :datas="item"></banner> <banner :datas="item"></banner>
</div> </div>
<div v-else-if="item.componentCode=='goods-list' && item.componentInfo.visible == 1" style="height:100%;"> <div v-else-if="item.componentCode=='goods-list' && item.componentInfo.visible == 1" style="height:100%;">
<goods-list :class="'goodsListItem' + index" :datas="item"></goods-list> <!-- ***这个商品列表组件中需要对数据做缓存,可能有多个地方同时引用此组件
必须在缓存前加个唯一标识不然所有组件全部操作同一个缓存
-->
<goods-list :storageKey="'home'+index" :class="'goodsListItem' + index" :datas="item"></goods-list>
</div> </div>
<div v-else-if="item.componentCode == 'area-navigation' && item.componentInfo.visible == 1"> <div v-else-if="item.componentCode == 'area-navigation' && item.componentInfo.visible == 1">
<area-navigation :datas="item" :changeLocation="changeLocation"></area-navigation> <area-navigation :datas="item" :changeLocation="changeLocation"></area-navigation>
...@@ -392,21 +395,23 @@ export default { ...@@ -392,21 +395,23 @@ export default {
} }
//清除懒加载缓存 //清除商品列表组件懒加载缓存
wx.removeStorage({ // 需清除的缓存keyList
key: 'pageGoodsList' let keyList = ['pageGoodsList','storageDatasList','datasIndex','ids','loadingFlag','pageNumList'];
}) wx.getStorageInfo({
wx.removeStorage({ success (res) {
key: 'storageDatasList' if(res.keys) {
}) res.keys.forEach((item,index)=>{
wx.removeStorage({ keyList.forEach((item1,index1)=>{
key: 'datasIndex' if(item.includes(item1)){
}) wx.removeStorage({
wx.removeStorage({ key: item
key: 'loadingFlag' })
}) }
wx.removeStorage({ })
key: 'pageNumList' })
}
}
}) })
console.log('storageGoodsList---detory'); console.log('storageGoodsList---detory');
......
const app = getApp(); const app = getApp();
const { log } = app;
const { goodsApi, DFSImg, $themeToLink } = app; const { goodsApi, DFSImg, $themeToLink } = app;
const componentOptions = { const componentOptions = {
// 组件选项 // 组件选项
...@@ -11,10 +12,16 @@ const componentOptions = { ...@@ -11,10 +12,16 @@ const componentOptions = {
type: Object type: Object
}, },
datasIndex:{ datasIndex:{
type: Number type: Number,
default: 0
}, },
goodsListIndex:{ goodsListIndex:{
type: Number type: Number,
default: 0
},
storageKey: {
type: String,
required: true // 必传
} }
}, },
// 组件数据 // 组件数据
...@@ -76,7 +83,7 @@ const componentOptions = { ...@@ -76,7 +83,7 @@ const componentOptions = {
methods: { methods: {
// setPageDatas(active){ // setPageDatas(active){
// this.pageGoodsList = wx.getStorageSync('pageGoodsList') // this.pageGoodsList = this.getStorageSync('pageGoodsList')
// console.log(this.pageGoodsList,active,'active'); // console.log(this.pageGoodsList,active,'active');
// }, // },
init() { init() {
...@@ -95,6 +102,17 @@ const componentOptions = { ...@@ -95,6 +102,17 @@ const componentOptions = {
titleIcon titleIcon
}); });
console.log(this.data.titleIcon, "----------------------------68"); console.log(this.data.titleIcon, "----------------------------68");
let ids = this.getStorageSync(`ids`);
console.log(ids,'---ids--104'+this.data.storageKey)
log.info(ids,'---ids--105')
// 如果不是横向标签组件初始化缓存
if (!this.data.storageKey.includes('transverseLabel')) {
this.setStorageSync("pageGoodsList",[[]])
this.setStorageSync("storageDatasList",[[]])
this.setStorageSync("ids",[[]])
this.setStorageSync("loadingFlag",[false])
this.setStorageSync("pageNumList",[1])
}
if (goodsType == 0) { if (goodsType == 0) {
if (goodsSource == "classify") { if (goodsSource == "classify") {
//商品分类 //商品分类
...@@ -202,13 +220,15 @@ const componentOptions = { ...@@ -202,13 +220,15 @@ const componentOptions = {
return element.terminalProductId; return element.terminalProductId;
}); });
let storageIds = wx.getStorageSync('ids') let storageIds = this.getStorageSync('ids')
console.log(this.data.goodsListIndex,storageIds,'--storageIds')
storageIds[this.data.goodsListIndex] = ids storageIds[this.data.goodsListIndex] = ids
wx.setStorageSync('ids',storageIds) this.setStorageSync('ids',storageIds)
let storageDatasList = wx.getStorageSync('storageDatasList') let storageDatasList = this.getStorageSync('storageDatasList')
console.log(storageDatasList,'------228'+this.data.storageKey)
storageDatasList[this.data.goodsListIndex] = this.data.datas.componentData storageDatasList[this.data.goodsListIndex] = this.data.datas.componentData
wx.setStorageSync('storageDatasList',storageDatasList) this.setStorageSync('storageDatasList',storageDatasList)
this.moreProduct(true); this.moreProduct(true);
} }
...@@ -217,26 +237,26 @@ const componentOptions = { ...@@ -217,26 +237,26 @@ const componentOptions = {
async moreProduct(flag) { async moreProduct(flag) {
// 没有数据了就不再请求了,直接return // 没有数据了就不再请求了,直接return
if (this.data.pageGoodsList.length != 0 && this.data.pageGoodsList[this.data.datasIndex].length == wx.getStorageSync('ids')[this.data.datasIndex].length) return if (this.data.pageGoodsList.length != 0 && this.data.pageGoodsList[this.data.datasIndex].length == this.getStorageSync('ids')[this.data.datasIndex].length) return
this.setData({ this.setData({
scrollLoading: true scrollLoading: true
}) })
let terminalProductIds = [] let terminalProductIds = []
console.log(pageNum,'page-----'); console.log(pageNum,'page-----');
let pageNumList = wx.getStorageSync('pageNumList') let pageNumList = this.getStorageSync('pageNumList')
let pageNum = null let pageNum = null
if (flag) { if (flag) {
pageNum = pageNumList[this.data.goodsListIndex] pageNum = pageNumList[this.data.goodsListIndex]
terminalProductIds = wx.getStorageSync('ids')[this.data.goodsListIndex].slice((pageNum - 1) * this.data.pageSize,pageNum * this.data.pageSize) terminalProductIds = this.getStorageSync('ids')[this.data.goodsListIndex].slice((pageNum - 1) * this.data.pageSize,pageNum * this.data.pageSize)
pageNum += 1 pageNum += 1
pageNumList[this.data.goodsListIndex] = pageNum pageNumList[this.data.goodsListIndex] = pageNum
}else{ }else{
pageNum = pageNumList[this.data.datasIndex] pageNum = pageNumList[this.data.datasIndex]
terminalProductIds = wx.getStorageSync('ids')[this.data.datasIndex].slice((pageNum - 1) * this.data.pageSize,pageNum * this.data.pageSize) terminalProductIds = this.getStorageSync('ids')[this.data.datasIndex].slice((pageNum - 1) * this.data.pageSize,pageNum * this.data.pageSize)
pageNum += 1 pageNum += 1
pageNumList[this.data.datasIndex] = pageNum pageNumList[this.data.datasIndex] = pageNum
} }
wx.setStorageSync('pageNumList',pageNumList) this.setStorageSync('pageNumList',pageNumList)
let { let {
vipPrice, vipPrice,
marketingTag, marketingTag,
...@@ -295,20 +315,20 @@ const componentOptions = { ...@@ -295,20 +315,20 @@ const componentOptions = {
}); });
var that = this var that = this
let pageGoodsList = wx.getStorageSync('pageGoodsList') || [] let pageGoodsList = this.getStorageSync('pageGoodsList') || []
if (flag) { if (flag) {
pageGoodsList[that.data.goodsListIndex].push(...goodsList) pageGoodsList[that.data.goodsListIndex].push(...goodsList)
}else{ }else{
pageGoodsList[that.data.datasIndex].push(...goodsList) pageGoodsList[that.data.datasIndex].push(...goodsList)
console.log(pageGoodsList[that.data.datasIndex],'--pageGoodsList[that.data.datasIndex]') console.log(pageGoodsList[that.data.datasIndex],'--pageGoodsList[that.data.datasIndex]')
} }
wx.setStorageSync('pageGoodsList', pageGoodsList); this.setStorageSync('pageGoodsList', pageGoodsList);
// 获取是否要开启请求拦截 // 获取是否要开启请求拦截
let loadingFlag = wx.getStorageSync('loadingFlag') let loadingFlag = this.getStorageSync('loadingFlag')
loadingFlag[that.data.datasIndex] = false loadingFlag[that.data.datasIndex] = false
wx.setStorageSync('loadingFlag', loadingFlag); this.setStorageSync('loadingFlag', loadingFlag);
that.setData({ that.setData({
pageGoodsList, pageGoodsList,
}) })
...@@ -353,7 +373,7 @@ const componentOptions = { ...@@ -353,7 +373,7 @@ const componentOptions = {
var that = this var that = this
console.log(that.data.datasIndex,that.data.goodsListIndex,'datasIndex'); console.log(that.data.datasIndex,that.data.goodsListIndex,'datasIndex');
console.log(that.data.pageGoodsList[that.data.datasIndex]); console.log(that.data.pageGoodsList[that.data.datasIndex]);
let storageDatasList = wx.getStorageSync('storageDatasList') || [] let storageDatasList = this.getStorageSync('storageDatasList') || []
let { style } = storageDatasList[that.data.datasIndex]; let { style } = storageDatasList[that.data.datasIndex];
let type = '' let type = ''
...@@ -365,17 +385,17 @@ const componentOptions = { ...@@ -365,17 +385,17 @@ const componentOptions = {
} }
let windowHeight = wx.getSystemInfoSync().windowHeight let windowHeight = wx.getSystemInfoSync().windowHeight
let pageGoodsList = wx.getStorageSync('pageGoodsList') || [] let pageGoodsList = this.getStorageSync('pageGoodsList') || []
console.log(that.data.pageGoodsList,pageGoodsList,that.data.datasIndex,'pageGoodsList--loading'); console.log(that.data.pageGoodsList,pageGoodsList,that.data.datasIndex,'pageGoodsList--loading');
let loadingFlag = wx.getStorageSync('loadingFlag') let loadingFlag = this.getStorageSync('loadingFlag')
// 如果所有的商品都加载完成直接return // 如果所有的商品都加载完成直接return
if (loadingFlag[that.data.datasIndex]) { if (loadingFlag[that.data.datasIndex]) {
console.log("如果所有的商品都加载完成直接return"); console.log("如果所有的商品都加载完成直接return");
return return
} }
let ids = wx.getStorageSync('ids')[that.data.datasIndex] let ids = this.getStorageSync('ids')[that.data.datasIndex]
if (ids.length == that.data.pageGoodsList[that.data.datasIndex].length && if (ids.length == that.data.pageGoodsList[that.data.datasIndex].length &&
that.data.pageGoodsList[that.data.datasIndex][that.data.pageGoodsList[that.data.datasIndex].length -1].loadState == true that.data.pageGoodsList[that.data.datasIndex][that.data.pageGoodsList[that.data.datasIndex].length -1].loadState == true
) { ) {
...@@ -396,7 +416,7 @@ const componentOptions = { ...@@ -396,7 +416,7 @@ const componentOptions = {
}) })
// that.pageGoodsList = pageGoodsList // that.pageGoodsList = pageGoodsList
console.log(rects,pageGoodsList[that.data.goodsListIndex], pageGoodsList[that.data.datasIndex],'fff'); console.log(rects,pageGoodsList[that.data.goodsListIndex], pageGoodsList[that.data.datasIndex],'fff');
wx.setStorageSync('pageGoodsList',pageGoodsList) that.setStorageSync('pageGoodsList',pageGoodsList)
...@@ -406,7 +426,7 @@ const componentOptions = { ...@@ -406,7 +426,7 @@ const componentOptions = {
that.setData({ that.setData({
loadingFlag, loadingFlag,
}) })
wx.setStorageSync('loadingFlag',loadingFlag) that.setStorageSync('loadingFlag',loadingFlag)
that.moreProduct(false) that.moreProduct(false)
...@@ -520,6 +540,14 @@ const componentOptions = { ...@@ -520,6 +540,14 @@ const componentOptions = {
type: 1, type: 1,
link: linkVal link: linkVal
}); });
},
setStorageSync(key, val) {
console.log(`${this.data.storageKey}_${key}`,'-------------533')
return wx.setStorageSync(`${this.data.storageKey}_${key}`,val)
},
getStorageSync(key) {
console.log(`${this.data.storageKey}_${key}`,'-------------537')
return wx.getStorageSync(`${this.data.storageKey}_${key}`)
} }
} }
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment