mirror of
https://gitee.com/js-yhsec/energy_storage.git
synced 2026-05-28 03:09:24 +08:00
230 lines
4.9 KiB
Vue
230 lines
4.9 KiB
Vue
<template>
|
|
<div class="energy">
|
|
<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="energy-chart"></div>
|
|
</div>
|
|
</template>
|
|
|
|
<script>
|
|
import {processData} from '@/utils/dealWithData'
|
|
|
|
export default {
|
|
name: '',
|
|
props: {
|
|
total: {
|
|
type: Object,
|
|
default: () => {}
|
|
},
|
|
deviceInfo: {
|
|
type: Array,
|
|
default: () => []
|
|
}
|
|
},
|
|
data() {
|
|
return {
|
|
uid:'1',
|
|
curList: [
|
|
{
|
|
name: '日充电电量',
|
|
key: 'storage_elect_in',
|
|
lineColor: '#22E4FF',
|
|
value: 0,
|
|
d: 'kW·h'
|
|
},
|
|
{
|
|
name: '日放电电量',
|
|
key: 'storage_elect_out',
|
|
lineColor: '#0E68E4',
|
|
value: 0,
|
|
d: 'kW·h'
|
|
}
|
|
],
|
|
energyChart: null,
|
|
energyChartData: {
|
|
ydata: [],
|
|
xdata: []
|
|
}
|
|
}
|
|
},
|
|
watch: {
|
|
total: {
|
|
handler(newVal,oldVal) {
|
|
if (newVal!==oldVal) {
|
|
let that = this
|
|
that.curList.forEach((item) => {
|
|
item.value = that.total[item.key]
|
|
})
|
|
}
|
|
},
|
|
|
|
},
|
|
deviceInfo: {
|
|
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.energyChart){
|
|
this.energyChart.dispose()
|
|
this.energyChart = null
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
handleResize() {
|
|
if(this.energyChart){
|
|
this.energyChart.resize()
|
|
}
|
|
},
|
|
|
|
getChargeData() {
|
|
const arr = this.curList
|
|
const keyList = this.curList.map((item) => item.key)
|
|
const result = processData(this.deviceInfo, keyList)
|
|
|
|
this.energyChartData.xdata = result.dates
|
|
arr.forEach((item, index) => {
|
|
this.energyChartData.ydata[index] = {
|
|
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)
|
|
if(this.energyChart){
|
|
this.energyChart.dispose()
|
|
}
|
|
const chartDom = document.getElementById('energy-chart')
|
|
if (!chartDom) return;
|
|
let energyChart = this.$echarts.init(chartDom)
|
|
this.energyChart = energyChart
|
|
const option = {
|
|
tooltip: {
|
|
trigger: 'axis',
|
|
axisPointer: {
|
|
type: 'shadow'
|
|
}
|
|
},
|
|
legend: {
|
|
top: 20,
|
|
textStyle: {
|
|
color: '#fff'
|
|
}
|
|
},
|
|
grid: {
|
|
left: '3%',
|
|
right: '4%',
|
|
bottom: '3%',
|
|
containLabel: true
|
|
},
|
|
xAxis: {
|
|
type: 'category',
|
|
data: this.energyChartData.xdata,
|
|
axisLine: {
|
|
lineStyle: { type: 'dashed', color: '#435463' }
|
|
},
|
|
axisLabel: {
|
|
color: '#fff'
|
|
}
|
|
},
|
|
yAxis: {
|
|
type: 'value',
|
|
splitLine: {
|
|
lineStyle: { type: 'dashed', color: '#435463' }
|
|
},
|
|
axisLabel: {
|
|
interval: 4,
|
|
color: '#fff',
|
|
fontSize:12
|
|
|
|
}
|
|
},
|
|
series: this.energyChartData.ydata
|
|
}
|
|
option && energyChart.setOption(option)
|
|
this.setupResizeListener()
|
|
},
|
|
setupResizeListener(){
|
|
window.removeEventListener('resize', this.handleResize);
|
|
window.addEventListener('resize', this.handleResize)
|
|
}
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<style lang="scss" scoped>
|
|
.energy {
|
|
height: calc(100% - 45px);
|
|
|
|
#energy-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>
|