diff --git a/src/utils/request.ts b/src/utils/request.ts index 9682b8197f727680c910182bae94f3a632a18bb1..00f43659bf38d884d4e0e3327cdbe1ec057017da 100644 --- a/src/utils/request.ts +++ b/src/utils/request.ts @@ -174,18 +174,26 @@ service.interceptors.response.use( } ); // 通用下载方法 -export function download(url: string, params: any, fileName: string) { +export function download(url: string, params: any, fileName: string, isJson: boolean = false) { downloadLoadingInstance = ElLoading.service({ text: '正在下载数据,请稍候', background: 'rgba(0, 0, 0, 0.7)' }); - // prettier-ignore - return service.post(url, params, { - transformRequest: [ + + const config = { + headers: { + 'Content-Type': isJson ? 'application/json' : 'application/x-www-form-urlencoded' + }, + responseType: 'blob' as const, + transformRequest: isJson + ? undefined + : [ (params: any) => { return tansParams(params); } - ], - headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, - responseType: 'blob' - }).then(async (resp: any) => { + ] + }; + + // prettier-ignore + return service.post(url, isJson ? params : tansParams(params), config) + .then(async (resp: any) => { const isLogin = blobValidate(resp); if (isLogin) { const blob = new Blob([resp]);