fix(order): 修复订单列表页下单后不自动刷新的问题
- 新增 Taro.useDidShow 钩子处理 tabBar 页面显示时的刷新 - 使用 isFirstShow 跳过首次显示,防止重复加载 - 切换 tab 时重置所有 tab 的 initialized 状态 - 下单后立即刷新当前 tab 订单列表,确保显示最新数据 - 解决 switchTab 不重新挂载导致订单数据不刷新的根因
This commit is contained in:
@@ -124,6 +124,23 @@ const OrderListPage: React.FC = () => {
|
||||
}
|
||||
}, [tabIndex, isLoggedIn, user?.userId])
|
||||
|
||||
// 页面每次显示时刷新数据(tabBar 页 switchTab 不会重新挂载组件)
|
||||
const isFirstShow = useRef(true)
|
||||
Taro.useDidShow(() => {
|
||||
// 首次显示由 useEffect 处理,跳过
|
||||
if (isFirstShow.current) {
|
||||
isFirstShow.current = false
|
||||
return
|
||||
}
|
||||
const userId = userIdRef.current
|
||||
if (!userId) return
|
||||
|
||||
// 标记所有 tab 为未初始化,切换时会重新加载
|
||||
setTabStates(prev => prev.map(s => ({ ...s, initialized: false })))
|
||||
// 立即刷新当前 tab
|
||||
loadOrders(tabIndex, 1)
|
||||
})
|
||||
|
||||
const handleLoadMore = () => {
|
||||
if (!currentState.finished && !currentState.loading) {
|
||||
loadOrders(tabIndex, currentState.page + 1)
|
||||
|
||||
Reference in New Issue
Block a user