|
@@ -58,7 +58,6 @@ export default function request(url, options) {
|
|
credentials: 'include',
|
|
credentials: 'include',
|
|
};
|
|
};
|
|
const newOptions = { ...defaultOptions, ...options };
|
|
const newOptions = { ...defaultOptions, ...options };
|
|
- console.log('>>>>>>>>>> 01newOptions',newOptions)
|
|
|
|
if (newOptions.method === 'POST' || newOptions.method === 'PUT' || newOptions.method === 'DELETE') {
|
|
if (newOptions.method === 'POST' || newOptions.method === 'PUT' || newOptions.method === 'DELETE') {
|
|
if (!(newOptions.body instanceof FormData)) {
|
|
if (!(newOptions.body instanceof FormData)) {
|
|
newOptions.headers = {
|
|
newOptions.headers = {
|
|
@@ -76,26 +75,29 @@ export default function request(url, options) {
|
|
'Content-Type': 'multipart/form-data',
|
|
'Content-Type': 'multipart/form-data',
|
|
...newOptions.headers,
|
|
...newOptions.headers,
|
|
};
|
|
};
|
|
- }
|
|
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- // download excel
|
|
|
|
- if ( newOptions.DOWNLOAD ) {
|
|
|
|
- console.log('download request');
|
|
|
|
- delete newOptions.DOWNLOAD;
|
|
|
|
- newOptions.headers = {
|
|
|
|
- Accept: 'application/binary',
|
|
|
|
- 'Content-Type': 'multipart/x-www-form-urlencoded',
|
|
|
|
- ...newOptions.headers,
|
|
|
|
- };
|
|
|
|
- }
|
|
|
|
- console.log('>>>>>>>>>newOptions',newOptions)
|
|
|
|
return fetch(url, newOptions)
|
|
return fetch(url, newOptions)
|
|
.then(checkHttpStatus)
|
|
.then(checkHttpStatus)
|
|
.then((response) => {
|
|
.then((response) => {
|
|
- if (response.status === 204) {
|
|
|
|
- return response.text();
|
|
|
|
|
|
+ if (response.headers.get('Content-Type') !== 'application/json;charset=UTF-8') {
|
|
|
|
+ response.blob().then(
|
|
|
|
+ (blob) => {
|
|
|
|
+ const a = document.createElement('a');
|
|
|
|
+ const fakeUrl = window.URL.createObjectURL(blob);
|
|
|
|
+ const filename = response.headers.get('Content-Disposition').split('filename=')[1];
|
|
|
|
+ a.href = fakeUrl;
|
|
|
|
+ a.download = filename;
|
|
|
|
+ a.click();
|
|
|
|
+ window.URL.revokeObjectURL(url);
|
|
|
|
+ });
|
|
|
|
+ return null;
|
|
|
|
+ } else {
|
|
|
|
+ if (response.status === 204) {
|
|
|
|
+ return response.text();
|
|
|
|
+ }
|
|
|
|
+ return response.json();
|
|
}
|
|
}
|
|
- return response.json();
|
|
|
|
})
|
|
})
|
|
.then(checkContentStatus)
|
|
.then(checkContentStatus)
|
|
.catch((e) => {
|
|
.catch((e) => {
|