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