From c6009d189a7f4eec4ba3e43a54b2205b4518d811 Mon Sep 17 00:00:00 2001 From: xulongbiao <1151051851@qq.com> Date: Thu, 27 Mar 2025 18:59:03 +0800 Subject: [PATCH] =?UTF-8?q?Fix:=20=E4=BF=AE=E5=A4=8D=E5=AE=89=E5=8D=93?= =?UTF-8?q?=E5=AF=BC=E5=87=BA=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- simple-mind-map/src/utils/index.js | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/simple-mind-map/src/utils/index.js b/simple-mind-map/src/utils/index.js index b3524ad85..9becbd1f0 100644 --- a/simple-mind-map/src/utils/index.js +++ b/simple-mind-map/src/utils/index.js @@ -270,11 +270,28 @@ export const parseDataUrl = data => { } // 下载文件 + export const downloadFile = (file, fileName) => { - let a = document.createElement('a') - a.href = file - a.download = fileName - a.click() + // 将 Base64 数据转换为 Blob 对象 + const byteCharacters = atob(file.split(',')[1]); + const byteNumbers = new Array(byteCharacters.length); + for (let i = 0; i < byteCharacters.length; i++) { + byteNumbers[i] = byteCharacters.charCodeAt(i); + } + const byteArray = new Uint8Array(byteNumbers); + const blob = new Blob([byteArray], { type: file.split(',')[0].split(':')[1].split(';')[0] }); + + // 创建一个临时的 URL + const url = URL.createObjectURL(blob); + + // 创建一个 a 标签并触发下载 + let a = document.createElement('a'); + a.href = url; + a.download = fileName; + a.click(); + + // 释放临时 URL + URL.revokeObjectURL(url); } // 节流函数