From d2e63ea81b9380cc4912eb146fefb0ba237cddb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E9=A3=9E=E6=B4=8B?= <15778543+xufeiyang6017@user.noreply.gitee.com> Date: Mon, 29 Dec 2025 15:12:15 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E4=B8=8B=E6=BB=91?= =?UTF-8?q?=E5=8A=A0=E8=BD=BD=E6=9B=B4=E5=A4=9A=E6=95=B0=E6=8D=AE=E7=BC=93?= =?UTF-8?q?=E5=AD=98=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 加载更多时追加数据到缓存而非覆盖 - 去重处理避免重复数据 - 确保缓存保存所有页数据 --- pages/index/index.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/pages/index/index.js b/pages/index/index.js index d6d7ebb..9fc8961 100644 --- a/pages/index/index.js +++ b/pages/index/index.js @@ -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)