feat:app嵌套h5返回键
This commit is contained in:
@@ -10,8 +10,6 @@ onMounted(async() => {
|
|||||||
appBridge.setHeaderShown(true);
|
appBridge.setHeaderShown(true);
|
||||||
// 设置系统状态栏明暗主题
|
// 设置系统状态栏明暗主题
|
||||||
appBridge.setStatusBarStyle('light');
|
appBridge.setStatusBarStyle('light');
|
||||||
// 设置禁止原生返回
|
|
||||||
appBridge.takeOverAndroidBack();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
40
src/main.ts
40
src/main.ts
@@ -27,27 +27,31 @@ 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);
|
||||||
|
// 定义路由是否可以返回的判断
|
||||||
|
const routerCanGoBack = () => {
|
||||||
|
const position = router.options.history.state?.position;
|
||||||
|
return typeof position === 'number' && position > 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
// 定义调用APP返回的方法
|
||||||
|
const callAppGoBack = () => {
|
||||||
|
appBridge.navigateBack(); // 使用现有的navigateBack方法替代不存在的goBack方法
|
||||||
|
};
|
||||||
|
// 添加 Android 返回按钮监听方法
|
||||||
|
window.onAndroidBack = () => {
|
||||||
|
// 设置禁止原生返回
|
||||||
|
appBridge.takeOverAndroidBack();
|
||||||
|
if (routerCanGoBack()) {
|
||||||
|
console.log('h5返回')
|
||||||
|
router.back(); // 执行 h5 路由返回
|
||||||
|
} else {
|
||||||
|
console.log('app返回')
|
||||||
|
callAppGoBack(); // 调用 APP 的返回方法
|
||||||
|
}
|
||||||
|
};
|
||||||
next();
|
next();
|
||||||
});
|
});
|
||||||
const app = createApp(App);
|
const app = createApp(App);
|
||||||
app.use(createPinia());
|
app.use(createPinia());
|
||||||
app.use(router);
|
app.use(router);
|
||||||
app.mount('#app');
|
app.mount('#app');
|
||||||
// 定义路由是否可以返回的判断
|
|
||||||
const routerCanGoBack = () => {
|
|
||||||
const position = router.options.history.state?.position;
|
|
||||||
return typeof position === 'number' && position > 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
// 定义调用APP返回的方法
|
|
||||||
const callAppGoBack = () => {
|
|
||||||
appBridge.navigateBack(); // 使用现有的navigateBack方法替代不存在的goBack方法
|
|
||||||
};
|
|
||||||
// 添加 Android 返回按钮监听方法
|
|
||||||
window.onAndroidBack = () => {
|
|
||||||
if (routerCanGoBack()) {
|
|
||||||
router.back(); // 使用 router.back() 而不是 router.goBack(),因为 Vue Router 使用 back() 方法
|
|
||||||
} else {
|
|
||||||
callAppGoBack(); // 调用 APP 的返回方法
|
|
||||||
}
|
|
||||||
};
|
|
||||||
Reference in New Issue
Block a user