Browse Source

更新自定义tab-bar和首页逻辑

pull/19/head
徐飞洋 1 month ago
parent
commit
d594ffb55d
  1. 32
      custom-tab-bar/index.js
  2. 51
      pages/index/index.js

32
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'
}
}
})
}
})
},

51
pages/index/index.js

@ -719,6 +719,7 @@ Page({
const currentKeyword = this.data.searchKeyword; const currentKeyword = this.data.searchKeyword;
const currentRegion = this.data.selectedRegion; const currentRegion = this.data.selectedRegion;
// 合并setData调用,减少iOS卡顿
this.setData({ this.setData({
isRefreshing: true, isRefreshing: true,
page: 1, page: 1,
@ -728,6 +729,7 @@ Page({
filteredGoods: [], filteredGoods: [],
// 清除缓存以确保获取最新数据 // 清除缓存以确保获取最新数据
categoryQueryCache: {}, categoryQueryCache: {},
goodsCache: [],
lastDataTimestamp: 0, lastDataTimestamp: 0,
// 保存当前筛选条件,用于验证请求结果 // 保存当前筛选条件,用于验证请求结果
refreshCategory: currentCategory, refreshCategory: currentCategory,
@ -738,20 +740,14 @@ Page({
publishedHasMore: true, publishedHasMore: true,
// 清除已浏览商品标记 // 清除已浏览商品标记
viewedGoods: [], viewedGoods: [],
isLoading: true,
loadingMore: false
}) })
const timestamp = new Date().getTime(); const timestamp = new Date().getTime();
const categoryParam = currentCategory === '全部' ? '' : currentCategory; const categoryParam = currentCategory === '全部' ? '' : currentCategory;
const pageSize = this.data.pageSize; const pageSize = this.data.pageSize;
// 强制刷新:清除所有缓存并重新从数据库加载
this.setData({
// 清除商品数据缓存
goodsCache: [],
// 重置缓存时间戳
lastDataTimestamp: 0
});
// 先只查询published状态的商品 // 先只查询published状态的商品
const statusList = ['published']; const statusList = ['published'];
const apiParams = { const apiParams = {
@ -776,15 +772,17 @@ Page({
return; return;
} }
this.setData({ isRefreshing: false })
if (res.success && res.products) { if (res.success && res.products) {
this.processRefreshData(res.products) // 使用setTimeout延迟处理数据,避免阻塞主线程
wx.showToast({ setTimeout(() => {
title: '刷新成功', this.processRefreshData(res.products)
icon: 'success', this.setData({ isRefreshing: false });
duration: 400 wx.showToast({
}) title: '刷新成功',
icon: 'success',
duration: 400
})
}, 0);
} else if (res.products.length === 0) { } else if (res.products.length === 0) {
// 如果published状态没有商品,则查询sold_out状态 // 如果published状态没有商品,则查询sold_out状态
console.log('没有published状态的商品,查询sold_out状态的商品'); console.log('没有published状态的商品,查询sold_out状态的商品');
@ -810,19 +808,22 @@ Page({
return; return;
} }
this.setData({ isRefreshing: false });
if (soldOutRes.success && soldOutRes.products && soldOutRes.products.length > 0) { if (soldOutRes.success && soldOutRes.products && soldOutRes.products.length > 0) {
this.processRefreshData(soldOutRes.products); // 使用setTimeout延迟处理数据,避免阻塞主线程
wx.showToast({ setTimeout(() => {
title: '刷新成功', this.processRefreshData(soldOutRes.products);
icon: 'success', this.setData({ isRefreshing: false });
duration: 1500 wx.showToast({
}); title: '刷新成功',
icon: 'success',
duration: 1500
});
}, 0);
} else { } else {
this.setData({ this.setData({
isLoading: false, isLoading: false,
loadingMore: false loadingMore: false,
isRefreshing: false
}); });
} }
}) })

Loading…
Cancel
Save