UNPKG

t-comm

Version:

专业、稳定、纯粹的工具库

51 lines (48 loc) 1.55 kB
import { b as __awaiter, c as __generator } from '../tslib.es6-096fffdd.js'; function downloadFileFromBlob(_a) { var blob = _a.blob, fileName = _a.fileName; var url = window.URL.createObjectURL(new Blob([blob])); var link = document.createElement('a'); link.href = url; link.download = fileName; link.style.visibility = 'hidden'; document.body.appendChild(link); link.click(); document.body.removeChild(link); } function downloadFilesToZip(_a) { var fileList = _a.fileList, zipName = _a.zipName, saveAs = _a.saveAs, JSZip = _a.JSZip; return __awaiter(this, void 0, void 0, function () { var zip, _i, fileList_1, file, content, error_1; return __generator(this, function (_b) { switch (_b.label) { case 0: _b.trys.push([0, 2,, 3]); zip = new JSZip(); // 异步下载每个文件并添加到zip中 for (_i = 0, fileList_1 = fileList; _i < fileList_1.length; _i++) { file = fileList_1[_i]; zip.file("".concat(file.name), file.content); } return [4 /*yield*/, zip.generateAsync({ type: 'blob' })]; case 1: content = _b.sent(); saveAs(content, zipName); return [2 /*return*/, true]; case 2: error_1 = _b.sent(); console.error('批量下载失败:', error_1); return [2 /*return*/, false]; case 3: return [2 /*return*/]; } }); }); } export { downloadFileFromBlob, downloadFilesToZip };