Files
emsfront/src/views/ems/dzjk/home/WeekChart.vue

121 lines
3.0 KiB
Vue
Raw Normal View History

2025-08-06 17:34:35 +08:00
<template>
2026-01-22 17:27:03 +08:00
<el-card shadow="always" class="common-card-container common-card-container-body-no-padding time-range-card">
<div slot="header" class="time-range-header">
<span class="card-title">一周充放曲线</span>
<date-range-select ref="dateRangeSelect" :showIcon="true" :mini-time-picker="true" @updateDate="updateDate"/>
</div>
<div style="height: 310px" id="weekChart"></div>
</el-card>
2025-08-06 17:34:35 +08:00
</template>
<script>
import * as echarts from 'echarts'
import resize from '@/mixins/ems/resize'
2025-08-11 21:50:38 +08:00
import DateRangeSelect from '@/components/Ems/DateRangeSelect/index.vue'
import {getSevenChargeData} from '@/api/ems/dzjk'
2026-01-22 17:27:03 +08:00
2025-08-06 17:34:35 +08:00
export default {
mixins: [resize],
2025-08-11 17:34:39 +08:00
components: {DateRangeSelect},
2025-08-06 17:34:35 +08:00
data() {
return {
2025-08-11 17:34:39 +08:00
chart: null,
2026-01-22 17:27:03 +08:00
timeRange: [],
siteId: '',
2025-08-06 17:34:35 +08:00
}
},
mounted() {
this.$nextTick(() => {
this.initChart()
})
},
beforeDestroy() {
if (!this.chart) {
return
}
this.chart.dispose()
this.chart = null
},
methods: {
2025-08-11 17:34:39 +08:00
// 更新时间范围 重置图表
2026-01-22 17:27:03 +08:00
updateDate(data) {
this.timeRange = data
2025-08-11 17:34:39 +08:00
this.getWeekKData()
},
2026-01-22 17:27:03 +08:00
getWeekKData() {
2025-08-11 17:34:39 +08:00
this.showLoading()
2026-01-22 17:27:03 +08:00
const {siteId, timeRange} = this
getSevenChargeData({siteId, startDate: timeRange[0], endDate: timeRange[1]}).then(response => {
2025-08-11 21:50:38 +08:00
this.setOption(response?.data || [])
2026-01-22 17:27:03 +08:00
}).finally(() => this.hideLoading())
2025-08-11 17:34:39 +08:00
},
2026-01-22 17:27:03 +08:00
init(siteId) {
2025-08-11 17:34:39 +08:00
//初始化 清空数据
this.siteId = siteId
2026-01-22 17:27:03 +08:00
this.timeRange = []
this.deviceId = ''
2025-08-11 17:34:39 +08:00
this.$refs.dateRangeSelect.init()
},
2025-08-06 17:34:35 +08:00
initChart() {
this.chart = echarts.init(document.querySelector('#weekChart'))
},
2026-01-22 17:27:03 +08:00
showLoading() {
2025-08-06 23:06:12 +08:00
this.chart && this.chart.showLoading()
},
2026-01-22 17:27:03 +08:00
hideLoading() {
2025-08-11 17:34:39 +08:00
this.chart && this.chart.hideLoading()
},
2026-01-22 17:27:03 +08:00
setOption(data, unit) {
const source = [['日期', '充电量', '放电量']]
data.forEach(item => {
source.push([item.ammeterDate, item.chargedCap, item.disChargedCap])
2025-08-06 17:34:35 +08:00
})
2025-08-11 17:34:39 +08:00
this.chart && this.chart.setOption({
2026-01-22 17:27:03 +08:00
color: ['#4472c4', '#70ad47'],//所有充放电颜色保持统一
2025-08-06 17:34:35 +08:00
tooltip: {
trigger: 'axis',
axisPointer: { // 坐标轴指示器,坐标轴触发有效
type: 'shadow' // 默认为直线,可选为:'line' | 'shadow'
}
},
2025-08-13 14:51:26 +08:00
grid: {
containLabel: true
},
2025-08-06 23:06:12 +08:00
legend: {
left: 'center',
2025-08-11 17:34:39 +08:00
bottom: '15',
2025-08-06 17:34:35 +08:00
},
xAxis: {
type: 'category',
2026-01-22 17:27:03 +08:00
name: unit,
nameLocation: 'center'
2025-08-06 17:34:35 +08:00
},
2025-08-06 23:06:12 +08:00
yAxis: [{
2025-08-06 17:34:35 +08:00
type: 'value',
2026-01-22 17:27:03 +08:00
name: '充电量/放电量kWh',
2025-08-06 17:34:35 +08:00
axisLine: {
2026-01-22 17:27:03 +08:00
lineStyle: {
2025-08-06 17:34:35 +08:00
color: '#333333',
2025-08-06 23:06:12 +08:00
},
2026-01-22 17:27:03 +08:00
onZero: false
2025-08-06 17:34:35 +08:00
}
2025-08-06 23:06:12 +08:00
}],
2026-01-22 17:27:03 +08:00
dataset: {
2025-08-06 17:34:35 +08:00
source
},
series: [
{
2026-01-22 17:27:03 +08:00
yAxisIndex: 0,
2025-09-08 18:01:48 +08:00
type: 'bar',
2025-08-06 23:06:12 +08:00
},
{
2026-01-22 17:27:03 +08:00
yAxisIndex: 0,
2025-09-08 18:01:48 +08:00
type: 'bar',
2025-08-06 23:06:12 +08:00
},
]
2025-08-06 17:34:35 +08:00
})
}
}
}
</script>