Commit d61ab8eb authored by 徐光星's avatar 徐光星

Merge branch 'feature/response_type_blob' into 'master'

Feature/response type blob

See merge request !4
parents 3b4b4681 1045ffc2
......@@ -12,7 +12,7 @@
### 发布方式
```
npm publish --registry http://172.16.3.15:4873
npm publish --registry http://npmprivate.quantgroups.com
```
......
......@@ -31,7 +31,7 @@ const onAccessTokenFetched = () => {
subscriber = [];
};
const refreshtoken = async () => {
const refreshToken = async () => {
return instance.get(`${instance._extend.refresTokenHost}/oauth/refreshtoken?refreshtoken=${localStorage.get('refreshToken')}`);
};
......@@ -43,7 +43,7 @@ const refreshRequest = async options => {
if (isRefreshing) {
isRefreshing = false;
await wait(500);
const data = await refreshtoken();
const data = await refreshToken();
localStorage.set('token', data.accessToken);
onAccessTokenFetched();
isRefreshing = true;
......@@ -68,7 +68,7 @@ function afterRequest(model, isLoading = true) {
if (!isLoading) return;
if (!model) model = 'common';
clearTimeout(loadingTimeOut);
var index = httpQueue.indexOf(model);
const index = httpQueue.indexOf(model);
if (index > -1) {
httpQueue.splice(index, 1);
}
......@@ -81,8 +81,8 @@ function afterRequest(model, isLoading = true) {
}
function clearRequest() {
let modelArr = Array.from(new Set(httpQueue));
for (let i = 0; i < modelArr.length; i++) {
Bus.$emit(`${modelArr[i]}HideLoading`);
for (const model of modelArr) {
Bus.$emit(`${model}HideLoading`);
}
httpQueue = [];
}
......@@ -119,17 +119,11 @@ instance.interceptors.request.use(
}
}
// todo: 某些接口不支持operator参数的话,需要排除
if (config.method === 'post' || config.method === 'get') {
if (typeof config.data === 'object') {
} else if (typeof config.data === 'string' && config.method === 'post') {
} else if (config.method === 'get') {
// //普通的get请求
if (config.url.indexOf('offline_record') !== -1) {
config.data = true;
config.headers.common['content-type'] = 'application/x-www-form-urlencoded';
}
}
//普通的get请求
// TODO: 某些接口不支持operator参数的话,需要排除
if (config.method === 'get' && config.url.indexOf('offline_record') !== -1) {
config.data = true;
config.headers.common['content-type'] = 'application/x-www-form-urlencoded';
}
return config;
},
......@@ -144,7 +138,7 @@ instance.interceptors.response.use(
if (response.headers['content-type'] === 'application/octet-stream' || (response.headers['content-type'] === 'application/vnd.ms-excel;charset=UTF-8' && response.data.byteLength !== 'undefied')) {
return response.data;
}
if (response.config.responseType === 'arraybuffer') {
if (['blob', 'arraybuffer'].includes(response.config.responseType)) {
return response.data;
}
......@@ -152,23 +146,24 @@ instance.interceptors.response.use(
// 200 - 300 之间的都是正常响应
if (response.status > 200 || response.status < 300) {
const codeArr = [0, '0', 2000];
if (response.data && ((response.data.code === '0000' && response.data.businessCode === '0000') || codeArr.includes(response.data.code))) {
const code = response.data && response.data.code;
if (response.data && ((code === '0000' && response.data.businessCode === '0000') || codeArr.includes(code))) {
if (instance._extend.dataParseMode === 'NOT_PARSE') {
return response.data;
}
if (instance._extend.dataParseMode === 'PARSE_BODY' && response.data.code === 0) {
if (instance._extend.dataParseMode === 'PARSE_BODY' && code === 0) {
return response.data.body;
}
return response.data.data || response.data;
}
if (response.data.code === 4033) {
if (+code === 4033) {
// token过期;
return refreshRequest(response.config);
}
if (response.data.code === 4010 || response.data.code === 4011) {
var href = window.location.href;
if (+code === 4010 || +code === 4011) {
let href = window.location.href;
href = href.replace(/\?token=[a-z0-9\-A-Z]+/g, '');
window.location.href = instance._extend.loginUrl + '?url=' + window.btoa(href);
return;
......@@ -195,7 +190,7 @@ instance.interceptors.response.use(
switch (error.response.status) {
case 401:
// todo: 系统中有3处处理401的地方
var href = window.location.href;
let href = window.location.href;
href = href.replace(/\?token=[a-z0-9\-A-Z]+/g, '');
window.location.href = instance._extend.loginUrl + '?url=' + window.btoa(href);
return;
......@@ -299,7 +294,7 @@ const http = {
});
},
cancel() {
cancelArr.map(cancel => cancel());
cancelArr.forEach(cancel => cancel());
},
};
......
{
"name": "@qg/sys-sdk",
"version": "1.0.18",
"version": "1.0.20",
"description": "",
"main": "index.js",
"scripts": {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment