fix: 修复鸿蒙元服务TabBar跳转失效问题
1. 修复多处页面onTabItemTap事件,使用uni.reLaunch兜底鸿蒙下switchTab静默失败的问题 2. 全局混入onTabItemTap兜底未手动处理的页面 3. 优化路由跳转逻辑,针对鸿蒙环境增加switchTab失败兜底和超时强制跳转 4. 优化可选链调用和空值判断,提升代码健壮性
This commit is contained in:
@@ -8,7 +8,21 @@
|
||||
export default {
|
||||
data() {
|
||||
return {}
|
||||
},
|
||||
// 鸿蒙元服务环境: 系统 TabBar 点击 uni.switchTab 静默失败
|
||||
// 手动接管 onTabItemTap, 用 uni.reLaunch 兜底, 确保 TabBar 跳转在鸿蒙下也能工作
|
||||
// #ifdef MP-HARMONY
|
||||
onTabItemTap(e) {
|
||||
if (!e || !e.pagePath) return;
|
||||
const pages = getCurrentPages();
|
||||
const currentPage = pages[pages.length - 1];
|
||||
const currentPath = currentPage ? '/' + currentPage.route : '';
|
||||
const targetPath = e.pagePath.startsWith('/') ? e.pagePath : '/' + e.pagePath;
|
||||
// 已经在目标页则不重复跳转
|
||||
if (currentPath === targetPath) return;
|
||||
uni.reLaunch({ url: targetPath });
|
||||
}
|
||||
// #endif
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
@@ -7,6 +7,20 @@ export default {
|
||||
shopInfo: null // 店铺信息
|
||||
};
|
||||
},
|
||||
// 鸿蒙元服务环境: 系统 TabBar 点击 uni.switchTab 静默失败
|
||||
// 手动接管 onTabItemTap, 用 uni.reLaunch 兜底, 确保 TabBar 跳转在鸿蒙下也能工作
|
||||
// #ifdef MP-HARMONY
|
||||
onTabItemTap(e) {
|
||||
if (!e || !e.pagePath) return;
|
||||
const pages = getCurrentPages();
|
||||
const currentPage = pages[pages.length - 1];
|
||||
const currentPath = currentPage ? '/' + currentPage.route : '';
|
||||
const targetPath = e.pagePath.startsWith('/') ? e.pagePath : '/' + e.pagePath;
|
||||
// 已经在目标页则不重复跳转
|
||||
if (currentPath === targetPath) return;
|
||||
uni.reLaunch({ url: targetPath });
|
||||
},
|
||||
// #endif
|
||||
onLoad(option) {
|
||||
// #ifdef H5
|
||||
// H5地图选择位置回调数据
|
||||
|
||||
Reference in New Issue
Block a user