fix: 修复网络概况 部分组件问题

This commit is contained in:
@changcode
2022-08-20 14:52:55 +08:00
parent 6ca3c96eb8
commit c4cf810011
6 changed files with 136 additions and 125 deletions

View File

@@ -508,3 +508,27 @@ export function trafficLineTooltipFormatter (params) {
str += '</div>' str += '</div>'
return str return str
} }
export function appStackedLineTooltipFormatter (params) {
let str = '<div>'
params.forEach((item, i) => {
const tData = item.data[0]
if (i === 0) {
str += '<div style="margin-bottom: 5px">'
str += dateFormatByAppearance(tData)
str += '</div>'
}
str += '<div class="cn-chart-tooltip">'
str += '<span class="cn-chart-tooltip-box">'
str += item.marker
str += `<span class="cn-chart-tooltip-content">
${item.seriesName}
</span>`
str += '</span>'
str += `<span class="cn-chart-tooltip-value cn-chart-tooltip__color">
${unitConvert(item.data[1], item.value[2]).join(' ')}
</span>`
str += '</div>'
})
str += '</div>'
return str
}

View File

@@ -107,7 +107,7 @@
<div class="body__searcher"> <div class="body__searcher">
<el-input v-model="searcherApp" @input="searcherAppChange" size="mini" :placeholder="$t('networkOverview.search')" prefix-icon="el-icon-search"></el-input> <el-input v-model="searcherApp" @input="searcherAppChange" size="mini" :placeholder="$t('networkOverview.search')" prefix-icon="el-icon-search"></el-input>
</div> </div>
<div class="body__loading" v-if="loading"><loading :loading="loading"></loading></div> <div class="body__loading"><loading :loading="loading"></loading></div>
</div> </div>
</div> </div>
</el-drawer> </el-drawer>
@@ -127,6 +127,7 @@ import { getSecond } from '@/utils/date-util'
import { getChainRatio } from '@/utils/tools' import { getChainRatio } from '@/utils/tools'
import loading from '@/components/common/Loading' import loading from '@/components/common/Loading'
import ChartNoData from '@/views/charts/charts/ChartNoData' import ChartNoData from '@/views/charts/charts/ChartNoData'
import { appStackedLineTooltipFormatter } from '@/views/charts/charts/tools'
export default { export default {
name: 'NetworkOverviewApps', name: 'NetworkOverviewApps',
props: { props: {
@@ -172,7 +173,6 @@ export default {
appTypeTab: 0, appTypeTab: 0,
appShowName: false, appShowName: false,
searcherApp: '', searcherApp: '',
appShowTypeTab: 0,
// 选中的app不区分app和provider // 选中的app不区分app和provider
toSaveApp: [], toSaveApp: [],
myChartArray: [], myChartArray: [],
@@ -186,13 +186,15 @@ export default {
timerScroll: null, timerScroll: null,
offset: 0, offset: 0,
flag: false, flag: false,
timerSearc: null timerSearc: null,
timerHandle: null
} }
}, },
watch: { watch: {
showAddApp: { showAddApp: {
deep: true, deep: true,
handler (n) { handler (n) {
this.searcherApp = ''
if (n) { if (n) {
window.addEventListener('scroll', this.handleScroll, true) window.addEventListener('scroll', this.handleScroll, true)
} else { } else {
@@ -307,7 +309,7 @@ export default {
const chartOption = _.cloneDeep(appListChartOption) const chartOption = _.cloneDeep(appListChartOption)
chartOption.series = [{ chartOption.series = [{
...chartOption.series[0], ...chartOption.series[0],
data: obj.lineData, data: obj.lineData.map(v => [Number(v[0]) * 1000, Number(v[1]), 'number']),
lineStyle: { lineStyle: {
color: obj.trend === 'up' ? '#7FA054' : '#35ADDA' color: obj.trend === 'up' ? '#7FA054' : '#35ADDA'
}, },
@@ -325,6 +327,13 @@ export default {
]) ])
} }
}] }]
chartOption.tooltip.formatter = (params) => {
params.forEach(t => {
t.seriesName = this.$t(t.seriesName)
})
const str = appStackedLineTooltipFormatter(params)
return str
}
chart.setOption(chartOption) chart.setOption(chartOption)
this.myChart.push(chart) this.myChart.push(chart)
this.$nextTick(() => { this.$nextTick(() => {
@@ -338,18 +347,38 @@ export default {
const scrollHeight = e.target.scrollHeight const scrollHeight = e.target.scrollHeight
if (scrollTop && (clientHeight + scrollTop) >= scrollHeight) { if (scrollTop && (clientHeight + scrollTop) >= scrollHeight) {
if (this.pageObj.pages > this.pageObj.pageNo) { if (this.pageObj.pages > this.pageObj.pageNo) {
this.pageObj.pageNo++
this.loading = true this.loading = true
this.pageObj.pageNo = this.pageObj.pageNo + 1
this.addApp(this.pageObj.pageNo, this.searcherApp, this.loading)
}
}
},
addApp (pageNo, val, show) {
this.showAddApp = true
const letter = 'abcdefghijklmnopqrstuvwxyz'
const params = { const params = {
startTime: getSecond(this.timeFilter.startTime), startTime: getSecond(this.timeFilter.startTime),
endTime: getSecond(this.timeFilter.endTime), endTime: getSecond(this.timeFilter.endTime),
pageSize: this.pageObj.pageSize, pageSize: this.pageObj.pageSize,
pageNo: this.pageObj.pageNo q: ''
} }
if (this.appShowTypeTab == 0) { if (val && show) { // 搜索有值 并且 true
params.q = val
params.pageNo = pageNo
} else if (!val && show) { // 搜索无值 并且 true
val = ''
params.pageNo = pageNo
} else if (val && !show) { // 搜索有值 并且 false
params.q = val
params.pageNo = 1
} else {
params.pageNo = 1
}
if (this.appTypeTab == 0) {
params.type = 'overviewProvide' params.type = 'overviewProvide'
get(api.dict, params).then(res => { get(api.dict, params).then(res => {
if (res.code === 200) { if (res.code === 200) {
this.pageObj.pages = res.data.pages
res.data.list.forEach(t => { res.data.list.forEach(t => {
this.toSaveApp.forEach(e => { this.toSaveApp.forEach(e => {
if (t.value === e.name) { if (t.value === e.name) {
@@ -357,16 +386,20 @@ export default {
} }
}) })
}) })
if (val && !show) {
this.providerOptions = res.data.list
} else {
this.providerOptions.push(...res.data.list) this.providerOptions.push(...res.data.list)
this.pageObj.pages = res.data.pages
this.appListData([], this.providerOptions) this.appListData([], this.providerOptions)
} }
}
this.loading = false this.loading = false
}) })
} else if (this.appShowTypeTab == 1) { } else if (this.appTypeTab == 1) {
params.type = 'overviewApp' params.type = 'overviewApp'
get(api.dict, params).then(res => { get(api.dict, params).then(res => {
if (res.code === 200) { if (res.code === 200) {
this.pageObj.pages = res.data.pages
res.data.list.forEach(t => { res.data.list.forEach(t => {
this.toSaveApp.forEach(e => { this.toSaveApp.forEach(e => {
if (t.value === e.name) { if (t.value === e.name) {
@@ -374,48 +407,16 @@ export default {
} }
}) })
}) })
if (val && !show) {
this.appOptions = res.data.list
} else {
this.appOptions.push(...res.data.list) this.appOptions.push(...res.data.list)
this.pageObj.pages = res.data.pages
this.appListData(this.appOptions, []) this.appListData(this.appOptions, [])
} }
}
this.loading = false this.loading = false
}) })
} }
}
}
},
addApp () {
this.showAddApp = true
this.searcherApp = ''
const letter = 'abcdefghijklmnopqrstuvwxyz'
this.providerOptions = []
this.appOptions = []
this.pageObj.pageNo = 1
const params = {
startTime: getSecond(this.timeFilter.startTime),
endTime: getSecond(this.timeFilter.endTime),
pageSize: this.pageObj.pageSize,
pageNo: this.pageObj.pageNo
}
if (this.appShowTypeTab == 0) {
params.type = 'overviewProvide'
get(api.dict, params).then(res => {
if (res.code === 200) {
this.providerOptions.push(...res.data.list)
this.pageObj.pages = res.data.pages
this.appListData([], this.providerOptions)
}
})
} else if (this.appShowTypeTab == 1) {
params.type = 'overviewApp'
get(api.dict, params).then(res => {
if (res.code === 200) {
this.appOptions.push(...res.data.list)
this.pageObj.pages = res.data.pages
this.appListData(this.appOptions, [])
}
})
}
}, },
appListData (appOptions, providerOptions) { appListData (appOptions, providerOptions) {
const oldApps = this.appData ? this.appData.filter(a => a.type === 'app') : [] const oldApps = this.appData ? this.appData.filter(a => a.type === 'app') : []
@@ -431,63 +432,30 @@ export default {
this.showAddApp = false this.showAddApp = false
}, },
appTypeTabChange (val) { appTypeTabChange (val) {
this.appShowTypeTab = val.index this.pageObj.pageNo = 1
this.searcherApp = '' this.searcherApp = ''
this.addApp(val.index) this.addApp()
window.addEventListener('scroll', this.scrollChange, true) window.addEventListener('scroll', this.scrollChange, true)
this.timerScroll = setTimeout(() => { this.timerScroll = setTimeout(() => {
window.removeEventListener('scroll', this.scrollChange, true) window.removeEventListener('scroll', this.scrollChange, true)
}, 300) }, 500)
}, },
scrollChange (e) { scrollChange (e) {
e.target.scrollTop = 0 e.target.scrollTop = 0
}, },
searcherAppChange (val) { searcherAppChange (val) {
clearTimeout(this.timerSearc) clearTimeout(this.timerSearc)
window.addEventListener('scroll', this.scrollChange, true)
this.timerSearc = setTimeout(() => { this.timerSearc = setTimeout(() => {
if (this.flag) { if (this.flag) {
return false return false
} }
this.flag = true this.flag = true
if (!val) {
this.pageObj.pageNo = 1 this.pageObj.pageNo = 1
} this.searcherApp = val
const params = { this.addApp(this.pageObj.pageNo, val)
startTime: getSecond(this.timeFilter.startTime),
endTime: getSecond(this.timeFilter.endTime),
pageSize: this.pageObj.pageSize,
pageNo: this.pageObj.pageNo
}
if (this.appShowTypeTab == 0) {
params.type = 'overviewProvide'
get(api.dict, params).then(res => {
if (res.code === 200) {
res.data.list.forEach(t => {
this.toSaveApp.forEach(e => {
if (t.value === e.name) {
t.provideShow = e.provideShow
}
})
})
this.providerOptions = res.data.list.filter(t => t.value.indexOf(val) > -1)
}
})
} else if (this.appShowTypeTab == 1) {
params.type = 'overviewApp'
get(api.dict, params).then(res => {
if (res.code === 200) {
res.data.list.forEach(t => {
this.toSaveApp.forEach(e => {
if (t.value === e.name) {
t.appShow = e.appShow
}
})
})
this.appOptions = res.data.list.filter(t => t.value.indexOf(val) > -1)
}
})
}
this.flag = false this.flag = false
window.removeEventListener('scroll', this.scrollChange, true)
}, 500) }, 500)
}, },
// 保存变更并且在增、删app后根据当前app数量更改整体高度 // 保存变更并且在增、删app后根据当前app数量更改整体高度

View File

@@ -295,7 +295,7 @@ export default {
label: { label: {
formatter (params) { formatter (params) {
const arr = unitConvert(params.value, unitTypes.number).join('') const arr = unitConvert(params.value, unitTypes.number).join('')
return _this.echartsLabelValue + '(' + arr + 'packets/s' + ')' return _this.echartsLabelValue + '(' + arr + echartsData[0].unitType + ')'
}, },
position: 'insideStartTop', position: 'insideStartTop',
color: '#717171', color: '#717171',

View File

@@ -64,9 +64,21 @@ export default {
return return
} }
res.data.result = res.data.result.map(t => { res.data.result = res.data.result.map(t => {
if (t.eventSeverity === 'critical') {
t.index = 0
} else if (t.eventSeverity === 'high') {
t.index = 1
} else if (t.eventSeverity === 'medium') {
t.index = 1
} else if (t.eventSeverity === 'low') {
t.index = 3
} else if (t.eventSeverity === 'info') {
t.index = 4
}
return { return {
name: t.eventSeverity, name: t.eventSeverity,
value: t.count value: t.count,
index: t.index
} }
}) })
if (res.data.result.length <= 0) { if (res.data.result.length <= 0) {
@@ -74,7 +86,7 @@ export default {
} else { } else {
this.chartOption.legend.show = true this.chartOption.legend.show = true
} }
this.chartOption.series[0].data = res.data.result this.chartOption.series[0].data = res.data.result.sort((a, b) => { return a.index - b.index })
this.myChart.setOption(this.chartOption) this.myChart.setOption(this.chartOption)
} }
}) })

View File

@@ -4,7 +4,7 @@
<div class="npm-traffic-line-body"> <div class="npm-traffic-line-body">
<chart-no-data v-if="isNoData"></chart-no-data> <chart-no-data v-if="isNoData"></chart-no-data>
<template v-else> <template v-else>
<div class="chart-drawing" id="chart"></div> <div class="chart-drawing" :id="chartData.name"></div>
</template> </template>
</div> </div>
</div> </div>
@@ -21,7 +21,6 @@ import { get } from '@/utils/http'
import { api } from '@/utils/api' import { api } from '@/utils/api'
import { getSecond } from '@/utils/date-util' import { getSecond } from '@/utils/date-util'
import ChartNoData from '@/views/charts/charts/ChartNoData' import ChartNoData from '@/views/charts/charts/ChartNoData'
import { npmTrafficLine } from '@/views/charts2/charts/npmLineData'
import _ from 'lodash' import _ from 'lodash'
export default { export default {
name: 'NpmTrafficLine', name: 'NpmTrafficLine',
@@ -45,8 +44,8 @@ export default {
unitConvert, unitConvert,
unitTypes, unitTypes,
isNoData: false, isNoData: false,
ip: '192.68.44.54', ip: '116.178.236.216',
side: 'client', side: '',
type: 'ip', type: 'ip',
mpackets: [ mpackets: [
{ name: 'network.total', show: true, positioning: 0, data: [], unitType: '' }, { name: 'network.total', show: true, positioning: 0, data: [], unitType: '' },
@@ -55,18 +54,25 @@ export default {
{ name: 'network.internal', show: true, positioning: 3, data: [], unitType: '' }, { name: 'network.internal', show: true, positioning: 3, data: [], unitType: '' },
{ name: 'network.through', show: true, positioning: 4, data: [], unitType: '' }, { name: 'network.through', show: true, positioning: 4, data: [], unitType: '' },
{ name: 'network.other', show: true, positioning: 5, data: [], unitType: '' } { name: 'network.other', show: true, positioning: 5, data: [], unitType: '' }
] ],
chartData: {}
} }
}, },
methods: { methods: {
init () { init () {
const condition = this.$store.getters.getQueryCondition
console.log(condition)
if (this.chartData.id === 24) {
this.side = 'client'
} else {
this.side = 'server'
}
const params = { const params = {
startTime: getSecond(this.timeFilter.startTime), startTime: getSecond(this.timeFilter.startTime),
endTime: getSecond(this.timeFilter.endTime), endTime: getSecond(this.timeFilter.endTime),
q: `ip='${this.ip}' and side='${this.side}'`, q: `ip='${this.ip}' and side='${this.side}'`,
type: 'ip' type: 'ip'
} }
// const condition = this.$store.getters.getQueryCondition
// if (condition) { // if (condition) {
// params.q = condition // params.q = condition
// params.type = this.type // params.type = this.type
@@ -74,21 +80,22 @@ export default {
get(api.npm.overview.trafficGraph, params).then((res) => { get(api.npm.overview.trafficGraph, params).then((res) => {
if (res.code === 200) { if (res.code === 200) {
// res.data.result.length = 0 // res.data.result.length = 0
res.data.result = npmTrafficLine
if (res.data.result.length === 0) { if (res.data.result.length === 0) {
this.isNoData = true this.isNoData = true
return return
} }
res.data.result.forEach((t, i) => { res.data.result.forEach((t, i) => {
if (t.type === 'bytes') {
const mpackets = _.cloneDeep(this.mpackets) const mpackets = _.cloneDeep(this.mpackets)
mpackets[0].data = t.totalBitsRate.values ? t.totalBitsRate.values : [] mpackets[0].data = t.totalBitsRate.values ? t.totalBitsRate.values : []
mpackets[1].data = t.inboundBitsRate.values ? t.inboundBitsRate.values : [] mpackets[1].data = t.inboundBitsRate.values ? t.inboundBitsRate.values : []
mpackets[2].data = t.outboundBitsRate.values ? t.outboundBitsRate.values : [] mpackets[2].data = t.outboundBitsRate.values ? t.outboundBitsRate.values : []
mpackets[3].data = t.internalBitsRate.values ? t.internalBitsRate.values : [] mpackets[3].data = t.internalBitsRate.values ? t.internalBitsRate.values : []
mpackets[4].data = t.externalBitsRate.values ? t.externalBitsRate.values : [] mpackets[4].data = t.throughBitsRate.values ? t.throughBitsRate.values : []
mpackets[5].data = t.other.values ? t.other.values : [] mpackets[5].data = t.other.values ? t.other.values : []
this.mpackets = mpackets this.mpackets = mpackets
this.echartsInit(this.mpackets) this.echartsInit(this.mpackets)
}
// else if (t.type === 'packets') { // else if (t.type === 'packets') {
// const mpackets = _.cloneDeep(this.mpackets) // const mpackets = _.cloneDeep(this.mpackets)
// mpackets[0].data = t.totalPacketsRate.values ? t.totalPacketsRate.values : [] // mpackets[0].data = t.totalPacketsRate.values ? t.totalPacketsRate.values : []
@@ -106,11 +113,13 @@ export default {
// this.echartsInit(this.mpackets) // this.echartsInit(this.mpackets)
// } // }
}) })
} else {
this.isNoData = true
} }
}) })
}, },
echartsInit (echartsData) { echartsInit (echartsData) {
const dom = document.getElementById('chart') const dom = document.getElementById(this.chartData.name)
this.myChart = echarts.init(dom) this.myChart = echarts.init(dom)
this.chartOption = trafficLineChartOption this.chartOption = trafficLineChartOption
const chartOption = this.chartOption.series[0] const chartOption = this.chartOption.series[0]
@@ -198,6 +207,9 @@ export default {
} }
}, },
mounted () { mounted () {
if (this.chart) {
this.chartData = _.cloneDeep(this.chart)
}
this.timer = setTimeout(() => { this.timer = setTimeout(() => {
this.init() this.init()
}, 200) }, 200)

View File

@@ -227,12 +227,7 @@ export const appListChartOption = {
}, },
yAxis: { yAxis: {
show: false, show: false,
type: 'value', type: 'value'
axisLabel: {
formatter: function (value) {
return unitConvert(value, unitTypes.number, null, null, 0).join(' ')
}
}
}, },
grid: { grid: {
left: 0, left: 0,