功能变化(instrumentBoard): 支持多条数据选择显示;

pull/19/head
xt12321 2021-04-24 15:40:33 +08:00
parent d003d194f3
commit 51581abe13
2 changed files with 109 additions and 68 deletions

View File

@ -1,10 +1,29 @@
<template>
<div class="instrument-board">
<div v-if="topTitle.show" class="instrument-board-title">
{{ topTitleKeyToNameMapping[topTitle.text] || topTitle.text }}
<div v-if="showTopTitle && haveMultipleData" class="instrument-board-title">
<el-select :value="topTitle"
@change="chooseDisplayInstrumentBoardData"
>
<el-option
v-for="(item,index) in instrumentBoardData"
:key="index"
:label="item.name || item['dir_name']"
:value="index"
>
</el-option>
</el-select>
</div>
<div v-else-if="showTopTitle" class="instrument-board-title">
{{ topTitle }}
</div>
<div :id="ringGraphId" class="instrument-board-body"></div>
<div v-if="subTitle.show" class="instrument-board-subtitle">{{ subTitleContent }}</div>
<div v-if="showSubTitle"
class="instrument-board-subtitle"
:title="subTitle.title"
>{{ subTitle.content }}
</div>
</div>
</template>
@ -14,58 +33,88 @@ import VueTypes from 'vue-types'
const echarts = require('echarts/lib/echarts')
require('echarts/lib/chart/gauge')
//
const NORMAL_COLOR = {
color: '#28BCFE',
itemColor: ['#25bfff', '#5284de', '#2a95f9']
}
const WARNING_COLOR = {
color: '#e6a23c',
itemColor: ['#e6a23c', '#cc8b1d', '#ffaf18']
}
const DANGER_COLOR = {
color: '#F56C6C',
itemColor: ['#fd666d', '#cf1717', '#b31212']
}
export default {
name: 'InstrumentBoard',
props: {
// id
ringGraphId: VueTypes.string.isRequired,
// key
ringGraphKey: VueTypes.string.isRequired,
//
topTitle: VueTypes.shape({
show: VueTypes.bool,
text: VueTypes.string
}).def({
show: false
}),
showTopTitle: VueTypes.bool.def(false),
//
subTitle: VueTypes.shape({
show: VueTypes.bool,
total: VueTypes.any,
used: VueTypes.any,
unit: VueTypes.string
}).def({
show: false
}),
// 使-
usingRate: VueTypes.number.isRequired,
// 使
usingRateStyle: VueTypes.object.def({
color: '#28BCFE',
fontSize: 18,
itemColor: ['#25BFFF', '#5284DE', '#2A95F9']
}),
showSubTitle: VueTypes.bool.def(false),
// top title
topTitleKeyToNameMapping: VueTypes.object.def({
cpu: 'CPU使用率',
memory: '内存使用率',
disk: '磁盘使用率'
})
memory: '内存使用率'
}),
instrumentBoardData: VueTypes.any.isRequired
},
data() {
return {}
return {
//
currentInstrumentBoardData: {}
}
},
computed: {
subTitleContent() {
let used = this.subTitle.used ? this.subTitle.used + '/' : ''
let total = this.subTitle.total ? this.subTitle.total : ''
let unit = this.subTitle.unit ? ` (${this.subTitle.unit})` : ''
return `${used}${total}${unit} `
//
haveMultipleData() {
return this.instrumentBoardData instanceof Array && this.instrumentBoardData.length > 0
},
// 使
ringRate() {
let ringRate = this.currentInstrumentBoardData.rate
return ringRate < 1 ? ringRate * 100 : ringRate
},
// id
ringGraphId() {
return `${this.ringGraphKey}UsingRate`
},
//
topTitle() {
return this.currentInstrumentBoardData['dir_name'] || this.topTitleKeyToNameMapping[this.ringGraphKey] || this.ringGraphKey
},
//
subTitle() {
let used = this.currentInstrumentBoardData['used'] ? this.currentInstrumentBoardData['used'] + '/' : ''
let total = this.currentInstrumentBoardData['total'] ? this.currentInstrumentBoardData['total'] : ''
let unit = this.currentInstrumentBoardData['unit'] ? ` (${this.currentInstrumentBoardData['unit']})` : ''
let content = `${used}${total}${unit} `
let title = (this.currentInstrumentBoardData['used'] ? '已用/' : '') + '总量(单位)'
return { content, title }
},
// 使
usingRateStyle() {
return {
fontSize: 18,
...this.getCircleColor(this.ringRate)
}
}
},
mounted() {
if (this.haveMultipleData) {
this.currentInstrumentBoardData = this.instrumentBoardData[0]
} else {
this.currentInstrumentBoardData = this.instrumentBoardData
}
this.drawBar()
},
methods: {
drawBar() {
let currentRate = [this.usingRate]
let currentRate = [this.ringRate]
// domecharts
let RingGraph = echarts.init(document.getElementById(this.ringGraphId))
@ -128,8 +177,24 @@ export default {
}
//
RingGraph.setOption(option)
},
// -
getCircleColor(usingRate) {
if (usingRate < 60) {
return NORMAL_COLOR
} else if (usingRate > 60 && usingRate < 80) {
return WARNING_COLOR
} else if (usingRate > 80) {
return DANGER_COLOR
}
return NORMAL_COLOR
},
chooseDisplayInstrumentBoardData(index) {
this.currentInstrumentBoardData = this.instrumentBoardData[index]
this.drawBar()
}
}
}
</script>

View File

@ -59,6 +59,7 @@
</el-button>
</div>
</div>
<div class="server-monitor-top">
<!-- 左侧服务器信息 -->
<el-card class="box-card server-information">
@ -99,15 +100,15 @@
</el-card>
<!-- 右侧仪表盘 -->
<el-card class="box-card information-instrument-panel" v-for="(key, index) of Object.keys(instrumentBoardData)"
<el-card class="box-card information-instrument-panel"
v-for="(key, index) of Object.keys(instrumentBoardData)"
:key="`${index}-${key}`">
<instrument-board
:top-title="{show:true, text: key}"
:ring-graph-id="`${key}UsingRate`"
:using-rate="instrumentBoardData[key].rate"
:show-top-title="true"
:show-sub-title="true"
:ring-graph-key="key"
:instrument-board-data="instrumentBoardData[key]"
:top-title-key-to-name-mapping="INSTRUMENT_BOARD_KEY_TO_NAME_MAPPING"
:sub-title="{show:true, used: instrumentBoardData[key].used, total:instrumentBoardData[key].total, unit: instrumentBoardData[key].unit}"
:using-rate-style="{...getCircleColor(instrumentBoardData[key].rate)}"
></instrument-board>
</el-card>
</div>
@ -190,21 +191,6 @@ const CHART_KEY_NAME_MAPPING = {
const INSTRUMENT_BOARD_KEY_TO_NAME_MAPPING = {
cpu: 'CPU使用率',
memory: '内存使用率',
disk: '磁盘使用率'
}
//
const NORMAL_COLOR = {
color: '#28BCFE',
itemColor: ['#25bfff', '#5284de', '#2a95f9']
}
const WARNING_COLOR = {
color: '#e6a23c',
itemColor: ['#e6a23c', '#cc8b1d', '#ffaf18']
}
const DANGER_COLOR = {
color: '#F56C6C',
itemColor: ['#fd666d', '#cf1717', '#b31212']
}
//
@ -401,16 +387,6 @@ export default {
}
}
},
// -
getCircleColor(usingRate) {
if (usingRate < 60) {
return NORMAL_COLOR
} else if (usingRate > 60 && usingRate < 80) {
return WARNING_COLOR
} else if (usingRate > 80) {
return DANGER_COLOR
}
}
}
}
</script>