From 59ac5ddc60b618573a208022b43ff52bc41ddec7 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, 26 Jan 2026 11:55:59 +0800 Subject: [PATCH] Fix filter function for goods list --- pages/goods/index.js | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/pages/goods/index.js b/pages/goods/index.js index 29db90b..31ec857 100644 --- a/pages/goods/index.js +++ b/pages/goods/index.js @@ -558,13 +558,17 @@ Page({ if (!isLoadMore && this.isCacheValid()) { const cache = this.data.cache + // 重新应用当前筛选条件到缓存数据 + const allCachedGoods = [...cache.publishedGoods, ...cache.soldOutGoods] + const filteredGoods = this.filterGoodsList(allCachedGoods) + this.setData({ - goodsList: [...cache.publishedGoods, ...cache.soldOutGoods], + goodsList: filteredGoods, publishedLoaded: true, soldOutLoaded: true, publishedHasMore: false, soldOutHasMore: false, - total: cache.publishedGoods.length + cache.soldOutGoods.length + total: filteredGoods.length }) return @@ -586,9 +590,12 @@ Page({ this.data.searchKeyword ) - newGoods = result.goods + // 应用筛选逻辑 + let filteredGoods = this.filterGoodsList(result.goods) + + newGoods = filteredGoods updatedPublishedHasMore = result.hasMore - publishedGoods = result.goods + publishedGoods = filteredGoods // 如果是加载更多,追加数据;否则替换数据 this.setData({ @@ -620,9 +627,12 @@ Page({ this.data.searchKeyword ) - newGoods = result.goods + // 应用筛选逻辑 + let filteredGoods = this.filterGoodsList(result.goods) + + newGoods = filteredGoods updatedSoldOutHasMore = result.hasMore - soldOutGoods = result.goods + soldOutGoods = filteredGoods // 追加售空商品数据 this.setData({ @@ -649,9 +659,13 @@ Page({ const publishedResult = await this.loadGoodsData(1, 1000, 'published', this.data.searchKeyword) const soldOutResult = await this.loadGoodsData(1, 1000, 'sold_out', this.data.searchKeyword) + // 应用筛选逻辑到缓存数据 + const filteredPublishedGoods = this.filterGoodsList(publishedResult.goods) + const filteredSoldOutGoods = this.filterGoodsList(soldOutResult.goods) + this.setData({ - 'cache.publishedGoods': publishedResult.goods, - 'cache.soldOutGoods': soldOutResult.goods, + 'cache.publishedGoods': filteredPublishedGoods, + 'cache.soldOutGoods': filteredSoldOutGoods, 'cache.timestamp': Date.now() }) }