feat: 新增安全导航工具并全量替换原生路由调用,解决页面连击、栈超限与白屏问题

新增全局安全导航工具 safeNavigateTo/safeRedirectTo/safeNavigateBack,实现防连击锁、页面栈超限降级、无历史页平滑重定向逻辑。全量替换所有页面及组件中的 uni 原生路由调用,包括充值页、商家详情页、优惠券页、收藏页、订单页、会员中心、首页、登录页等多个页面,同时更新 tabbar 跳转逻辑杜绝 reLaunch 白屏,新增路由工具单元测试,优化分类页空数据兜底提示,提升页面跳转稳定性与用户体验。
这个提交包含在:
2026-11-04 10:59:49 +08:00
父节点 de7b96ae9f
当前提交 25a3a3d52f
共有 18 个文件被更改,包括 427 次插入 和 256 次删除

查看文件

@@ -267,6 +267,7 @@ import { ORDER_TEXT, ORDER_ICON_KEY } from '@/common/constants/ui.js'
import { formatTime } from '@/common/utils/format.js'
import { iconUrl, loadUiConfig, uiState } from '@/common/store/ui.js'
import { pay } from '@/common/utils/pay.js'
import { safeNavigateBack } from '@/common/utils/nav.js'
export default {
components: { FcNavbar, FcEmpty },
@@ -533,30 +534,10 @@ export default {
},
/**
* 点击左上角返回按钮
* 优先 navigateBack,若无历史页面或返回失败则重定向至我的订单,绝不卡死失效
* 统一通过 safeNavigateBack 执行(优先返回上一页,无历史页面安全重定向至我的订单)
*/
handleNavBack() {
const pages = (typeof getCurrentPages === 'function') ? getCurrentPages() : []
if (pages && pages.length > 1) {
uni.navigateBack({
delta: 1,
fail: () => {
uni.redirectTo({
url: '/pages/member/orders',
fail: () => {
uni.reLaunch({ url: '/pages/index/index' })
},
})
},
})
} else {
uni.redirectTo({
url: '/pages/member/orders',
fail: () => {
uni.reLaunch({ url: '/pages/index/index' })
},
})
}
safeNavigateBack('/pages/member/orders', 1)
},
},
}

查看文件

@@ -82,6 +82,7 @@
import FcNavbar from '@/components/fc-navbar/fc-navbar.vue'
import { formatTime } from '@/common/utils/format.js'
import { useUserStore } from '@/common/store/index.js'
import { safeRedirectTo } from '@/common/utils/nav.js'
export default {
name: 'PaymentSuccessPage',
@@ -211,13 +212,13 @@ export default {
handlePrimaryAction() {
if (this.type === 'member') {
// 返回会员中心页面刷新状态
uni.redirectTo({ url: '/pages/member/index' })
safeRedirectTo('/pages/member/index')
} else if (this.type === 'post') {
uni.redirectTo({ url: '/pages/post/mine' })
safeRedirectTo('/pages/post/mine')
} else if (this.type === 'recharge') {
uni.redirectTo({ url: '/pages/member/orders' })
safeRedirectTo('/pages/member/orders')
} else {
uni.switchTab({ url: '/pages/index/index' })
safeRedirectTo('/pages/index/index')
}
},
@@ -225,7 +226,7 @@ export default {
* 点击次操作按钮:返回个人中心
*/
handleSecondaryAction() {
uni.switchTab({ url: '/pages/mine/index' })
safeRedirectTo('/pages/mine/index')
},
},
}