fix:修复bug

This commit is contained in:
2026-01-22 10:52:58 +08:00
parent b0daa7b59b
commit 6a1dff4b94
46 changed files with 3779 additions and 2522 deletions
+37 -8
View File
@@ -249,16 +249,45 @@ class OrderMonitor {
export const orderMonitor = new OrderMonitor()
// 监听页面切换事件
uni.onAppRoute((route) => {
const pagePath = route.path || ''
const pageSegments = pagePath.split('/')
const pageName = pageSegments[pageSegments.length - 1]
// #ifdef MP-WEIXIN || APP-PLUS
if (typeof uni.onAppRoute === 'function') {
uni.onAppRoute((route) => {
const pagePath = route.path || ''
const pageSegments = pagePath.split('/')
const pageName = pageSegments[pageSegments.length - 1]
// 设置当前活跃页面
orderMonitor.setActivePage(pageName || null)
console.log('页面切换:', pagePath, '当前活跃页面:', pageName)
})
}
// #endif
// #ifdef H5
// H5环境下通过路由监听实现页面切换检测
if (typeof window !== 'undefined') {
const updateActivePageForH5 = () => {
const pagePath = window.location.pathname || window.location.hash
const pageSegments = pagePath.split('/')
const pageName = pageSegments[pageSegments.length - 1].replace(/[?#].*$/, '')
if (pageName) {
orderMonitor.setActivePage(pageName)
console.log('页面切换(H5):', pagePath, '当前活跃页面:', pageName)
}
}
// 设置当前活跃页面
orderMonitor.setActivePage(pageName || null)
// 监听 popstate 事件(浏览器前进后退)
window.addEventListener('popstate', updateActivePageForH5)
console.log('页面切换:', pagePath, '当前活跃页面:', pageName)
})
// 监听 hashchange 事件(hash 模式路由)
window.addEventListener('hashchange', updateActivePageForH5)
// 初始化时执行一次
updateActivePageForH5()
}
// #endif
// 页面加载时自动恢复监控上次的活跃订单(如果有)
const initOrderMonitor = () => {