TalentService-mobile/common/routerInterceptor.js

34 lines
702 B
JavaScript
Raw Normal View History

2024-10-27 00:26:19 +08:00
// 需要登录的界面
let needLogin = [
2024-10-31 21:24:54 +08:00
"/pages/my/mySetting"
2024-10-27 00:26:19 +08:00
];
// 拦截类型
let list = ["navigateTo", "redirectTo", "reLaunch", "switchTab"];
const install = (Vue,vm) => {
list.forEach(item => {
uni.addInterceptor(item, {
invoke(e) {
2024-10-31 21:24:54 +08:00
const token = vm.$store.state.vuex_token;
console.log(token)
2024-10-27 00:26:19 +08:00
const url = e.url.split('?')[0];
if (needLogin.includes(url) && !token) {
2024-10-31 21:24:54 +08:00
console.log(url)
2024-10-27 00:26:19 +08:00
uni.showToast({
title: '该页面需要登录才能访问,请先登录',
icon: 'none'
});
uni.navigateTo({
2024-10-31 21:24:54 +08:00
url: "/pages/my/wxLogin?nextUrl="+e.url
2024-10-27 00:26:19 +08:00
});
return false;
}
return true;
}
});
});
}
export default {
install
}