fix(user): 修复「我的」页订单数量统计显示为 0 的问题
- 修正 UserOrderStats 接口字段与后端 DTO 完全对齐 - getUserOrderStats() 读取后端真实字段,数值使用 Number(x) 兜底 - 「我的订单」快捷入口 count 和 status 与 OrderListStatus 枚举对齐 - localStorage 缓存 key 升级至 v3,避免旧缓存干扰冷启动渲染 - 保证所有跳转订单列表的入口传递正确 status 参数,防止跳转错误的 tab
This commit is contained in:
@@ -41,7 +41,8 @@ const UserPage: React.FC = () => {
|
||||
cacheKey: 'user_order_stats',
|
||||
cacheTime: 30 * 1000,
|
||||
onSuccess: (data) => {
|
||||
Taro.setStorageSync('user_order_stats_v2', data)
|
||||
// v3: 字段结构变更(与后端 UserOrderStats DTO 对齐),旧版 v2 缓存自动失效
|
||||
Taro.setStorageSync('user_order_stats_v3', data)
|
||||
},
|
||||
})
|
||||
|
||||
@@ -51,7 +52,7 @@ const UserPage: React.FC = () => {
|
||||
// 冷启动优化:先从 localStorage 读取缓存即时展示,消除骨架屏
|
||||
const cachedCardStats = Taro.getStorageSync('user_card_stats_v2')
|
||||
if (cachedCardStats) mutateCardStats(cachedCardStats)
|
||||
const cachedOrderStats = Taro.getStorageSync('user_order_stats_v2')
|
||||
const cachedOrderStats = Taro.getStorageSync('user_order_stats_v3')
|
||||
if (cachedOrderStats) mutateOrderStats(cachedOrderStats)
|
||||
// 然后发起网络请求(stale-while-revalidate 后台刷新)
|
||||
runCardStats()
|
||||
@@ -78,7 +79,7 @@ const UserPage: React.FC = () => {
|
||||
if (cachedCardStats) {
|
||||
mutateCardStats(cachedCardStats)
|
||||
}
|
||||
const cachedOrderStats = Taro.getStorageSync('user_order_stats_v2')
|
||||
const cachedOrderStats = Taro.getStorageSync('user_order_stats_v3')
|
||||
if (cachedOrderStats) {
|
||||
mutateOrderStats(cachedOrderStats)
|
||||
}
|
||||
@@ -263,10 +264,11 @@ const UserPage: React.FC = () => {
|
||||
</View>
|
||||
<View className='grid grid-cols-4 gap-2'>
|
||||
{[
|
||||
{ icon: '💳', label: '待付款', status: 0, count: orderStats?.pending },
|
||||
{ icon: '📦', label: '待发货', status: 1, count: orderStats?.paid },
|
||||
{ icon: '🚚', label: '待收货', status: 2, count: orderStats?.shipped },
|
||||
{ icon: '✅', label: '已完成', status: 3, count: orderStats?.completed },
|
||||
// status 与 OrderListStatus 对齐:0待付款 1待发货 3待收货 5已完成
|
||||
{ icon: '💳', label: '待付款', status: 0, count: orderStats?.waitPay },
|
||||
{ icon: '📦', label: '待发货', status: 1, count: orderStats?.waitDeliver },
|
||||
{ icon: '🚚', label: '待收货', status: 3, count: orderStats?.waitReceive },
|
||||
{ icon: '✅', label: '已完成', status: 5, count: orderStats?.completed },
|
||||
].map(item => (
|
||||
<View
|
||||
key={item.status}
|
||||
|
||||
Reference in New Issue
Block a user