Merge branch 'feature/开门红' into dev

# Conflicts:
#	src/assets/js/utils/request.js
This commit is contained in:
mengxiaolong
2020-11-25 16:20:54 +08:00

View File

@@ -131,16 +131,17 @@ service.interceptors.request.use(
/** /**
* 请求拦截处理(待添加 判断走统一网关处理) * 请求拦截处理(待添加 判断走统一网关处理)
*/ */
if(config.url && /api\/$/.test(config.url.split(configApp.API_VERSION)[0]) && configApp.API_VERSION == 'v2'){ if (config.url && /api\/$/.test(config.url.split(configApp.API_VERSION)[0]) && configApp.API_VERSION == 'v2') {
if(!config.data || config.data == null){ if (!config.data || config.data == null) {
config.data = {} config.data = {}
} }
if(!!config.data && config.data != null){ if (!!config.data && config.data != null) {
let encrypt = AESTools.AESEncrypt(JSON.stringify(config.data),configApp.REQ_PWD) let encrypt = AESTools.AESEncrypt(JSON.stringify(config.data), configApp.REQ_PWD)
config.data = {"data": encrypt } config.data = { data: encrypt }
} }
} }
let token = CacheUtils.getLocItem('token') let token = CacheUtils.getLocItem('token')
console.log('localstorage token: ', token)
/** /**
* 在HomeProduct页面获取代理人信息时, 客户端可能还未将token存储在本地 * 在HomeProduct页面获取代理人信息时, 客户端可能还未将token存储在本地
* 此时如果token为空, 调用客户端方法获取token并放入localstorage中 * 此时如果token为空, 调用客户端方法获取token并放入localstorage中
@@ -153,6 +154,7 @@ service.interceptors.request.use(
// eslint-disable-next-line no-undef // eslint-disable-next-line no-undef
const res = await EWebBridge.webCallAppInJs('getToken') const res = await EWebBridge.webCallAppInJs('getToken')
const token = JSON.parse(res).token const token = JSON.parse(res).token
console.log('调用客户端获取token: ', res)
CacheUtils.setLocItem('token', token) CacheUtils.setLocItem('token', token)
} }
} }
@@ -173,9 +175,15 @@ service.interceptors.request.use(
service.interceptors.response.use( service.interceptors.response.use(
response => { response => {
let res = response.data let res = response.data
if( configApp.API_VERSION == 'v2' && response.config.url && response.headers['content-type'].match(/application\/json/) && /api\/$/.test(response.config.url.split(configApp.API_VERSION)[0])){ if (
if(res.response){// 正常情況返回必有response 节点 configApp.API_VERSION == 'v2' &&
res = JSON.parse(AESTools.AESDecrypt(res.response,configApp.REQ_PWD)) response.config.url &&
response.headers['content-type'].match(/application\/json/) &&
/api\/$/.test(response.config.url.split(configApp.API_VERSION)[0])
) {
if (res.response) {
// 正常情況返回必有response 节点
res = JSON.parse(AESTools.AESDecrypt(res.response, configApp.REQ_PWD))
} }
} }
Toast.clear() Toast.clear()