This commit is contained in:
oneao committed 2026-03-24 21:27:27 +08:00
1 parent b7f50f3ccb
commit 11bcef03e1
8 files changed
+437 -537

No files matched your search

+14 -18
View File
@@ -287,7 +287,6 @@ export function getAliyunFileBlob(url) {
// 检查响应状态
if (!response.ok) {
ElMessage.error(`下载失败:${response.status}`);
reject(new Error(`下载失败:${response.status}`));
return;
}
@@ -298,8 +297,6 @@ export function getAliyunFileBlob(url) {
// 返回blob
resolve(blob);
} catch (error) {
// 捕获网络请求失败或其他错误
ElMessage.error("下载文件时发生错误");
reject(error);
}
}
@@ -311,27 +308,26 @@ export function getAliyunFileBlob(url) {
export function downloadZip(files, fileName = "文件合集", callback) {
const zip = new JSZip();
const addedFiles = new Set(); // 用来存储已添加的文件名
const addedFiles = new Set();
let result = files.map((item) => {
let promise = getAliyunFileBlob(item.mx_mapfilename).then((res) => {
// 处理文件名重复的情况
let uniqueFileName = getUniqueFileName(item.mx_filename, addedFiles);
const tasks = files.map((item) => {
return getAliyunFileBlob(item.mx_mapfilename).then((res) => {
const uniqueFileName = getUniqueFileName(item.mx_filename, addedFiles);
zip.file(uniqueFileName, res, { binary: true });
addedFiles.add(uniqueFileName); // 添加文件名到已添加的集合中
addedFiles.add(uniqueFileName);
});
return promise;
});
Promise.all(result)
.then(() => {
zip.generateAsync({ type: "blob" }).then((res) => {
callback && callback();
saveAs(res, `${fileName}.zip`);
});
})
.catch(() => {
// ✅ 关键:return
return Promise.all(tasks)
.then(() => zip.generateAsync({ type: "blob" }))
.then((res) => {
saveAs(res, `${fileName}.zip`);
callback && callback();
})
.catch((err) => {
callback && callback();
throw err; // ✅ 继续往外抛
});
}