feat: 优化下载逻辑

This commit is contained in:
2025-12-10 16:17:17 +08:00
parent 024cb1e56b
commit 911cc73db8

View File

@ -200,9 +200,30 @@ const handlePictureCardPreview = (file) => {
dialogImageUrl.value = file.url || '';
dialogVisible.value = true;
};
function downloadFile(url, filename) {
fetch(url)
.then((response) => 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));
}
const handleDownload = (file) => {
window.open(file.response.data);
if (file?.response?.data) {
window.open(file.response.data);
} else if (file?.url) {
downloadFile(file.url, file.name);
}
};
// const handleDownload = (file) => {
// window.open(file.response.data);
// };
// 删除文件 触发父组件更新
const beforeRemove = (file) => {