api 如果设置了 dataType 直接在 amis 就处理好了

This commit is contained in:
2betop 2020-04-09 17:23:25 +08:00
parent d9ad07d50a
commit ddc1817d60

View File

@ -178,16 +178,28 @@ export function wrapFetcher(
return function(api, data, options) { return function(api, data, options) {
api = buildApi(api, data, options) as ApiObject; api = buildApi(api, data, options) as ApiObject;
api.requestAdaptor && (api = api.requestAdaptor(api) || api);
if (api.data && (hasFile(api.data) || api.dataType === 'form-data')) { if (api.data && (hasFile(api.data) || api.dataType === 'form-data')) {
api.data = object2formData(api.data, api.qsOptions); api.data = object2formData(api.data, api.qsOptions);
} else if (api.data && api.dataType === 'form') { } else if (
api.data &&
typeof api.data !== 'string' &&
api.dataType === 'form'
) {
api.data = qsstringify(api.data, api.qsOptions) as any; api.data = qsstringify(api.data, api.qsOptions) as any;
api.headers = api.headers || (api.headers = {}); api.headers = api.headers || (api.headers = {});
api.headers['Content-Type'] = 'application/x-www-form-urlencoded'; api.headers['Content-Type'] = 'application/x-www-form-urlencoded';
} else if (
api.data &&
typeof api.data !== 'string' &&
api.dataType === 'json'
) {
api.data = JSON.stringify(api.data) as any;
api.headers = api.headers || (api.headers = {});
api.headers['Content-Type'] = 'application/json';
} }
api.requestAdaptor && (api = api.requestAdaptor(api) || api);
if (typeof api.cache === 'number' && api.cache > 0) { if (typeof api.cache === 'number' && api.cache > 0) {
const apiCache = getApiCache(api); const apiCache = getApiCache(api);
return wrapAdaptor( return wrapAdaptor(