fix:文件下载接口修改

This commit is contained in:
2025-12-23 09:54:06 +08:00
parent d630ac9875
commit 06bdfd6f27
2 changed files with 4 additions and 30 deletions

View File

@@ -90,6 +90,7 @@ const download = (url: string, params = {}, filename = 'download') => {
let fileName = filename;
if (contentDisposition) {
fileName = contentDisposition;
const parts = contentDisposition
.split(';')
.map((p: string) => p.trim())
@@ -156,31 +157,4 @@ const download = (url: string, params = {}, filename = '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 };
export { get, post, upload, download };