2020-04-21 19:28:01 +08:00
|
|
|
<template>
|
2020-07-03 19:23:58 +08:00
|
|
|
<div class="promqlInput" :style="{height:(errorMsg || appendMsg)?'50px':'auto'}">
|
2020-04-21 19:28:01 +08:00
|
|
|
<div class="query-row">
|
|
|
|
|
<div class="query-input">
|
2020-07-02 22:25:06 +08:00
|
|
|
<!--explore页面的样式-->
|
2020-07-02 20:10:16 +08:00
|
|
|
<template v-if="styleType == 1">
|
2020-07-03 19:23:58 +08:00
|
|
|
<div class="metric-btn" v-if="plugins.indexOf('metric-selector') > -1">
|
|
|
|
|
<el-dropdown class="metric-selector">
|
2020-07-02 20:10:16 +08:00
|
|
|
<el-dropdown-menu style="display: none"></el-dropdown-menu>
|
2020-09-10 17:00:32 +08:00
|
|
|
<el-button class="metric-btn nz-btn nz-btn-size-normal nz-btn-style-light" @click="toggleDropdown">Metric <i class="nz-icon nz-icon-arrow-down"></i></el-button>
|
2020-07-29 18:41:40 +08:00
|
|
|
<el-cascader-panel v-show="dropDownVisible" v-model="cascaderValue" slot="dropdown" ref="metricSelector" :props="{emitPath:false}" :options="metricOptions" @change="metricChange" ></el-cascader-panel>
|
2020-07-02 20:10:16 +08:00
|
|
|
</el-dropdown>
|
|
|
|
|
</div>
|
2020-07-03 19:23:58 +08:00
|
|
|
<div class="input-box" @click="dropDownVisible=false" v-if="plugins.indexOf('metric-input') > -1">
|
2020-07-02 20:10:16 +08:00
|
|
|
<!-- <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>-->
|
2020-07-29 18:41:40 +08:00
|
|
|
<editor :styleType="styleType" :metric-list="metricStore" :history-param="historyParam" v-model="expressionList[index]" ref="editor" @on-enter="expressionChange" @on-blur="expressionChange" ></editor>
|
2020-07-02 20:10:16 +08:00
|
|
|
<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>
|
|
|
|
|
</template>
|
2020-07-02 22:25:06 +08:00
|
|
|
<!--right-box里的样式-->
|
2020-07-02 20:10:16 +08:00
|
|
|
<template v-if="styleType == 2">
|
2020-07-03 11:45:54 +08:00
|
|
|
<el-row v-if="plugins.indexOf('metric-input') > -1 || plugins.indexOf('metric-selector') > -1" style="width: 100%;">
|
2020-07-02 20:10:16 +08:00
|
|
|
<el-col style="width: 120px; padding-right: 20px; text-align: right; color: #666">
|
2020-07-03 11:45:54 +08:00
|
|
|
<el-dropdown class="metric-selector" v-if="plugins.indexOf('metric-selector') > -1">
|
2020-07-02 22:25:06 +08:00
|
|
|
<el-dropdown-menu style="display: none"></el-dropdown-menu>
|
2020-09-10 17:00:32 +08:00
|
|
|
<span :class="{'expr-title':projectRightBox}" style="cursor: pointer;" @click="toggleDropdown">Metric <i class="nz-icon nz-icon-arrow-down" style="font-size: 14px; -webkit-transform:scale(0.75);display:inline-block;"></i></span>
|
2020-07-02 22:25:06 +08:00
|
|
|
<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>
|
2020-07-03 11:45:54 +08:00
|
|
|
<label style="line-height: 30px;" v-else>{{$t("alert.config.expr")}}</label>
|
2020-07-02 20:10:16 +08:00
|
|
|
</el-col>
|
2020-07-03 19:23:58 +08:00
|
|
|
<el-col style="width: calc(100% - 120px); height: 100%;">
|
2020-07-03 11:45:54 +08:00
|
|
|
<div class="input-box" @click="dropDownVisible=false" v-if="plugins.indexOf('metric-input') > -1">
|
2020-07-29 18:41:40 +08:00
|
|
|
<editor :styleType="styleType" :metric-list="metricStore" :historyParam="historyParam" v-model="expressionList[index]" ref="editor" @on-enter="expressionChange" @on-blur="expressionChange" ></editor>
|
2020-07-02 22:25:06 +08:00
|
|
|
<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>
|
2020-07-02 20:10:16 +08:00
|
|
|
</el-col>
|
|
|
|
|
</el-row>
|
|
|
|
|
</template>
|
2020-04-21 19:28:01 +08:00
|
|
|
</div>
|
|
|
|
|
</div>
|
2020-10-15 15:34:00 +08:00
|
|
|
<div v-if="styleType == 1" style="margin-left: 10px">
|
2020-04-22 19:45:10 +08:00
|
|
|
<div class="query-options nz-btn-group nz-btn-group-size-normal nz-btn-group-light">
|
2020-09-10 17:00:32 +08:00
|
|
|
<div class="option nz-btn nz-btn-size-normal nz-btn-style-light" @click="addExpression" v-if="plugins.indexOf('add') > -1"><i class="nz-icon nz-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="nz-icon nz-icon-minus"></i></div>
|
2020-04-21 19:28:01 +08:00
|
|
|
</div>
|
|
|
|
|
</div>
|
2020-08-24 15:02:23 +08:00
|
|
|
<div v-if="styleType == 2&&showRemove">
|
2020-09-10 17:00:32 +08:00
|
|
|
<div class="option" @click="addExpression" v-if="plugins.indexOf('add') > -1"><i class="nz-icon nz-icon-plus"></i></div>
|
|
|
|
|
<div class="option" style="margin-left: 5px; line-height: 32px;" @click="removeExpression" v-if="plugins.indexOf('remove') > -1"><i class="nz-icon nz-icon-minus"></i></div>
|
2020-07-02 22:25:06 +08:00
|
|
|
</div>
|
2020-04-21 19:28:01 +08:00
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
2020-06-22 19:16:04 +08:00
|
|
|
import editor from './editor'
|
2020-04-21 19:28:01 +08:00
|
|
|
export default {
|
|
|
|
|
name: "promqlInput",
|
2020-06-22 19:16:04 +08:00
|
|
|
components:{
|
|
|
|
|
'editor':editor
|
|
|
|
|
},
|
2020-04-21 19:28:01 +08:00
|
|
|
props:{
|
|
|
|
|
index:{type:Number},
|
2020-07-02 20:10:16 +08:00
|
|
|
expressionList:{},
|
|
|
|
|
plugins: {type: Array},
|
2020-07-29 18:41:40 +08:00
|
|
|
styleType: Number,
|
2020-08-24 15:02:23 +08:00
|
|
|
historyParam:{type:Object},
|
2020-09-07 14:33:34 +08:00
|
|
|
showRemove:{type:Boolean,default:true},
|
|
|
|
|
projectRightBox:{type:Boolean,default:false}
|
2020-04-21 19:28:01 +08:00
|
|
|
},
|
|
|
|
|
data(){
|
|
|
|
|
return {
|
|
|
|
|
dropDownVisible:false,
|
|
|
|
|
metricStore:[],
|
|
|
|
|
metricOptions:[],
|
2020-04-23 16:45:59 +08:00
|
|
|
cascaderValue:'',
|
2020-04-24 17:41:33 +08:00
|
|
|
errorMsg:null,
|
|
|
|
|
appendMsg:null,
|
2020-06-22 19:16:04 +08:00
|
|
|
editorValue:'',
|
2020-11-20 16:13:23 +08:00
|
|
|
firstAddEvent:true
|
2020-04-21 19:28:01 +08:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
created() {
|
|
|
|
|
this.queryMetrics();
|
|
|
|
|
},
|
|
|
|
|
methods:{
|
|
|
|
|
clearExpression:function(){
|
2020-04-22 19:45:10 +08:00
|
|
|
this.expressionChange();
|
2020-04-23 16:45:59 +08:00
|
|
|
this.cascaderValue='';
|
2020-04-21 19:28:01 +08:00
|
|
|
},
|
|
|
|
|
addExpression:function(){
|
|
|
|
|
this.$emit('addExpression',this.index);
|
|
|
|
|
},
|
|
|
|
|
removeExpression:function(){
|
|
|
|
|
this.$emit('removeExpression',this.index);
|
|
|
|
|
},
|
|
|
|
|
toggleDropdown:function(){
|
|
|
|
|
this.dropDownVisible=!this.dropDownVisible;
|
2020-11-20 18:24:57 +08:00
|
|
|
if(this.dropDownVisible == true){
|
2020-04-21 19:28:01 +08:00
|
|
|
let $temp=this;
|
2020-11-20 16:13:23 +08:00
|
|
|
document.addEventListener('click',this.dropDownDisvisible.bind('',event,this),false)
|
|
|
|
|
this.$el.addEventListener('click',this.eStopPropagation.bind('',event),false)
|
2020-04-21 19:28:01 +08:00
|
|
|
}
|
|
|
|
|
},
|
2020-11-20 16:13:23 +08:00
|
|
|
dropDownDisvisible(e,self){
|
|
|
|
|
e.stopPropagation ? e.stopPropagation() : e.cancelBubble = true;
|
|
|
|
|
self.dropDownVisible=false;
|
2020-11-20 18:24:57 +08:00
|
|
|
document.removeEventListener('click',this.dropDownDisvisible.bind('',event,this),false)
|
2020-11-20 16:13:23 +08:00
|
|
|
},
|
|
|
|
|
eStopPropagation(e){
|
|
|
|
|
e.stopPropagation ? e.stopPropagation() : e.cancelBubble = true;
|
2020-11-20 18:24:57 +08:00
|
|
|
this.$el.removeEventListener('click',this.eStopPropagation.bind('',event),false);
|
2020-11-20 16:13:23 +08:00
|
|
|
},
|
2020-04-21 19:28:01 +08:00
|
|
|
queryMetrics:function(){
|
|
|
|
|
this.metricOptions=[];
|
|
|
|
|
this.$get('prom/api/v1/label/__name__/values').then(response=>{
|
|
|
|
|
if(response.status == 'success'){
|
|
|
|
|
let metrics=response.data.sort();
|
|
|
|
|
let metricMap=new Map();
|
|
|
|
|
metrics.forEach((item)=>{
|
|
|
|
|
let key='';
|
|
|
|
|
if(/^[a-zA-Z]+?_[a-zA-Z]*/.test(item)){
|
|
|
|
|
key=item.split('_')[0];
|
|
|
|
|
}else if(/^_\w*/.test(item)){
|
|
|
|
|
key=' ';
|
|
|
|
|
}else{
|
|
|
|
|
key=item;
|
|
|
|
|
}
|
|
|
|
|
if(metricMap.get(key)){
|
|
|
|
|
let values=metricMap.get(key);
|
|
|
|
|
values.push({label:item,value:item});
|
|
|
|
|
}else{
|
|
|
|
|
let values=[{label:item,value:item}];
|
|
|
|
|
metricMap.set(key,values);
|
|
|
|
|
}
|
2020-06-22 19:16:04 +08:00
|
|
|
this.metricStore.push({label:item,value:item,insertText:item})
|
2020-04-21 19:28:01 +08:00
|
|
|
})
|
|
|
|
|
for(let key of metricMap.keys()){
|
|
|
|
|
let option={
|
|
|
|
|
label:key,
|
|
|
|
|
value:key,
|
|
|
|
|
}
|
|
|
|
|
if(metricMap.get(key) && metricMap.get(key).length>1){
|
|
|
|
|
option.children=metricMap.get(key);
|
|
|
|
|
}
|
|
|
|
|
this.metricOptions.push(option);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
filterInput:function(queryString, cb){
|
|
|
|
|
let metrics=Object.assign([],this.metricStore);
|
|
|
|
|
let result=queryString?metrics.filter((item)=>{
|
|
|
|
|
return item.value.toLowerCase().indexOf(queryString.toLowerCase()) != -1;
|
|
|
|
|
}):metrics;
|
|
|
|
|
cb(result)
|
|
|
|
|
},
|
|
|
|
|
metricChange:function(value){
|
|
|
|
|
this.expressionList[this.index]=value;
|
2020-06-22 19:16:04 +08:00
|
|
|
this.$refs.editor.setContent(value)
|
2020-04-21 19:28:01 +08:00
|
|
|
this.dropDownVisible=false;
|
|
|
|
|
this.$emit('change')
|
|
|
|
|
},
|
|
|
|
|
expressionChange:function(){
|
|
|
|
|
this.$emit('change')
|
2020-04-24 17:41:33 +08:00
|
|
|
},
|
|
|
|
|
setError:function(errMsg){
|
|
|
|
|
console.log(errMsg)
|
|
|
|
|
this.errorMsg=errMsg;
|
|
|
|
|
},
|
|
|
|
|
setMsg:function(){
|
|
|
|
|
this.appendMsg
|
2020-04-21 19:28:01 +08:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
watch:{
|
|
|
|
|
dropDownVisible:function(n,o){
|
|
|
|
|
if(this.$refs.metricSelector){
|
|
|
|
|
this.$refs.metricSelector.dropDownVisible=n;
|
2020-07-29 18:41:40 +08:00
|
|
|
if(!this.expressionList[this.index]||this.expressionList[this.index] == ''){
|
|
|
|
|
this.cascaderValue="";
|
|
|
|
|
}
|
2020-04-21 19:28:01 +08:00
|
|
|
}
|
|
|
|
|
},
|
2020-06-22 19:16:04 +08:00
|
|
|
|
2020-11-20 16:13:23 +08:00
|
|
|
},
|
|
|
|
|
beforeDestroy(){
|
|
|
|
|
document.removeEventListener('click',this.dropDownDisvisible.bind('',event,this),false)
|
|
|
|
|
this.$el.removeEventListener('click',this.eStopPropagation.bind('',event),false)
|
2020-04-21 19:28:01 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
|
2020-07-02 22:25:06 +08:00
|
|
|
<style scoped lang="scss">
|
2020-04-21 19:28:01 +08:00
|
|
|
.promqlInput{
|
|
|
|
|
position: relative;
|
2020-04-22 19:45:10 +08:00
|
|
|
height: 36px;
|
2020-04-21 19:28:01 +08:00
|
|
|
width: 100%;
|
|
|
|
|
display: flex;
|
2020-07-03 19:23:58 +08:00
|
|
|
margin-bottom: 18px;
|
2020-04-21 19:28:01 +08:00
|
|
|
}
|
|
|
|
|
.promqlInput .query-row{
|
|
|
|
|
width: 100%;
|
|
|
|
|
}
|
2020-07-02 22:25:06 +08:00
|
|
|
.input-box .append-msg{
|
2020-04-24 17:41:33 +08:00
|
|
|
font-size: 12px;
|
|
|
|
|
line-height: 1;
|
|
|
|
|
padding-top: 4px;
|
|
|
|
|
}
|
2020-07-02 22:25:06 +08:00
|
|
|
.input-box .error{
|
2020-04-24 17:41:33 +08:00
|
|
|
color: #F56C6C;
|
|
|
|
|
}
|
2020-04-21 19:28:01 +08:00
|
|
|
.query-row .query-input{
|
|
|
|
|
display: flex;
|
|
|
|
|
justify-content: flex-start;
|
|
|
|
|
}
|
|
|
|
|
.promqlInput .query-options{
|
2020-04-22 19:45:10 +08:00
|
|
|
/*display: flex;*/
|
|
|
|
|
/*justify-content: flex-start;*/
|
|
|
|
|
/*width: 84px;*/
|
2020-04-21 19:28:01 +08:00
|
|
|
}
|
|
|
|
|
.query-options .option{
|
2020-04-22 19:45:10 +08:00
|
|
|
/*border-right: 1px solid #dde4ed;*/
|
|
|
|
|
/*border-radius: 3px;*/
|
|
|
|
|
/*background-color: #dde4ed;*/
|
|
|
|
|
width: 34px;
|
|
|
|
|
height: 34px !important;
|
|
|
|
|
line-height: 34px;
|
2020-04-21 19:28:01 +08:00
|
|
|
text-align: center;
|
|
|
|
|
}
|
|
|
|
|
.query-options .option:focus,.query-options .option:hover{
|
|
|
|
|
background-color: #CCD7E4;
|
|
|
|
|
}
|
2020-07-02 22:25:06 +08:00
|
|
|
.query-input .metric-btn {
|
2020-04-21 19:28:01 +08:00
|
|
|
width: 100px;
|
|
|
|
|
margin-right: 10px;
|
|
|
|
|
}
|
2020-07-02 22:25:06 +08:00
|
|
|
.query-input .input-box{
|
2020-04-21 19:28:01 +08:00
|
|
|
width: 100%;
|
2020-07-03 19:23:58 +08:00
|
|
|
height: 100%;
|
2020-04-21 19:28:01 +08:00
|
|
|
}
|
|
|
|
|
.metric-btn{
|
2020-04-22 19:45:10 +08:00
|
|
|
height: 36px !important;
|
|
|
|
|
width: 105px;
|
|
|
|
|
margin-left: 1px;
|
2020-04-21 19:28:01 +08:00
|
|
|
}
|
|
|
|
|
.metric-btn:hover ,.metric-btn:focus {
|
|
|
|
|
background-color: #CCD7E4;
|
|
|
|
|
color:#606266;
|
|
|
|
|
}
|
|
|
|
|
.metric-selector .el-cascader-panel{
|
|
|
|
|
height: 300px;
|
|
|
|
|
position: absolute;
|
|
|
|
|
z-index: 2100;
|
|
|
|
|
background-color: #FFF;
|
|
|
|
|
}
|
2020-09-07 14:33:34 +08:00
|
|
|
.expr-title{
|
|
|
|
|
width: 120px;
|
|
|
|
|
padding-right: 20px;
|
|
|
|
|
text-align: right;
|
|
|
|
|
color: #666;
|
|
|
|
|
font-size: 14px;
|
|
|
|
|
letter-spacing: 0;
|
|
|
|
|
line-height: 22px;
|
|
|
|
|
}
|
2020-04-21 19:28:01 +08:00
|
|
|
</style>
|
|
|
|
|
<style>
|
|
|
|
|
.metric-selector-pop{
|
|
|
|
|
position:relative;
|
|
|
|
|
z-index: 2100;
|
|
|
|
|
}
|
2020-07-02 22:25:06 +08:00
|
|
|
.input-box .el-input__inner{
|
2020-04-22 19:45:10 +08:00
|
|
|
height: 36px;
|
|
|
|
|
}
|
2020-04-21 19:28:01 +08:00
|
|
|
</style>
|