From 94882bc9a559ec94933fd512208d1678d2ed3d33 Mon Sep 17 00:00:00 2001 From: 2910410219 <2910410219@qq.com> Date: Wed, 22 Apr 2026 12:42:23 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=9B=B4=E6=96=B0=E4=B8=8B=E8=BD=BD?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=E4=BB=A5=E6=94=AF=E6=8C=81Blob=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 移除`localPath`参数,简化下载接口 - 在`downloadToFile`函数中添加`responseType: 'blob'`以处理二进制数据 - 更新下载逻辑,使用Blob对象创建下载链接并触发下载成功提示 --- src/api/digitalHuman/creation/index.ts | 3 ++- src/views/digitalHuman/creation/index.vue | 15 +++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/api/digitalHuman/creation/index.ts b/src/api/digitalHuman/creation/index.ts index 68a28c9..610e6fd 100644 --- a/src/api/digitalHuman/creation/index.ts +++ b/src/api/digitalHuman/creation/index.ts @@ -59,7 +59,6 @@ export interface CreationSubmitParams { export interface DownloadToFileParams { fileURL: string; - localPath: string; } export function getCreationList(params: CreationListParams) { @@ -75,6 +74,7 @@ export function createCreation(data: CreationSubmitParams) { url: '/black-deacon/creation/info/creation', method: 'post', data, + timeout: 0, }); } @@ -83,5 +83,6 @@ export function downloadToFile(data: DownloadToFileParams) { url: '/oss/file/downloadToBrowser', method: 'post', data, + responseType: 'blob', }); } diff --git a/src/views/digitalHuman/creation/index.vue b/src/views/digitalHuman/creation/index.vue index bb05a05..4cc7be8 100644 --- a/src/views/digitalHuman/creation/index.vue +++ b/src/views/digitalHuman/creation/index.vue @@ -249,8 +249,19 @@ const downloadNode = async (data: TreeNode) => { if (data.nodeType !== 'html' && data.nodeType !== 'image') return; if (!data.fileUrl) return ElMessage.warning('当前节点没有可下载地址'); try { - await downloadToFile({ fileURL: data.fileUrl, localPath: 'C:/Users/AI/Desktop' }); - ElMessage.success('已提交下载到本地'); + const response = await downloadToFile({ fileURL: data.fileUrl }); + const blob = response instanceof Blob ? response : response?.data; + if (!(blob instanceof Blob)) throw new Error('无效的下载数据'); + const fileName = decodeURIComponent(data.fileUrl.split('/').pop() || `${data.label}.${data.nodeType === 'html' ? 'html' : 'png'}`); + const objectUrl = window.URL.createObjectURL(blob); + const link = document.createElement('a'); + link.href = objectUrl; + link.download = fileName; + document.body.appendChild(link); + link.click(); + document.body.removeChild(link); + window.URL.revokeObjectURL(objectUrl); + ElMessage.success('下载成功'); } catch { ElMessage.error('下载失败'); }