view.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 = XML_EXPORT_BASE;
  12. const _cache = _base.CACHE;
  13. // 导出数据缓存,为了自检完后,再导出的时候不需要重新运行相关提取程序。(暂时取消了自检,但还是留着这个缓存机制)
  14. const _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. $('#export-confirm').click(async function () {
  29. let checkedDatas = $('#export input[type="checkbox"]:checked');
  30. if (!checkedDatas.length) {
  31. return;
  32. }
  33. if (STATE.exporting) {
  34. return;
  35. }
  36. STATE.exporting = true;
  37. let pr = new SCComponent.InitProgressBar();
  38. try {
  39. if (!_exportCache || !_exportCache.length) {
  40. pr.start('导出数据接口', '正在导出文件,请稍候……');
  41. for (let checkedData of checkedDatas) {
  42. let fileKind = parseInt($(checkedData).val());
  43. let exportData = await _base.extractExportData(XMLStandard.entry, _base.CONFIG.GRANULARITY.PROJECT,
  44. XMLStandard.summaryObj, fileKind, projectObj.project.ID(), userID);
  45. _exportCache.push(...exportData);
  46. }
  47. if (_exportCache && _exportCache.length) {
  48. // 导出文件
  49. await _base.exportFile(_exportCache, XMLStandard.saveAsFile);
  50. }
  51. }
  52. } catch (err) {
  53. console.log(err);
  54. alert(err);
  55. } finally {
  56. pr.end();
  57. setTimeout(() => {
  58. STATE.exporting = false;
  59. }, 300);
  60. }
  61. });
  62. //导出窗口--------
  63. $('#export').on('hide.bs.modal', function () {
  64. resetState();
  65. STATE.checking = false;
  66. STATE.exporting = false;
  67. $('#export input[type="checkbox"]:eq(0)').prop('checked', true);
  68. });
  69. $('#export input[type="checkbox"]').click(function () {
  70. resetState();
  71. });
  72. }
  73. return { exportListener }
  74. })();