2024-06-04 22:00:48 +08:00
|
|
|
import { getToken } from "@/utils/auth";
|
2024-04-23 23:01:35 +08:00
|
|
|
|
2024-06-08 19:02:43 +08:00
|
|
|
|
2024-06-08 18:49:58 +08:00
|
|
|
// // 登录页面
|
|
|
|
// const loginPage = "/pages/loginInfo/login";
|
2024-06-04 22:00:48 +08:00
|
|
|
|
2024-06-08 18:49:58 +08:00
|
|
|
// // 页面白名单
|
|
|
|
// const whiteList = [
|
|
|
|
// "/pages/loginInfo/login",
|
|
|
|
// "/pages/register",
|
|
|
|
// "/pages/common/webview/index",
|
|
|
|
// ];
|
2024-06-08 19:02:43 +08:00
|
|
|
|
2024-04-23 23:01:35 +08:00
|
|
|
// 登录页面
|
2024-06-08 18:42:51 +08:00
|
|
|
const loginPage = "/pages/login";
|
2024-06-04 22:00:48 +08:00
|
|
|
|
2024-04-23 23:01:35 +08:00
|
|
|
// 页面白名单
|
|
|
|
const whiteList = [
|
2024-06-08 18:42:51 +08:00
|
|
|
"/pages/login",
|
2024-06-13 23:15:52 +08:00
|
|
|
"/pages/loginInfo/upPassword",
|
|
|
|
"/pages/loginInfo/phoneCode",
|
|
|
|
"/pages/loginInfo/register",
|
2024-06-04 22:00:48 +08:00
|
|
|
"/pages/common/webview/index",
|
|
|
|
];
|
2024-06-08 19:02:43 +08:00
|
|
|
|
2024-04-23 23:01:35 +08:00
|
|
|
|
2024-06-08 18:49:58 +08:00
|
|
|
// // 检查地址白名单
|
2024-06-13 23:15:52 +08:00
|
|
|
function checkWhite(url) {
|
|
|
|
const path = url.split("?")[0];
|
|
|
|
return whiteList.indexOf(path) !== -1;
|
|
|
|
}
|
2024-04-23 23:01:35 +08:00
|
|
|
|
|
|
|
// 页面跳转验证拦截器
|
2024-06-13 23:15:52 +08:00
|
|
|
let list = ["navigateTo", "redirectTo", "reLaunch", "switchTab"]
|
|
|
|
list.forEach(item => {
|
|
|
|
uni.addInterceptor(item, {
|
|
|
|
invoke(to) {
|
|
|
|
|
|
|
|
if (getToken()) {
|
|
|
|
if (to.url === loginPage) {
|
|
|
|
console.log("to:",to);
|
|
|
|
uni.reLaunch({ url: "/" })
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
} else {
|
|
|
|
if (checkWhite(to.url)) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
uni.reLaunch({ url: loginPage })
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
},
|
|
|
|
fail(err) {
|
|
|
|
console.log("错误信息:",err)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|