From 125d801424b9cc3436b579931017b68ea027ca67 Mon Sep 17 00:00:00 2001 From: daihh Date: Sat, 10 Dec 2022 10:24:28 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B7=B3=E8=BD=AC=E7=99=BB=E5=BD=95=E5=8E=BB?= =?UTF-8?q?=E6=8E=89=E5=A4=9A=E5=8A=A0=E7=9A=84/=EF=BC=8C=E5=90=8C?= =?UTF-8?q?=E6=97=B6=E6=B8=85=E9=99=A4=E4=B8=80=E4=B8=8Btoken?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/ajax.js | 8 +++++--- api/boe/boeApiAjax.js | 6 ++++-- utils/xajax.js | 8 +++++--- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/api/ajax.js b/api/ajax.js index 8895378..e24799c 100644 --- a/api/ajax.js +++ b/api/ajax.js @@ -1,5 +1,5 @@ import config from '@/config/index.js' -import {getToken} from '@/utils/token.js' +import {getToken,removeToken} from '@/utils/token.js' import qs from 'qs' const ReLoginUrl="/login"; @@ -34,6 +34,7 @@ const formRequest=function(method,url,data){ success:function(rs,statusCode){ 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 @@ -41,7 +42,7 @@ const formRequest=function(method,url,data){ // #endif // #ifdef H5 //window.open(loginPath) - let returnUrl=window.location.protocol+'//'+window.location.host+"/"+config.context; + let returnUrl=window.location.protocol+'//'+window.location.host+config.context; location.href=config.loginPath+"?returnUrl="+encodeURIComponent(returnUrl+'/pages/login/loading'); // #endif }else{ @@ -84,13 +85,14 @@ const jsonRequest=function(method,url,data){ success:function(rs,statusCode){ 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; + let returnUrl=window.location.protocol+'//'+window.location.host+config.context; location.href=config.loginPath+"?returnUrl="+encodeURIComponent(returnUrl+'/pages/login/loading'); // #endif }else{ diff --git a/api/boe/boeApiAjax.js b/api/boe/boeApiAjax.js index c743cdc..51ffb6c 100644 --- a/api/boe/boeApiAjax.js +++ b/api/boe/boeApiAjax.js @@ -42,7 +42,8 @@ const formRequest=function(method,url,data){ // #endif // #ifdef H5 //window.open(loginPath) - location.href=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({ @@ -91,7 +92,8 @@ const jsonRequest=function(method,url,data){ // #endif // #ifdef H5 //window.open(loginPath) - location.href=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({ diff --git a/utils/xajax.js b/utils/xajax.js index 939c59e..b2661c6 100644 --- a/utils/xajax.js +++ b/utils/xajax.js @@ -1,5 +1,5 @@ import config from '../config/index.js' -import {getToken} from '@/utils/token.js' +import {getToken,removeToken} from '@/utils/token.js' import qs from 'qs' const ReLoginUrl="/login"; @@ -33,6 +33,7 @@ const formRequest=function(method,url,data){ success:function(rs,statusCode){ 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 @@ -40,7 +41,7 @@ const formRequest=function(method,url,data){ // #endif // #ifdef H5 //window.open(loginPath) - let returnUrl=window.location.protocol+'//'+window.location.host+"/"+config.context; + let returnUrl=window.location.protocol+'//'+window.location.host+config.context; location.href=config.loginPath+"?returnUrl="+encodeURIComponent(returnUrl+'/pages/login/loading'); // #endif }else{ @@ -83,6 +84,7 @@ const jsonRequest=function(method,url,data){ success:function(rs,statusCode){ 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 @@ -90,7 +92,7 @@ const jsonRequest=function(method,url,data){ // #endif // #ifdef H5 //window.open(loginPath) - let returnUrl=window.location.protocol+'//'+window.location.host+"/"+config.context; + let returnUrl=window.location.protocol+'//'+window.location.host+config.context; location.href=config.loginPath+"?returnUrl="+encodeURIComponent(returnUrl+'/pages/login/loading'); // #endif }else{