对登录控制验证进行整理

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

33
utils/tologin.js Normal file
View File

@@ -0,0 +1,33 @@
import config from '@/config/index.js'
export function toLogin(ajaxUrl) {
let pageUrl=location.href;
console.log(pageUrl,'pageUrl');
let urlPre=window.location.protocol+'//'+window.location.host;
console.log(urlPre,'urlPre');
let urlContext=config.context;
console.log(urlContext,'urlContext');
let returnPage=pageUrl.substring((urlPre+urlContext).length);
console.log(returnPage,'returnPage');
console.log(config.loginPath+"?returnUrl="+urlPre+urlContext+'/pages/login/loading?returnUrl='+returnPage,'生成的url');
if(ajaxUrl && ajaxUrl.indexOf('/xboe/portal/init')>-1){
return;
}
//http://localhost:8081/mobile/pages/study/courseStudy?id=1028700304503054336
if(pageUrl.indexOf('returnUrl')>-1){
console.log(pageUrl,'to pageUrl')
//location.href=config.loginPath+"?returnUrl="+pageUrl;
// uni.redirectTo({
// url:config.loginPath
// })
}else{
if(process.env.NODE_ENV === 'development'){
location.href=config.loginPath+"?returnUrl="+encodeURIComponent(returnPage);
}else{
location.href=config.loginPath+"?returnUrl="+encodeURIComponent(urlPre+urlContext+'/pages/login/loading?returnUrl='+returnPage);
}
//location.href=config.loginPath
}
}

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'
@@ -34,21 +35,22 @@ const formRequest=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
//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==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)
// 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);
}