view.js 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /**
  2. *
  3. *
  4. * @author Zhong
  5. * @date 2019/6/5
  6. * @version
  7. */
  8. //导出接口相关
  9. const EXPORT_VIEW = (() => {
  10. 'use strict';
  11. const _base = INTERFACE_EXPORT_BASE;
  12. const _cache = _base.CACHE;
  13. // 导出数据缓存,为了自检完后,再导出的时候不需要重新运行相关提取程序。(暂时取消了自检,但还是留着这个缓存机制)
  14. let _exportCache = [];
  15. // 操作状态
  16. const STATE = {
  17. checking: false, // 自检
  18. exporting: false, // 导出
  19. };
  20. // 回到初始状态,需要清空cache中的数据
  21. function resetState() {
  22. _exportCache = [];
  23. _cache.clear();
  24. }
  25. //事件监听
  26. function exportListener() {
  27. // 导出接口
  28. $('#interface-export-confirm').click(async function () {
  29. const pr = new SCComponent.InitProgressBar();
  30. try {
  31. const checkedDatas = $('#interface-export-modal input[type="checkbox"]:checked');
  32. if (!checkedDatas.length) {
  33. throw '请勾选导出文件。';
  34. }
  35. const parentArea = $('#export-parent-area').val();
  36. const subArea = $('#export-sub-area').val();
  37. if (!parentArea || !subArea) {
  38. throw '请选择有效地区。';
  39. }
  40. // 按照地区动态加载导出脚本
  41. const areaKey = `${parentArea}@${subArea}`;
  42. await STD_INTERFACE.loadScriptByArea(areaKey, STD_INTERFACE.ScriptType.EXPORT);
  43. if (STATE.exporting) {
  44. return;
  45. }
  46. STATE.exporting = true;
  47. if (!_exportCache || !_exportCache.length) {
  48. pr.start('导出数据接口', '正在导出文件,请稍候……');
  49. for (const checkedData of checkedDatas) {
  50. const boqType = parseInt($(checkedData).val());
  51. const requestForSummaryInfo = INTERFACE_EXPORT.requestForSummaryInfo || null;
  52. const projectID = projectObj.project.ID();
  53. const exportData = await _base.extractExportData(INTERFACE_EXPORT.entry, requestForSummaryInfo, boqType, areaKey, projectID, userID);
  54. _exportCache.push(...exportData);
  55. }
  56. }
  57. if (_exportCache && _exportCache.length) {
  58. // 导出文件
  59. await _base.exportFile(_exportCache, INTERFACE_EXPORT.saveAsFile || INTERFACE_EXPORT_BASE.defaultSaveAs);
  60. }
  61. } catch (err) {
  62. console.log(err);
  63. alert(err);
  64. } finally {
  65. pr.end();
  66. setTimeout(() => {
  67. STATE.exporting = false;
  68. }, 300);
  69. }
  70. });
  71. //导出窗口--------
  72. $('#interface-export-modal').on('hide.bs.modal', function () {
  73. resetState();
  74. STATE.checking = false;
  75. STATE.exporting = false;
  76. $('#interface-export-modal input[type="checkbox"]:eq(0)').prop('checked', true);
  77. });
  78. $('#interface-export-modal input[type="checkbox"]').click(function () {
  79. resetState();
  80. });
  81. }
  82. return { exportListener, resetState }
  83. })();
  84. $(document).ready(() => {
  85. $('#interface-export-modal').on('show.bs.modal', () => STD_INTERFACE.initExportAreas($('#export-parent-area'), $('#export-sub-area')));
  86. EXPORT_VIEW.exportListener();
  87. })