| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- /**
- *
- *
- * @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() {
- // 导出接口
- $('#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 || {};
- const projectID = projectObj.project.ID();
- const exportData = await _base.extractExportData(INTERFACE_EXPORT.entry, requestForSummaryInfo, boqType, projectID, userID);
- _exportCache.push(...exportData);
- }
- if (_exportCache && _exportCache.length) {
- // 导出文件
- await _base.exportFile(_exportCache, INTERFACE_EXPORT.saveAsFile || null);
- }
- }
- } 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 }
- })();
- $(document).ready(() => {
- $('#interface-export-modal').on('show.bs.modal', () => STD_INTERFACE.initExportAreas($('#export-parent-area'), $('#export-sub-area')));
- EXPORT_VIEW.exportListener();
- })
|