From 5c8b21279c71dcbc62bdbee5c65b3d8428ec985e Mon Sep 17 00:00:00 2001 From: liugang Date: Mon, 6 Nov 2023 10:20:01 +0800 Subject: [PATCH] + chartJS: add function to filter a chart. --- module/chart/js/preview.ui.js | 47 +++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/module/chart/js/preview.ui.js b/module/chart/js/preview.ui.js index 5d644a7ddd..cc6952cb24 100644 --- a/module/chart/js/preview.ui.js +++ b/module/chart/js/preview.ui.js @@ -23,3 +23,50 @@ function previewCharts() postAndLoadPage(previewUrl, form, '#chartPanel'); } } + +/** + * 筛选一个图表。 + * Filter a chart. + * + * @param string chartID + * @access public + * @return bool|void + */ +loadChart = function(chartID) +{ + if(!chartID.includes('_')) return false; + + const keys = chartID.split('_'); + const form = new FormData(); + form.append('groupID', keys[0]); + form.append('chartID', keys[1]); + + $('#filter_' + chartID + ' .filter').each(function(index) + { + const $filter = $(this); + if ($filter.hasClass('filter-input')) + { + form.append('filterValues[' + index + ']', $filter.find('input').val()); + } + else if($filter.hasClass('filter-select')) + { + const value = $filter.find('.pick-value').val(); + form.append('filterValues[' + index + ']', typeof value == 'array' ? value.filter(Boolean) : value); + } + else if($filter.hasClass('filter-date') || $filter.hasClass('filter-datetime')) + { + const $pickValue = $filter.find('.pick-value'); + if($pickValue.length == 1) + { + form.append('filterValues[' + index + ']', $pickValue.val()); + } + else if($pickValue.length == 2) + { + form.append('filterValues[' + index + '][begin]', $pickValue.eq(0).val()); + form.append('filterValues[' + index + '][end]', $pickValue.eq(1).val()); + } + } + }); + + postAndLoadPage(previewUrl, form, '#chart_' + chartID); +}