删除底部导航销冠,调整小程序前端架构

This commit is contained in:
zhonghua.li
2026-02-07 13:17:19 +08:00
parent 4e192fe9f9
commit 11cc4a7664
56 changed files with 6365 additions and 8590 deletions

View File

@@ -251,6 +251,10 @@
// 加载项目统计信息
this.loadProjectStatistics()
},
onReady() {
// 页面加载后的URL隐藏初始化只在用户导航时执行
this.initUrlHidingAfterPageLoad();
},
computed: {
userInfo() {
return store.userInfo || {}
@@ -685,7 +689,115 @@
} finally {
this.changePwdSubmitting = false
}
},
// 页面加载后的URL隐藏初始化只在用户导航时执行
initUrlHidingAfterPageLoad() {
// #ifdef H5
console.log('[UCenter][initUrlHidingAfterPageLoad] 开始页面加载后URL隐藏初始化');
// 路径映射
this.urlPathMap = {
'pages/furniture_customer/furniture_customer': '/customer',
'pages/furniture_reception/furniture_reception': '/reception',
'pages/furniture_top_sales/furniture_top_sales': '/top-sales',
'pages/ucenter/ucenter': '/profile'
};
// 策略只在用户明确进行页面导航时才隐藏URL
// 避免在页面刷新或直接访问时执行,以防止空白页面
// 监听tabBar切换事件用户主动导航
this.setupTabNavigationHiding();
// 监听浏览器前进后退(用户主动导航)
this.setupBrowserNavigationHiding();
console.log('[UCenter][initUrlHidingAfterPageLoad] URL隐藏系统已准备只在用户导航时激活');
// #endif
},
// 设置tab导航时的URL隐藏
setupTabNavigationHiding() {
// #ifdef H5
console.log('[UCenter][setupTabNavigationHiding] 设置tab导航监听');
// 监听uni-app的页面显示事件当通过tabBar切换到此页面时
if (typeof uni !== 'undefined' && uni.on) {
uni.on('onShow', () => {
console.log('[UCenter][setupTabNavigationHiding] 页面显示事件触发可能是tab切换');
// 延迟检查确保是tab切换而不是页面刷新
setTimeout(() => {
this.attemptUrlHidingForCurrentPage();
}, 300);
});
}
console.log('[UCenter][setupTabNavigationHiding] tab导航监听已设置');
// #endif
},
// 设置浏览器导航时的URL隐藏
setupBrowserNavigationHiding() {
// #ifdef H5
console.log('[UCenter][setupBrowserNavigationHiding] 设置浏览器导航监听');
// 监听前进后退按钮
window.addEventListener('popstate', () => {
console.log('[UCenter][setupBrowserNavigationHiding] 浏览器前进后退事件');
setTimeout(() => {
this.attemptUrlHidingForCurrentPage();
}, 200);
});
console.log('[UCenter][setupBrowserNavigationHiding] 浏览器导航监听已设置');
// #endif
},
// 为当前页面尝试URL隐藏
attemptUrlHidingForCurrentPage() {
// #ifdef H5
try {
const pages = getCurrentPages();
if (pages.length === 0) {
console.log('[UCenter][attemptUrlHidingForCurrentPage] 页面栈为空,跳过');
return;
}
const currentPage = pages[pages.length - 1];
const currentPath = currentPage.route;
if (!currentPath) {
console.log('[UCenter][attemptUrlHidingForCurrentPage] 页面路径为空,跳过');
return;
}
// 只为当前页面的路径执行URL隐藏
if (currentPath === 'pages/ucenter/ucenter' && this.urlPathMap[currentPath]) {
const shortPath = this.urlPathMap[currentPath];
const currentPathname = window.location.pathname;
if (currentPathname !== shortPath) {
console.log(`[UCenter][attemptUrlHidingForCurrentPage] 执行URL隐藏: ${currentPathname} -> ${shortPath}`);
// 使用try-catch包装history操作
try {
const newUrl = `${window.location.origin}${shortPath}`;
window.history.replaceState(null, '', newUrl);
console.log('[UCenter][attemptUrlHidingForCurrentPage] URL隐藏成功');
} catch (historyError) {
console.warn('[UCenter][attemptUrlHidingForCurrentPage] history操作失败:', historyError);
}
} else {
console.log('[UCenter][attemptUrlHidingForCurrentPage] URL已经是隐藏状态');
}
}
} catch (error) {
console.warn('[UCenter][attemptUrlHidingForCurrentPage] URL隐藏尝试失败:', error);
}
// #endif
}
}
}
</script>