51 lines
1.4 KiB
TypeScript
Raw Normal View History

2022-11-03 16:55:01 +08:00
import { service } from './service'
2022-07-18 19:06:37 +08:00
2022-11-03 16:55:01 +08:00
import { config } from './config'
2022-07-19 22:33:54 +08:00
2022-11-03 16:55:01 +08:00
const { default_headers } = config
2022-07-20 00:27:13 +08:00
2022-11-03 16:55:01 +08:00
const request = (option: any) => {
const { url, method, params, data, headersType, responseType } = option
return service({
url: url,
method,
params,
data,
responseType: responseType,
headers: {
'Content-Type': headersType || default_headers
}
})
}
export default {
get: async <T = any>(option: any) => {
const res = await request({ method: 'GET', ...option })
return res.data as unknown as T
2022-07-18 19:06:37 +08:00
},
2022-11-03 16:55:01 +08:00
post: async <T = any>(option: any) => {
const res = await request({ method: 'POST', ...option })
return res.data as unknown as T
2022-07-19 22:33:54 +08:00
},
2022-11-17 10:12:50 +08:00
postOriginal: async (option: any) => {
const res = await request({ method: 'POST', ...option })
return res
},
2022-11-03 16:55:01 +08:00
delete: async <T = any>(option: any) => {
const res = await request({ method: 'DELETE', ...option })
return res.data as unknown as T
},
put: async <T = any>(option: any) => {
const res = await request({ method: 'PUT', ...option })
return res.data as unknown as T
},
download: async <T = any>(option: any) => {
const res = await request({ method: 'GET', responseType: 'blob', ...option })
return res as unknown as Promise<T>
},
upload: async <T = any>(option: any) => {
option.headersType = 'multipart/form-data'
2022-12-21 16:10:28 +08:00
const res = await request({ method: 'POST', ...option })
2022-11-03 16:55:01 +08:00
return res as unknown as Promise<T>
2022-07-19 22:33:54 +08:00
}
2022-07-18 19:06:37 +08:00
}