|
|
|
@ -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) { |
|
|
|
// 使用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) { |
|
|
|
// 使用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 |
|
|
|
}); |
|
|
|
} |
|
|
|
}) |
|
|
|
|