/** * * * @author Zhong * @date 2019/6/5 * @version */ //导出接口相关 const EXPORT_VIEW = (() => { 'use strict'; const _base = XML_EXPORT_BASE; const _cache = _base.CACHE; // 导出数据缓存,为了自检完后,再导出的时候不需要重新运行相关提取程序。(暂时取消了自检,但还是留着这个缓存机制) const _exportCache = []; // 操作状态 const STATE = { checking: false, // 自检 exporting: false, // 导出 }; // 回到初始状态,需要清空cache中的数据 function resetState() { _exportCache = []; _cache.clear(); } //事件监听 function exportListener() { // 导出接口 $('#export-confirm').click(async function () { let checkedDatas = $('#export input[type="checkbox"]:checked'); if (!checkedDatas.length) { return; } if (STATE.exporting) { return; } STATE.exporting = true; let pr = new SCComponent.InitProgressBar(); try { if (!_exportCache || !_exportCache.length) { pr.start('导出数据接口', '正在导出文件,请稍候……'); for (let checkedData of checkedDatas) { let fileKind = parseInt($(checkedData).val()); let exportData = await _base.extractExportData(XMLStandard.entry, _base.CONFIG.GRANULARITY.PROJECT, XMLStandard.summaryObj, fileKind, projectObj.project.ID(), userID); _exportCache.push(...exportData); } if (_exportCache && _exportCache.length) { // 导出文件 await _base.exportFile(_exportCache, XMLStandard.saveAsFile); } } } catch (err) { console.log(err); alert(err); } finally { pr.end(); setTimeout(() => { STATE.exporting = false; }, 300); } }); //导出窗口-------- $('#export').on('hide.bs.modal', function () { resetState(); STATE.checking = false; STATE.exporting = false; $('#export input[type="checkbox"]:eq(0)').prop('checked', true); }); $('#export input[type="checkbox"]').click(function () { resetState(); }); } return { exportListener } })();