This repository has been archived on 2025-09-14. You can view files and clone it, but cannot push or open issues or pull requests.
Files
nezha-nezha-fronted/nezha-fronted/src/components/common/rightBox/chart/systemChartConfig.vue

600 lines
23 KiB
Vue
Raw Normal View History

2021-11-30 16:39:21 +08:00
<template>
2021-12-02 18:33:28 +08:00
<div class="chart-config">
<el-form
ref="chartForm"
:model="chartConfig"
:rules="rules"
label-position= "top"
label-width="120px"
>
<div class="chart-title chart-title-config">
System
</div>
<div class="system-chart-config" v-loading="loading" v-for="(item, index) in chartConfig.param.datasource " :key="index">
2021-12-02 18:33:28 +08:00
<div class="system-chart-config-left">
<ul>
2021-12-02 18:52:32 +08:00
<li
v-for="(system,index1) in systemData"
:key="index1"
2021-12-02 18:52:32 +08:00
class="system-chart-item"
:class="item.type === system.system ? 'is-select' : ''"
@click="changeSystem(system, index)"
>{{system.name}}</li>
2021-12-02 18:33:28 +08:00
</ul>
</div>
<div class="system-chart-config-right">
<div class="form-items--half-width-group">
<el-form-item
2021-12-03 16:24:19 +08:00
:label="$t('dashboard.panel.chartForm.dimension')"
2021-12-02 18:33:28 +08:00
class="form-item--half-width"
prop="param.systemGroup"
>
<el-select size="small" v-model="item.systemGroup" multiple collapse-tags :placeholder="$t('el.select.placeholder')" @change="systemGroupChange(index)">
<el-option v-for="group in groupList" :value="group.name" :key="group.name" :label="group.name"/>
2021-12-02 18:33:28 +08:00
</el-select>
</el-form-item>
<el-form-item
2021-12-03 10:08:34 +08:00
v-if="selectList.length"
2021-12-02 18:33:28 +08:00
:label="$t('dashboard.panel.chartForm.select')"
class="form-item--half-width"
2021-12-03 10:08:34 +08:00
prop="param.systemSelect"
2021-12-02 18:33:28 +08:00
>
<el-select size="small" v-model="item.systemSelect" :placeholder="$t('el.select.placeholder')" @change="systemSelectChange(index)">
<el-option v-for="selectItem in selectList" :value="selectItem.name" :key="selectItem.name" :label="selectItem.name"/>
2021-12-03 10:08:34 +08:00
</el-select>
2021-12-02 18:33:28 +08:00
</el-form-item>
</div>
<div class="form-items--half-width-group">
<el-form-item
:label="$t('dashboard.panel.chartForm.sort')"
class="form-item--half-width"
prop="param.sort"
>
<el-select
id="chart-box-height"
v-model="item.sort"
2021-12-02 18:33:28 +08:00
placeholder=""
popper-class="right-box-select-top prevent-clickoutside"
size="small"
value-key="chartSpan"
@change="change"
>
<el-option :value="'desc'" :label="$t('dashboard.explore.descending')">
</el-option>
<el-option :value="'asc'" :label="$t('dashboard.explore.ascending')">
</el-option>
</el-select>
</el-form-item>
<el-form-item
2021-12-03 10:08:34 +08:00
:label="$t('dashboard.panel.chartForm.result')"
2021-12-02 18:33:28 +08:00
class="form-item--half-width"
prop="param.limit"
>
<el-input-number :controls="false" v-model.number="item.limit" :placeholder="$t('placeholder.system.limit')" size="small" @change="change"/>
2021-12-02 18:33:28 +08:00
</el-form-item>
</div>
</div>
</div>
<!--title-->
<div class="form__sub-title">
<span>{{$t('dashboard.panel.chartForm.displayConfig')}}</span>
</div>
<div class="form-items--half-width-group">
<!-- type -->
<el-form-item
:label="$t('dashboard.panel.chartForm.type')"
class="form-item--half-width"
prop="type"
2021-12-02 15:36:01 +08:00
>
2021-12-02 18:33:28 +08:00
<el-select
id="chart-box-type"
v-model="chartConfig.type"
:disabled="chartConfig.type==='group'&&chartConfig.children&&chartConfig.children.length"
placeholder=""
popper-class="right-box-select-top prevent-clickoutside"
size="small"
value-key="chartType"
@change="chartTypeChange">
<el-option
v-for="item in chartTypeList"
:key="item.id"
:disabled="item.id==='group' && chartConfig.isGroup"
:label="item.name"
:value="item.id">
<span class="panel-dropdown-label-txt" >{{item.name}}</span>
</el-option>
</el-select>
</el-form-item>
<!--refer-->
<el-form-item
:label="$t('dashboard.panel.chartForm.refer')"
class="form-item--half-width"
prop="param.stack"
2021-12-07 14:19:16 +08:00
style="display: none"
2021-12-02 15:36:01 +08:00
>
2021-12-02 18:33:28 +08:00
<el-select
id="chart-box-height"
v-model="chartConfig.param.refer"
placeholder=""
popper-class="right-box-select-top prevent-clickoutside"
size="small"
value-key="chartSpan"
@change="change"
>
<el-option :value="1" label="true">
</el-option>
<el-option :value="0" label="false">
</el-option>
</el-select>
</el-form-item>
2021-12-15 17:55:56 +08:00
<!-- index -->
<el-form-item
v-show="isTable(chartConfig.type)"
:label="$t('dashboard.panel.chartForm.tableIndex')"
class="form-item--half-width"
prop="param.index"
>
<vue-tags-input
v-model="tag"
:maxlength="32"
:placeholder="$t('overall.addParameter')"
:tags="chartConfig.param.tags"
@tags-changed="(newTags)=>{tagsChange(newTags)}"
/>
</el-form-item>
2021-12-02 18:33:28 +08:00
</div>
<div class="form-items--half-width-group">
<!--width-->
<el-form-item
:label="$t('dashboard.panel.chartForm.width')"
class="form-item--half-width"
prop="span">
<el-select
id="chart-box-span"
v-model="chartConfig.span"
:disabled="chartConfig.type === 'group'"
placeholder=""
popper-class="right-box-select-top prevent-clickoutside"
size="small"
value-key="chartSpan"
@change="change"
>
<el-option
v-for="item in spanList"
:key="item"
:label="'span-' + item"
:value="item">
<span class="panel-dropdown-label-txt" > span-{{item}}</span>
</el-option>
</el-select>
</el-form-item>
2021-12-02 15:36:01 +08:00
2021-12-02 18:33:28 +08:00
<!--height-->
<el-form-item
:label="$t('dashboard.panel.chartForm.high')"
class="form-item--half-width"
prop="height">
<!-- 由px改为span -->
<el-select
id="chart-box-height"
v-model="chartConfig.height"
:disabled="chartConfig.type === 'group'"
placeholder=""
popper-class="right-box-select-top prevent-clickoutside"
size="small"
value-key="chartSpan"
@change="change"
2021-12-02 15:36:01 +08:00
>
2021-12-02 18:33:28 +08:00
<el-option
v-for="item in spanList"
:key="item"
:label="'span-' + item"
:value="item"
>
<span class="panel-dropdown-label-txt" > span-{{item}}</span>
</el-option>
</el-select>
</el-form-item>
</div>
2021-12-03 10:08:34 +08:00
2021-12-16 10:10:27 +08:00
<!-- table column-->
<div v-if="isTable(chartConfig.type)">
<div class="form__sub-title">
<span>{{$t('dashboard.panel.chartForm.columns')}}</span>
</div>
<div v-for="(item,index) in chartConfig.param.columns" :key="index">
<div class="chart-title chart-title-config">
<span class="chart-title-content">
<i class="nz-icon nz-icon-arrow-down" :class="item.show?'':'is-active'" @click="showColumns(index)"></i>
<span v-show="!item.show" class="title-content-left">
<span>
{{item.value}}
</span>
</span>
</span>
<span>
<span @click="addColumns('')">
<i class="nz-icon nz-icon-create-square" style="font-weight: normal; font-size: 17px; cursor: pointer;"></i>
</span>
<span class="nz-icon-copy">
<i @click="copyColumns(index)" class="nz-icon nz-icon-override"></i>
</span>
<span class="nz-icon-minus-medium">
<i @click="removeColumns(index)" class="nz-icon nz-icon-minus"></i>
</span>
</span>
</div>
<transition-group appear tag="div" name="el-zoom-in-top">
<el-row class="thresholds-item" v-show="item.show" :key="1">
<div>
<div class='mapping-display'>Title</div>
</div>
<el-form-item :prop="'param.columns.' + index + '.title'" :rules="{ required: true, message: $t('validate.required'), trigger: 'blur'}" class="thresholds-from-item" style="flex: 1">
<el-input size="small" v-model="item.title" placeholder="regx" @change="change"></el-input>
</el-form-item>
<div>
<div class='mapping-display'>Unit</div>
</div>
<el-cascader :id="'columns-unit' + index" v-model="item.unit" :options="unitOptions" :props="{ expandTrigger: 'hover',emitPath:false }" :show-all-levels="false" filterable
placeholder=""
popper-class="dc-dropdown right-box-select-top right-public-box-dropdown-top prevent-clickoutside chart-box-unit"
size="small"
style="flex: 1"
@change="unitSelected"
>
</el-cascader>
</el-row>
<el-row class="thresholds-item" v-show="item.show" :key="2">
<div>
<div class='mapping-display'>Display</div>
</div>
<el-form-item :prop="'param.columns.' + index + '.display'" :rules="{ required: true, message: $t('validate.required'), trigger: 'blur'}" class="thresholds-from-item">
<el-input v-model="item.display" style="margin-right: 10px" size="small" @change="change"/>
</el-form-item>
</el-row>
</transition-group>
</div>
<div @click="addColumns" class="thresholds-add">
Add Colums
</div>
</div>
2021-12-03 10:08:34 +08:00
<!-- valueMapping -->
2021-12-16 10:10:27 +08:00
<div v-if="isShowValueMapping(chartConfig.type) || isTable(chartConfig.type)">
2021-12-03 10:08:34 +08:00
<div class="form__sub-title">
<span>{{$t('dashboard.panel.chartForm.valueMapping')}}</span>
<el-switch
v-model="chartConfig.param.enable.valueMapping"
2021-12-03 10:08:34 +08:00
size="small"
@change="change"
></el-switch>
</div>
<transition name="el-zoom-in-top">
<el-row v-if="chartConfig.param.enable.valueMapping">
2021-12-03 10:08:34 +08:00
<div
v-for="(item,index) in chartConfig.param.valueMapping"
2021-12-03 10:08:34 +08:00
:key="index"
>
<div class="chart-title chart-title-config">
2021-12-16 10:10:27 +08:00
<span class="chart-title-content">
2021-12-03 10:08:34 +08:00
<i class="nz-icon nz-icon-arrow-down" :class="item.show?'':'is-active'" @click="showMapping(index)"></i>
<span v-show="!item.show" class="title-content-left">
<span v-if="item.type === 'value'">
{{item.value}}
</span>
<span v-if="item.type === 'range'">
{{item.from}} -> {{item.to}}
</span>
<span v-if="item.type === 'regx'">
{{item.regx}}
</span>
<div :style="{background:item.color.bac}" class="prev-mapping-box">
<span :style="{color:item.color.text}">
{{item.display || "T"}}
</span>
</div>
</span>
</span>
<span>
2021-12-16 10:10:27 +08:00
<span @click="addMapping('')" style="margin-right: 5px">
<i class="nz-icon nz-icon-create-square"></i>
2021-12-03 10:08:34 +08:00
</span>
2021-12-16 10:10:27 +08:00
<span @click="copyMapping(index)" style="margin-right: 5px">
<i class="nz-icon nz-icon-override"></i>
2021-12-03 10:08:34 +08:00
</span>
2021-12-16 10:10:27 +08:00
<span @click="removeMapping(index)" style="margin-right: 5px">
<i class="nz-icon nz-icon-minus"></i>
2021-12-03 10:08:34 +08:00
</span>
</span>
</div>
<transition-group appear tag="div" name="el-zoom-in-top">
<el-row
v-show="item.show"
:key="1"
class="thresholds-item"
>
<div>
<el-select
v-model="item.type"
size="small"
style="width: 100px"
@change="(val)=>{mappingItemChange(index,val)}"
>
<el-option
v-for="item in mappingTypeList"
:value="item.value"
:label="item.label"
:key="item.value"/>
</el-select>
</div>
<el-form-item
v-if="item.type === 'value'"
:prop="'param.valueMapping.' + index + '.value'"
:rules="{ required: true, message: $t('validate.required'), trigger: 'blur'}"
2021-12-03 10:08:34 +08:00
class="thresholds-from-item"
>
<el-input-number
2021-12-03 10:08:34 +08:00
:controls="false"
size="small"
v-model.number="item.value"
2021-12-03 10:08:34 +08:00
placeholder="value"
@change="change"
></el-input-number>
2021-12-03 10:08:34 +08:00
</el-form-item>
<el-form-item
v-if="item.type === 'range'"
:prop="'param.valueMapping.' + index + '.from'"
:rules="{ required: true, message: $t('validate.required'), trigger: 'blur'}"
2021-12-03 10:08:34 +08:00
class="thresholds-from-item"
>
<el-input-number
2021-12-03 10:08:34 +08:00
:controls="false"
size="small"
v-model.number="item.from"
2021-12-03 10:08:34 +08:00
placeholder="from"
@change="change"
></el-input-number>
2021-12-03 10:08:34 +08:00
</el-form-item>
<el-form-item
v-if="item.type === 'range'"
:prop="'param.valueMapping.' + index + '.to'"
:rules="{ required: true, message: $t('validate.required'), trigger: 'blur'}"
2021-12-03 10:08:34 +08:00
class="thresholds-from-item"
>
<el-input-number
2021-12-03 10:08:34 +08:00
:controls="false"
size="small"
v-model.number="item.to"
@change="change"
2021-12-16 10:10:27 +08:00
placeholder="to"
></el-input-number>
2021-12-03 10:08:34 +08:00
</el-form-item>
<el-form-item
v-if="item.type === 'regx'"
:prop="'param.valueMapping.' + index + '.regx'"
:rules="{ required: true, message: $t('validate.required'), trigger: 'blur'}"
2021-12-03 10:08:34 +08:00
class="thresholds-from-item"
>
<el-input
size="small"
v-model="item.regx"
placeholder="regx"
@change="change"
2021-12-03 10:08:34 +08:00
></el-input>
</el-form-item>
</el-row>
<el-row v-show="item.show" :key="2" class="thresholds-item">
2021-12-16 10:10:27 +08:00
<div v-if="isTable(chartConfig.type)">
<div class='mapping-display'>Columns</div>
</div>
<el-form-item v-if="isTable(chartConfig.type)" :prop="'param.valueMapping.' + index + '.column'" :rules="{ required: true, message: $t('validate.required'), trigger: 'blur'}" class="thresholds-from-item">
2021-12-16 10:10:27 +08:00
<el-input v-model="item.column" style="margin-right: 10px" :placeholder="$t('placeholder.chart.column')" size="small" @change="change"/>
</el-form-item>
2021-12-03 10:08:34 +08:00
<div>
<div class='mapping-display'>Display</div>
</div>
<el-form-item :prop="'param.valueMapping.' + index + '.display'" :rules="{ required: true, message: $t('validate.required'), trigger: 'blur'}" class="thresholds-from-item">
2021-12-16 10:10:27 +08:00
<el-input v-model="item.display" style="margin-right: 10px" :placeholder="$t('placeholder.chart.display')" size="small" @change="change"/>
2021-12-03 10:08:34 +08:00
</el-form-item>
<nezhaColor :color-val="item.color" :single="false" :value-arr="[{name:'bac',value:item.color.bac,key:'bac'},{name:'text',value:item.color.text,key:'text'}]" @colorChange="(val,key)=>{colorChange(val, key, index)}"/>
</el-row>
</transition-group>
</div>
<div @click="addMapping" class="thresholds-add">
Add valueMapping
</div>
</el-row>
</transition>
</div>
2021-12-02 18:33:28 +08:00
</el-form>
</div>
2021-11-30 16:39:21 +08:00
</template>
<script>
2021-12-02 15:36:01 +08:00
import publicConfig from '@/components/common/rightBox/chart/publicConfig'
import chartTypeShow from '@/components/common/rightBox/chart/chartTypeShow'
2021-12-03 10:08:34 +08:00
import nezhaColor from '@/components/common/nezhaColor'
2021-12-16 10:10:27 +08:00
import VueTagsInput from '@johmun/vue-tags-input'
2021-11-30 16:39:21 +08:00
export default {
2021-12-02 15:36:01 +08:00
name: 'systemChartConfig',
mixins: [publicConfig, chartTypeShow],
2021-12-03 10:08:34 +08:00
components: {
2021-12-16 10:10:27 +08:00
nezhaColor,
VueTagsInput
2021-12-03 10:08:34 +08:00
},
2021-12-02 15:36:01 +08:00
data () {
return {
2021-12-02 18:52:32 +08:00
systemData: [],
loading: false,
2021-12-02 18:33:28 +08:00
rules: {},
2021-12-03 10:08:34 +08:00
groupList: [],
selectList: [],
2021-12-07 14:19:16 +08:00
oldType: '',
2021-12-15 17:55:56 +08:00
tag: '',
2021-12-02 15:36:01 +08:00
chartTypeList: [
{
id: 'stat',
2021-12-02 18:33:28 +08:00
name: this.$t('dashboard.panel.chartForm.typeVal.singleStat.label')
2021-12-02 15:36:01 +08:00
},
{
2021-12-02 18:33:28 +08:00
id: 'bar',
name: this.$t('dashboard.panel.chartForm.typeVal.bar.label')
2021-12-02 15:36:01 +08:00
},
{
2021-12-02 18:33:28 +08:00
id: 'pie',
name: this.$t('dashboard.panel.chartForm.typeVal.pie.label')
2021-12-03 10:08:34 +08:00
},
{
id: 'guage',
name: this.$t('dashboard.panel.chartForm.typeVal.guage.label')
},
{
id: 'treemap',
name: this.$t('dashboard.panel.chartForm.typeVal.treemap.label')
},
{
id: 'table',
name: this.$t('dashboard.panel.chartForm.typeVal.table.label')
2021-12-02 18:52:32 +08:00
}
2021-12-02 15:36:01 +08:00
]
}
},
2021-12-03 17:59:27 +08:00
watch: {
selectList (n) {
if (n.length === 1 && !this.chartConfig.param.datasource[0].systemSelect) {
this.chartConfig.param.datasource[0].systemSelect = this.selectList[0].name
this.systemSelectChange(0)
2021-12-03 17:59:27 +08:00
}
}
},
2021-12-02 15:36:01 +08:00
methods: {
init () {
this.chartConfig = JSON.parse(JSON.stringify(this.params))
2021-12-07 14:19:16 +08:00
this.oldType = this.chartConfig.type
2021-12-02 15:36:01 +08:00
},
2021-12-02 18:52:32 +08:00
getSystemData () {
this.loading = true
2021-12-06 15:25:09 +08:00
this.$get('/sys/config/key/stat_query_json').then(res => {
2021-12-02 18:52:32 +08:00
this.loading = false
if (res.code === 200) {
2021-12-06 15:25:09 +08:00
this.systemData = JSON.parse(res.data.paramValue)
if (this.systemData.length) {
if (!this.chartConfig.param.system) {
this.chartConfig.param.datasource[0].type = this.systemData[0].name
2021-12-06 15:25:09 +08:00
this.groupList = this.systemData[0].group
this.selectList = this.systemData[0].select
} else {
const system = this.systemData.find(item => item.name === this.chartConfig.param.datasource[0].type)
2021-12-06 15:25:09 +08:00
this.chartConfig.param.system = system.name
this.groupList = system.group
this.selectList = system.select
}
this.$refs.chartForm && this.$refs.chartForm.clearValidate()
2021-12-02 18:52:32 +08:00
}
} else {
this.$message.error(res.msg)
}
})
},
2021-12-02 15:36:01 +08:00
chartTypeChange (type) {
switch (type) {
case 'stat':
2021-12-03 10:08:34 +08:00
case 'bar':
case 'pie':
case 'guage':
case 'treemap':
2021-12-07 14:19:16 +08:00
if (this.oldType !== 'table') {
break
}
2021-12-15 17:55:56 +08:00
this.chartConfig.param = {
refer: 1,
nullType: 'null',
statistics: 'last',
valueMapping: [],
enable: {
legend: true,
valueMapping: true,
thresholds: true
},
datasource: [{
name: 'System',
type: '',
systemGroup: '',
systemSelect: '',
group: '',
select: '',
limit: 100,
sort: 'desc'
2021-12-15 17:55:56 +08:00
}
]
2021-12-02 15:36:01 +08:00
}
break
2021-12-03 10:08:34 +08:00
case 'table':
2021-12-15 17:55:56 +08:00
this.chartConfig.param = {
refer: 1,
system: '',
indexs: '',
2021-12-16 10:10:27 +08:00
tags: [],
2021-12-15 17:55:56 +08:00
nullType: 'null',
statistics: 'last',
2021-12-16 10:10:27 +08:00
columns: [],
valueMapping: [],
enable: {
legend: true,
valueMapping: true,
thresholds: true
},
datasource: [{
name: 'System',
type: '',
systemGroup: '',
systemSelect: '',
group: '',
select: '',
limit: 100,
sort: 'desc'
2021-12-16 10:10:27 +08:00
}
]
2021-12-15 17:55:56 +08:00
}
2021-12-02 15:36:01 +08:00
break
}
this.chartConfig.param.datasource[0].type = this.systemData[0].name
this.groupList = this.systemData[0].group
this.selectList = this.systemData[0].select
2021-12-07 14:19:16 +08:00
this.oldType = type
2021-12-02 15:36:01 +08:00
this.change()
},
2021-12-02 18:52:32 +08:00
changeSystem (item) {
this.chartConfig.param.datasource[0].type = item.name
this.chartConfig.param.datasource[0].systemGroup = ''
this.chartConfig.param.datasource[0].systemSelect = ''
this.chartConfig.param.datasource[0].group = ''
this.chartConfig.param.datasource[0].select = ''
2021-12-03 10:08:34 +08:00
this.groupList = item.group
2021-12-03 17:59:27 +08:00
this.selectList = JSON.parse(JSON.stringify(item.select))
2021-12-16 10:10:27 +08:00
},
systemGroupChange (index) {
this.chartConfig.param.datasource[index].group = this.chartConfig.param.datasource[index].systemGroup.map(item => {
2021-12-16 10:10:27 +08:00
const obj = this.groupList.find(group => group.name === item)
return obj
})
this.change()
},
systemSelectChange (index) {
this.chartConfig.param.datasource[index].select = this.selectList.find(item => item.name === this.chartConfig.param.datasource[index].systemSelect)
2021-12-16 10:10:27 +08:00
this.change()
2021-12-02 18:52:32 +08:00
}
2021-12-02 18:33:28 +08:00
},
created () {
this.init()
2021-12-02 18:52:32 +08:00
},
mounted () {
this.getSystemData()
2021-12-02 15:36:01 +08:00
}
2021-11-30 16:39:21 +08:00
}
</script>
<style scoped>
</style>