update:文件下载接口修改,相关界面的统一适配修改

This commit is contained in:
2025-12-22 15:59:03 +08:00
parent 9af3e61651
commit e8bd34bc21
8 changed files with 91 additions and 44 deletions

View File

@@ -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 };