UNPKG

t-comm

Version:

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

56 lines (51 loc) 1.68 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var tslib_es6 = require('../tslib.es6-01322ba9.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 tslib_es6.__awaiter(this, void 0, void 0, function () { var zip, _i, fileList_1, file, content, error_1; return tslib_es6.__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*/]; } }); }); } exports.downloadFileFromBlob = downloadFileFromBlob; exports.downloadFilesToZip = downloadFilesToZip;