From 59ae4e3efe378a880f27a242f7a75bb075b7fe3e Mon Sep 17 00:00:00 2001 From: zhangyu Date: Mon, 7 Dec 2020 11:08:18 +0800 Subject: [PATCH] =?UTF-8?q?fix=EF=BC=9A=E4=BF=AE=E6=94=B9chart=E9=A2=84?= =?UTF-8?q?=E8=A7=88=E7=9A=84=E6=97=B6=E5=80=99last=E4=B8=8D=E7=94=9F?= =?UTF-8?q?=E6=95=88=E7=9A=84=E9=97=AE=E9=A2=98=20=E4=BB=A5=E5=8F=8Atype?= =?UTF-8?q?=E4=B8=BAtable=E6=97=B6=E7=9A=84value=E5=80=BC=E7=9A=84?= =?UTF-8?q?=E9=A2=9C=E8=89=B2=E4=B8=8D=E6=98=AF=E6=8C=89=E7=85=A7=E8=8C=83?= =?UTF-8?q?=E5=9B=B4=E6=9D=A5=E7=9A=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nezha-fronted/src/components/charts/chart-table.vue | 3 ++- nezha-fronted/src/components/charts/chartPreview.vue | 12 +++++++++++- .../src/components/page/dashboard/chartBox.vue | 2 ++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/nezha-fronted/src/components/charts/chart-table.vue b/nezha-fronted/src/components/charts/chart-table.vue index edb8e4ca4..fd8186b98 100644 --- a/nezha-fronted/src/components/charts/chart-table.vue +++ b/nezha-fronted/src/components/charts/chart-table.vue @@ -65,7 +65,7 @@ @@ -397,6 +397,7 @@ mapping=mappings.find(t=>{return t.from <= value&& t.to >= value}); } this.mapping=mapping; + item.mapping=mapping; item.value = mapping?mapping.text.replace('{{value}}', item.value):chartDataFormat.getUnit(chartItem.unit?chartItem.unit:2).compute(value,null,2); } return item; diff --git a/nezha-fronted/src/components/charts/chartPreview.vue b/nezha-fronted/src/components/charts/chartPreview.vue index 72b7f575c..2a29aaf80 100644 --- a/nezha-fronted/src/components/charts/chartPreview.vue +++ b/nezha-fronted/src/components/charts/chartPreview.vue @@ -143,7 +143,7 @@ @@ -368,6 +368,7 @@ // 获取一个图表具体数据 getChartData() { const chartItem = this.chart; + console.log(chartItem); if(chartItem.type === 'alertList'){ this.getAlertListChartData(chartItem,null); return; @@ -401,6 +402,9 @@ const axiosArr = chartItem.elements.map((ele) => { const filterItem = ele; let query = encodeURIComponent(filterItem.expression); + if(chartItem.type === 'table'&&chartItem.param&&chartItem.param.last == 1){ + return this.$get('/prom/api/v1/query_range?query=' + query + "&start=" + this.$stringTimeParseToUnix(endTime) + "&end=" + this.$stringTimeParseToUnix(endTime) + '&step=' + step); + } return this.$get('/prom/api/v1/query_range?query='+query+"&start="+this.$stringTimeParseToUnix(startTime)+"&end="+this.$stringTimeParseToUnix(endTime)+'&step='+step); }); // 一个图表的所有element单独获取数据 @@ -1049,6 +1053,7 @@ mapping=mappings.find(t=>{return t.from <= value&& t.to >= value}); } this.mapping=mapping; + item.mapping=mapping; item.value = mapping?mapping.text.replace('{{value}}', item.value):this.unit.compute(value,null,2); } return item; @@ -1121,6 +1126,8 @@ // 查询数据,修改日期查询全屏数据 getQueryChart(type) { let axiosArr = []; + const chartItem = this.chart; + console.log(chartItem); this.$nextTick(() => { let startTime = bus.timeFormate(this.searchTime[0], 'yyyy-MM-dd hh:mm:ss'); let endTime = bus.timeFormate(this.searchTime[1], 'yyyy-MM-dd hh:mm:ss'); @@ -1135,6 +1142,9 @@ axiosArr = this.chart.elements.map((ele) => { const filterItem = ele; let query = encodeURIComponent(filterItem.expression); + if(chartItem.type === 'table'&&chartItem.param&&chartItem.param.last == 1){ + return this.$get('/prom/api/v1/query_range?query=' + query + "&start=" + this.$stringTimeParseToUnix(endTime) + "&end=" + this.$stringTimeParseToUnix(endTime) + '&step=' + step); + } return this.$get('/prom/api/v1/query_range?query='+query+"&start="+this.$stringTimeParseToUnix(startTime)+"&end="+this.$stringTimeParseToUnix(endTime)+'&step='+step); }); // 一个图表 diff --git a/nezha-fronted/src/components/page/dashboard/chartBox.vue b/nezha-fronted/src/components/page/dashboard/chartBox.vue index 5144f11a0..37302bb87 100644 --- a/nezha-fronted/src/components/page/dashboard/chartBox.vue +++ b/nezha-fronted/src/components/page/dashboard/chartBox.vue @@ -1432,6 +1432,7 @@ } params.param.nullType=this.editChart.param.nullType; params.param.legendValue=this.editChart.param.legendValue; + params.param.last=this.editChart.param.last; } else { delete params.param.threshold; delete params.param.nullType; @@ -1446,6 +1447,7 @@ }); }); params.elements = elements; + console.log(params,'params'); if (valid) { this.$refs.chartsPreview.show(params); }