/**
* 预览链接生成文件
* @param url 预览链接
* @param fileName 导出生成文件名
*/
const downloadPDF = async (url, fileName) => {
fetch(url)
.then(response => {
if (!response.ok) throw new Error('网络错误');
return response.blob();
})
.then(blob => {
const link = document.createElement('a');
link.href = URL.createObjectURL(blob);
link.download = fileName;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
URL.revokeObjectURL(link.href); // 释放内存
})
.catch(error => {
console.error('下载失败:', error);
});
};
将文件预览链接通过点击下载文件
最新推荐文章于 2025-03-16 17:18:06 发布