|
|
|
@ -738,15 +738,23 @@ Page({ |
|
|
|
const totalPages = res.totalPages || Math.ceil(totalGoods / this.data.pageSize); |
|
|
|
const hasMoreData = page < totalPages && res.products.length > 0; |
|
|
|
|
|
|
|
// 更新缓存
|
|
|
|
// 更新缓存(加载更多时追加数据)
|
|
|
|
const updatedCache = { ...this.data.categoryQueryCache }; |
|
|
|
updatedCache[cacheKey] = res.products; |
|
|
|
if (isLoadMore && updatedCache[cacheKey]) { |
|
|
|
// 追加新数据到缓存
|
|
|
|
const existingIds = new Set(updatedCache[cacheKey].map(item => item.id)); |
|
|
|
const newProducts = res.products.filter(item => !existingIds.has(item.id)); |
|
|
|
updatedCache[cacheKey] = [...updatedCache[cacheKey], ...newProducts]; |
|
|
|
} else { |
|
|
|
// 首次加载或刷新时替换缓存
|
|
|
|
updatedCache[cacheKey] = res.products; |
|
|
|
} |
|
|
|
|
|
|
|
this.setData({ |
|
|
|
hasMoreData, |
|
|
|
categoryQueryCache: updatedCache, |
|
|
|
lastDataTimestamp: now, |
|
|
|
goodsCache: res.products |
|
|
|
goodsCache: updatedCache[cacheKey] |
|
|
|
}) |
|
|
|
|
|
|
|
this.processGoodsData(res.products, isLoadMore) |
|
|
|
|