启动时,增加对token的检查

This commit is contained in:
daihh
2023-03-16 16:10:18 +08:00
parent 17dd44937e
commit 13e83580d3
5 changed files with 53 additions and 43 deletions

View File

@@ -1,4 +1,5 @@
import config from '@/config/index.js'
import {toLogin} from '@/utils/tologin.js'
import {getToken,removeToken} from '@/utils/token.js'
import qs from 'qs'
@@ -35,21 +36,22 @@ const formRequest=function(method,url,data){
if(rs.data.status==6001){
//uni.removeStorageSync('userInfo');
removeToken();
let loginPath=config.loginPath;
if(loginPath.startsWith('http')){
// #ifdef APP-PLUS
plus.runtime.openURL(loginPath) //这里默认使用外部浏览器打开而不是内部web-view组件打开
// #endif
// #ifdef H5
//window.open(loginPath)
let returnUrl=window.location.protocol+'//'+window.location.host+config.context;
location.href=config.loginPath+"?returnUrl="+encodeURIComponent(returnUrl+'/pages/login/loading');
// #endif
}else{
uni.redirectTo({
url:loginPath
})
}
toLogin(reUrl);
// let loginPath=config.loginPath;
// if(loginPath.startsWith('http')){
// // #ifdef APP-PLUS
// plus.runtime.openURL(loginPath) //这里默认使用外部浏览器打开而不是内部web-view组件打开
// // #endif
// // #ifdef H5
// //window.open(loginPath)
// let returnUrl=window.location.protocol+'//'+window.location.host+config.context;
// location.href=config.loginPath+"?returnUrl="+encodeURIComponent(returnUrl+'/pages/login/loading');
// // #endif
// }else{
// uni.redirectTo({
// url:loginPath
// })
// }
}else{
resolve(rs.data);
}
@@ -85,21 +87,22 @@ const jsonRequest=function(method,url,data){
if(rs.statusCode==200){
if(rs.data.status==6001){
removeToken();
let loginPath=config.loginPath;
if(loginPath.startsWith('http')){
// #ifdef APP-PLUS
plus.runtime.openURL(loginPath) //这里默认使用外部浏览器打开而不是内部web-view组件打开
// #endif
// #ifdef H5
//window.open(loginPath)
let returnUrl=window.location.protocol+'//'+window.location.host+config.context;
location.href=config.loginPath+"?returnUrl="+encodeURIComponent(returnUrl+'/pages/login/loading');
// #endif
}else{
uni.redirectTo({
url:loginPath
})
}
toLogin(reUrl);
// let loginPath=config.loginPath;
// if(loginPath.startsWith('http')){
// // #ifdef APP-PLUS
// plus.runtime.openURL(loginPath) //这里默认使用外部浏览器打开而不是内部web-view组件打开
// // #endif
// // #ifdef H5
// //window.open(loginPath)
// let returnUrl=window.location.protocol+'//'+window.location.host+config.context;
// location.href=config.loginPath+"?returnUrl="+encodeURIComponent(returnUrl+'/pages/login/loading');
// // #endif
// }else{
// uni.redirectTo({
// url:loginPath
// })
// }
}else{
resolve(rs.data);
}

View File

@@ -31,6 +31,11 @@ const getUserInfoById = function(id) {
return ajax.postJson('/user/list',{id});
}
/**获取当前登录用户的信息*/
const getUserInfo = function() {
return ajax.postJson('/user/info',{});
}
/**
* https://u-pre.boe.com/userbasic/audience/userAudiences
* 获取当前用户受众信息
@@ -81,6 +86,7 @@ export default {
getOrgInfo,
findOrgTreeByOrgId,
getUserInfoById,
getUserInfo,
getUserCrowds,
getOrgHrbpInfo,
modifyPassword,