Pre Merge pull request !165 from LionZzzi/通用download新增json格式

This commit is contained in:
LionZzzi 2024-12-06 02:03:16 +00:00 committed by Gitee
commit a88660e928
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F

View File

@ -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]);