feat: 优化下载逻辑
This commit is contained in:
@ -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) => {
|
||||
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) => {
|
||||
|
||||
Reference in New Issue
Block a user