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

269 lines
6.5 KiB
Vue
Raw Normal View History

2025-09-01 16:58:54 +08:00
<template>
<div class="charge">
<!-- <div class="text_Cur">
2025-09-03 13:53:00 +08:00
<div v-for="item in curList" :key="item.key">
2025-09-01 16:58:54 +08:00
<div>{{ item.name }}</div>
2025-09-03 13:53:00 +08:00
<span class="mark">{{ item.value ? item.value : 0 }}</span>
<span class="d">{{ item.d }}</span>
2025-09-01 16:58:54 +08:00
</div>
</div> -->
2025-09-01 16:58:54 +08:00
<div id="charge-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 13:53:00 +08:00
total: {
type: Object,
default: () => {}
},
2025-09-01 16:58:54 +08:00
deviceInfo: {
type: Array,
default: () => []
},
myData: {
type: Number,
default: () => -1
2025-09-01 16:58:54 +08:00
}
},
data() {
return {
curList: [
{
2025-09-15 15:47:38 +08:00
name: '充电电量',
2025-09-04 11:12:20 +08:00
key: 'charge_elect',
2025-09-01 16:58:54 +08:00
lineColor: '#00BBA3',
colorStart: ' rgba(10, 250, 106, 0.15)',
colorEnd: ' rgba(171, 255, 249, 0.3)',
2025-09-03 13:53:00 +08:00
value: 0,
d: 'kW·h'
2025-09-01 16:58:54 +08:00
},
{
2025-09-15 15:47:38 +08:00
name: '充电次数',
2025-09-04 11:12:20 +08:00
key: 'charge_num',
2025-09-01 16:58:54 +08:00
lineColor: '#3F80F2',
colorStart: ' rgba(99, 151, 235, 0.3)',
colorEnd: ' rgba(24, 109, 245, 0.3)',
2025-09-03 13:53:00 +08:00
value: 0,
d: ''
2025-09-01 16:58:54 +08:00
}
],
curListEcharts: [
{
2025-09-15 15:47:38 +08:00
name: '充电电量',
2025-09-04 11:12:20 +08:00
key: 'charge_elect',
2025-09-01 16:58:54 +08:00
lineColor: '#00BBA3',
colorStart: ' rgba(10, 250, 106, 0.15)',
colorEnd: ' rgba(171, 255, 249, 0.3)',
2025-09-03 13:53:00 +08:00
value: 0,
d: 'kW·h'
2025-09-01 16:58:54 +08:00
},
{
2025-09-15 15:47:38 +08:00
name: '充电收益',
2025-09-04 11:12:20 +08:00
key: 'income_charge',
2025-09-01 16:58:54 +08:00
lineColor: '#3F80F2',
colorStart: ' rgba(99, 151, 235, 0.3)',
colorEnd: ' rgba(24, 109, 245, 0.3)',
2025-09-03 13:53:00 +08:00
value: 0,
d: ''
2025-09-01 16:58:54 +08:00
}
],
chargeChart: null,
2025-09-04 11:12:20 +08:00
chargeChartData: {
2025-09-01 16:58:54 +08:00
ydata: [],
xdata: []
2025-09-03 13:53:00 +08:00
}
2025-09-01 16:58:54 +08:00
}
},
watch: {
2025-09-03 13:53:00 +08:00
total: {
2025-09-04 11:12:20 +08:00
handler(newVal,oldVal) {
if (newVal!==oldVal) {
this.curList.forEach((item) => {
item.value = this.total[item.key]
2025-09-03 13:53:00 +08:00
})
}
},
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 // 确保深度比较
},
myData: {
handler(newVal,oldVal) {
},
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.chargeChart){
this.chargeChart.dispose()
this.chargeChart = null
}
2025-09-01 16:58:54 +08:00
},
methods: {
handleResize() {
2025-09-04 11:12:20 +08:00
if(this.chargeChart){
this.chargeChart.resize()
}
2025-09-01 16:58:54 +08:00
},
2025-09-04 16:04:37 +08:00
2025-09-01 16:58:54 +08:00
getChargeData() {
2025-09-03 13:53:00 +08:00
const arr = this.curListEcharts
const keyList = this.curListEcharts.map((item) => item.key)
2025-09-04 16:04:37 +08:00
const result = processData(this.deviceInfo, keyList)
2025-09-01 16:58:54 +08:00
2025-09-04 11:12:20 +08:00
this.chargeChartData.xdata = result.dates
2025-09-01 16:58:54 +08:00
arr.forEach((item, index) => {
2025-09-04 11:12:20 +08:00
this.chargeChartData.ydata[index] = {
2025-09-01 16:58:54 +08:00
name: item.name,
// smooth: true,
// type: 'line',
// barWidth: 10,
// itemStyle: {
// borderRadius: 10,
// color: item.lineColor
// },
// emphasis: {
// focus: 'series'
// },
// areaStyle: {
// global: false,
// color: {
// type: 'linear', x: 0, y: 0, x2: 0, y2: 1,
// colorStops: [
// { offset: 0, color: JSON.parse(JSON.stringify(item)).colorStart }, // 顶部颜色
// { offset: 1, color: JSON.parse(JSON.stringify(item)).colorEnd } // 底部颜色
// ]
// }
// },
// global: false,
// showSymbol: false,
// yAxisIndex: index,
// data: result.values[index]
type: 'bar',
data: [18,25,39,17,37,41,62],
color: item.lineColor
2025-09-01 16:58:54 +08:00
}
})
},
drawLineChart(activeKey) {
// const labelCount = Math.floor(500 / 30);
2025-09-01 16:58:54 +08:00
this.getChargeData(activeKey)
2025-09-04 11:12:20 +08:00
if(this.chargeChart){
this.chargeChart.dispose()
}
2025-09-01 16:58:54 +08:00
const chartDom = document.getElementById('charge-chart')
2025-09-04 11:12:20 +08:00
if (!chartDom) return;
2025-09-01 16:58:54 +08:00
let chargeChart = this.$echarts.init(chartDom)
this.chargeChart = chargeChart
const option = {
tooltip: {
trigger: 'axis',
axisPointer: {
type: 'shadow'
}
},
legend: {
top: 10,
2025-09-01 16:58:54 +08:00
textStyle: {
color: '#fff'
}
},
grid: {
left: '3%',
right: '4%',
bottom: '1%',
top: '32%',
// containLabel: true
2025-09-01 16:58:54 +08:00
},
xAxis: {
type: 'category',
2025-09-04 11:12:20 +08:00
data: this.chargeChartData.xdata,
2025-09-01 16:58:54 +08:00
axisLine: {
lineStyle: { type: 'dashed', color: '#435463' }
},
axisLabel: {
color: '#fff'
}
},
2025-10-10 11:01:13 +08:00
yAxis: [
{
name: '充电电量(kWh)',
2025-10-10 11:01:13 +08:00
type: 'value',
splitNumber: 2,
2025-10-10 11:01:13 +08:00
nameTextStyle: {
color: '#fff' // 绿色名称
},
splitLine: {
lineStyle: { type: 'dashed', color: '#435463' }
},
axisLabel: {
// interval: 2,
2025-10-10 11:01:13 +08:00
color: '#fff',
fontSize:12
},
// axisLine : {show: true, color: '#f00'}
2025-09-01 16:58:54 +08:00
},
2025-10-10 11:01:13 +08:00
{
name: '充电收益(元)',
type: 'value',
splitNumber: 2,
2025-10-10 11:01:13 +08:00
splitLine: {
lineStyle: { type: 'dashed', color: '#435463' }
},
nameTextStyle: {
color: '#fff' // 绿色名称
},
axisLabel: {
// interval: 4,
2025-10-10 11:01:13 +08:00
color: '#fff',
fontSize:12
},
// axisLine : {show: true, lineStyle: { color: '#ff0000', width: 2 } }
2025-10-10 11:01:13 +08:00
},
],
2025-09-04 11:12:20 +08:00
series: this.chargeChartData.ydata
// serise: [
// { name: '2011', type: 'bar', data: [18, 23, 29, 10, 13, 63] }
// ]
2025-09-01 16:58:54 +08:00
}
option && chargeChart.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>
.charge {
height: calc(100% - 35px);
background-color: #50505050;
2025-09-01 16:58:54 +08:00
#charge-chart {
height: calc(100% - 5px);
2025-09-01 16:58:54 +08:00
}
}
</style>