55 lines
1.2 KiB
JavaScript
55 lines
1.2 KiB
JavaScript
|
|
//不需要登陆可访问页面(白名单)
|
|||
|
|
export const whiteList = [
|
|||
|
|
'/pages/login/login', //登陆
|
|||
|
|
]
|
|||
|
|
|
|||
|
|
export function hasPermission(url, compulsion = false) {
|
|||
|
|
// 在白名单中或有token,直接跳转
|
|||
|
|
url = url.indexOf("?") !== -1 ? url.substring(0, url.indexOf("?")) : url
|
|||
|
|
if (whiteList.indexOf(url) !== -1 || uni.getStorageSync('loginType')) {
|
|||
|
|
return true
|
|||
|
|
}
|
|||
|
|
uni.showModal({
|
|||
|
|
title: '温馨提示',
|
|||
|
|
content: '您还没有登录!',
|
|||
|
|
cancelText: compulsion ? '去登录' : '再看看',
|
|||
|
|
confirmText: '去登录',
|
|||
|
|
//showCancel 不显示取消
|
|||
|
|
success: function(res) {
|
|||
|
|
if (res.confirm) {
|
|||
|
|
uni.navigateTo({
|
|||
|
|
url: '/pages/login/login'
|
|||
|
|
});
|
|||
|
|
} else if (res.cancel) {
|
|||
|
|
if(compulsion){
|
|||
|
|
//返回首页
|
|||
|
|
// uni.reLaunch({
|
|||
|
|
// url: '/pages/index/index'
|
|||
|
|
// });
|
|||
|
|
}
|
|||
|
|
console.log('再看看');
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
});
|
|||
|
|
return false
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
export function toLogin(){
|
|||
|
|
uni.showModal({
|
|||
|
|
title: '温馨提示',
|
|||
|
|
content: '您还没有登录!',
|
|||
|
|
cancelText: '返回首页',
|
|||
|
|
confirmText: '去登录',
|
|||
|
|
success: function(res) {
|
|||
|
|
if (res.confirm) {
|
|||
|
|
uni.navigateTo({
|
|||
|
|
url: '/pages/login/login'
|
|||
|
|
});
|
|||
|
|
} else if (res.cancel) {
|
|||
|
|
// uni.reLaunch({
|
|||
|
|
// url: '/pages/index/index'
|
|||
|
|
// });
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
});
|
|||
|
|
}
|