Pre Merge pull request !165 from LionZzzi/通用download新增json格式
This commit is contained in:
commit
a88660e928
@ -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]);
|
||||
|
Loading…
x
Reference in New Issue
Block a user