feat: 新增安全导航工具并全量替换原生路由调用,解决页面连击、栈超限与白屏问题
新增全局安全导航工具 safeNavigateTo/safeRedirectTo/safeNavigateBack,实现防连击锁、页面栈超限降级、无历史页平滑重定向逻辑。全量替换所有页面及组件中的 uni 原生路由调用,包括充值页、商家详情页、优惠券页、收藏页、订单页、会员中心、首页、登录页等多个页面,同时更新 tabbar 跳转逻辑杜绝 reLaunch 白屏,新增路由工具单元测试,优化分类页空数据兜底提示,提升页面跳转稳定性与用户体验。
这个提交包含在:
@@ -50,6 +50,11 @@
|
||||
import { iconUrl } from '@/common/store/ui.js'
|
||||
import messageApi from '@/common/api/message.js'
|
||||
import { useUserStore } from '@/common/store/index.js'
|
||||
import { safeNavigateTo, safeRedirectTo } from '@/common/utils/nav.js'
|
||||
|
||||
// 未读消息请求节流时间戳(毫秒)
|
||||
let lastFetchUnreadAt = 0
|
||||
let cachedUnreadCount = 0
|
||||
|
||||
export default {
|
||||
name: 'FcTabbar',
|
||||
@@ -98,26 +103,39 @@ export default {
|
||||
*/
|
||||
iconUrl,
|
||||
/**
|
||||
* 静默拉取当前用户未读消息总数
|
||||
* 静默拉取当前用户未读消息总数(带 10 秒防抖节流,避免高频切页重复刷接口)
|
||||
* @param {boolean} force 是否强制跳过缓存刷新
|
||||
*/
|
||||
async fetchUnread() {
|
||||
async fetchUnread(force = false) {
|
||||
let logged = false
|
||||
try {
|
||||
logged = !!useUserStore().isLogin.value
|
||||
} catch (e) {}
|
||||
if (!logged) {
|
||||
this.unreadCount = 0
|
||||
cachedUnreadCount = 0
|
||||
return
|
||||
}
|
||||
|
||||
const now = Date.now()
|
||||
if (!force && now - lastFetchUnreadAt < 10000) {
|
||||
this.unreadCount = cachedUnreadCount
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
const res = await messageApi.unreadCount()
|
||||
this.unreadCount = Number((res && res.count) || 0)
|
||||
const count = Number((res && res.count) || 0)
|
||||
this.unreadCount = count
|
||||
cachedUnreadCount = count
|
||||
lastFetchUnreadAt = now
|
||||
} catch (e) {
|
||||
this.unreadCount = 0
|
||||
this.unreadCount = cachedUnreadCount || 0
|
||||
}
|
||||
},
|
||||
/**
|
||||
* 切换底部导航目标页面
|
||||
* 杜绝 reLaunch 全局冷重启白屏,常驻 Tab 统一采用 safeRedirectTo 平滑切换
|
||||
* @param {Object} item 目标 Tab 配置对象
|
||||
* @param {number} idx 目标 Tab 索引
|
||||
*/
|
||||
@@ -126,22 +144,12 @@ export default {
|
||||
|
||||
// 中间突出加号(发布):作为独立模态表单页推入,保留前序页面栈,支持原路返回
|
||||
if (item.primary) {
|
||||
uni.navigateTo({ url: item.path })
|
||||
safeNavigateTo(item.path)
|
||||
return
|
||||
}
|
||||
|
||||
// 其余常驻 Tab 页面平滑切换:H5 环境优先 redirectTo 避免 reLaunch 闪屏
|
||||
// #ifdef H5
|
||||
uni.redirectTo({
|
||||
url: item.path,
|
||||
fail: () => {
|
||||
uni.reLaunch({ url: item.path })
|
||||
},
|
||||
})
|
||||
// #endif
|
||||
// #ifndef H5
|
||||
uni.reLaunch({ url: item.path })
|
||||
// #endif
|
||||
// 其余常驻 Tab 页面平滑切换:杜绝 reLaunch 造成的整个小程序销毁与白屏
|
||||
safeRedirectTo(item.path)
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
在新工单中引用
屏蔽一个用户