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.
47 lines
948 B
47 lines
948 B
12 months ago
|
//只要是未登录状态,想要跳转到名单内的路径时,直接跳到登录页
|
||
|
// 页面白名单,不受拦截
|
||
|
const whiteList = [
|
||
|
'/pages/login/index'
|
||
|
]
|
||
|
|
||
|
function hasPermission(url) {
|
||
|
|
||
|
var isLogin = sessionStorage.getItem("hasLogin");
|
||
|
if (isLogin == null) {
|
||
|
isLogin = false
|
||
|
}
|
||
|
|
||
|
// 在白名单中或有登录判断条件可以直接跳转
|
||
|
if (whiteList.indexOf(url) !== -1 || isLogin) {
|
||
|
return true
|
||
|
}
|
||
|
return false
|
||
|
}
|
||
|
uni.addInterceptor('navigateTo', {
|
||
|
// 页面跳转前进行拦截, invoke根据返回值进行判断是否继续执行跳转
|
||
|
invoke(e) {
|
||
|
if (!hasPermission(e.url)) {
|
||
|
uni.reLaunch({
|
||
|
url: '/pages/login/index'
|
||
|
})
|
||
|
return false
|
||
|
}
|
||
|
return true
|
||
|
},
|
||
|
success(e) {}
|
||
|
})
|
||
|
|
||
|
uni.addInterceptor('switchTab', {
|
||
|
// tabbar页面跳转前进行拦截
|
||
|
invoke(e) {
|
||
|
if (!hasPermission(e.url)) {
|
||
|
uni.reLaunch({
|
||
|
url: '/pages/login/index'
|
||
|
})
|
||
|
return false
|
||
|
}
|
||
|
return true
|
||
|
},
|
||
|
success(e) {}
|
||
|
})
|