Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions simple-mind-map/src/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

// 节流函数
Expand Down