提交 | 用户 | 时间
|
314507
|
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: { |
|
17 |
'Content-Type': headersType || default_headers, |
906991
|
18 |
'tenant-id': import.meta.env.VITE_TENANT_ID |
314507
|
19 |
} |
H |
20 |
}) |
|
21 |
} |
|
22 |
export default { |
|
23 |
get: async <T = any>(option: any) => { |
|
24 |
const res = await request({ method: 'GET', ...option }) |
|
25 |
return res.data as unknown as T |
|
26 |
}, |
|
27 |
post: async <T = any>(option: any) => { |
|
28 |
const res = await request({ method: 'POST', ...option }) |
|
29 |
return res.data as unknown as T |
|
30 |
}, |
|
31 |
postOriginal: async (option: any) => { |
|
32 |
const res = await request({ method: 'POST', ...option }) |
|
33 |
return res |
|
34 |
}, |
|
35 |
delete: async <T = any>(option: any) => { |
|
36 |
const res = await request({ method: 'DELETE', ...option }) |
|
37 |
return res.data as unknown as T |
|
38 |
}, |
|
39 |
put: async <T = any>(option: any) => { |
|
40 |
const res = await request({ method: 'PUT', ...option }) |
|
41 |
return res.data as unknown as T |
|
42 |
}, |
|
43 |
download: async <T = any>(option: any) => { |
|
44 |
const res = await request({ method: 'GET', responseType: 'blob', ...option }) |
|
45 |
return res as unknown as Promise<T> |
|
46 |
}, |
|
47 |
upload: async <T = any>(option: any) => { |
|
48 |
option.headersType = 'multipart/form-data' |
|
49 |
const res = await request({ method: 'POST', ...option }) |
|
50 |
return res as unknown as Promise<T> |
|
51 |
} |
|
52 |
} |