Files
energy_storage/web/src/components/Home/Modal/Utilization.vue
2025-09-04 16:04:37 +08:00

195 lines
4.2 KiB
Vue

<template>
<div class="utilization">
<div id="utilization-chart"></div>
</div>
</template>
<script>
import {processData} from '@/utils/dealWithData'
export default {
name: '',
props: {
propsInfo: {
type: Array,
default: () => []
}
},
data() {
return {
curList: [
{
name: '日设备利用率',
key: 'usage_rate',
lineColor: '#F69B52',
value: 0,
d: 'kW·h'
}
],
utilizationChart: null,
utilizationChartData: {
ydata: [],
xdata: []
}
}
},
watch: {
propsInfo: {
handler(newVal, oldVal) {
if (JSON.stringify(newVal) !== JSON.stringify(oldVal)) {
this.$nextTick(() => {
this.drawLineChart()
})
}
},
deep: true // 确保深度比较
}
},
mounted() {},
beforeUnmount() {
window.removeEventListener('resize', this.handleResize)
if (this.utilizationChart) {
this.utilizationChart.dispose()
this.utilizationChart = null
}
},
methods: {
handleResize() {
if (this.utilizationChart) {
this.utilizationChart.resize()
}
},
getUtilizationData() {
const arr = this.curList
const keyList = this.curList.map((item) => item.key)
const result = processData(this.propsInfo, keyList)
this.utilizationChartData.xdata = result.dates
arr.forEach((item, index) => {
this.utilizationChartData.ydata[index] = {
name: item.name,
smooth: false,
type: 'line',
barWidth: 10,
itemStyle: {
borderRadius: 10,
color: item.lineColor
},
emphasis: {
focus: 'series'
},
global: false,
showSymbol: false,
data: result.values[index]
}
})
},
drawLineChart(activeKey) {
this.getUtilizationData(activeKey)
if (this.utilizationChart) {
this.utilizationChart.dispose()
}
const chartDom = document.getElementById('utilization-chart')
if (!chartDom) return
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',
data: this.utilizationChartData.xdata,
axisLine: {
lineStyle: { type: 'dashed', color: '#435463' }
},
axisLabel: {
color: '#fff'
}
},
yAxis: {
type: 'value',
splitLine: {
lineStyle: { type: 'dashed', color: '#435463' }
},
axisLabel: {
color: '#fff'
}
},
series: this.utilizationChartData.ydata
}
option && utilizationChart.setOption(option)
this.setupResizeListener()
},
setupResizeListener() {
window.removeEventListener('resize', this.handleResize)
window.addEventListener('resize', this.handleResize)
}
}
}
</script>
<style lang="scss" scoped>
.utilization {
height: calc(100% - 45px);
#utilization-chart {
height: 100%;
}
}
.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;
& > div:last-child {
display: flex;
flex-direction: column;
justify-content: center;
align-items: end;
}
.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%
);
.d {
margin-left: 1px;
font-size: 12px;
}
}
</style>