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

258 lines
5.8 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>
<div id="charge-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-03 13:53:00 +08:00
key: 'chargeElect',
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
},
{
name: '日充电次数',
2025-09-03 13:53:00 +08:00
key: 'chargeNum',
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: [
{
name: '日充电电量',
2025-09-03 13:53:00 +08:00
key: 'chargeElect',
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
},
{
name: '日充电收益',
2025-09-03 13:53:00 +08:00
key: 'incomeCharge',
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,
lineChartData: {
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: {
handler(n) {
if (n) {
let that = this
that.curList.forEach((item) => {
item.value = that.total[item.key]
})
}
},
deep: true, // 深度监听
immediate: true
},
2025-09-01 16:58:54 +08:00
deviceInfo: {
handler(n) {
this.$nextTick(() => {
this.drawLineChart()
})
}
// immediate: true
}
},
mounted() {},
onBeforeUnmount() {
this.chargeChart = null
window.removeEventListener('resize', this.handleResize)
},
methods: {
handleResize() {
this.chargeChart.resize()
},
processData(data, keys) {
data.sort((a, b) => {
return new Date(a.date) - new Date(b.date)
})
const dates = data.map((item) => item.date)
2025-09-03 13:53:00 +08:00
const values = []
keys.forEach((item, index) => {
values[index] = data.map((dataValue) => dataValue[keys[index]])
2025-09-01 16:58:54 +08:00
})
2025-09-03 13:53:00 +08:00
2025-09-01 16:58:54 +08:00
return {
dates,
2025-09-03 13:53:00 +08:00
values
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-01 16:58:54 +08:00
const result = this.processData(this.deviceInfo, keyList)
this.lineChartData.xdata = result.dates
arr.forEach((item, index) => {
this.lineChartData.ydata[index] = {
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 }, // 顶部颜色
2025-09-03 13:53:00 +08:00
{ offset: 1, color: JSON.parse(JSON.stringify(item)).colorEnd } // 底部颜色
2025-09-01 16:58:54 +08:00
]
}
},
global: false,
showSymbol: false,
2025-09-03 13:53:00 +08:00
data: result.values[index]
2025-09-01 16:58:54 +08:00
}
})
},
drawLineChart(activeKey) {
this.getChargeData(activeKey)
const chartDom = document.getElementById('charge-chart')
let chargeChart = this.$echarts.init(chartDom)
this.chargeChart = chargeChart
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.lineChartData.xdata,
axisLine: {
lineStyle: { type: 'dashed', color: '#435463' }
},
axisLabel: {
color: '#fff'
}
},
yAxis: {
type: 'value',
splitLine: {
lineStyle: { type: 'dashed', color: '#435463' }
},
axisLabel: {
color: '#fff'
}
},
series: this.lineChartData.ydata
}
option && chargeChart.setOption(option)
window.addEventListener('resize', this.handleResize)
}
}
}
</script>
<style lang="scss" scoped>
.charge {
height: calc(100% - 45px);
#charge-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;
2025-09-03 13:53:00 +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-03 13:53:00 +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-03 13:53:00 +08:00
.d {
2025-09-01 16:58:54 +08:00
margin-left: 1px;
font-size: 12px;
}
}
</style>