2020-04-21 19:28:01 +08:00
|
|
|
<template>
|
2021-04-29 22:24:38 +08:00
|
|
|
<div class="promqlInput">
|
2021-03-16 17:54:05 +08:00
|
|
|
<div class="query-row">
|
2021-04-30 18:54:11 +08:00
|
|
|
<!--explore页面的样式-->
|
|
|
|
|
<template v-if="styleType == 1">
|
|
|
|
|
<div v-if="plugins.indexOf('metric-selector') > -1">
|
|
|
|
|
<el-dropdown class="metric-selector">
|
|
|
|
|
<el-dropdown-menu style="display: none"></el-dropdown-menu>
|
2021-05-14 17:51:02 +08:00
|
|
|
<button class="top-tool-btn top-tool-btn--text" type="button" @click="toggleDropdown">{{ $t("overall.metric") }}
|
2021-04-30 18:54:11 +08:00
|
|
|
<i class="nz-icon nz-icon-arrow-down" style="font-size: 12px"></i></button>
|
|
|
|
|
<el-cascader-panel v-show="dropDownVisible" ref="metricSelector" slot="dropdown" v-model="cascaderValue"
|
|
|
|
|
v-clickoutside="closeDropdown" v-loading="tempBoxShowLoading" :loading="loading" :options="metricOptions"
|
|
|
|
|
:props="{emitPath:false,}" @change="metricChange">
|
2021-03-16 17:54:05 +08:00
|
|
|
|
2021-04-30 18:54:11 +08:00
|
|
|
<template slot-scope="{ node, data }">
|
|
|
|
|
<div :class="['nz-cascade',data.temp&&!data.child?'nz-cascade-temp':'']" @click="()=>{lazyLoad(node,data)}">
|
|
|
|
|
<i class="nz-icon nz-icon-template2"></i>
|
|
|
|
|
{{data.label}}
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
2021-03-16 17:54:05 +08:00
|
|
|
|
2021-04-30 18:54:11 +08:00
|
|
|
</el-cascader-panel>
|
|
|
|
|
</el-dropdown>
|
|
|
|
|
</div>
|
|
|
|
|
<div v-if="plugins.indexOf('metric-input') > -1" class="input-box" @click="dropDownVisible=false">
|
|
|
|
|
<el-input :id="inputId" v-model="expressionList[index]" :autosize="{ minRows: 1, maxRows: 6}"
|
|
|
|
|
class="not-fixed-height no-resize" type="textarea"
|
2021-05-13 10:06:03 +08:00
|
|
|
@input="metricKeyDown" @keyup.enter.native="expressionChange" ref="elInput"></el-input>
|
2021-04-30 18:54:11 +08:00
|
|
|
<div v-if="errorMsg" class="append-msg error"><span>{{errorMsg}}</span></div>
|
|
|
|
|
<div v-if="appendMsg" class="append-msg error"><span>{{appendMsg}}</span></div>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="top-tool-btn-group">
|
|
|
|
|
<button v-if="plugins.indexOf('add') > -1" class="top-tool-btn"
|
|
|
|
|
@click="addExpression"><i class="nz-icon nz-icon-plus"></i></button>
|
|
|
|
|
<button v-if="plugins.indexOf('copy') > -1" class="top-tool-btn"
|
|
|
|
|
@click="copyExpression"><i class="nz-icon nz-icon-override"></i></button>
|
|
|
|
|
<button v-if="plugins.indexOf('remove') > -1" class="top-tool-btn"
|
|
|
|
|
@click="removeExpression"><i class="nz-icon nz-icon-minus"></i></button>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
<!--right-box里的样式-->
|
|
|
|
|
<template v-if="styleType == 2">
|
2021-03-16 17:54:05 +08:00
|
|
|
<el-row v-if="plugins.indexOf('metric-input') > -1 || plugins.indexOf('metric-selector') > -1"
|
|
|
|
|
style="width: 100%;">
|
|
|
|
|
<el-col
|
2021-03-18 17:03:29 +08:00
|
|
|
:class="[plugins.indexOf('metric-selector') > -1 ?'metric-selector-title':'metric-null-title']">
|
2021-03-16 17:54:05 +08:00
|
|
|
<el-dropdown class="metric-selector" v-if="plugins.indexOf('metric-selector') > -1">
|
2020-07-02 20:10:16 +08:00
|
|
|
<el-dropdown-menu style="display: none"></el-dropdown-menu>
|
2021-05-14 18:24:38 +08:00
|
|
|
<span :class="{'expr-title':projectRightBox}" style="cursor: pointer;" @click="toggleDropdown">{{$t("overall.metric")}} <i
|
2021-03-16 17:54:05 +08:00
|
|
|
class="nz-icon nz-icon-arrow-down"
|
|
|
|
|
style="font-size: 14px; -webkit-transform:scale(0.75);display:inline-block;"></i></span>
|
|
|
|
|
<el-cascader-panel v-loading="tempBoxShowLoading" v-if="dropDownVisible" v-clickoutside="closeDropdown" v-model="cascaderValue"
|
|
|
|
|
style="text-align: left;" slot="dropdown" ref="metricSelector"
|
|
|
|
|
:props="{emitPath:false}" :options="metricOptions" @change="metricChange">
|
|
|
|
|
|
|
|
|
|
<template slot-scope="{ node, data }">
|
2021-03-18 13:58:55 +08:00
|
|
|
<div :class="['nz-cascade',data.temp&&!data.child?'nz-cascade-temp':'']" @click="()=>{lazyLoad(node,data)}">
|
2021-04-07 19:18:22 +08:00
|
|
|
<i class="nz-icon nz-icon-template2"></i>
|
2021-03-18 13:58:55 +08:00
|
|
|
{{data.label}}
|
2021-03-16 17:54:05 +08:00
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
</el-cascader-panel>
|
2020-07-02 20:10:16 +08:00
|
|
|
</el-dropdown>
|
2021-03-16 17:54:05 +08:00
|
|
|
</el-col>
|
|
|
|
|
<el-col
|
2021-03-18 17:03:29 +08:00
|
|
|
:class="plugins.indexOf('metric-selector') > -1 ?'metric-selector-input-box':'metric-null-input-box'"
|
2021-04-26 21:42:15 +08:00
|
|
|
:style="{'width':plugins.indexOf('metric-selector') > -1 ? 'calc(100% - 160px)':'100%',height: '100%',}">
|
2021-03-16 17:54:05 +08:00
|
|
|
<div class="input-box" @click="dropDownVisible=false" v-if="plugins.indexOf('metric-input') > -1">
|
|
|
|
|
<!--<editor :styleType="styleType" :metric-list="metricStore" :historyParam="historyParam" v-model="expressionList[index]" ref="editor" @on-enter="expressionChange" @on-blur="expressionChange" ></editor>-->
|
2021-05-13 14:59:03 +08:00
|
|
|
<el-input v-model="expressionList[index]" @input="metricKeyDown" type="textarea"
|
2021-05-13 10:06:03 +08:00
|
|
|
:autosize="{ minRows: 1, maxRows: 6}" class="not-fixed-height no-resize" ref="elInput"></el-input>
|
2021-03-16 17:54:05 +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>
|
|
|
|
|
</el-col>
|
|
|
|
|
</el-row>
|
|
|
|
|
</template>
|
|
|
|
|
</div>
|
|
|
|
|
<div v-if="styleType == 2&&showRemove">
|
|
|
|
|
<div class="option" @click="addExpression" v-if="plugins.indexOf('add') > -1"><i class="nz-icon nz-icon-plus"></i>
|
2020-07-02 22:25:06 +08:00
|
|
|
</div>
|
2021-03-16 17:54:05 +08:00
|
|
|
<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-04-21 19:28:01 +08:00
|
|
|
</div>
|
2021-03-16 17:54:05 +08:00
|
|
|
|
|
|
|
|
<el-dialog
|
|
|
|
|
:visible.sync="tempBoxShow"
|
|
|
|
|
:append-to-body="true"
|
|
|
|
|
:width="'auto'"
|
|
|
|
|
:custom-class="'nz-temp-box'"
|
|
|
|
|
:destroy-on-close="true"
|
2021-03-17 15:49:47 +08:00
|
|
|
@closed="tempBoxClose"
|
2021-03-16 17:54:05 +08:00
|
|
|
center>
|
|
|
|
|
<el-form v-model="tempBox" class="temp-form-box" ref="tempFormBox" v-if="tempBoxShow">
|
|
|
|
|
<span class="temp-form-box-title">Expression</span>
|
|
|
|
|
<el-form-item prop="expression">
|
|
|
|
|
<el-input v-model="tempBox.expression" size="small" disabled></el-input>
|
|
|
|
|
</el-form-item>
|
2021-03-18 13:58:55 +08:00
|
|
|
<span class="temp-form-box-title" v-if="tempBox.vars.length">Variable</span>
|
2021-03-16 17:54:05 +08:00
|
|
|
<el-form-item v-for="(item,index) in tempBox.vars" :prop="item" :key="index">
|
|
|
|
|
<el-row>
|
2021-03-16 18:16:10 +08:00
|
|
|
<el-col :span="6" class="temp-form-box-col">
|
2021-03-16 17:54:05 +08:00
|
|
|
<el-input v-model="tempBox.vars[index]" :id="'tempBox'+index" size="small" :disabled="true"></el-input>
|
|
|
|
|
</el-col>
|
|
|
|
|
<el-col :span="17" v-if="format(item).key">
|
|
|
|
|
<!--<el-input v-model="tempBox[item]" :id="'tempBox'+item" size="small"></el-input>-->
|
2021-03-18 13:58:55 +08:00
|
|
|
<!--<el-select v-model="tempBox[item]" size="small" style="width: 100%" :popper-class="'nz-temp-box'">-->
|
|
|
|
|
<!--<el-option v-for="(item1,index) in format(item).arr" :key="index" :label="item1[format(item).value]" :value="item1[format(item).value]">-->
|
|
|
|
|
<!--</el-option>-->
|
|
|
|
|
<!--</el-select>-->
|
|
|
|
|
<select-alert-silence :filter-silence="filterSilence" :silence-data="format(item).arr" :panel-lock="false" :placement="'bottom-start'" :typeContentLoading="typeContentLoading"
|
|
|
|
|
@selectSilence="(val)=>{silenceChange(val,item)}" ref="selectPanel" style="width: 300px;">
|
|
|
|
|
<template v-slot:header>
|
|
|
|
|
<div class="panel-select-header">
|
|
|
|
|
<el-input :placeholder="$t('overall.search')" clearable size="mini" style="width: 340px; margin-right: 5px;" v-model="filterSilence" id="panel-list-search"></el-input>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<template v-slot:trigger>
|
|
|
|
|
<el-input class="panel-name" placeholder="" readonly="readonly" v-model="tempBox[item]" size="small">
|
|
|
|
|
<span slot="suffix" class="el-input__icon el-icon-circle-close el-input__clear" @click.stop="clearValue(item)"></span>
|
|
|
|
|
</el-input>
|
|
|
|
|
</template>
|
|
|
|
|
</select-alert-silence>
|
2021-03-16 17:54:05 +08:00
|
|
|
</el-col>
|
|
|
|
|
<el-col :span="17" v-else>
|
|
|
|
|
<el-input v-model="tempBox[item]" :id="'tempBox'+item" size="small"></el-input>
|
|
|
|
|
</el-col>
|
|
|
|
|
</el-row>
|
|
|
|
|
</el-form-item>
|
|
|
|
|
</el-form>
|
|
|
|
|
<span slot="footer">
|
|
|
|
|
<button id="temp-box-esc" class="nz-btn nz-btn-size-normal-new nz-btn-style-light-new" @click="tempBoxShowChange(false)">
|
|
|
|
|
<span>{{$t('overall.cancel')}}</span>
|
|
|
|
|
</button>
|
2021-04-21 10:57:53 +08:00
|
|
|
<button :disabled="prevent_opt.save" @click="tempBoxShowChange(true)" class="nz-btn nz-btn-size-normal-new nz-btn-style-normal-new" id="chart-box-save" v-has="`expressionTemplate_add`" >
|
2021-03-16 17:54:05 +08:00
|
|
|
<span>{{$t('overall.save')}}</span>
|
|
|
|
|
</button>
|
|
|
|
|
</span>
|
|
|
|
|
</el-dialog>
|
|
|
|
|
|
|
|
|
|
</div>
|
2020-04-21 19:28:01 +08:00
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
2021-03-19 18:52:19 +08:00
|
|
|
import selectAlertSilence from '../../../common/alert/selectAlertSilence'
|
2021-03-22 10:25:41 +08:00
|
|
|
import editor from './editor'
|
2021-03-19 18:52:19 +08:00
|
|
|
export default {
|
|
|
|
|
name: 'promqlInput',
|
|
|
|
|
components: {
|
2021-03-22 10:25:41 +08:00
|
|
|
editor: editor,
|
2021-03-19 18:52:19 +08:00
|
|
|
selectAlertSilence
|
|
|
|
|
},
|
|
|
|
|
props: {
|
|
|
|
|
index: { type: Number },
|
|
|
|
|
expressionList: {},
|
|
|
|
|
plugins: { type: Array },
|
|
|
|
|
styleType: Number,
|
|
|
|
|
historyParam: { type: Object },
|
|
|
|
|
showRemove: { type: Boolean, default: true },
|
|
|
|
|
projectRightBox: { type: Boolean, default: false },
|
|
|
|
|
metricOptionsParent: { type: Array },
|
|
|
|
|
inputId: String,
|
|
|
|
|
required: {
|
|
|
|
|
type: Boolean, default: false
|
2021-03-16 17:54:05 +08:00
|
|
|
},
|
2021-03-19 18:52:19 +08:00
|
|
|
showTemp: {
|
|
|
|
|
type: Boolean,
|
|
|
|
|
default: true
|
|
|
|
|
},
|
|
|
|
|
typeContentLoading: {
|
|
|
|
|
type: Boolean,
|
|
|
|
|
default: false
|
2021-04-28 19:26:49 +08:00
|
|
|
},
|
|
|
|
|
fromFatherData: {
|
|
|
|
|
type: Boolean,
|
|
|
|
|
default: false
|
2021-03-19 18:52:19 +08:00
|
|
|
}
|
|
|
|
|
// metricOptions: {type: Array},
|
|
|
|
|
// metricStore: {type: Array}
|
|
|
|
|
},
|
|
|
|
|
data () {
|
|
|
|
|
return {
|
|
|
|
|
dropDownVisible: false,
|
|
|
|
|
// metricStore:[],
|
|
|
|
|
metricOptions: [],
|
|
|
|
|
cascaderValue: '',
|
|
|
|
|
errorMsg: null,
|
|
|
|
|
appendMsg: null,
|
|
|
|
|
editorValue: '',
|
|
|
|
|
firstAddEvent: true,
|
|
|
|
|
tempBoxShow: false,
|
|
|
|
|
tempBox: {
|
|
|
|
|
expression: '',
|
|
|
|
|
vars: []
|
2021-03-18 13:58:55 +08:00
|
|
|
},
|
2021-03-19 18:52:19 +08:00
|
|
|
tempBoxShowLoading: false,
|
|
|
|
|
assetOption: [],
|
|
|
|
|
moduleOption: [],
|
|
|
|
|
endpointOption: [],
|
|
|
|
|
datacenterOption: [],
|
|
|
|
|
projectOption: [],
|
|
|
|
|
filterSilence: '',
|
2021-04-28 19:26:49 +08:00
|
|
|
tempBoxId: {},
|
|
|
|
|
loading: false
|
2021-03-19 18:52:19 +08:00
|
|
|
}
|
|
|
|
|
},
|
2021-04-28 19:26:49 +08:00
|
|
|
mounted () {
|
|
|
|
|
if (!this.fromFatherData) {
|
|
|
|
|
this.queryMetrics()
|
|
|
|
|
}
|
2021-03-19 18:52:19 +08:00
|
|
|
},
|
|
|
|
|
methods: {
|
|
|
|
|
closeDropdown () {
|
|
|
|
|
this.dropDownVisible = false
|
2021-03-16 17:54:05 +08:00
|
|
|
},
|
2021-03-19 18:52:19 +08:00
|
|
|
clearExpression: function () {
|
|
|
|
|
this.expressionChange()
|
|
|
|
|
this.cascaderValue = ''
|
2021-03-16 17:54:05 +08:00
|
|
|
},
|
2021-03-19 18:52:19 +08:00
|
|
|
addExpression: function () {
|
|
|
|
|
this.$emit('addExpression', this.index)
|
2021-03-16 17:54:05 +08:00
|
|
|
},
|
2021-03-19 18:52:19 +08:00
|
|
|
copyExpression () {
|
|
|
|
|
this.$emit('copyExpression', this.index)
|
|
|
|
|
},
|
|
|
|
|
removeExpression: function () {
|
|
|
|
|
this.$emit('removeExpression', this.index)
|
|
|
|
|
},
|
|
|
|
|
toggleDropdown () {
|
|
|
|
|
this.dropDownVisible = !this.dropDownVisible
|
2021-04-28 19:26:49 +08:00
|
|
|
this.getMetricOptions()
|
|
|
|
|
},
|
|
|
|
|
getMetricOptions () {
|
|
|
|
|
if (!this.metricOptions.length) {
|
|
|
|
|
this.queryMetrics()
|
|
|
|
|
}
|
2021-03-19 18:52:19 +08:00
|
|
|
},
|
|
|
|
|
queryMetrics: function () {
|
2021-04-28 19:26:49 +08:00
|
|
|
this.loading = true
|
2021-03-19 18:52:19 +08:00
|
|
|
this.$get('prom/api/v1/label/__name__/values').then(response => {
|
|
|
|
|
if (response.status == 'success') {
|
2021-03-22 10:25:41 +08:00
|
|
|
const metrics = response.data.sort()
|
|
|
|
|
const metricMap = new Map()
|
2021-03-19 18:52:19 +08:00
|
|
|
metrics.forEach((item) => {
|
|
|
|
|
let key = ''
|
2021-05-07 14:29:07 +08:00
|
|
|
if (/^[a-zA-Z_:][a-zA-Z0-9_:]*/.test(item)) {
|
|
|
|
|
key = item.split(/[_:]/, 1)[0]
|
2021-03-19 18:52:19 +08:00
|
|
|
} else {
|
|
|
|
|
key = item
|
|
|
|
|
}
|
|
|
|
|
if (metricMap.get(key)) {
|
2021-03-22 10:25:41 +08:00
|
|
|
const values = metricMap.get(key)
|
2021-03-19 18:52:19 +08:00
|
|
|
values.push({ label: item, value: item })
|
|
|
|
|
} else {
|
2021-03-22 10:25:41 +08:00
|
|
|
const values = [{ label: item, value: item }]
|
2021-03-19 18:52:19 +08:00
|
|
|
metricMap.set(key, values)
|
2020-11-22 16:51:30 +08:00
|
|
|
}
|
2021-03-19 18:52:19 +08:00
|
|
|
// this.metricStore.push({label:item,value:item,insertText:item})
|
|
|
|
|
})
|
2021-03-22 10:25:41 +08:00
|
|
|
for (const key of metricMap.keys()) {
|
|
|
|
|
const option = {
|
2021-03-19 18:52:19 +08:00
|
|
|
label: key,
|
|
|
|
|
value: key
|
2020-04-21 19:28:01 +08:00
|
|
|
}
|
2021-03-19 18:52:19 +08:00
|
|
|
if (metricMap.get(key) && metricMap.get(key).length > 1) {
|
|
|
|
|
option.children = metricMap.get(key)
|
|
|
|
|
}
|
|
|
|
|
this.metricOptions.push(option)
|
2021-02-25 15:06:15 +08:00
|
|
|
}
|
2021-03-19 18:52:19 +08:00
|
|
|
if (this.showTemp) {
|
|
|
|
|
this.getExprTemp()
|
2021-03-16 17:54:05 +08:00
|
|
|
}
|
2021-03-19 18:52:19 +08:00
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
filterInput: function (queryString, cb) {
|
2021-03-22 10:25:41 +08:00
|
|
|
const metrics = Object.assign([], this.metricStore)
|
|
|
|
|
const result = queryString
|
2021-03-19 18:52:19 +08:00
|
|
|
? metrics.filter((item) => {
|
|
|
|
|
return item.value.toLowerCase().indexOf(queryString.toLowerCase()) != -1
|
2021-03-16 17:54:05 +08:00
|
|
|
})
|
2021-03-19 18:52:19 +08:00
|
|
|
: metrics
|
|
|
|
|
cb(result)
|
|
|
|
|
},
|
|
|
|
|
metricChange: function (value) {
|
|
|
|
|
if (!value) return
|
2021-05-13 10:06:03 +08:00
|
|
|
// this.expressionList[this.index] = value
|
|
|
|
|
this.insertText(value)
|
2021-03-19 18:52:19 +08:00
|
|
|
// this.$refs.editor.setContent(value)
|
|
|
|
|
this.dropDownVisible = false
|
2021-05-12 19:07:07 +08:00
|
|
|
this.$emit('change', value)
|
2021-04-22 18:03:56 +08:00
|
|
|
this.$forceUpdate()
|
2021-05-11 14:11:24 +08:00
|
|
|
this.cascaderValue = ''
|
2021-03-19 18:52:19 +08:00
|
|
|
},
|
|
|
|
|
metricKeyDown (val) {
|
|
|
|
|
if (this.required) {
|
|
|
|
|
this.metricChange(val)
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
expressionChange: function () {
|
2021-05-12 19:07:07 +08:00
|
|
|
this.$emit('change')
|
2021-03-19 18:52:19 +08:00
|
|
|
},
|
|
|
|
|
setError: function (errMsg) {
|
|
|
|
|
// console.log(errMsg)
|
|
|
|
|
this.errorMsg = errMsg
|
|
|
|
|
},
|
|
|
|
|
getExprTemp () {
|
|
|
|
|
this.$get('/expression/tmpl/gname').then(res => {
|
2021-04-28 19:26:49 +08:00
|
|
|
this.loading = false
|
2021-03-19 18:52:19 +08:00
|
|
|
if (res.code === 200) {
|
|
|
|
|
res.data.list.forEach(item => {
|
|
|
|
|
this.metricOptions.unshift({
|
|
|
|
|
label: item,
|
|
|
|
|
value: item,
|
|
|
|
|
children: [],
|
|
|
|
|
temp: true,
|
|
|
|
|
child: false
|
2021-03-16 17:54:05 +08:00
|
|
|
})
|
2021-03-19 18:52:19 +08:00
|
|
|
})
|
2021-03-16 17:54:05 +08:00
|
|
|
}
|
2021-03-19 18:52:19 +08:00
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
lazyLoad (node, data) {
|
|
|
|
|
if (data.temp) {
|
|
|
|
|
if (!data.child) {
|
|
|
|
|
this.tempBoxShowLoading = true
|
|
|
|
|
this.$get('/expression/tmpl?pageSize=-1&gname=' + data.value).then(res => {
|
|
|
|
|
this.tempBoxShowLoading = false
|
|
|
|
|
if (res.code === 200) {
|
|
|
|
|
res.data.list.forEach(item => {
|
|
|
|
|
item.label = item.name
|
|
|
|
|
item.value = false
|
|
|
|
|
item.temp = true
|
|
|
|
|
item.child = true
|
|
|
|
|
})
|
|
|
|
|
this.metricOptions.find(item => item.value === data.value).children = res.data.list
|
2021-03-16 17:54:05 +08:00
|
|
|
}
|
2021-03-19 18:52:19 +08:00
|
|
|
})
|
|
|
|
|
} else {
|
|
|
|
|
this.dropDownVisible = false
|
|
|
|
|
this.$get('/expression/tmpl/' + data.id).then(res => {
|
|
|
|
|
if (res.code === 200) {
|
2021-04-21 10:57:53 +08:00
|
|
|
if (!res.data.vars || !res.data.vars.length) {
|
|
|
|
|
this.metricChange(data.expression)
|
|
|
|
|
return
|
|
|
|
|
}
|
2021-03-19 18:52:19 +08:00
|
|
|
res.data.vars.forEach(item => {
|
|
|
|
|
res.data[item] = ''
|
|
|
|
|
const arr = item.split('.')
|
|
|
|
|
const keyword = arr[0].toLowerCase()
|
|
|
|
|
this.getAllOptins(keyword, keyword + 'Option')
|
|
|
|
|
})
|
|
|
|
|
this.tempBox = {
|
|
|
|
|
...this.tempBox,
|
|
|
|
|
...res.data
|
|
|
|
|
}
|
2021-03-18 13:58:55 +08:00
|
|
|
|
2021-03-19 18:52:19 +08:00
|
|
|
setTimeout(() => {
|
|
|
|
|
this.tempBoxShow = true
|
|
|
|
|
}, 100)
|
2020-11-24 17:31:40 +08:00
|
|
|
}
|
2021-03-16 17:54:05 +08:00
|
|
|
})
|
|
|
|
|
}
|
2021-03-19 18:52:19 +08:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
tempBoxShowChange (flag) {
|
|
|
|
|
this.tempBoxShow = flag
|
|
|
|
|
if (flag) {
|
|
|
|
|
this.cascaderValue = ''
|
2021-03-22 10:25:41 +08:00
|
|
|
const params = {}
|
2021-03-19 18:52:19 +08:00
|
|
|
params.expression = this.tempBox.expression
|
|
|
|
|
params.varsVal = {}
|
|
|
|
|
let returnFlag = false
|
|
|
|
|
let errorStr = ''
|
|
|
|
|
this.tempBox.vars.forEach((item) => {
|
2021-03-22 16:02:58 +08:00
|
|
|
params.varsVal[item] = this.tempBoxId[item] || this.tempBox[item]
|
2021-03-19 18:52:19 +08:00
|
|
|
if (!this.tempBox[item]) {
|
|
|
|
|
errorStr += item + ','
|
|
|
|
|
returnFlag = true
|
|
|
|
|
}
|
|
|
|
|
})
|
2021-03-16 17:54:05 +08:00
|
|
|
|
2021-03-19 18:52:19 +08:00
|
|
|
if (returnFlag) {
|
|
|
|
|
this.$message({
|
|
|
|
|
message: this.$t('config.exprTemp.errorStr', { errorStr: errorStr }),
|
|
|
|
|
type: 'error'
|
|
|
|
|
})
|
|
|
|
|
return
|
2021-03-16 17:54:05 +08:00
|
|
|
}
|
2021-03-18 13:58:55 +08:00
|
|
|
|
2021-03-19 18:52:19 +08:00
|
|
|
if (this.tempBox.vars.length == 0) {
|
|
|
|
|
this.tempBoxShow = false
|
2021-03-22 16:02:58 +08:00
|
|
|
// eslint-disable-next-line vue/no-mutating-props
|
2021-05-13 10:06:03 +08:00
|
|
|
// this.expressionList[this.index] = params.expression
|
|
|
|
|
this.insertText(params.expression)
|
2021-05-12 19:07:07 +08:00
|
|
|
this.$emit('change', params.expression)
|
2021-03-19 18:52:19 +08:00
|
|
|
return
|
|
|
|
|
}
|
2021-03-16 17:54:05 +08:00
|
|
|
|
2021-03-19 18:52:19 +08:00
|
|
|
this.$post('/expression/tmpl/render', params).then(res => {
|
|
|
|
|
if (res.code === 200) {
|
|
|
|
|
this.tempBoxShow = false
|
2021-05-13 10:06:03 +08:00
|
|
|
// this.expressionList[this.index] = res.data.expression
|
|
|
|
|
this.insertText(res.data.expression)
|
2021-05-12 19:07:07 +08:00
|
|
|
this.$emit('change', res.data.expression)
|
2021-03-19 18:52:19 +08:00
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
} else {
|
|
|
|
|
this.tempBox = {}
|
|
|
|
|
}
|
|
|
|
|
},
|
2021-03-16 17:54:05 +08:00
|
|
|
|
2021-03-19 18:52:19 +08:00
|
|
|
format (str) {
|
2021-03-22 10:25:41 +08:00
|
|
|
const arr = str.split('.')
|
|
|
|
|
const keyword = arr[0].toLowerCase()
|
2021-03-19 18:52:19 +08:00
|
|
|
switch (keyword) {
|
|
|
|
|
case 'asset':
|
|
|
|
|
case 'module':
|
|
|
|
|
case 'endpoint':
|
|
|
|
|
case 'datacenter':
|
|
|
|
|
case 'project':
|
|
|
|
|
return {
|
|
|
|
|
arr: this[keyword + 'Option'],
|
|
|
|
|
key: keyword,
|
|
|
|
|
value: ((keyword == 'module' || keyword == 'project' || keyword == 'datacenter') ? 'name' : 'host')
|
|
|
|
|
}
|
|
|
|
|
default:
|
|
|
|
|
return {
|
|
|
|
|
key: false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
getAllOptins (key, arr) {
|
|
|
|
|
switch (key) {
|
|
|
|
|
case 'asset':
|
2021-05-11 14:11:24 +08:00
|
|
|
this.$get('asset/asset', { pageNo: 1, pageSize: -1 }).then(response => {
|
2021-03-19 18:52:19 +08:00
|
|
|
if (response.code == 200) {
|
2021-03-22 10:25:41 +08:00
|
|
|
const arr = []
|
2021-03-19 18:52:19 +08:00
|
|
|
response.data.list.forEach(asset => {
|
|
|
|
|
asset.name = asset.sn
|
2021-05-11 14:11:24 +08:00
|
|
|
const dcF = arr.find(dc => dc.id === asset.dc.id)
|
|
|
|
|
if (dcF) {
|
|
|
|
|
dcF.children.push(asset)
|
2021-03-19 18:52:19 +08:00
|
|
|
} else {
|
2021-05-11 14:11:24 +08:00
|
|
|
const dc = { ...asset.dc }
|
|
|
|
|
dc.children = [asset]
|
|
|
|
|
arr.push(dc)
|
2021-03-19 18:52:19 +08:00
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
this.assetOption = arr
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
break
|
|
|
|
|
case 'module':
|
2021-05-11 14:11:24 +08:00
|
|
|
this.$get('monitor/module/tree', { pageNo: 1, pageSize: -1 }).then(response => {
|
2021-03-19 18:52:19 +08:00
|
|
|
if (response.code == 200) {
|
2021-05-11 14:11:24 +08:00
|
|
|
this.moduleOption = response.data.list
|
2021-03-19 18:52:19 +08:00
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
break
|
|
|
|
|
case 'endpoint':
|
2021-05-11 14:11:24 +08:00
|
|
|
this.$get('monitor/endpoint/tree', { pageNo: 1, pageSize: -1 }).then(response => {
|
2021-03-19 18:52:19 +08:00
|
|
|
if (response.code == 200) {
|
2021-05-11 14:11:24 +08:00
|
|
|
this.endpointOption = response.data.list
|
2021-03-19 18:52:19 +08:00
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
break
|
|
|
|
|
case 'datacenter':
|
2021-05-11 14:11:24 +08:00
|
|
|
this.$get('dc', { pageNo: 1, pageSize: -1 }).then(response => {
|
2021-03-19 18:52:19 +08:00
|
|
|
if (response.code == 200) {
|
|
|
|
|
this.datacenterOption = response.data.list
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
break
|
|
|
|
|
case 'project':
|
2021-05-11 14:11:24 +08:00
|
|
|
this.$get('monitor/project', { pageNo: 1, pageSize: -1 }).then(response => {
|
2021-03-19 18:52:19 +08:00
|
|
|
if (response.code == 200) {
|
|
|
|
|
this.projectOption = response.data.list
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
break
|
|
|
|
|
default:
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
silenceChange (val, key) {
|
|
|
|
|
this.tempBox[key] = val.name
|
2021-03-22 10:25:41 +08:00
|
|
|
this.tempBoxId[key] = val.id
|
2021-03-19 18:52:19 +08:00
|
|
|
},
|
|
|
|
|
clearValue (key) {
|
|
|
|
|
this.tempBox[key] = ''
|
|
|
|
|
},
|
|
|
|
|
tempBoxClose () {
|
|
|
|
|
this.cascaderValue = ''
|
2021-05-13 10:06:03 +08:00
|
|
|
},
|
|
|
|
|
insertText (insertTxt) {
|
|
|
|
|
// 获取el-input中的input元素
|
|
|
|
|
const elInput = this.$refs.elInput.$el.firstElementChild
|
|
|
|
|
// 获取el-input的值
|
|
|
|
|
const txt = elInput.value
|
|
|
|
|
// 获取选区开始位置
|
|
|
|
|
const startPos = elInput.selectionStart
|
|
|
|
|
// 获取选区结束位置
|
|
|
|
|
const endPos = elInput.selectionEnd
|
|
|
|
|
if (startPos === undefined || endPos === undefined) return
|
2021-03-16 17:54:05 +08:00
|
|
|
|
2021-05-13 10:06:03 +08:00
|
|
|
// 将文本插入光标位置
|
|
|
|
|
this.expressionList[this.index] = txt.substring(0, startPos) + insertTxt + txt.substring(endPos)
|
|
|
|
|
// 将光标移至文本末尾
|
|
|
|
|
elInput.focus()
|
|
|
|
|
elInput.selectionStart = startPos + insertTxt.length
|
|
|
|
|
elInput.selectionEnd = startPos + insertTxt.length
|
|
|
|
|
}
|
2021-03-19 18:52:19 +08:00
|
|
|
/* setMsg:function(){
|
2021-03-16 17:54:05 +08:00
|
|
|
this.appendMsg
|
2021-03-19 18:52:19 +08:00
|
|
|
} */
|
|
|
|
|
},
|
|
|
|
|
watch: {
|
|
|
|
|
dropDownVisible: function (n, o) {
|
|
|
|
|
if (this.$refs.metricSelector) {
|
|
|
|
|
this.$refs.metricSelector.dropDownVisible = n
|
|
|
|
|
if (!this.expressionList[this.index] || this.expressionList[this.index] == '') {
|
|
|
|
|
this.cascaderValue = ''
|
2021-03-16 17:54:05 +08:00
|
|
|
}
|
2021-03-19 18:52:19 +08:00
|
|
|
}
|
|
|
|
|
}
|
2021-03-16 17:54:05 +08:00
|
|
|
}
|
2021-03-19 18:52:19 +08:00
|
|
|
}
|
2020-04-21 19:28:01 +08:00
|
|
|
</script>
|
|
|
|
|
|
2020-07-02 22:25:06 +08:00
|
|
|
<style scoped lang="scss">
|
2021-03-16 17:54:05 +08:00
|
|
|
.promqlInput {
|
2020-04-21 19:28:01 +08:00
|
|
|
position: relative;
|
|
|
|
|
width: 100%;
|
|
|
|
|
display: flex;
|
|
|
|
|
}
|
2021-03-16 17:54:05 +08:00
|
|
|
|
|
|
|
|
.promqlInput .query-row {
|
2021-04-30 18:54:11 +08:00
|
|
|
display: flex;
|
|
|
|
|
flex-wrap: wrap;
|
2020-04-21 19:28:01 +08:00
|
|
|
width: 100%;
|
|
|
|
|
}
|
2021-03-16 17:54:05 +08:00
|
|
|
|
|
|
|
|
.input-box .append-msg {
|
2020-04-24 17:41:33 +08:00
|
|
|
font-size: 12px;
|
|
|
|
|
line-height: 1;
|
|
|
|
|
padding-top: 4px;
|
|
|
|
|
}
|
2021-03-16 17:54:05 +08:00
|
|
|
|
|
|
|
|
.input-box .error {
|
2020-04-24 17:41:33 +08:00
|
|
|
color: #F56C6C;
|
|
|
|
|
}
|
2021-03-16 17:54:05 +08:00
|
|
|
|
|
|
|
|
.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
|
|
|
}
|
2021-03-16 17:54:05 +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;
|
2021-03-05 20:34:58 +08:00
|
|
|
height: 29px !important;
|
|
|
|
|
line-height: 30px;
|
2020-04-21 19:28:01 +08:00
|
|
|
text-align: center;
|
|
|
|
|
}
|
2021-03-16 17:54:05 +08:00
|
|
|
|
|
|
|
|
.query-options .option:focus, .query-options .option:hover {
|
2021-03-19 11:12:09 +08:00
|
|
|
background-color: rgb(247, 248, 250);
|
2020-04-21 19:28:01 +08:00
|
|
|
}
|
2021-03-16 17:54:05 +08:00
|
|
|
|
2021-04-30 18:54:11 +08:00
|
|
|
.query-row .input-box {
|
|
|
|
|
flex: auto;
|
2021-05-06 13:33:07 +08:00
|
|
|
margin-right: 10px;
|
2020-04-21 19:28:01 +08:00
|
|
|
}
|
2021-03-16 17:54:05 +08:00
|
|
|
|
|
|
|
|
.metric-btn {
|
2021-03-05 20:34:58 +08:00
|
|
|
height: 29px !important;
|
2020-04-22 19:45:10 +08:00
|
|
|
width: 105px;
|
|
|
|
|
margin-left: 1px;
|
2020-04-21 19:28:01 +08:00
|
|
|
}
|
2021-03-16 17:54:05 +08:00
|
|
|
|
|
|
|
|
.metric-btn:hover, .metric-btn:focus {
|
2021-03-19 11:12:09 +08:00
|
|
|
background-image: linear-gradient(180deg, rgb(247, 248, 250) 0%, rgb(247, 248, 250) 100%);
|
2021-03-16 17:54:05 +08:00
|
|
|
color: #606266;
|
2020-04-21 19:28:01 +08:00
|
|
|
}
|
2021-03-16 17:54:05 +08:00
|
|
|
|
|
|
|
|
.metric-selector .el-cascader-panel {
|
2020-04-21 19:28:01 +08:00
|
|
|
height: 300px;
|
|
|
|
|
position: absolute;
|
|
|
|
|
z-index: 2100;
|
|
|
|
|
background-color: #FFF;
|
|
|
|
|
}
|
2021-03-16 17:54:05 +08:00
|
|
|
|
|
|
|
|
.expr-title {
|
2020-09-07 14:33:34 +08:00
|
|
|
width: 120px;
|
|
|
|
|
padding-right: 20px;
|
|
|
|
|
text-align: right;
|
|
|
|
|
color: #666;
|
|
|
|
|
font-size: 14px;
|
|
|
|
|
letter-spacing: 0;
|
|
|
|
|
line-height: 22px;
|
|
|
|
|
}
|
2021-03-16 17:54:05 +08:00
|
|
|
|
|
|
|
|
/deep/ .el-cascader-node {
|
|
|
|
|
padding: 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/deep/ .el-cascader-menu:last-child .el-cascader-node, /deep/ .el-cascader-node__label {
|
|
|
|
|
padding: 0;
|
|
|
|
|
}
|
2021-03-18 17:03:29 +08:00
|
|
|
.metric-selector-title{
|
|
|
|
|
/*'width':plugins.indexOf('metric-selector') > -1 ? '110px':'100%',*/
|
|
|
|
|
/*'padding': plugins.indexOf('metric-selector') > -1 ?'0 0 0 10px':'0 20px 0 0 ',*/
|
|
|
|
|
/*'text-align':'left', 'color': '#666',*/
|
|
|
|
|
/*'font-weight':plugins.indexOf('metric-selector') > -1 ?'400':'bold',*/
|
2021-03-19 11:12:09 +08:00
|
|
|
width:100px;
|
2021-03-18 17:03:29 +08:00
|
|
|
margin-left: 10px;
|
2021-03-19 11:12:09 +08:00
|
|
|
margin-right: 10px;
|
2021-04-26 21:42:15 +08:00
|
|
|
height: 32px;
|
2021-03-18 17:03:29 +08:00
|
|
|
text-align: left;
|
|
|
|
|
padding: 0 0 0 10px;
|
|
|
|
|
font-weight: 400;
|
|
|
|
|
line-height: 33px;
|
|
|
|
|
background: #E7EAED;
|
2021-04-26 21:42:15 +08:00
|
|
|
border-radius: $--primary-border-radius;
|
2021-03-18 17:03:29 +08:00
|
|
|
font-family: ArialMT;
|
|
|
|
|
font-size: 14px;
|
|
|
|
|
color: #333333;
|
|
|
|
|
letter-spacing: 0;
|
|
|
|
|
}
|
|
|
|
|
.metric-selector-input-box{
|
2021-04-26 21:42:15 +08:00
|
|
|
width: calc(100% - 160px);
|
2021-03-18 17:03:29 +08:00
|
|
|
}
|
|
|
|
|
.metric-null-input-box{
|
|
|
|
|
width: 100%;
|
|
|
|
|
}
|
|
|
|
|
.metric-null-title{
|
|
|
|
|
width:100%;
|
|
|
|
|
font-weight: bold;
|
|
|
|
|
letter-spacing: 0;
|
|
|
|
|
}
|
2021-03-16 17:54:05 +08:00
|
|
|
.nz-cascade {
|
2021-03-19 11:12:09 +08:00
|
|
|
padding: 0 10px 0 25px;
|
2021-03-18 17:03:29 +08:00
|
|
|
position: relative;
|
2021-03-16 17:54:05 +08:00
|
|
|
}
|
2021-04-07 19:18:22 +08:00
|
|
|
.nz-cascade .nz-icon-template2 {
|
2021-03-18 13:58:55 +08:00
|
|
|
display: none;
|
|
|
|
|
}
|
2021-03-16 17:54:05 +08:00
|
|
|
|
2021-04-07 19:18:22 +08:00
|
|
|
.nz-cascade-temp .nz-icon-template2{
|
2021-03-18 13:58:55 +08:00
|
|
|
display: inline-block;
|
2021-03-18 17:03:29 +08:00
|
|
|
position: absolute;
|
2021-03-19 11:12:09 +08:00
|
|
|
left: 5px;
|
2021-03-18 17:03:29 +08:00
|
|
|
|
2021-03-18 13:58:55 +08:00
|
|
|
/*background: #F8F9FB;*/
|
2021-03-16 17:54:05 +08:00
|
|
|
}
|
|
|
|
|
.temp-form-box{
|
|
|
|
|
width: 480px;
|
|
|
|
|
}
|
|
|
|
|
.temp-form-box .temp-form-box-title{
|
|
|
|
|
font-family: PingFangSC-Medium;
|
|
|
|
|
font-size: 14px;
|
|
|
|
|
color: #666666;
|
|
|
|
|
letter-spacing: 0;
|
|
|
|
|
font-weight: 600;
|
|
|
|
|
margin-bottom: 5px;
|
|
|
|
|
}
|
|
|
|
|
.temp-form-box .temp-form-box-col{
|
|
|
|
|
margin-right: 10px;
|
|
|
|
|
}
|
2020-04-21 19:28:01 +08:00
|
|
|
</style>
|
|
|
|
|
<style>
|
2021-03-16 17:54:05 +08:00
|
|
|
.metric-selector-pop {
|
|
|
|
|
position: relative;
|
2020-04-21 19:28:01 +08:00
|
|
|
z-index: 2100;
|
|
|
|
|
}
|
2021-03-16 17:54:05 +08:00
|
|
|
.input-box .el-input__inner {
|
2021-03-05 20:34:58 +08:00
|
|
|
height: 30px;
|
2020-04-22 19:45:10 +08:00
|
|
|
}
|
2021-03-16 17:54:05 +08:00
|
|
|
.nz-temp-box /deep/ .el-dialog__body{
|
|
|
|
|
padding: 10px 20px 0 20px;
|
|
|
|
|
}
|
|
|
|
|
.nz-temp-box /deep/ .el-dialog__footer{
|
|
|
|
|
margin-top: 0;
|
|
|
|
|
}
|
|
|
|
|
.nz-temp-box .nz-btn-style-light-new{
|
|
|
|
|
margin-right: 10px;
|
|
|
|
|
}
|
|
|
|
|
.nz-temp-box .nz-btn-style-normal-new{
|
|
|
|
|
margin-left: 10px;
|
|
|
|
|
}
|
2020-04-21 19:28:01 +08:00
|
|
|
</style>
|