You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
62 lines
1.4 KiB
62 lines
1.4 KiB
9 months ago
|
/**
|
||
|
* @author 大雄
|
||
|
* @Date 2021年7月1日20:49:58
|
||
|
* @description 路由导航守卫(简单版,后续需要功能再完善)
|
||
|
*/
|
||
|
export default function() {
|
||
|
// 监听路由前进
|
||
|
function routerPush({ type = 'navigateTo' } = {}) {
|
||
|
routeWatchClearModal();
|
||
|
}
|
||
|
// 监听路由后退
|
||
|
function routerBack() {
|
||
|
routeWatchClearModal();
|
||
|
}
|
||
|
|
||
|
// 页面跳转后,销毁当前页面未关闭的弹框
|
||
|
function routeWatchClearModal() {
|
||
|
try {
|
||
|
var FyShowModalView = plus.nativeObj.View.getViewById("FyShowModalView");
|
||
|
if (FyShowModalView) {
|
||
|
FyShowModalView.clear();
|
||
|
}
|
||
|
var FyShowModalCancel = plus.nativeObj.View.getViewById("FyShowModalCancel");
|
||
|
if (FyShowModalCancel) {
|
||
|
FyShowModalCancel.clear();
|
||
|
}
|
||
|
var FyShowModalConfirm = plus.nativeObj.View.getViewById("FyShowModalConfirm");
|
||
|
if (FyShowModalConfirm) {
|
||
|
FyShowModalConfirm.clear();
|
||
|
}
|
||
|
} catch(err) {
|
||
|
console.log(err);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
uni.addInterceptor('navigateTo', {
|
||
|
success(e) {
|
||
|
routerPush({ type: 'navigateTo' });
|
||
|
}
|
||
|
})
|
||
|
uni.addInterceptor('redirectTo', {
|
||
|
success(e) {
|
||
|
routerPush({ type: 'redirectTo' });
|
||
|
}
|
||
|
})
|
||
|
uni.addInterceptor('reLaunch', {
|
||
|
success(e) {
|
||
|
routerPush({ type: 'reLaunch' });
|
||
|
}
|
||
|
})
|
||
|
uni.addInterceptor('switchTab', {
|
||
|
success(e) {
|
||
|
routerPush({ type: 'switchTab' });
|
||
|
}
|
||
|
})
|
||
|
uni.addInterceptor('navigateBack', {
|
||
|
success(e) {
|
||
|
routerBack();
|
||
|
}
|
||
|
})
|
||
|
|
||
|
}
|