feat: 更新下载功能以支持Blob数据处理

- 移除`localPath`参数,简化下载接口
- 在`downloadToFile`函数中添加`responseType: 'blob'`以处理二进制数据
- 更新下载逻辑,使用Blob对象创建下载链接并触发下载成功提示
This commit is contained in:
2026-04-22 12:42:23 +08:00
parent 049f9dd68f
commit 94882bc9a5
2 changed files with 15 additions and 3 deletions

View File

@@ -59,7 +59,6 @@ export interface CreationSubmitParams {
export interface DownloadToFileParams { export interface DownloadToFileParams {
fileURL: string; fileURL: string;
localPath: string;
} }
export function getCreationList(params: CreationListParams) { export function getCreationList(params: CreationListParams) {
@@ -75,6 +74,7 @@ export function createCreation(data: CreationSubmitParams) {
url: '/black-deacon/creation/info/creation', url: '/black-deacon/creation/info/creation',
method: 'post', method: 'post',
data, data,
timeout: 0,
}); });
} }
@@ -83,5 +83,6 @@ export function downloadToFile(data: DownloadToFileParams) {
url: '/oss/file/downloadToBrowser', url: '/oss/file/downloadToBrowser',
method: 'post', method: 'post',
data, data,
responseType: 'blob',
}); });
} }

View File

@@ -249,8 +249,19 @@ const downloadNode = async (data: TreeNode) => {
if (data.nodeType !== 'html' && data.nodeType !== 'image') return; if (data.nodeType !== 'html' && data.nodeType !== 'image') return;
if (!data.fileUrl) return ElMessage.warning('当前节点没有可下载地址'); if (!data.fileUrl) return ElMessage.warning('当前节点没有可下载地址');
try { try {
await downloadToFile({ fileURL: data.fileUrl, localPath: 'C:/Users/AI/Desktop' }); const response = await downloadToFile({ fileURL: data.fileUrl });
ElMessage.success('已提交下载到本地'); 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 { } catch {
ElMessage.error('下载失败'); ElMessage.error('下载失败');
} }