update:文件下载接口修改,相关界面的统一适配修改
This commit is contained in:
@@ -156,4 +156,31 @@ const download = (url: string, params = {}, filename = 'download') => {
|
||||
});
|
||||
};
|
||||
|
||||
export { get, post, upload, download };
|
||||
const getDownload = (url: string, filename = 'download') => {
|
||||
return service
|
||||
.get(url, {
|
||||
responseType: 'blob',
|
||||
})
|
||||
.then(async (res: any) => {
|
||||
const xFileName = res.headers?.['x-file-name'];
|
||||
let fileName = filename;
|
||||
|
||||
if (xFileName) {
|
||||
fileName = xFileName;
|
||||
}
|
||||
|
||||
const blob = new Blob([res.data]);
|
||||
const link = document.createElement('a');
|
||||
link.href = window.URL.createObjectURL(blob);
|
||||
link.download = fileName;
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
document.body.removeChild(link);
|
||||
window.URL.revokeObjectURL(link.href);
|
||||
})
|
||||
.catch(() => {
|
||||
ElMessage.warning('下载失败');
|
||||
});
|
||||
};
|
||||
|
||||
export { get, post, upload, download, getDownload };
|
||||
|
||||
Reference in New Issue
Block a user