diff --git a/src/components/MyComponents/Upload/index.vue b/src/components/MyComponents/Upload/index.vue index 28e3d61..8ced42e 100644 --- a/src/components/MyComponents/Upload/index.vue +++ b/src/components/MyComponents/Upload/index.vue @@ -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) => {