NEZ-343 feat: expr(部分)

This commit is contained in:
陈劲松
2020-07-02 22:25:06 +08:00
parent 37dad22498
commit 127ac61ee0
6 changed files with 92 additions and 37 deletions

View File

@@ -67,7 +67,7 @@
</div> </div>
<button class="to-top" :class="{'to-top-is-hover': tableHover}" v-show="showTopBtn" @click="$toTop('el', $refs.dashboardScrollbar.wrap)" style="bottom: 0;"><i class="nz-icon nz-icon-top"></i></button> <button class="to-top" :class="{'to-top-is-hover': tableHover}" v-show="showTopBtn" @click="$toTop('el', $refs.dashboardScrollbar.wrap)" style="bottom: 0;"><i class="nz-icon nz-icon-top"></i></button>
<chart-box ref="addChartModal" :showPanel="showPanel" :panel-data="panelData" @on-create-success="createSuccess" @on-delete-success="delChartOk"></chart-box> <chart-box v-if="rightBox.show" ref="addChartModal" :showPanel="showPanel" :panel-data="panelData" @on-create-success="createSuccess" @on-delete-success="delChartOk"></chart-box>
</div> </div>
</template> </template>
@@ -186,8 +186,9 @@
}, },
/*图表相关操作--start*/ /*图表相关操作--start*/
toAddChart: function () { toAddChart: function () {
this.rightBox.show = true;
this.$refs.addChartModal.setTitle(this.$t("dashboard.panel.createChartTitle")); this.$refs.addChartModal.setTitle(this.$t("dashboard.panel.createChartTitle"));
this.$refs.addChartModal.show(true); //this.$refs.addChartModal.show(true);
this.$refs.addChartModal.createData(this.panelId); //初始化创建图表需要的初始数据 this.$refs.addChartModal.createData(this.panelId); //初始化创建图表需要的初始数据
}, },
// 切换tab // 切换tab

View File

@@ -28,10 +28,19 @@
<div v-if="!rightBox.isEdit" class="right-box-form-content-txt">{{alertRule.alertName}}</div> <div v-if="!rightBox.isEdit" class="right-box-form-content-txt">{{alertRule.alertName}}</div>
</el-form-item> </el-form-item>
<!--expr--> <!--expr-->
<el-form-item :label="$t('alert.config.expr')" prop="expr"> <!--<el-form-item :label="$t('alert.config.expr')" prop="expr">
<el-input maxlength="512" rows="4" show-word-limit v-if="rightBox.isEdit" type="textarea" placeholder="" v-model="alertRule.expr" size="small"></el-input> <el-input maxlength="512" rows="4" show-word-limit v-if="rightBox.isEdit" type="textarea" placeholder="" v-model="alertRule.expr" size="small"></el-input>
<div v-if="!rightBox.isEdit" class="right-box-form-content-txt">{{alertRule.expr}}</div> <div v-if="!rightBox.isEdit" class="right-box-form-content-txt">{{alertRule.expr}}</div>
</el-form-item> </el-form-item>-->
<promql-input
ref="promql"
:expression-list.sync="expressions"
:index="0"
:styleType="2"
:plugins="['metric']"
@change="expressionChange"
@removeExpression="removeExpression"
></promql-input>
<!--operator--> <!--operator-->
<el-form-item :label="$t('alert.config.operator')" prop="operator" style="width: 400px;display: inline-block;"> <el-form-item :label="$t('alert.config.operator')" prop="operator" style="width: 400px;display: inline-block;">
<el-select v-if="rightBox.isEdit" popper-class="config-dropdown" v-model="alertRule.operator" placeholder="" size="small"> <el-select v-if="rightBox.isEdit" popper-class="config-dropdown" v-model="alertRule.operator" placeholder="" size="small">
@@ -122,14 +131,18 @@
<script> <script>
import chartDataFormat from "../../charts/chartDataFormat"; import chartDataFormat from "../../charts/chartDataFormat";
import promqlInput from "../../page/dashboard/explore/promqlInput";
export default { export default {
name: "alertConfigBox", name: "alertConfigBox",
props: { props: {
parentAlertRule: Object parentAlertRule: Object
}, },
components: {
'promql-input': promqlInput,
},
data() { data() {
return { return {
expressions: [],
alertRule: {id: '', receiverShow: [], receiver: ''}, alertRule: {id: '', receiverShow: [], receiver: ''},
rightBox: {show: false, isEdit: false, title: ''}, rightBox: {show: false, isEdit: false, title: ''},
rules:{ rules:{

View File

@@ -41,6 +41,7 @@
.element-item { .element-item {
padding: 20px 0; padding: 20px 0;
border-bottom: 1px dashed #dfe7f2; border-bottom: 1px dashed #dfe7f2;
width: 100%;
} }
/*metric样式--end*/ /*metric样式--end*/
.label-center{ .label-center{
@@ -180,7 +181,7 @@
<alert-chart-param ref="alertParamBox" @on-enter-complate="getAlertParam"></alert-chart-param> <alert-chart-param ref="alertParamBox" @on-enter-complate="getAlertParam"></alert-chart-param>
</el-row> </el-row>
<el-row v-if="!isUrl && !isSingleStat&&!isAlert" class="element-item" v-for="index of promqlKeys.length" :key="'ele' + index"> <el-row v-if="!isUrl && !isSingleStat&&!isAlert" class="element-item" style="" v-for="index of promqlKeys.length" :key="'ele' + index">
<!--<chart-metric ref="chartTag" <!--<chart-metric ref="chartTag"
:pointer="index" :pointer="index"
:metric-list="metricList" :metric-list="metricList"
@@ -210,7 +211,7 @@
</el-popover> </el-popover>
</el-col> </el-col>
<el-col style="width: calc(100% - 120px);"> <el-col style="width: calc(100% - 120px);">
<el-input v-model="legends[index-1]" type="text" size="mini"></el-input> <el-input v-model="legends[index-1]" type="text" size="small"></el-input>
</el-col> </el-col>
</el-row> </el-row>
</el-row> </el-row>

View File

@@ -1,7 +1,7 @@
<template> <template>
<div class="metric-editor" v-clickoutside="clickout"> <div class="metric-editor" v-clickoutside="clickout" :class="{'metric-editor-rb': styleType == 2}">
<div :id="id" class="editor-core" ref="editor" ></div> <div :id="id" class="editor-core" ref="editor" ></div>
<span class="nz-input-append editor-clear" style="padding-top:8px;display: none" @click="clearContent"><i class="el-icon-circle-close"></i></span> <span class="nz-input-append editor-clear" style="display: none" @click="clearContent"><i class="el-icon-circle-close"></i></span>
<div class="metric-editor-popper" :style="{left:popperPos.left+'px'}"> <div class="metric-editor-popper" :style="{left:popperPos.left+'px'}">
<div class="metric-popper-main" v-show="showType&&Object.keys(showSuggestions).length>0"> <div class="metric-popper-main" v-show="showType&&Object.keys(showSuggestions).length>0">
<el-scrollbar style="height: 100%;width:100%" class="el-scrollbar-small" ref="scroll"> <el-scrollbar style="height: 100%;width:100%" class="el-scrollbar-small" ref="scroll">
@@ -28,7 +28,8 @@
name: "editor", name: "editor",
props: { props: {
value: String, value: String,
metricList:{type:Array} metricList:{type:Array},
styleType: Number
}, },
model:{ model:{
prop:'value', prop:'value',
@@ -814,7 +815,7 @@
} }
</script> </script>
<style scoped> <style scoped lang="scss">
.metric-editor{ .metric-editor{
position: relative; position: relative;
height: 36px; height: 36px;
@@ -883,11 +884,14 @@
.editor-core:hover + .editor-clear{ .editor-core:hover + .editor-clear{
display: inline-block !important; display: inline-block !important;
} }
.editor-clear {
padding-top: 8px;
}
.editor-clear:hover{ .editor-clear:hover{
display: inline-block !important; display: inline-block !important;
} }
</style> </style>
<style> <style lang="scss">
mark{ mark{
color: rgb(255, 133, 27); color: rgb(255, 133, 27);
border-bottom: 1px solid rgb(255, 133, 27); border-bottom: 1px solid rgb(255, 133, 27);
@@ -896,8 +900,27 @@
padding: 0; padding: 0;
} }
.ql-editor{ .ql-editor{
padding:10px 10px !important; padding:10px !important;
overflow: hidden; overflow: hidden;
} }
.metric-editor.metric-editor-rb {
.editor-clear {
padding-top: 4px;
}
height: 32px;
.ql-container.ql-snow {
border-radius: 4px;
border: 1px solid #DCDFE6;
box-sizing: border-box;
.ql-editor {
padding: 6px 0 !important;
>p {
padding-left: 15px;
font-size: 12px;
color: rgb(96, 98, 102);
}
}
}
}
</style> </style>

View File

@@ -193,7 +193,7 @@ instance_cpu_time_ns{app="fox", proc="widget", rev="4d3a513", env="prod", job="c
</div> </div>
</div> </div>
<chart-box ref="addChartModal" :panel-data="panelData" @on-create-success="createSuccess" :show-panel="{}"></chart-box> <chart-box v-if="rightBox.show" ref="addChartModal" :panel-data="panelData" @on-create-success="createSuccess" :show-panel="{}"></chart-box>
<element-set <element-set
:allowed-all="true" :allowed-all="true"
v-clickoutside="elementsetHide" v-clickoutside="elementsetHide"
@@ -227,6 +227,9 @@ instance_cpu_time_ns{app="fox", proc="widget", rev="4d3a513", env="prod", job="c
}, },
data() { data() {
return { return {
rightBox: { //面板弹出框相关
show: false,
},
promqlCount: 1, promqlCount: 1,
promqlKeys: [], promqlKeys: [],
expressions: [''], expressions: [''],
@@ -445,8 +448,9 @@ instance_cpu_time_ns{app="fox", proc="widget", rev="4d3a513", env="prod", job="c
this.tableVisible = !this.tableVisible; this.tableVisible = !this.tableVisible;
}, },
saveChart: function () { saveChart: function () {
this.rightBox.show = true;
this.$refs.addChartModal.setTitle(this.$t("dashboard.panel.createChartTitle")); this.$refs.addChartModal.setTitle(this.$t("dashboard.panel.createChartTitle"));
this.$refs.addChartModal.show(true); //this.$refs.addChartModal.show(true);
let metricInfo = {}; let metricInfo = {};
metricInfo.elements = []; metricInfo.elements = [];
// {"metric":"ALERTS_FOR_STATE","elements":[{"expression":"ALERTS_FOR_STATE{project='kafka',module='node_exporter'}","type":"normal"}]} // {"metric":"ALERTS_FOR_STATE","elements":[{"expression":"ALERTS_FOR_STATE{project='kafka',module='node_exporter'}","type":"normal"}]}

View File

@@ -2,40 +2,53 @@
<div class="promqlInput" :style="{height:(errorMsg || appendMsg)?'50px':'36px'}"> <div class="promqlInput" :style="{height:(errorMsg || appendMsg)?'50px':'36px'}">
<div class="query-row"> <div class="query-row">
<div class="query-input"> <div class="query-input">
<!--explore页面的样式-->
<template v-if="styleType == 1"> <template v-if="styleType == 1">
<div class="metricBtn" v-if="plugins.indexOf('metric') > -1"> <div class="metric-btn" v-if="plugins.indexOf('metric') > -1">
<el-dropdown class="metric-selector" > <el-dropdown class="metric-selector" >
<el-dropdown-menu style="display: none"></el-dropdown-menu> <el-dropdown-menu style="display: none"></el-dropdown-menu>
<el-button class="metric-btn nz-btn nz-btn-size-normal nz-btn-style-light" @click="toggleDropdown">Metric &nbsp;<i class="el-icon-arrow-down"></i></el-button> <el-button class="metric-btn nz-btn nz-btn-size-normal nz-btn-style-light" @click="toggleDropdown">Metric &nbsp;<i class="el-icon-arrow-down"></i></el-button>
<el-cascader-panel v-show="dropDownVisible" v-model="cascaderValue" slot="dropdown" ref="metricSelector" :props="{emitPath:false}" :options="metricOptions" @change="metricChange"></el-cascader-panel> <el-cascader-panel v-show="dropDownVisible" v-model="cascaderValue" slot="dropdown" ref="metricSelector" :props="{emitPath:false}" :options="metricOptions" @change="metricChange"></el-cascader-panel>
</el-dropdown> </el-dropdown>
</div> </div>
<div class="inputBox" @click="dropDownVisible=false"> <div class="input-box" @click="dropDownVisible=false">
<!-- <el-autocomplete :placeholder="$t('dashboard.metricPreview.inputTip')" :fetch-suggestions="filterInput" clearable @clear="clearExpression" :trigger-on-focus="false" v-model="expressionList[index]" @blur="expressionChange" style="width: 100%;height:36px"></el-autocomplete>--> <!-- <el-autocomplete :placeholder="$t('dashboard.metricPreview.inputTip')" :fetch-suggestions="filterInput" clearable @clear="clearExpression" :trigger-on-focus="false" v-model="expressionList[index]" @blur="expressionChange" style="width: 100%;height:36px"></el-autocomplete>-->
<editor :metric-list="metricStore" v-model="expressionList[index]" ref="editor" @on-enter="expressionChange" @on-blur="expressionChange" ></editor> <editor :styleType="styleType" :metric-list="metricStore" v-model="expressionList[index]" ref="editor" @on-enter="expressionChange" @on-blur="expressionChange" ></editor>
<div class="append-msg error" v-if="errorMsg"><span>{{errorMsg}}</span></div> <div class="append-msg error" v-if="errorMsg"><span>{{errorMsg}}</span></div>
<div class="append-msg error" v-if="appendMsg"><span>{{appendMsg}}</span></div> <div class="append-msg error" v-if="appendMsg"><span>{{appendMsg}}</span></div>
</div> </div>
</template> </template>
<!--right-box里的样式-->
<template v-if="styleType == 2"> <template v-if="styleType == 2">
<el-row v-if="plugins.indexOf('metric') > -1"> <el-row v-if="plugins.indexOf('metric') > -1" style="width: 100%;">
<el-col style="width: 120px; padding-right: 20px; text-align: right; color: #666"> <el-col style="width: 120px; padding-right: 20px; text-align: right; color: #666">
Metric&nbsp;<i class="nz-icon nz-icon-info-normal" style="font-size: 12px; -webkit-transform:scale(0.75);display:inline-block;"></i> <el-dropdown class="metric-selector">
<el-dropdown-menu style="display: none"></el-dropdown-menu>
<span style="cursor: pointer;" @click="toggleDropdown">Metric&nbsp;<i class="el-icon-arrow-down" style="font-size: 14px; -webkit-transform:scale(0.75);display:inline-block;"></i></span>
<el-cascader-panel v-show="dropDownVisible" v-model="cascaderValue" style="text-align: left;" slot="dropdown" ref="metricSelector" :props="{emitPath:false}" :options="metricOptions" @change="metricChange"></el-cascader-panel>
</el-dropdown>
</el-col> </el-col>
<el-col style="width: calc(100% - 120px);"> <el-col style="width: calc(100% - 120px);">
<el-input v-model="legends[index-1]" type="text" size="mini"></el-input> <div class="input-box" @click="dropDownVisible=false">
<editor :styleType="styleType" :metric-list="metricStore" v-model="expressionList[index]" ref="editor" @on-enter="expressionChange" @on-blur="expressionChange" ></editor>
<div class="append-msg error" v-if="errorMsg"><span>{{errorMsg}}</span></div>
<div class="append-msg error" v-if="appendMsg"><span>{{appendMsg}}</span></div>
</div>
</el-col> </el-col>
</el-row> </el-row>
</template> </template>
</div> </div>
</div> </div>
<div style="margin-left: 5px"> <div v-if="styleType == 1">
<div class="query-options nz-btn-group nz-btn-group-size-normal nz-btn-group-light"> <div class="query-options nz-btn-group nz-btn-group-size-normal nz-btn-group-light">
<div class="option nz-btn nz-btn-size-normal nz-btn-style-light" @click="addExpression" v-if="plugins.indexOf('add') > -1"><i class="el-icon-plus"></i></div> <div class="option nz-btn nz-btn-size-normal nz-btn-style-light" @click="addExpression" v-if="plugins.indexOf('add') > -1"><i class="el-icon-plus"></i></div>
<div class="option nz-btn nz-btn-size-normal nz-btn-style-light" @click="removeExpression" v-if="plugins.indexOf('remove') > -1"><i class="el-icon-minus"></i></div> <div class="option nz-btn nz-btn-size-normal nz-btn-style-light" @click="removeExpression" v-if="plugins.indexOf('remove') > -1"><i class="el-icon-minus"></i></div>
</div> </div>
</div> </div>
<div v-if="styleType == 2">
<div class="option" @click="addExpression" v-if="plugins.indexOf('add') > -1"><i class="el-icon-plus"></i></div>
<div class="option" @click="removeExpression" v-if="plugins.indexOf('remove') > -1"><i class="el-icon-minus"></i></div>
</div>
</div> </div>
</template> </template>
@@ -163,7 +176,7 @@
} }
</script> </script>
<style scoped> <style scoped lang="scss">
.promqlInput{ .promqlInput{
position: relative; position: relative;
height: 36px; height: 36px;
@@ -174,12 +187,12 @@
.promqlInput .query-row{ .promqlInput .query-row{
width: 100%; width: 100%;
} }
.inputBox .append-msg{ .input-box .append-msg{
font-size: 12px; font-size: 12px;
line-height: 1; line-height: 1;
padding-top: 4px; padding-top: 4px;
} }
.inputBox .error{ .input-box .error{
color: #F56C6C; color: #F56C6C;
} }
.query-row .query-input{ .query-row .query-input{
@@ -203,11 +216,11 @@
.query-options .option:focus,.query-options .option:hover{ .query-options .option:focus,.query-options .option:hover{
background-color: #CCD7E4; background-color: #CCD7E4;
} }
.query-input .metricBtn{ .query-input .metric-btn {
width: 100px; width: 100px;
margin-right: 10px; margin-right: 10px;
} }
.query-input .inputBox{ .query-input .input-box{
width: 100%; width: 100%;
} }
.metric-btn{ .metric-btn{
@@ -231,7 +244,7 @@
position:relative; position:relative;
z-index: 2100; z-index: 2100;
} }
.inputBox .el-input__inner{ .input-box .el-input__inner{
height: 36px; height: 36px;
} }
</style> </style>