提交 | 用户 | 时间
|
820397
|
1 |
import { service } from './service' |
H |
2 |
|
|
3 |
import { config } from './config' |
|
4 |
|
|
5 |
const { default_headers } = config |
|
6 |
|
|
7 |
const request = (option: any) => { |
|
8 |
const { url, method, params, data, headersType, responseType, ...config } = option |
|
9 |
return service({ |
|
10 |
url: url, |
|
11 |
method, |
|
12 |
params, |
|
13 |
data, |
|
14 |
...config, |
|
15 |
responseType: responseType, |
|
16 |
headers: { |
39248b
|
17 |
'Content-Type': headersType || default_headers, |
820397
|
18 |
} |
H |
19 |
}) |
|
20 |
} |
|
21 |
export default { |
|
22 |
get: async <T = any>(option: any) => { |
|
23 |
const res = await request({ method: 'GET', ...option }) |
|
24 |
return res.data as unknown as T |
|
25 |
}, |
|
26 |
post: async <T = any>(option: any) => { |
|
27 |
const res = await request({ method: 'POST', ...option }) |
|
28 |
return res.data as unknown as T |
|
29 |
}, |
|
30 |
postOriginal: async (option: any) => { |
|
31 |
const res = await request({ method: 'POST', ...option }) |
|
32 |
return res |
|
33 |
}, |
|
34 |
delete: async <T = any>(option: any) => { |
|
35 |
const res = await request({ method: 'DELETE', ...option }) |
|
36 |
return res.data as unknown as T |
|
37 |
}, |
|
38 |
put: async <T = any>(option: any) => { |
|
39 |
const res = await request({ method: 'PUT', ...option }) |
|
40 |
return res.data as unknown as T |
|
41 |
}, |
|
42 |
download: async <T = any>(option: any) => { |
|
43 |
const res = await request({ method: 'GET', responseType: 'blob', ...option }) |
|
44 |
return res as unknown as Promise<T> |
|
45 |
}, |
3f10e7
|
46 |
downloadByPost: async <T = any>(option: any) => { |
J |
47 |
const res = await request({ method: 'POST', responseType: 'blob', ...option }) |
|
48 |
return res as unknown as Promise<T> |
|
49 |
}, |
820397
|
50 |
upload: async <T = any>(option: any) => { |
H |
51 |
option.headersType = 'multipart/form-data' |
|
52 |
const res = await request({ method: 'POST', ...option }) |
|
53 |
return res as unknown as Promise<T> |
|
54 |
} |
|
55 |
} |