From d594ffb55da2b69e6f25b2f362aa67dc92ed3db5 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, 23 Jan 2026 17:31:57 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E8=87=AA=E5=AE=9A=E4=B9=89ta?= =?UTF-8?q?b-bar=E5=92=8C=E9=A6=96=E9=A1=B5=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- custom-tab-bar/index.js | 32 +------------------------- pages/index/index.js | 51 +++++++++++++++++++++-------------------- 2 files changed, 27 insertions(+), 56 deletions(-) diff --git a/custom-tab-bar/index.js b/custom-tab-bar/index.js index 704e6f4..86ff0e5 100644 --- a/custom-tab-bar/index.js +++ b/custom-tab-bar/index.js @@ -176,37 +176,7 @@ Component({ }) }, - // 跳转到估价页面 - goToEvaluatePage() { - wx.switchTab({ - url: '/pages/evaluate1/index', - success: (res) => { - console.log('跳转到估价页面成功:', res) - // 更新选中状态 - this.setData({ selected: 'evaluate' }) - // 更新全局状态 - const app = getApp() - if (app && app.globalData) { - app.globalData.currentTab = 'evaluate' - } - }, - fail: (err) => { - console.error('跳转到估价页面失败:', err) - // 失败时尝试使用reLaunch - wx.reLaunch({ - url: '/pages/evaluate1/index', - success: (res) => { - console.log('使用reLaunch跳转到估价页面成功:', res) - this.setData({ selected: 'evaluate' }) - const app = getApp() - if (app && app.globalData) { - app.globalData.currentTab = 'evaluate' - } - } - }) - } - }) - }, + diff --git a/pages/index/index.js b/pages/index/index.js index 32f3dee..814a773 100644 --- a/pages/index/index.js +++ b/pages/index/index.js @@ -719,6 +719,7 @@ Page({ const currentKeyword = this.data.searchKeyword; const currentRegion = this.data.selectedRegion; + // 合并setData调用,减少iOS卡顿 this.setData({ isRefreshing: true, page: 1, @@ -728,6 +729,7 @@ Page({ filteredGoods: [], // 清除缓存以确保获取最新数据 categoryQueryCache: {}, + goodsCache: [], lastDataTimestamp: 0, // 保存当前筛选条件,用于验证请求结果 refreshCategory: currentCategory, @@ -738,20 +740,14 @@ Page({ publishedHasMore: true, // 清除已浏览商品标记 viewedGoods: [], + isLoading: true, + loadingMore: false }) const timestamp = new Date().getTime(); const categoryParam = currentCategory === '全部' ? '' : currentCategory; const pageSize = this.data.pageSize; - // 强制刷新:清除所有缓存并重新从数据库加载 - this.setData({ - // 清除商品数据缓存 - goodsCache: [], - // 重置缓存时间戳 - lastDataTimestamp: 0 - }); - // 先只查询published状态的商品 const statusList = ['published']; const apiParams = { @@ -776,15 +772,17 @@ Page({ return; } - this.setData({ isRefreshing: false }) - if (res.success && res.products) { - this.processRefreshData(res.products) - wx.showToast({ - title: '刷新成功', - icon: 'success', - duration: 400 - }) + // 使用setTimeout延迟处理数据,避免阻塞主线程 + setTimeout(() => { + this.processRefreshData(res.products) + this.setData({ isRefreshing: false }); + wx.showToast({ + title: '刷新成功', + icon: 'success', + duration: 400 + }) + }, 0); } else if (res.products.length === 0) { // 如果published状态没有商品,则查询sold_out状态 console.log('没有published状态的商品,查询sold_out状态的商品'); @@ -810,19 +808,22 @@ Page({ return; } - this.setData({ isRefreshing: false }); - if (soldOutRes.success && soldOutRes.products && soldOutRes.products.length > 0) { - this.processRefreshData(soldOutRes.products); - wx.showToast({ - title: '刷新成功', - icon: 'success', - duration: 1500 - }); + // 使用setTimeout延迟处理数据,避免阻塞主线程 + setTimeout(() => { + this.processRefreshData(soldOutRes.products); + this.setData({ isRefreshing: false }); + wx.showToast({ + title: '刷新成功', + icon: 'success', + duration: 1500 + }); + }, 0); } else { this.setData({ isLoading: false, - loadingMore: false + loadingMore: false, + isRefreshing: false }); } })