Files
energy_storage/web/src/components/Home/Modal/Revenue.vue

229 lines
4.9 KiB
Vue
Raw Normal View History

2025-09-01 16:58:54 +08:00
<template>
<div class="revenue">
<div id="revenue-chart"></div>
</div>
</template>
<script>
export default {
name: '',
props: {
2025-09-03 15:41:12 +08:00
propsInfo: {
2025-09-01 16:58:54 +08:00
type: Array,
default: () => []
}
},
data() {
return {
curList: [
{
name: '日收益',
key: 'key1',
lineColor: '#00BBA3',
colorStart: ' rgba(10, 250, 106, 0.15)',
colorEnd: ' rgba(171, 255, 249, 0.3)',
value:0,
d:'kW·h'
},
],
revenueChart: null,
2025-09-04 11:12:20 +08:00
RevenueChartData: {
2025-09-01 16:58:54 +08:00
ydata: [],
xdata: []
},
}
},
watch: {
2025-09-03 15:41:12 +08:00
propsInfo: {
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.revenueChart) {
this.revenueChart.dispose()
this.revenueChart = null
}
2025-09-01 16:58:54 +08:00
},
methods: {
handleResize() {
2025-09-04 11:12:20 +08:00
if (this.revenueChart) {
this.revenueChart.resize()
}
2025-09-01 16:58:54 +08:00
},
processData(data, keys) {
data.sort((a, b) => {
return new Date(a.date) - new Date(b.date)
})
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,
}
},
getRevenueData() {
const arr=this.curList
const keyList=this.curList.map((item)=>item.key)
2025-09-03 15:41:12 +08:00
const result = this.processData(this.propsInfo, keyList)
2025-09-01 16:58:54 +08:00
2025-09-04 11:12:20 +08:00
this.RevenueChartData.xdata = result.dates
2025-09-01 16:58:54 +08:00
arr.forEach((item, index) => {
2025-09-04 11:12:20 +08:00
this.RevenueChartData.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,
data:result.values[index]
}
})
},
drawLineChart(activeKey) {
this.getRevenueData(activeKey)
2025-09-04 11:12:20 +08:00
if (this.revenueChart) {
this.revenueChart.dispose()
}
2025-09-01 16:58:54 +08:00
const chartDom = document.getElementById('revenue-chart')
2025-09-04 11:12:20 +08:00
if (!chartDom) return
2025-09-01 16:58:54 +08:00
let revenueChart = this.$echarts.init(chartDom)
this.revenueChart = revenueChart
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.RevenueChartData.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: {
color: '#fff'
}
},
2025-09-04 11:12:20 +08:00
series: this.RevenueChartData.ydata
2025-09-01 16:58:54 +08:00
}
option && revenueChart.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>
.revenue {
height:calc(100% - 45px);
#revenue-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>