2025-09-01 16:58:54 +08:00
|
|
|
<template>
|
|
|
|
|
<div class="utilization">
|
|
|
|
|
<div id="utilization-chart"></div>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
2025-09-04 16:04:37 +08:00
|
|
|
import {processData} from '@/utils/dealWithData'
|
|
|
|
|
|
2025-09-01 16:58:54 +08:00
|
|
|
export default {
|
|
|
|
|
name: '',
|
|
|
|
|
props: {
|
2025-09-03 15:41:12 +08:00
|
|
|
propsInfo: {
|
2025-09-01 16:58:54 +08:00
|
|
|
type: Array,
|
|
|
|
|
default: () => []
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
data() {
|
|
|
|
|
return {
|
|
|
|
|
curList: [
|
|
|
|
|
{
|
|
|
|
|
name: '日设备利用率',
|
2025-09-04 16:04:37 +08:00
|
|
|
key: 'usage_rate',
|
2025-09-01 16:58:54 +08:00
|
|
|
lineColor: '#F69B52',
|
2025-09-04 11:12:20 +08:00
|
|
|
value: 0,
|
|
|
|
|
d: 'kW·h'
|
|
|
|
|
}
|
2025-09-01 16:58:54 +08:00
|
|
|
],
|
2025-09-04 11:12:20 +08:00
|
|
|
|
2025-09-01 16:58:54 +08:00
|
|
|
utilizationChart: null,
|
2025-09-04 11:12:20 +08:00
|
|
|
utilizationChartData: {
|
2025-09-01 16:58:54 +08:00
|
|
|
ydata: [],
|
|
|
|
|
xdata: []
|
2025-09-04 11:12:20 +08:00
|
|
|
}
|
2025-09-01 16:58:54 +08:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
watch: {
|
2025-09-03 15:41:12 +08:00
|
|
|
propsInfo: {
|
2025-09-04 11:12:20 +08:00
|
|
|
handler(newVal, oldVal) {
|
|
|
|
|
if (JSON.stringify(newVal) !== JSON.stringify(oldVal)) {
|
|
|
|
|
this.$nextTick(() => {
|
|
|
|
|
this.drawLineChart()
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
deep: true // 确保深度比较
|
2025-09-01 16:58:54 +08:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
mounted() {},
|
2025-09-04 11:12:20 +08:00
|
|
|
beforeUnmount() {
|
2025-09-01 16:58:54 +08:00
|
|
|
window.removeEventListener('resize', this.handleResize)
|
2025-09-04 11:12:20 +08:00
|
|
|
if (this.utilizationChart) {
|
|
|
|
|
this.utilizationChart.dispose()
|
|
|
|
|
this.utilizationChart = null
|
|
|
|
|
}
|
2025-09-01 16:58:54 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
methods: {
|
|
|
|
|
handleResize() {
|
2025-09-04 11:12:20 +08:00
|
|
|
if (this.utilizationChart) {
|
|
|
|
|
this.utilizationChart.resize()
|
|
|
|
|
}
|
2025-09-01 16:58:54 +08:00
|
|
|
},
|
2025-09-04 11:12:20 +08:00
|
|
|
|
2025-09-01 16:58:54 +08:00
|
|
|
getUtilizationData() {
|
2025-09-04 11:12:20 +08:00
|
|
|
const arr = this.curList
|
|
|
|
|
const keyList = this.curList.map((item) => item.key)
|
2025-09-04 16:04:37 +08:00
|
|
|
const result = processData(this.propsInfo, keyList)
|
2025-09-01 16:58:54 +08:00
|
|
|
|
2025-09-04 11:12:20 +08:00
|
|
|
this.utilizationChartData.xdata = result.dates
|
2025-09-01 16:58:54 +08:00
|
|
|
arr.forEach((item, index) => {
|
2025-09-04 11:12:20 +08:00
|
|
|
this.utilizationChartData.ydata[index] = {
|
2025-09-01 16:58:54 +08:00
|
|
|
name: item.name,
|
|
|
|
|
smooth: false,
|
|
|
|
|
type: 'line',
|
|
|
|
|
barWidth: 10,
|
|
|
|
|
itemStyle: {
|
|
|
|
|
borderRadius: 10,
|
|
|
|
|
color: item.lineColor
|
|
|
|
|
},
|
|
|
|
|
emphasis: {
|
|
|
|
|
focus: 'series'
|
|
|
|
|
},
|
2025-09-04 11:12:20 +08:00
|
|
|
|
2025-09-01 16:58:54 +08:00
|
|
|
global: false,
|
|
|
|
|
showSymbol: false,
|
2025-09-04 11:12:20 +08:00
|
|
|
data: result.values[index]
|
2025-09-01 16:58:54 +08:00
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
drawLineChart(activeKey) {
|
|
|
|
|
this.getUtilizationData(activeKey)
|
2025-09-04 11:12:20 +08:00
|
|
|
if (this.utilizationChart) {
|
|
|
|
|
this.utilizationChart.dispose()
|
|
|
|
|
}
|
2025-09-01 16:58:54 +08:00
|
|
|
const chartDom = document.getElementById('utilization-chart')
|
2025-09-04 11:12:20 +08:00
|
|
|
if (!chartDom) return
|
2025-09-01 16:58:54 +08:00
|
|
|
let utilizationChart = this.$echarts.init(chartDom)
|
|
|
|
|
this.utilizationChart = utilizationChart
|
|
|
|
|
const option = {
|
|
|
|
|
tooltip: {
|
|
|
|
|
trigger: 'axis',
|
|
|
|
|
axisPointer: {
|
|
|
|
|
type: 'shadow'
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
legend: {
|
|
|
|
|
top: 20,
|
|
|
|
|
textStyle: {
|
|
|
|
|
color: '#fff'
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
grid: {
|
|
|
|
|
left: '3%',
|
|
|
|
|
right: '4%',
|
|
|
|
|
bottom: '5%',
|
|
|
|
|
containLabel: true
|
|
|
|
|
},
|
|
|
|
|
xAxis: {
|
|
|
|
|
type: 'category',
|
2025-09-04 11:12:20 +08:00
|
|
|
data: this.utilizationChartData.xdata,
|
2025-09-01 16:58:54 +08:00
|
|
|
axisLine: {
|
|
|
|
|
lineStyle: { type: 'dashed', color: '#435463' }
|
|
|
|
|
},
|
|
|
|
|
axisLabel: {
|
|
|
|
|
color: '#fff'
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
yAxis: {
|
|
|
|
|
type: 'value',
|
|
|
|
|
splitLine: {
|
|
|
|
|
lineStyle: { type: 'dashed', color: '#435463' }
|
|
|
|
|
},
|
|
|
|
|
axisLabel: {
|
|
|
|
|
color: '#fff'
|
|
|
|
|
}
|
|
|
|
|
},
|
2025-09-04 11:12:20 +08:00
|
|
|
series: this.utilizationChartData.ydata
|
2025-09-01 16:58:54 +08:00
|
|
|
}
|
|
|
|
|
option && utilizationChart.setOption(option)
|
2025-09-04 11:12:20 +08:00
|
|
|
this.setupResizeListener()
|
|
|
|
|
},
|
|
|
|
|
setupResizeListener() {
|
|
|
|
|
window.removeEventListener('resize', this.handleResize)
|
2025-09-01 16:58:54 +08:00
|
|
|
window.addEventListener('resize', this.handleResize)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
|
.utilization {
|
2025-09-04 11:12:20 +08:00
|
|
|
height: calc(100% - 45px);
|
2025-09-01 16:58:54 +08:00
|
|
|
|
|
|
|
|
#utilization-chart {
|
2025-09-04 11:12:20 +08:00
|
|
|
height: 100%;
|
2025-09-01 16:58:54 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.text_Cur {
|
|
|
|
|
border-bottom: 1px solid transparent;
|
|
|
|
|
border-top: 1px solid transparent;
|
|
|
|
|
border-image: linear-gradient(to right, transparent, #1d8a7b, transparent) 1;
|
|
|
|
|
padding: 0px 15px;
|
|
|
|
|
font-size: 14px;
|
|
|
|
|
margin: 3px 0px;
|
|
|
|
|
height: 45px;
|
|
|
|
|
display: flex;
|
|
|
|
|
justify-content: space-between;
|
|
|
|
|
align-items: center;
|
2025-09-04 11:12:20 +08:00
|
|
|
& > div:last-child {
|
2025-09-01 16:58:54 +08:00
|
|
|
display: flex;
|
|
|
|
|
flex-direction: column;
|
|
|
|
|
justify-content: center;
|
|
|
|
|
align-items: end;
|
2025-09-04 11:12:20 +08:00
|
|
|
}
|
2025-09-01 16:58:54 +08:00
|
|
|
.mark {
|
|
|
|
|
font-size: 16px;
|
|
|
|
|
margin-right: 2px;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
background: linear-gradient(
|
|
|
|
|
90deg,
|
|
|
|
|
rgba(0, 186, 173, 0.15) 0%,
|
|
|
|
|
rgba(61, 254, 250, 0.15) 49.2%,
|
|
|
|
|
rgba(61, 254, 250, 0) 100%
|
|
|
|
|
);
|
2025-09-04 11:12:20 +08:00
|
|
|
.d {
|
2025-09-01 16:58:54 +08:00
|
|
|
margin-left: 1px;
|
|
|
|
|
font-size: 12px;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</style>
|