|
|
|
@ -158,23 +158,22 @@ export class VAxios {
@@ -158,23 +158,22 @@ export class VAxios {
|
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 支持表单数据
|
|
|
|
|
supportFormData(config: AxiosRequestConfig) { |
|
|
|
|
/** 转换配置数据格式 */ |
|
|
|
|
transformConfigFormat(config: AxiosRequestConfig) { |
|
|
|
|
const headers = config.headers || this.options.headers; |
|
|
|
|
const contentType = headers?.['Content-Type'] || headers?.['content-type']; |
|
|
|
|
const arrayFormat = headers.arrayFormat || 'indices'; |
|
|
|
|
|
|
|
|
|
if ( |
|
|
|
|
contentType !== ContentTypeEnum.FORM_URLENCODED || |
|
|
|
|
!Reflect.has(config, 'data') || |
|
|
|
|
config.method?.toUpperCase() === RequestEnum.GET |
|
|
|
|
) { |
|
|
|
|
return config; |
|
|
|
|
if (config.method?.toUpperCase() === RequestEnum.POST && contentType === ContentTypeEnum.FORM_URLENCODED) { |
|
|
|
|
// post请求参数处理
|
|
|
|
|
config.data = qs.stringify(config.data, { allowDots: true, arrayFormat: arrayFormat }); |
|
|
|
|
} else if (config.method?.toUpperCase() === RequestEnum.GET) { |
|
|
|
|
// get请求参数处理
|
|
|
|
|
config.params = qs.stringify(config.params, { allowDots: true, arrayFormat: arrayFormat }); |
|
|
|
|
config.params = qs.parse(config.params); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return { |
|
|
|
|
...config, |
|
|
|
|
data: qs.stringify(config.data, { arrayFormat: 'brackets' }), |
|
|
|
|
}; |
|
|
|
|
return config; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
get<T = any>(config: AxiosRequestConfig, options?: RequestOptions): Promise<T> { |
|
|
|
@ -207,7 +206,7 @@ export class VAxios {
@@ -207,7 +206,7 @@ export class VAxios {
|
|
|
|
|
} |
|
|
|
|
conf.requestOptions = opt; |
|
|
|
|
|
|
|
|
|
conf = this.supportFormData(conf); |
|
|
|
|
conf = this.transformConfigFormat(conf); |
|
|
|
|
|
|
|
|
|
return new Promise((resolve, reject) => { |
|
|
|
|
this.axiosInstance |
|
|
|
|