perf:explore unit选择功能补充

This commit is contained in:
wangwenrui
2020-04-29 11:48:47 +08:00
parent 8e6e49647d
commit 690db89452
3 changed files with 31 additions and 17 deletions

View File

@@ -1,13 +1,17 @@
<template> <template>
<el-cascader filterable placeholder="" popper-class="no-style-class unit-pop-class" size="mini" <div style="display: flex;justify-content: flex-start">
:options="chartUnits" <button class="input-prepend nz-btn nz-btn-size-small nz-btn-style-light nz-btn-style-square nz-input-group-prepend" @click="openSeletor">{{$t('dashboard.panel.chartForm.unit')}}</button>
class="chart-unit" <el-cascader filterable placeholder="" popper-class="no-style-class unit-pop-class" size="mini"
:props="{ expandTrigger: 'click' ,emitPath:false}" :options="chartUnits"
:show-all-levels="false" class="chart-unit"
v-model="unit" :props="{ expandTrigger: 'click' ,emitPath:false}"
@change="unitSelected" :show-all-levels="false"
> v-model="unit"
</el-cascader> @change="unitSelected"
ref="unitSelector"
>
</el-cascader>
</div>
</template> </template>
<script> <script>
@@ -36,6 +40,9 @@
this.unit=value; this.unit=value;
this.$emit('change',this.unit); this.$emit('change',this.unit);
}, },
openSeletor:function(){
this.$refs.unitSelector.toggleDropDownVisible(!this.$refs.unitSelector.dropDownVisible);
}
} }
} }
</script> </script>
@@ -49,4 +56,11 @@
height: 200px; height: 200px;
background-color: #FFF; background-color: #FFF;
} }
.input-prepend{
height: 26px;
margin-top: 1px;
padding:0 5px !important;
border-bottom-right-radius: 0px !important;
border-top-right-radius: 0px !important;
}
</style> </style>

View File

@@ -134,7 +134,7 @@
<el-col v-show="!isUrl" :span="10"> <el-col v-show="!isUrl" :span="10">
<el-cascader filterable placeholder="" popper-class="dc-dropdown" size="mini" <el-cascader filterable placeholder="" popper-class="dc-dropdown" size="mini"
:options="unitOptions" :options="unitOptions"
:props="{ expandTrigger: 'hover' }" :props="{ expandTrigger: 'hover',emitPath:false }"
:show-all-levels="false" :show-all-levels="false"
v-model="chart.unit" v-model="chart.unit"
@change="unitSelected" @change="unitSelected"
@@ -378,6 +378,9 @@
setTitle(title) { setTitle(title) {
this.rightBox.title = title; this.rightBox.title = title;
}, },
setUnit:function(unit){
this.$set(this.chart,'unit',Number.parseInt(unit))
},
save() { save() {
this.$refs['chartForm'].validate((valid) => { this.$refs['chartForm'].validate((valid) => {
if (valid) { if (valid) {

View File

@@ -200,6 +200,7 @@ instance_cpu_time_ns{app="fox", proc="widget", rev="4d3a513", env="prod", job="c
import axios from 'axios'; import axios from 'axios';
import chartBox from "../../../page/dashboard/chartBox"; import chartBox from "../../../page/dashboard/chartBox";
import {getUUID} from "../../../common/js/common"; import {getUUID} from "../../../common/js/common";
import chartDataFormat from "../../../charts/chartDataFormat";
export default { export default {
name: "explore", name: "explore",
@@ -256,7 +257,7 @@ instance_cpu_time_ns{app="fox", proc="widget", rev="4d3a513", env="prod", job="c
chartUnitChange:function(unit){ chartUnitChange:function(unit){
this.chartUnit=unit; this.chartUnit=unit;
this.$nextTick(()=>{ this.$nextTick(()=>{
this.queryChartData(); this.expressionChange()
}) })
}, },
queryChartData: function () { queryChartData: function () {
@@ -296,7 +297,6 @@ instance_cpu_time_ns{app="fox", proc="widget", rev="4d3a513", env="prod", job="c
seriesItem.data = result.values.map((item) => { seriesItem.data = result.values.map((item) => {
return [item[0] * 1000, item[1]]; return [item[0] * 1000, item[1]];
}) })
console.log(result)
if(result.metric&&Object.keys(result.metric).length>0){ if(result.metric&&Object.keys(result.metric).length>0){
let metric = Object.assign({}, result.metric); let metric = Object.assign({}, result.metric);
seriesItem.name += metric.__name__ + '{'; seriesItem.name += metric.__name__ + '{';
@@ -358,7 +358,7 @@ instance_cpu_time_ns{app="fox", proc="widget", rev="4d3a513", env="prod", job="c
if (data) { if (data) {
data.forEach((result, i) => { data.forEach((result, i) => {
let metrics = Object.assign({}, result.metric); let metrics = Object.assign({}, result.metric);
this.$set(metrics, 'value#' + index, result.value[1]); this.$set(metrics, 'value#' + index, chartDataFormat.getUnit(this.chartUnit).compute(result.value[1],null,2));
for (let key in metrics) { for (let key in metrics) {
let label = { let label = {
label: key == '__name__' ? 'metric' : key, label: key == '__name__' ? 'metric' : key,
@@ -380,7 +380,6 @@ instance_cpu_time_ns{app="fox", proc="widget", rev="4d3a513", env="prod", job="c
return a.prop.charCodeAt(0) - b.prop.charCodeAt(0); return a.prop.charCodeAt(0) - b.prop.charCodeAt(0);
}) })
}) })
console.log(tData.length)
if(tData.length>0){ if(tData.length>0){
this.storedTableData = Object.assign([], tData); this.storedTableData = Object.assign([], tData);
this.pageObj.total = this.storedTableData.length; this.pageObj.total = this.storedTableData.length;
@@ -410,9 +409,6 @@ instance_cpu_time_ns{app="fox", proc="widget", rev="4d3a513", env="prod", job="c
this.promqlCount++; this.promqlCount++;
}, },
removeExpression: function (index) { removeExpression: function (index) {
console.log(this.expressions)
console.log(this.promqlKeys)
console.log(this.promqlCount)
if (this.promqlCount > 1) { if (this.promqlCount > 1) {
this.expressions.splice(index, 1); this.expressions.splice(index, 1);
this.promqlKeys.splice(index, 1); this.promqlKeys.splice(index, 1);
@@ -439,6 +435,7 @@ instance_cpu_time_ns{app="fox", proc="widget", rev="4d3a513", env="prod", job="c
} }
} }
this.$refs.addChartModal.createData(-1, metricInfo); this.$refs.addChartModal.createData(-1, metricInfo);
this.$refs.addChartModal.setUnit(this.chartUnit)
}, },
createSuccess(type, response, param, panel) { //添加chart成功 createSuccess(type, response, param, panel) { //添加chart成功
this.$confirm(this.$t("dashboard.metric.goPanelTip"), this.$t("tip.saveSuccess"), { this.$confirm(this.$t("dashboard.metric.goPanelTip"), this.$t("tip.saveSuccess"), {