任意页面都可以作为首页,回到这个页面点关闭,可关闭webview
。
router
的 beforeEach
中,判断是否是首页,如果是,则设置sessionStorage
的closeOnSite
为3
或4
。
ts
router.beforeEach((to: ToRouteType, from, next) => {
if ((!from?.path || from.fullPath === '/') && to.name === 'single-match-detail') {
window.sessionStorage.setItem('closeOnSite', '3');
}
if ((!from?.path || from.fullPath === '/') && to.name === 'my-awards') {
window.sessionStorage.setItem('closeOnSite', '4');
}
next();
});
关闭的时候,判断这个变量,如何命中,就关闭,否则返回。
ts
clickCancel() {
if (window.sessionStorage.getItem('closeOnSite') === '4' && this.$route.name === 'my-awards') {
this.closeView();
} else {
this.$router.back();
}
},
closeView() {
if ((this.env.isMsdkV5) && window.msdkCall) {
const closeWebView = '{"MsdkMethod":"closeWebView"}';
window.msdkCall(closeWebView);
} else if ((this.env.isMsdk || this.isMacintoshMsdk) && window.msdkCloseWebview) {
if (!this.env.isIOS || (this.env.isIOS && window.msdkiOSHandler)) {
window.msdkCloseWebview();
}
} else if (this.env.isSlugSdk) {
if (window.customBrowserInterface) {
window.customBrowserInterface.closeWebview();
}
} else {
window.location.href = 'about:blank';
}
},