From 06bdfd6f276632984f048f4ea0db5a6fc7fb8a30 Mon Sep 17 00:00:00 2001 From: zhouyang Date: Tue, 23 Dec 2025 09:54:06 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E6=96=87=E4=BB=B6=E4=B8=8B=E8=BD=BD?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/data/data.ts | 4 ++-- src/api/request.ts | 30 ++---------------------------- 2 files changed, 4 insertions(+), 30 deletions(-) diff --git a/src/api/data/data.ts b/src/api/data/data.ts index 41b235b1..7ee82446 100644 --- a/src/api/data/data.ts +++ b/src/api/data/data.ts @@ -1,4 +1,4 @@ -import { download, get, getDownload, post, upload } from '@/api/request'; +import { download, get, post, upload } from '@/api/request'; const env = import.meta.env; const PREFIX = env.VITE_API_PREFIX_DATA; @@ -205,5 +205,5 @@ export const dataTreeListDirApi = (params: any) => { * @returns */ export const systemDataDownloadFileApi = (params: any) => { - return getDownload(`${PREFIX}data/downloadFile?fileId=${params.fileId}`); + return download(`${PREFIX}data/downloadFile`, params); }; diff --git a/src/api/request.ts b/src/api/request.ts index 11e892dc..bdef770e 100644 --- a/src/api/request.ts +++ b/src/api/request.ts @@ -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 };