|
@@ -18,18 +18,18 @@ import { downloadBlob } from './download';
|
18
|
18
|
*
|
19
|
19
|
*/
|
20
|
20
|
|
21
|
|
-function requestInterceptor (url, options) {
|
|
21
|
+function requestInterceptor(url, options) {
|
22
|
22
|
const headers = options.headers || {};
|
23
|
23
|
const token = localStorage.getItem('token')
|
24
|
24
|
? { Authorization: localStorage.getItem('token') }
|
25
|
25
|
: {};
|
26
|
26
|
|
27
|
|
- console.log('------------->', API_BASE)
|
|
27
|
+ console.log('------------->', API_BASE);
|
28
|
28
|
|
29
|
29
|
const prefix = `${API_BASE}/api/admin`;
|
30
|
|
- let requestType = 'json'
|
|
30
|
+ let requestType = 'json';
|
31
|
31
|
if (options.data instanceof FormData) {
|
32
|
|
- requestType = 'form'
|
|
32
|
+ requestType = 'form';
|
33
|
33
|
}
|
34
|
34
|
return {
|
35
|
35
|
url: `${prefix}${url}`,
|
|
@@ -44,7 +44,7 @@ function requestInterceptor (url, options) {
|
44
|
44
|
};
|
45
|
45
|
}
|
46
|
46
|
|
47
|
|
-async function responseInterceptor (response, ctx) {
|
|
47
|
+async function responseInterceptor(response, ctx) {
|
48
|
48
|
const contextType = response.headers.get('content-type');
|
49
|
49
|
if (contextType.indexOf('json') > -1) {
|
50
|
50
|
const result = await response.clone().json();
|
|
@@ -55,7 +55,7 @@ async function responseInterceptor (response, ctx) {
|
55
|
55
|
|
56
|
56
|
if (contextType.indexOf('application/vnd.ms-excel') > -1) {
|
57
|
57
|
const data = await response.clone().blob();
|
58
|
|
- console.info(response)
|
|
58
|
+ console.info(response);
|
59
|
59
|
const content = response.headers.get('content-disposition');
|
60
|
60
|
const fileName = content.replace('attachment;filename=', '');
|
61
|
61
|
downloadBlob(data, decodeURIComponent(fileName));
|
|
@@ -89,9 +89,12 @@ export const requestConfig = {
|
89
|
89
|
responseInterceptors: [responseInterceptor],
|
90
|
90
|
};
|
91
|
91
|
|
92
|
|
-export default (...args) => request(...args).then((r) => r.data);
|
|
92
|
+export default (...args) => {
|
93
|
93
|
|
94
|
|
-export function queryTable (apiRequest) {
|
|
94
|
+ return request(...args).then((r) => (args[1]?.download ? r: r.data ));
|
|
95
|
+};
|
|
96
|
+
|
|
97
|
+export function queryTable(apiRequest) {
|
95
|
98
|
return function (params) {
|
96
|
99
|
const { current, pageSize, ...leftParams } = params;
|
97
|
100
|
return apiRequest({
|