环境token
This commit is contained in:
+25
-3
@@ -20,7 +20,15 @@ function request(url, method, data, loding = false) {
|
||||
mask: true
|
||||
})
|
||||
}
|
||||
let token = wx.getStorageSync('AUTH_TOKEN');
|
||||
let token='';
|
||||
const { envVersion } = wx.getAccountInfoSync().miniProgram;
|
||||
if(envVersion=='release'){
|
||||
token = wx.getStorageSync('AUTH_TOKEN');
|
||||
}else{
|
||||
token = wx.getStorageSync('DEV_AUTH_TOKEN');
|
||||
|
||||
}
|
||||
|
||||
if (!token) {
|
||||
let freelist = ["/login/wechat_mobile_login", '/login/mobile_login','/code/phone','/patient/index',"/popup","/sign/im"];//接口白名单
|
||||
let currentUrl=getCurrentPageUrl();
|
||||
@@ -53,7 +61,14 @@ function request(url, method, data, loding = false) {
|
||||
|
||||
var Authorization_token = res.header.Authorization;
|
||||
if (Authorization_token) {
|
||||
wx.setStorageSync('AUTH_TOKEN', Authorization_token); //当token快过期时,服务器会返回新token,本地刷新
|
||||
const { envVersion } = wx.getAccountInfoSync().miniProgram;
|
||||
if(envVersion=='release'){
|
||||
wx.setStorageSync('AUTH_TOKEN', Authorization_token);
|
||||
}else{
|
||||
wx.setStorageSync('DEV_AUTH_TOKEN', Authorization_token);
|
||||
|
||||
}
|
||||
//当token快过期时,服务器会返回新token,本地刷新
|
||||
}
|
||||
if (loding) {
|
||||
wx.hideLoading()
|
||||
@@ -90,7 +105,14 @@ function request(url, method, data, loding = false) {
|
||||
}else if (Number(res.data.code) == 401 || Number(res.data.code) == 403 || Number(res.data.code) == 405 || Number(res.data.code) == 406) {
|
||||
let redirectUrl=formatUrl();
|
||||
if(!isLock){
|
||||
wx.setStorageSync('AUTH_TOKEN','');
|
||||
const { envVersion } = wx.getAccountInfoSync().miniProgram;
|
||||
if(envVersion=='release'){
|
||||
wx.setStorageSync('AUTH_TOKEN','');
|
||||
}else{
|
||||
wx.setStorageSync('DEV_AUTH_TOKEN','');
|
||||
|
||||
}
|
||||
// wx.setStorageSync('AUTH_TOKEN','');
|
||||
isLock=true;
|
||||
wx.reLaunch({
|
||||
url: '/patient/pages/login/login?redirectUrl='+redirectUrl
|
||||
|
||||
Reference in New Issue
Block a user