Files
energy_storage/web/src/components/Home/Pv.vue

241 lines
5.1 KiB
Vue
Raw Normal View History

2025-09-01 16:58:54 +08:00
<template>
<div class="pv">
<div class="text_Cur">
<div v-for="item in curList" :key="item.key">
<div>{{ item.name }}</div>
<div>
<span class="mark">{{ item.value ? item.value : 0 }}</span>
<span class="d">{{ item.d }}</span>
</div>
</div>
</div>
<div id="pv-chart"></div>
</div>
</template>
<script>
export default {
name: '',
props: {
2025-09-03 13:53:00 +08:00
total: {
type: Object,
default: () => {}
},
2025-09-01 16:58:54 +08:00
deviceInfo: {
type: Array,
default: () => []
}
},
data() {
return {
curList: [
{
name: '日发电量',
2025-09-04 11:12:20 +08:00
key: 'solar_elect_gen',
2025-09-01 16:58:54 +08:00
lineColor: '#22E4FF',
value: 0,
d: 'kW·h'
},
{
name: '日入网电量',
2025-09-04 11:12:20 +08:00
key: 'solar_elect_grid',
2025-09-01 16:58:54 +08:00
lineColor: '#0E68E4',
value: 0,
d: 'kW·h'
}
],
2025-09-04 11:12:20 +08:00
pvChart: null,
pvChartData: {
2025-09-01 16:58:54 +08:00
ydata: [],
xdata: []
},
count: {
charge: {
cur: [1, 2]
}
}
}
},
watch: {
2025-09-03 13:53:00 +08:00
total: {
2025-09-04 11:12:20 +08:00
handler(newVal, oldVal) {
if (newVal !== oldVal) {
2025-09-03 13:53:00 +08:00
let that = this
that.curList.forEach((item) => {
item.value = that.total[item.key]
})
}
2025-09-04 11:12:20 +08:00
}
2025-09-03 13:53:00 +08:00
},
2025-09-01 16:58:54 +08:00
deviceInfo: {
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.pvChart) {
this.pvChart.dispose()
this.pvChart = null
}
2025-09-01 16:58:54 +08:00
},
methods: {
handleResize() {
2025-09-04 11:12:20 +08:00
if (this.pvChart) {
this.pvChart.resize()
}
2025-09-01 16:58:54 +08:00
},
processData(data, keys) {
data.sort((a, b) => {
2025-09-04 11:12:20 +08:00
return new Date(a.dt) - new Date(b.dt)
2025-09-01 16:58:54 +08:00
})
2025-09-04 11:12:20 +08:00
const dates = data.map((item) => item.dt)
2025-09-01 16:58:54 +08:00
const values = []
keys.forEach((item, index) => {
values[index] = data.map((dataValue) => dataValue[keys[index]])
})
return {
dates,
values
}
},
getChargeData() {
const arr = this.curList
const keyList = this.curList.map((item) => item.key)
const result = this.processData(this.deviceInfo, keyList)
2025-09-04 11:12:20 +08:00
this.pvChartData.xdata = result.dates
2025-09-01 16:58:54 +08:00
arr.forEach((item, index) => {
2025-09-04 11:12:20 +08:00
this.pvChartData.ydata[index] = {
2025-09-01 16:58:54 +08:00
name: item.name,
smooth: true,
type: 'bar',
barWidth: 5,
itemStyle: {
borderRadius: [5, 5, 0, 0],
color: item.lineColor
},
emphasis: {
focus: 'series'
},
global: false,
showSymbol: false,
data: result.values[index]
}
})
},
drawLineChart(activeKey) {
this.getChargeData(activeKey)
2025-09-04 11:12:20 +08:00
if (this.pvChart) {
this.pvChart.dispose()
}
2025-09-01 16:58:54 +08:00
const chartDom = document.getElementById('pv-chart')
2025-09-04 11:12:20 +08:00
if (!chartDom) return
let pvChart = this.$echarts.init(chartDom)
this.pvChart = pvChart
2025-09-01 16:58:54 +08:00
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.pvChartData.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: {
2025-09-04 11:12:20 +08:00
interval: 4,
2025-09-01 16:58:54 +08:00
color: '#fff'
}
},
2025-09-04 11:12:20 +08:00
series: this.pvChartData.ydata
2025-09-01 16:58:54 +08:00
}
2025-09-04 11:12:20 +08:00
option && pvChart.setOption(option)
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>
.pv {
height: calc(100% - 45px);
#pv-chart {
height: calc(100% - 45px);
}
}
.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>