2024-12-03 09:34:24 +08:00
|
|
|
// 需要登录的界面
|
|
|
|
let needLogin = [
|
2024-12-11 19:36:51 +08:00
|
|
|
"/pages/my/mySetting",
|
|
|
|
"/pages/mobile_web/workshops/index",
|
|
|
|
"/pages/mobile_web/my/child_pages/contact"
|
2024-12-03 09:34:24 +08:00
|
|
|
];
|
|
|
|
// 多端通用路由
|
|
|
|
let filterRoute = [
|
|
|
|
"/uview-ui/components/u-avatar-cropper/u-avatar-cropper",
|
2024-12-05 11:46:54 +08:00
|
|
|
"/pages/index/rich-detail",
|
|
|
|
"/pages/index/webview",
|
2024-12-03 09:34:24 +08:00
|
|
|
];
|
|
|
|
// 拦截类型
|
|
|
|
let list = ["navigateTo", "redirectTo", "reLaunch", "switchTab"];
|
|
|
|
|
|
|
|
const install = (vm) => {
|
|
|
|
// #ifdef H5
|
|
|
|
// H5路由拦截,用于拦截用户地址栏输入地址
|
|
|
|
const token = vm.$store.state.vuex_token;
|
|
|
|
let locationUrl = window.location.href.split("/#")[1];
|
|
|
|
if(needLogin.includes(locationUrl)&&!token){
|
|
|
|
uni.showToast({
|
|
|
|
title: '该页面需要登录才能访问,请先登录',
|
|
|
|
icon: 'none'
|
|
|
|
});
|
|
|
|
uni.navigateTo({
|
2024-12-11 19:36:51 +08:00
|
|
|
url: "/pages/mobile_web/my/child_pages/login?nextUrl="+locationUrl
|
2024-12-03 09:34:24 +08:00
|
|
|
});
|
|
|
|
} else if(!filterRoute.includes(locationUrl)&&locationUrl!=='/'&&vm.$store.state.current_platform&&
|
|
|
|
locationUrl.indexOf(vm.$store.state.current_platform)==-1){
|
|
|
|
uni.navigateTo({
|
|
|
|
url: `/pages/${vm.$store.state.current_platform}/index/index`,
|
|
|
|
complete() {
|
|
|
|
setTimeout(()=>{
|
|
|
|
uni.showToast({
|
|
|
|
title: '该设备端无法访问对应页面!',
|
|
|
|
icon: 'none',
|
|
|
|
});
|
|
|
|
},500)
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
// #endif
|
|
|
|
|
|
|
|
// uniapp跳转页面路由拦截器
|
|
|
|
list.forEach(item => {
|
|
|
|
uni.addInterceptor(item, {
|
|
|
|
invoke(e) {
|
|
|
|
const token = vm.$store.state.vuex_token;
|
|
|
|
// console.log(vm.$store.state.current_platform)
|
|
|
|
const url = e.url.split('?')[0];
|
|
|
|
if (needLogin.includes(url) && !token) {
|
|
|
|
console.log(url)
|
|
|
|
uni.showToast({
|
|
|
|
title: '该页面需要登录才能访问,请先登录',
|
|
|
|
icon: 'none'
|
|
|
|
});
|
|
|
|
uni.navigateTo({
|
2024-12-11 19:36:51 +08:00
|
|
|
url: "/pages/mobile_web/my/child_pages/login?nextUrl="+e.url
|
2024-12-03 09:34:24 +08:00
|
|
|
});
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// #ifndef APP
|
|
|
|
else if(!filterRoute.includes(url)&&url.indexOf(vm.$store.state.current_platform)==-1){
|
|
|
|
uni.showToast({
|
|
|
|
title: '该设备端无法访问对应页面!',
|
|
|
|
icon: 'none'
|
|
|
|
});
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// #endif
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
export default {
|
|
|
|
install
|
|
|
|
}
|