feat:app嵌套h5返回键

This commit is contained in:
liu.huiying@ebiz-digits.com
2025-03-14 17:32:00 +08:00
parent 8a2e54bf93
commit db11da048b
2 changed files with 22 additions and 20 deletions

View File

@@ -10,8 +10,6 @@ onMounted(async() => {
appBridge.setHeaderShown(true); appBridge.setHeaderShown(true);
// 设置系统状态栏明暗主题 // 设置系统状态栏明暗主题
appBridge.setStatusBarStyle('light'); appBridge.setStatusBarStyle('light');
// 设置禁止原生返回
appBridge.takeOverAndroidBack();
} }
}); });
</script> </script>

View File

@@ -27,12 +27,6 @@ router.beforeEach((to, from, next) => {
utils.setSessionStorage('xToken', to.query.digitalYiliToken); utils.setSessionStorage('xToken', to.query.digitalYiliToken);
} }
appBridge.setTitle(to.meta.title as string); appBridge.setTitle(to.meta.title as string);
next();
});
const app = createApp(App);
app.use(createPinia());
app.use(router);
app.mount('#app');
// 定义路由是否可以返回的判断 // 定义路由是否可以返回的判断
const routerCanGoBack = () => { const routerCanGoBack = () => {
const position = router.options.history.state?.position; const position = router.options.history.state?.position;
@@ -45,9 +39,19 @@ const callAppGoBack = () => {
}; };
// 添加 Android 返回按钮监听方法 // 添加 Android 返回按钮监听方法
window.onAndroidBack = () => { window.onAndroidBack = () => {
// 设置禁止原生返回
appBridge.takeOverAndroidBack();
if (routerCanGoBack()) { if (routerCanGoBack()) {
router.back(); // 使用 router.back() 而不是 router.goBack(),因为 Vue Router 使用 back() 方法 console.log('h5返回')
router.back(); // 执行 h5 路由返回
} else { } else {
console.log('app返回')
callAppGoBack(); // 调用 APP 的返回方法 callAppGoBack(); // 调用 APP 的返回方法
} }
}; };
next();
});
const app = createApp(App);
app.use(createPinia());
app.use(router);
app.mount('#app');