From b1eea9afa70651a679f5d229b7e6a84ecd4d98ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=8B=E8=BE=B0=E8=BD=A9?= Date: Mon, 17 Apr 2023 17:15:07 +0800 Subject: [PATCH] * Fix bug #34275. --- module/chart/js/common.js | 14 +++++ module/chart/js/preview.js | 86 +++++++++++++++--------------- module/chart/view/preview.html.php | 6 +-- 3 files changed, 61 insertions(+), 45 deletions(-) diff --git a/module/chart/js/common.js b/module/chart/js/common.js index f7d9bf587c..715932d691 100644 --- a/module/chart/js/common.js +++ b/module/chart/js/common.js @@ -87,3 +87,17 @@ function initDatepicker($obj, callback) if(typeof callback == 'function') callback($obj); } + +/** + * Attr date check. + * + * @param object $obj + * @access public + * @return void + */ +function attrDateCheck($obj) +{ + $obj.find('.form-date').attr('onchange', 'checkDate(this, this.value)'); + $obj.find('.form-datetime').attr('onchange', 'checkDate(this, this.value)'); +} + diff --git a/module/chart/js/preview.js b/module/chart/js/preview.js index 44955b951e..48b48de670 100644 --- a/module/chart/js/preview.js +++ b/module/chart/js/preview.js @@ -1,10 +1,8 @@ $(function() { initCheckBox(); - initQueryBtn(); $('#exportchart').modalTrigger(); - chartMap = new Map(); if(charts.length > 0) { var chartPros = charts.map(function(chart) @@ -12,7 +10,6 @@ $(function() var echartDom = $('#chartDraw' + chart.currentGroup + '_' + chart.id).get(0); var echart = echarts.init(echartDom); ajaxGetChart(false, chart, echart); - chartMap.set(chart.cudrrentGroup + chart.id, chart); return renderFilters(chart); }); @@ -21,9 +18,14 @@ $(function() calcPreviewGrowFilter(); $('body').resize(() => {calcPreviewGrowFilter(true);}); }); - } + chartMap = new Map(); + charts.forEach(function(chart) + { + chartMap.set(chart.currentGroup + '_' + chart.id, chart); + }); + $('[data-toggle="tooltip"]').tooltip(); }) @@ -73,53 +75,53 @@ function initCheckBox() /** * Init query button. * + * @param object $obj * @access public * @return void */ -function initQueryBtn() +function queryData(obj) { - $('.btn-query').click(function() + var chartID = $(obj).parents('.filterBox').attr('data-chart'); + var chartInfo = chartMap.get(chartID); + chartInfo.searchFilters = JSON.parse(JSON.stringify(chartInfo.filters)); + + // Foreach filters and set current value in searchFilters. */ + $('#filterItems' + chartID + ' .filter-items').children().each(function(index) { - var chartID = $(this).attr('data-chart'); - var chartInfo = chartMap.get(chartID); - chartInfo.searchFilters = JSON.parse(JSON.stringify(chartInfo.filters)); + var $child = $(this); + if(!$child.hasClass('filter-item')) return; - // Foreach filters and set current value in searchFilters. */ - $('#filterItems' + chartID + ' .filter-items').children().each(function(index) + var filter = chartInfo.searchFilters[index]; + var type = filter.type; + var value = null; + + if(type == 'input' || type == 'select') { - var $child = $(this); - var filter = chartInfo.searchFilters[index]; - var type = filter.type; - var value = null; + var value = $child.find('#default').val(); + chartInfo.searchFilters[index].default = value; + } + else if(type == 'date' || type == 'datetime') + { + var begin = $child.find('input').first().val(); + var end = $child.find('input').last().val(); - if(type == 'input' || type == 'select') - { - var value = $child.find('#default').val(); - chartInfo.searchFilters[index].default = value; - } - else if(type == 'date' || type == 'datetime') - { - var begin = $child.find('input').first().val(); - var end = $child.find('input').last().val(); + var value = {"begin":begin, "end":end}; + chartInfo.searchFilters[index].default = value; + } + else if(type == 'condition') + { + var operator = $child.find('#operator').data('zui.picker').getValue(); + var value = $child.find('#value').val(); - var value = {"begin":begin, "end":end}; - chartInfo.searchFilters[index].default = value; - } - else if(type == 'condition') - { - var operator = $child.find('#operator').data('zui.picker').getValue(); - var value = $child.find('#value').val(); - - chartInfo.searchFilters[index].operator = operator; - chartInfo.searchFilters[index].value = value; - } - }); - - //* Reload echart. */ - var echartDom = $('#chartDraw' + chartID).get(0); - var echartInfo = echarts.init(echartDom); - ajaxGetChart(false, chartInfo, echartInfo); + chartInfo.searchFilters[index].operator = operator; + chartInfo.searchFilters[index].value = value; + } }); + + //* Reload echart. */ + var echartDom = $('#chartDraw' + chartID).get(0); + var echartInfo = echarts.init(echartDom); + ajaxGetChart(false, chartInfo, echartInfo); } function calcPreviewGrowFilter(resize = false) @@ -247,6 +249,6 @@ function renderFilterItem(filter, resp, index, step) }; var html = $($.zui.formatString(tpl, data)) initPicker(html, 'picker-select', true); - initDatepicker(html); + initDatepicker(html, attrDateCheck); return html; } diff --git a/module/chart/view/preview.html.php b/module/chart/view/preview.html.php index 758931353d..f9ed630a22 100644 --- a/module/chart/view/preview.html.php +++ b/module/chart/view/preview.html.php @@ -20,7 +20,7 @@ chart->widthInput);?> chart->widthDate);?> bi->pickerHeight);?> - ";?> + ";?>
-
+
filters)):?> -
chart->query, "data-chart={$chart->currentGroup}{$chart->id}", 'btn btn-primary btn-query');?>
+
chart->query, "onclick='queryData(this)'", 'btn btn-primary btn-query');?>