|
|
|
@ -21,6 +21,60 @@ Vue.prototype.$getimg = Api_url |
|
|
|
Vue.mixin(minxin) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 全局封装跳转方法:this.$navigateTo({ url: 'xxx' }) |
|
|
|
* 支持在页面栈 >= 8 层时,关闭全部页面打开页面 |
|
|
|
*/ |
|
|
|
Vue.prototype.$navigateTo = function (options) { |
|
|
|
// 只接受 { url: 'xxx' } 的形式作为参数
|
|
|
|
if (typeof options !== 'object' || !options.url) { |
|
|
|
console.error('跳转参数错误', options); |
|
|
|
// uni.showToast({ title: '参数错误', icon: 'none' });
|
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
const url = options.url; // 获取要跳转的页面路径
|
|
|
|
const maxStackSize = 4; // 页面栈最大保留数量
|
|
|
|
|
|
|
|
const pages = getCurrentPages(); // 获取当前页面栈
|
|
|
|
const currentPage = pages[pages.length - 1]; |
|
|
|
const currentRoute = currentPage.route; |
|
|
|
|
|
|
|
|
|
|
|
console.log('view-页面栈长度:',pages.length) |
|
|
|
|
|
|
|
// 判断当前页面栈是否已满
|
|
|
|
if (pages.length >= maxStackSize) { |
|
|
|
// 页面栈已满,使用 reLaunch 关闭所有页面并跳转
|
|
|
|
uni.reLaunch({ |
|
|
|
url, |
|
|
|
success: () => { |
|
|
|
// 可选:用于调试
|
|
|
|
// console.log('已通过 reLaunch 跳转到:', url);
|
|
|
|
}, |
|
|
|
fail: (err) => { |
|
|
|
console.error('reLaunch 跳转失败:', err); |
|
|
|
// uni.showToast({ title: '页面跳转失败', icon: 'none' });
|
|
|
|
} |
|
|
|
}); |
|
|
|
} else { |
|
|
|
// 页面栈未满,正常使用 navigateTo 正常跳转
|
|
|
|
uni.navigateTo({ |
|
|
|
url, |
|
|
|
success: () => { |
|
|
|
// 可选:用于调试
|
|
|
|
// console.log('当前页面栈:', getCurrentPages().map(p => p.route));
|
|
|
|
}, |
|
|
|
fail: (err) => { |
|
|
|
console.error('navigateTo 跳转失败:', err); |
|
|
|
// uni.showToast({ title: '页面跳转失败', icon: 'none' });
|
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
const app = new Vue({ |
|
|
|
store, |
|
|
|
...App |
|
|
|
|