/** * * * @author Zhong * @date 2019/6/5 * @version */ //导出接口相关 const EXPORT_VIEW = (() => { 'use strict'; const _base = INTERFACE_EXPORT_BASE; const _cache = _base.CACHE; // 导出数据缓存,为了自检完后,再导出的时候不需要重新运行相关提取程序。(暂时取消了自检,但还是留着这个缓存机制) let _exportCache = []; // 操作状态 const STATE = { checking: false, // 自检 exporting: false, // 导出 }; // 回到初始状态,需要清空cache中的数据 function resetState() { _exportCache = []; _cache.clear(); } //事件监听 function exportListener() { // 导出接口 $('#interface-export-confirm').click(async function () { const pr = new SCComponent.InitProgressBar(); try { const checkedDatas = $('#interface-export-modal input[type="checkbox"]:checked'); if (!checkedDatas.length) { throw '请勾选导出文件。'; } const parentArea = $('#export-parent-area').val(); const subArea = $('#export-sub-area').val(); if (!parentArea || !subArea) { throw '请选择有效地区。'; } // 按照地区动态加载导出脚本 const areaKey = `${parentArea}@${subArea}`; await STD_INTERFACE.loadScriptByArea(areaKey, STD_INTERFACE.ScriptType.EXPORT); if (STATE.exporting) { return; } STATE.exporting = true; if (!_exportCache || !_exportCache.length) { pr.start('导出数据接口', '正在导出文件,请稍候……'); for (const checkedData of checkedDatas) { const boqType = parseInt($(checkedData).val()); const requestForSummaryInfo = INTERFACE_EXPORT.requestForSummaryInfo || null; const projectID = projectObj.project.ID(); const exportData = await _base.extractExportData(INTERFACE_EXPORT.entry, requestForSummaryInfo, boqType, areaKey, projectID, userID); _exportCache.push(...exportData); } } if (_exportCache && _exportCache.length) { // 导出文件 await _base.exportFile(_exportCache, INTERFACE_EXPORT.saveAsFile || INTERFACE_EXPORT_BASE.defaultSaveAs); } } catch (err) { console.log(err); alert(err); } finally { pr.end(); setTimeout(() => { STATE.exporting = false; }, 300); } }); //导出窗口-------- $('#interface-export-modal').on('hide.bs.modal', function () { resetState(); STATE.checking = false; STATE.exporting = false; $('#interface-export-modal input[type="checkbox"]:eq(0)').prop('checked', true); }); $('#interface-export-modal input[type="checkbox"]').click(function () { resetState(); }); } return { exportListener, resetState } })(); $(document).ready(() => { $('#interface-export-modal').on('show.bs.modal', () => STD_INTERFACE.initExportAreas($('#export-parent-area'), $('#export-sub-area'))); EXPORT_VIEW.exportListener(); })