preview.ui.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /**
  2. * 预览选中的图表。
  3. * Preview the selected charts.
  4. *
  5. * @access public
  6. * @return void
  7. */
  8. function previewCharts()
  9. {
  10. const checkedList = $('#moduleMenu menu').zui('tree').$.getChecks();
  11. const checkedCharts = [];
  12. checkedList.forEach((itemKey, index) => {
  13. if(itemKey.includes(':') && itemKey.includes('_'))
  14. {
  15. const keys = itemKey.split(':')[1].split('_');
  16. checkedCharts.push({index, keys});
  17. }
  18. });
  19. if(checkedCharts.length == 0) return;
  20. if(checkedCharts.length > maxPreviewCount)
  21. {
  22. zui.Modal.alert(maxPreviewTips);
  23. return false;
  24. }
  25. const form = new FormData();
  26. checkedCharts.forEach(chart => {
  27. const {index, keys} = chart;
  28. form.append('charts[' + index + '][groupID]', keys[0]);
  29. form.append('charts[' + index + '][chartID]', keys[1]);
  30. });
  31. postAndLoadPage(previewUrl, form, '#chartPanel');
  32. }
  33. /**
  34. * 筛选一个图表。
  35. * Filter a chart.
  36. *
  37. * @param string chartID
  38. * @access public
  39. * @return bool|void
  40. */
  41. loadChart = function(chartID)
  42. {
  43. if(!chartID.includes('_')) return false;
  44. const keys = chartID.split('_');
  45. const form = new FormData();
  46. form.append('groupID', keys[0]);
  47. form.append('chartID', keys[1]);
  48. $('#filter_' + chartID + ' .filter').each(function(index)
  49. {
  50. const $filter = $(this);
  51. if ($filter.hasClass('filter-input'))
  52. {
  53. form.append('filterValues[' + index + ']', $filter.find('input').val());
  54. }
  55. else if($filter.hasClass('filter-select'))
  56. {
  57. const value = $filter.find('.pick-value').val();
  58. if(Array.isArray(value))
  59. {
  60. value.filter(Boolean).forEach((item) => form.append('filterValues[' + index + '][]', item));
  61. }
  62. else
  63. {
  64. form.append('filterValues[' + index + ']', value);
  65. }
  66. }
  67. else if($filter.hasClass('filter-date') || $filter.hasClass('filter-datetime'))
  68. {
  69. const $pickValue = $filter.find('.pick-value');
  70. if($pickValue.length == 1)
  71. {
  72. form.append('filterValues[' + index + ']', $pickValue.val());
  73. }
  74. else if($pickValue.length == 2)
  75. {
  76. form.append('filterValues[' + index + '][begin]', $pickValue.eq(0).val());
  77. form.append('filterValues[' + index + '][end]', $pickValue.eq(1).val());
  78. }
  79. }
  80. });
  81. postAndLoadPage(previewUrl, form, '#chart_' + chartID);
  82. }