mirror of
https://codeup.aliyun.com/67762337eccfc218f6110e0e/vue/learning-system-mobile.git
synced 2025-12-06 09:26:45 +08:00
对登录控制验证进行整理
This commit is contained in:
33
utils/tologin.js
Normal file
33
utils/tologin.js
Normal 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
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user