From a3ab225520d23b20995efecfac48e9302b6a247f 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: Fri, 26 Dec 2025 17:13:28 +0800
Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BC=98=E5=8C=96=E9=A6=96=E9=A1=B5?=
=?UTF-8?q?=E8=BF=94=E5=9B=9E=E6=97=B6=E7=9A=84=E5=8D=A1=E9=A1=BF=E9=97=AE?=
=?UTF-8?q?=E9=A2=98?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
- 避免onShow每次都重新加载商品数据
- 添加needRefresh标志控制是否需要刷新
- 在onHide/onUnload时标记需要刷新
- 返回首页时仅在需要时才刷新列表
---
pages/index/index.js | 16 +++++++++++++++-
pages/index/index.wxml | 4 ++--
2 files changed, 17 insertions(+), 3 deletions(-)
diff --git a/pages/index/index.js b/pages/index/index.js
index c07bc87..0900e0d 100644
--- a/pages/index/index.js
+++ b/pages/index/index.js
@@ -44,6 +44,9 @@ Page({
previewImageUrls: [],
previewImageIndex: 0,
showImagePreview: false,
+
+ // 页面刷新标志
+ needRefresh: false,
},
// 跳转到聊天页面
@@ -189,7 +192,18 @@ Page({
app.updateCurrentTab('index');
app.globalData.showTabBar = true;
this.checkAndRestoreLoginStatus()
- this.refreshGoodsList()
+ if (this.data.needRefresh) {
+ this.setData({ needRefresh: false })
+ this.refreshGoodsList()
+ }
+ },
+
+ onHide: function () {
+ this.setData({ needRefresh: true })
+ },
+
+ onUnload: function () {
+ this.setData({ needRefresh: true })
},
onPullDownRefresh: function() {
diff --git a/pages/index/index.wxml b/pages/index/index.wxml
index 2a1f895..49a02f5 100644
--- a/pages/index/index.wxml
+++ b/pages/index/index.wxml
@@ -218,7 +218,7 @@
{{item.negotiateStatus}}
- 已售{{item.sales || item.reservedCount || 0}}件
+ 已有{{item.reservedCount || 0}}人收藏
{{item.region || ''}}
@@ -276,7 +276,7 @@
{{item.negotiateStatus}}
- 已售{{item.sales || item.reservedCount || 0}}件
+ 已有{{item.reservedCount || 0}}人收藏
{{item.region || ''}}