对登录控制验证进行整理

This commit is contained in:
daihh
2023-03-01 19:25:50 +08:00
parent 8d2a270fa7
commit b874ef5307
9 changed files with 180 additions and 114 deletions

View File

@@ -1,9 +1,11 @@
import config from '@/config/index.js'
import {toLogin} from '@/utils/tologin.js'
import {getToken,removeToken} from '@/utils/token.js'
import qs from 'qs'
const ReLoginUrl="/login";
const formatUrl=function(url){
return url;
// if(url.startsWith('http') || url.startsWith('https')){
@@ -32,24 +34,28 @@ const formRequest=function(method,url,data){
dataType: 'json',
header: headers,
success:function(rs,statusCode){
//toLogin();
if(rs.statusCode==200){
if(rs.data.status==401 || rs.data.status==402){
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)
// toLogin();
// //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);
}
@@ -86,20 +92,21 @@ const jsonRequest=function(method,url,data){
if(rs.statusCode==200){
if(rs.data.status==401 || rs.data.status==402){
removeToken();
let loginPath=config.loginPath;
if(loginPath.startsWith('http')){
// #ifdef APP-PLUS
plus.runtime.openURL(loginPath) //这里默认使用外部浏览器打开而不是内部web-view组件打开
// #endif
// #ifdef H5
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
// 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

@@ -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);
}