Browse Source

perf: 优化首页返回时的卡顿问题

- 避免onShow每次都重新加载商品数据
- 添加needRefresh标志控制是否需要刷新
- 在onHide/onUnload时标记需要刷新
- 返回首页时仅在需要时才刷新列表
pull/1/head
徐飞洋 2 months ago
parent
commit
a3ab225520
  1. 16
      pages/index/index.js
  2. 4
      pages/index/index.wxml

16
pages/index/index.js

@ -44,6 +44,9 @@ Page({
previewImageUrls: [], previewImageUrls: [],
previewImageIndex: 0, previewImageIndex: 0,
showImagePreview: false, showImagePreview: false,
// 页面刷新标志
needRefresh: false,
}, },
// 跳转到聊天页面 // 跳转到聊天页面
@ -189,7 +192,18 @@ Page({
app.updateCurrentTab('index'); app.updateCurrentTab('index');
app.globalData.showTabBar = true; app.globalData.showTabBar = true;
this.checkAndRestoreLoginStatus() 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() { onPullDownRefresh: function() {

4
pages/index/index.wxml

@ -218,7 +218,7 @@
<view class="status-tag negotiate-{{item.negotiateStatus === '可议价' ? 'yes' : 'no'}}">{{item.negotiateStatus}}</view> <view class="status-tag negotiate-{{item.negotiateStatus === '可议价' ? 'yes' : 'no'}}">{{item.negotiateStatus}}</view>
</view> </view>
<view class="product-meta"> <view class="product-meta">
<text class="sales-count">已售{{item.sales || item.reservedCount || 0}}件</text> <text class="sales-count">已有{{item.reservedCount || 0}}人收藏</text>
<text class="product-location">{{item.region || ''}}</text> <text class="product-location">{{item.region || ''}}</text>
</view> </view>
</view> </view>
@ -276,7 +276,7 @@
<view class="status-tag negotiate-{{item.negotiateStatus === '可议价' ? 'yes' : 'no'}}">{{item.negotiateStatus}}</view> <view class="status-tag negotiate-{{item.negotiateStatus === '可议价' ? 'yes' : 'no'}}">{{item.negotiateStatus}}</view>
</view> </view>
<view class="product-meta"> <view class="product-meta">
<text class="sales-count">已售{{item.sales || item.reservedCount || 0}}件</text> <text class="sales-count">已有{{item.reservedCount || 0}}人收藏</text>
<text class="product-location">{{item.region || ''}}</text> <text class="product-location">{{item.region || ''}}</text>
</view> </view>
</view> </view>

Loading…
Cancel
Save