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.
59 lines
1.4 KiB
59 lines
1.4 KiB
import store from '@/store'
|
|
import { getToken } from '@/utils/token'
|
|
import { saveAccessLog } from '@/utils/accessLog'
|
|
|
|
// 登录页面
|
|
const loginPage = "/pages/user/login"
|
|
|
|
// 页面白名单
|
|
const whiteList = [
|
|
'/pages/user/login',
|
|
'/pages/user/register',
|
|
'/pages/user/forget',
|
|
'/pages/setting/protocol',
|
|
'/pages/common/webview/index'
|
|
]
|
|
|
|
// 检查地址白名单
|
|
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) {
|
|
if (getToken()) {
|
|
if (to.url === loginPage) {
|
|
uni.reLaunch({ url: "/" })
|
|
}
|
|
saveAccessLog(to, "generate");
|
|
return true
|
|
} else {
|
|
if (checkWhite(to.url)) {
|
|
saveAccessLog(to, "white");
|
|
return true
|
|
}
|
|
saveAccessLog(to, "nologin");
|
|
// 密码登录的,实现自动重新登录
|
|
let loginInfo = store.state.user.loginInfo;
|
|
if(loginInfo && loginInfo.loginType == 0){
|
|
store.dispatch('Login', {
|
|
loginType: loginInfo.loginType,
|
|
userName: loginInfo.userName,
|
|
password: loginInfo.password,
|
|
registerFlag: "N"
|
|
}).then(() => {
|
|
store.dispatch('GetInfo');
|
|
})
|
|
}
|
|
return true
|
|
}
|
|
},
|
|
fail(err) {
|
|
console.error(err)
|
|
}
|
|
})
|
|
})
|