2022-07-26 22:07:53 +08:00
|
|
|
<template>
|
2022-07-29 15:15:36 +08:00
|
|
|
<div class="npm-line">
|
2022-08-12 19:12:44 +08:00
|
|
|
<template v-if="chartData.id === 11">
|
|
|
|
|
<div class="npm-line-header">
|
|
|
|
|
<div class="npm-line-header-title">{{chartData.name}}</div>
|
|
|
|
|
<div class="npm-line-header-rights" v-if="chartData.params && chartData.params.showLegend">
|
|
|
|
|
<div class="npm-line-header-right" :class="{'active': item.show}" v-for="(item, index) in chartOptionLineData" :key="index" @click="highlightEvent(item)">
|
|
|
|
|
<div class="npm-line-header-icon" :class="'icon' + index"></div>
|
|
|
|
|
<div class="npm-line-header-value">{{$t(item.legend)}}</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2022-07-29 15:15:36 +08:00
|
|
|
</div>
|
2022-08-12 19:12:44 +08:00
|
|
|
<div class="chart-drawing" :id="`chart${chartData.name}`"></div>
|
|
|
|
|
</template>
|
|
|
|
|
<template v-if="chartData.id === 12">
|
|
|
|
|
<div class="npm-line-title">{{chartData.name}}</div>
|
|
|
|
|
<div class="chart-drawing" :id="`chart${chartData.name}`"></div>
|
|
|
|
|
</template>
|
|
|
|
|
<template v-if="chartData.id === 13">
|
|
|
|
|
<div class="npm-line-title">{{chartData.name}}</div>
|
|
|
|
|
<div class="chart-drawing" :id="`chart${chartData.name}`"></div>
|
|
|
|
|
</template>
|
|
|
|
|
<template v-if="chartData.id === 14">
|
|
|
|
|
<div class="npm-line-title">{{chartData.name}}</div>
|
|
|
|
|
<div class="chart-drawing" :id="`chart${chartData.name}`"></div>
|
|
|
|
|
</template>
|
|
|
|
|
<template v-if="chartData.id === 15">
|
|
|
|
|
<div class="npm-line-title">{{chartData.name}}</div>
|
|
|
|
|
<div class="chart-drawing" :id="`chart${chartData.name}`"></div>
|
|
|
|
|
</template>
|
|
|
|
|
<template v-if="chartData.id === 16">
|
|
|
|
|
<div class="npm-line-title">{{chartData.name}}</div>
|
|
|
|
|
<div class="chart-drawing" :id="`chart${chartData.name}`"></div>
|
|
|
|
|
</template>
|
2022-07-29 15:15:36 +08:00
|
|
|
</div>
|
2022-07-26 22:07:53 +08:00
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
2022-07-29 15:15:36 +08:00
|
|
|
import * as echarts from 'echarts'
|
|
|
|
|
import { npmLineChartOption } from '@/views/charts2/charts/options/echartOption.js'
|
|
|
|
|
import { shallowRef } from 'vue'
|
|
|
|
|
import _ from 'lodash'
|
|
|
|
|
import { stackedLineTooltipFormatter } from '@/views/charts/charts/tools'
|
2022-08-12 19:12:44 +08:00
|
|
|
import { getSecond } from '@/utils/date-util'
|
|
|
|
|
import { get } from '@/utils/http'
|
|
|
|
|
import { api } from '@/utils/api'
|
2022-07-29 15:15:36 +08:00
|
|
|
|
2022-07-26 22:07:53 +08:00
|
|
|
export default {
|
2022-07-29 15:15:36 +08:00
|
|
|
name: 'NpmLine',
|
|
|
|
|
props: {
|
2022-08-12 19:12:44 +08:00
|
|
|
chart: Object,
|
|
|
|
|
timeFilter: Object,
|
|
|
|
|
// side: String,
|
|
|
|
|
// country: String,
|
|
|
|
|
// province: String
|
2022-07-29 15:15:36 +08:00
|
|
|
},
|
|
|
|
|
setup () {
|
|
|
|
|
return {
|
|
|
|
|
myChart: shallowRef()
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
data () {
|
|
|
|
|
return {
|
|
|
|
|
chartData: {},
|
|
|
|
|
chartOptionLineData: [
|
2022-08-09 16:57:16 +08:00
|
|
|
{ legend: 'network.total', index: 0, invertTab: true },
|
|
|
|
|
{ legend: 'network.inbound', index: 1, invertTab: true },
|
|
|
|
|
{ legend: 'network.outbound', index: 2, invertTab: true }
|
2022-07-29 15:15:36 +08:00
|
|
|
],
|
|
|
|
|
timer: null,
|
2022-08-12 19:12:44 +08:00
|
|
|
myChartArray: [],
|
|
|
|
|
side: 'server',
|
|
|
|
|
country: '北京',
|
|
|
|
|
province: '北京'
|
2022-07-29 15:15:36 +08:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
methods: {
|
|
|
|
|
init () {
|
2022-08-12 19:12:44 +08:00
|
|
|
const params = {
|
|
|
|
|
startTime: getSecond(this.timeFilter.startTime),
|
|
|
|
|
endTime: getSecond(this.timeFilter.endTime),
|
|
|
|
|
side: this.side,
|
|
|
|
|
country: this.country,
|
|
|
|
|
province: this.province
|
|
|
|
|
}
|
|
|
|
|
console.log(this.chartData)
|
|
|
|
|
if (this.chartData.id === 11) {
|
|
|
|
|
get(api.npm.location.thoughput, params).then(res => {
|
|
|
|
|
if (res.code === 200) {
|
|
|
|
|
console.log(res)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
this.echartsInit()
|
|
|
|
|
},
|
|
|
|
|
echartsInit () {
|
2022-07-29 15:15:36 +08:00
|
|
|
const dom = document.getElementById(`chart${this.chartData.name}`)
|
|
|
|
|
this.myChart = echarts.init(dom)
|
|
|
|
|
this.chartOption = npmLineChartOption
|
|
|
|
|
const seriesTemplate = this.chartOption.series[0]
|
|
|
|
|
this.chartOption.color = this.chartData.params.color
|
|
|
|
|
let result = [
|
|
|
|
|
{
|
2022-08-12 19:12:44 +08:00
|
|
|
type: 'inboundBytesRate',
|
|
|
|
|
values: [[1435781430781, '3'], [1435781431781, '4']]
|
2022-07-29 15:15:36 +08:00
|
|
|
},
|
|
|
|
|
{
|
2022-08-12 19:12:44 +08:00
|
|
|
type: 'totalBytesRate',
|
|
|
|
|
values: [[1435781430781, '5'], [1435781431781, '6']]
|
2022-07-29 15:15:36 +08:00
|
|
|
},
|
|
|
|
|
{
|
2022-08-12 19:12:44 +08:00
|
|
|
type: 'outboundBytesRate',
|
|
|
|
|
values: [[1435781430781, '2'], [1435781431781, '9']]
|
2022-07-29 15:15:36 +08:00
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
result = result.filter(item => this.chartData.params.color.indexOf(item.color) > -1)
|
|
|
|
|
this.chartOption.series = result.map((t, i) => {
|
|
|
|
|
return {
|
|
|
|
|
...seriesTemplate,
|
|
|
|
|
name: t.legend,
|
|
|
|
|
stack: this.chartData.params.isStack ? 'network.total' : '',
|
|
|
|
|
lineStyle: {
|
|
|
|
|
width: 1
|
|
|
|
|
},
|
|
|
|
|
areaStyle: {
|
|
|
|
|
opacity: 0.1
|
|
|
|
|
},
|
|
|
|
|
data: t.values.map((v) => [Number(v[0]) * 1000, Number(v[1]), this.chartData.params.unitType])
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
this.chartOption.tooltip.formatter = (params) => {
|
|
|
|
|
params.forEach(t => {
|
|
|
|
|
t.seriesName = this.$t(t.seriesName)
|
|
|
|
|
})
|
|
|
|
|
const str = stackedLineTooltipFormatter(params)
|
|
|
|
|
return str
|
|
|
|
|
}
|
|
|
|
|
this.myChartArray.push(this.myChart)
|
|
|
|
|
this.myChart.setOption(this.chartOption)
|
|
|
|
|
},
|
|
|
|
|
dispatchLegendSelectAction (name) {
|
|
|
|
|
this.myChart.dispatchAction({
|
|
|
|
|
type: 'legendSelect',
|
|
|
|
|
name: name
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
dispatchLegendUnSelectAction (name) {
|
|
|
|
|
this.myChart.dispatchAction({
|
|
|
|
|
type: 'legendUnSelect',
|
|
|
|
|
name: name
|
|
|
|
|
})
|
|
|
|
|
},
|
2022-08-09 16:57:16 +08:00
|
|
|
highlightEvent (item) {
|
|
|
|
|
this.chartOptionLineData.forEach(t => {
|
|
|
|
|
if (t.legend === item.legend) {
|
|
|
|
|
t.invertTab = !t.invertTab
|
|
|
|
|
} else {
|
|
|
|
|
t.show = t.invertTab
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
const legend = this.chartOptionLineData.filter(t => t.invertTab)
|
|
|
|
|
const legends = this.chartOptionLineData.filter(t => !t.invertTab)
|
|
|
|
|
this.chartOptionLineData.forEach(t => {
|
|
|
|
|
if ((t.legend === item.legend) && t.invertTab) {
|
|
|
|
|
legend.forEach(r => {
|
|
|
|
|
r.show = false
|
|
|
|
|
})
|
|
|
|
|
} else if ((t.legend !== item.legend) && !t.invertTab) {
|
|
|
|
|
legends.forEach(r => {
|
|
|
|
|
if (r.legend === item.legend) {
|
|
|
|
|
r.show = false
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
if (legend.length === 0) {
|
|
|
|
|
this.chartOptionLineData.forEach((t, i) => {
|
|
|
|
|
t.invertTab = true
|
2022-07-29 15:15:36 +08:00
|
|
|
})
|
2022-08-09 16:57:16 +08:00
|
|
|
}
|
|
|
|
|
this.legendSelectChange(legends, legend)
|
|
|
|
|
},
|
|
|
|
|
legendSelectChange (legends, legend) {
|
|
|
|
|
if (legends.length > 0) {
|
|
|
|
|
this.chartOptionLineData.forEach(t => {
|
|
|
|
|
legends.forEach(r => {
|
|
|
|
|
if (t.legend !== r.legend) {
|
2022-07-29 15:15:36 +08:00
|
|
|
this.dispatchLegendUnSelectAction(t.legend)
|
|
|
|
|
}
|
2022-08-09 16:57:16 +08:00
|
|
|
if (!t.show) {
|
|
|
|
|
this.dispatchLegendSelectAction(t.legend)
|
|
|
|
|
}
|
2022-07-29 15:15:36 +08:00
|
|
|
})
|
2022-08-09 16:57:16 +08:00
|
|
|
})
|
|
|
|
|
} else if (legend.length > 0) {
|
|
|
|
|
this.chartOptionLineData.forEach(t => {
|
|
|
|
|
legend.forEach(r => {
|
|
|
|
|
if (t.legend !== r.legend) {
|
|
|
|
|
this.dispatchLegendSelectAction(t.legend)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
})
|
2022-07-29 15:15:36 +08:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
resize () {
|
|
|
|
|
this.myChartArray.forEach(t => {
|
|
|
|
|
t.resize()
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
mounted () {
|
|
|
|
|
if (this.chart) {
|
|
|
|
|
this.chartData = _.cloneDeep(this.chart)
|
|
|
|
|
}
|
|
|
|
|
this.timer = setTimeout(() => {
|
|
|
|
|
this.init()
|
|
|
|
|
}, 100)
|
|
|
|
|
window.addEventListener('resize', this.resize)
|
|
|
|
|
},
|
|
|
|
|
beforeUnmount () {
|
|
|
|
|
clearTimeout(this.timer)
|
|
|
|
|
}
|
2022-07-26 22:07:53 +08:00
|
|
|
}
|
|
|
|
|
</script>
|