This commit is contained in:
oneao committed 2026-03-25 17:31:22 +08:00
1 parent 11bcef03e1
commit a4e59dd5d1
39 files changed
+2333 -459

No files matched your search

@@ -0,0 +1,53 @@
import { ElMessage } from "element-plus";
/**
* 复制文本到剪切板
* @param text 复制内容
* @returns 是否复制成功
*/
export function copyText(text) {
if (navigator.clipboard && window.isSecureContext) {
// 现代浏览器和安全环境下,直接用 Clipboard API
return navigator.clipboard
.writeText(text)
.then(() => {
ElMessage.success("复制成功");
})
.catch((err) => {
ElMessage.error("复制失败:" + err);
});
} else {
// 退回到传统方式
fallbackCopyText(text);
}
}
/**
* 复制文本到剪切板的传统方式
* @param text 复制内容
*/
function fallbackCopyText(text) {
const textArea = document.createElement("textarea");
textArea.value = text;
// 避免滚动到页面底部
textArea.style.position = "fixed";
textArea.style.top = "0";
textArea.style.left = "0";
document.body.appendChild(textArea);
textArea.focus();
textArea.select();
try {
const successful = document.execCommand("copy");
if (successful) {
console.log("复制成功(fallback)");
} else {
console.log("复制失败(fallback)");
}
} catch (err) {
console.error("复制失败(fallback)", err);
}
document.body.removeChild(textArea);
}
+12 -7
View File
@@ -311,14 +311,19 @@ export function downloadZip(files, fileName = "文件合集", callback) {
const addedFiles = new Set();
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);
});
return getAliyunFileBlob(item.mx_mapfilename)
.then((res) => {
const uniqueFileName = getUniqueFileName(item.mx_filename, addedFiles);
zip.file(uniqueFileName, res, { binary: true });
addedFiles.add(uniqueFileName);
})
.catch((err) => {
// 捕获单个文件下载失败的错误,不影响其他文件下载
console.error(`Failed to download file: ${item.mx_filename}`, err);
});
});
// ✅ 关键:return
// 关键:使用 Promise.all 确保所有任务完成
return Promise.all(tasks)
.then(() => zip.generateAsync({ type: "blob" }))
.then((res) => {
@@ -327,7 +332,7 @@ export function downloadZip(files, fileName = "文件合集", callback) {
})
.catch((err) => {
callback && callback();
throw err; // ✅ 继续往外抛
throw err;
});
}