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:
65
api/ajax.js
65
api/ajax.js
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user