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.
96 lines
2.3 KiB
96 lines
2.3 KiB
import store from '@/store'
|
|
import { getToken } from '@/utils/token'
|
|
import { setNodeId, getNodeId } from '@/utils/nodeId'
|
|
import { diyApi } from '@/utils/queryByDiy';
|
|
import { getLongRandom } from '@/utils/nineTool';
|
|
|
|
// 登录页面
|
|
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
|
|
}
|
|
|
|
// 保存访问日志
|
|
function saveAccessLog(to, f) {
|
|
// 开发环境不保存日志
|
|
if(import.meta.env.VITE_APP_ENV == 'development'){
|
|
return;
|
|
}
|
|
// 生成一个nodeId,用于记录日志
|
|
let nodeId = getNodeId();
|
|
if(!nodeId){
|
|
nodeId = getLongRandom(24)
|
|
setNodeId(nodeId)
|
|
}
|
|
let flag = "udemo_im_other_" + f;
|
|
// #ifdef MP-WEIXIN
|
|
flag = "udemo_im_wx_" + f;
|
|
// #endif
|
|
// #ifdef H5
|
|
flag = "udemo_im_h5_" + f;
|
|
// #endif
|
|
// #ifdef APP-PLUS
|
|
flag = "udemo_im_app_" + f;
|
|
// #endif
|
|
let data = {
|
|
flag: flag,
|
|
fullPath: to.url.split("?")[0],
|
|
allPath: to.url,
|
|
menuName: to.tabBarText,
|
|
userId: store.state.user.userInfo.userId,
|
|
userName: store.state.user.userInfo.userName,
|
|
nodeId: nodeId
|
|
}
|
|
diyApi("/system/log/insSysAccessLog", data);
|
|
}
|
|
|
|
// 页面跳转验证拦截器
|
|
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
|
|
}
|
|
return true
|
|
}
|
|
},
|
|
fail(err) {
|
|
console.error(err)
|
|
}
|
|
})
|
|
})
|