add:新增优化功能

This commit is contained in:
2026-01-12 10:30:40 +08:00
parent be01fb211e
commit dbf7fa0c95
8 changed files with 426 additions and 168 deletions
+8 -18
View File
@@ -28,33 +28,23 @@
// 规范化路径格式进行比较
const normalizedLaunchPath = launchPath.replace(/\.html$/, '')
// 只在「单页面栈」时生效,避免影响正常多页面跳转(如下单后跳详情)
if (pages.length === 1 && currentRoute !== normalizedLaunchPath) {
// 只要当前不在目标页面,就进行一次跳转
// 下单流程不会受影响,因为在下单离开设备详情页时不会写入 launchPath
if (currentRoute !== normalizedLaunchPath) {
console.log('当前页面:', currentRoute, '目标页面:', normalizedLaunchPath)
// 清除启动路径标记(在跳转前清除,避免重复触发)
uni.removeStorageSync('launchPath')
// 跳转到启动路径(首页)
// 先尝试 switchTab(如果首页是 tabBar 页面)
// 使用 reLaunch 跳转到启动路径(首页)
uni.reLaunch({
url: normalizedLaunchPath,
success: () => {
console.log('成功跳转到启动路径(switchTab')
console.log('成功跳转到启动路径(reLaunch')
},
fail: (err) => {
console.log('switchTab 失败,使用 reLaunch:', err)
// 如果 switchTab 失败,使用 reLaunch(适用于非 tabBar 页面)
uni.reLaunch({
url: normalizedLaunchPath,
success: () => {
console.log('成功跳转到启动路径(reLaunch')
},
fail: (reLaunchErr) => {
console.error('跳转到启动路径失败:', reLaunchErr)
}
})
fail: (reLaunchErr) => {
console.error('跳转到启动路径失败:', reLaunchErr)
}
})
} else if (currentRoute === normalizedLaunchPath) {
} else {
// 如果已经在目标页面,清除启动路径标记
console.log('当前已在目标页面,清除启动路径标记')
uni.removeStorageSync('launchPath')