144 lines
4.1 KiB
Vue
144 lines
4.1 KiB
Vue
<template>
|
|
<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>
|
|
</template>
|
|
|
|
<script>
|
|
import * as echarts from 'echarts'
|
|
import resize from '@/mixins/ems/resize'
|
|
import DateRangeSelect from '@/components/Ems/DateRangeSelect/index.vue'
|
|
import {getProjectDisplayData} from '@/api/ems/dzjk'
|
|
import {getPointConfigCurve} from '@/api/ems/site'
|
|
|
|
export default {
|
|
mixins: [resize],
|
|
components: {DateRangeSelect},
|
|
data() {
|
|
return {
|
|
chart: null,
|
|
timeRange: [],
|
|
siteId: '',
|
|
}
|
|
},
|
|
mounted() {
|
|
this.$nextTick(() => {
|
|
this.initChart()
|
|
})
|
|
},
|
|
beforeDestroy() {
|
|
if (!this.chart) {
|
|
return
|
|
}
|
|
this.chart.dispose()
|
|
this.chart = null
|
|
},
|
|
methods: {
|
|
// 更新时间范围 重置图表
|
|
updateDate(data) {
|
|
this.timeRange = data
|
|
this.getWeekKData()
|
|
},
|
|
getWeekKData() {
|
|
this.showLoading()
|
|
const {siteId, timeRange} = this
|
|
getProjectDisplayData(siteId).then(response => {
|
|
const displayData = response?.data || []
|
|
const sectionRows = displayData.filter(item =>
|
|
item && item.sectionName === '一周充放曲线' && item.useFixedDisplay !== 1 && item.dataPoint
|
|
)
|
|
const tasks = sectionRows.map(row => {
|
|
const pointId = String(row.dataPoint || '').trim()
|
|
if (!pointId) return Promise.resolve(null)
|
|
return getPointConfigCurve({
|
|
siteId,
|
|
pointId,
|
|
pointType: 'data',
|
|
rangeType: 'custom',
|
|
startTime: this.normalizeDateTime(timeRange[0], false),
|
|
endTime: this.normalizeDateTime(timeRange[1], true)
|
|
}).then(curveResponse => {
|
|
const list = curveResponse?.data || []
|
|
return {
|
|
name: row.fieldName || row.fieldCode || pointId,
|
|
data: list
|
|
.map(item => [this.parseToTimestamp(item.dataTime), Number(item.pointValue)])
|
|
.filter(item => item[0] && !Number.isNaN(item[1]))
|
|
}
|
|
}).catch(() => null)
|
|
})
|
|
return Promise.all(tasks)
|
|
}).then(series => {
|
|
this.setOption((series || []).filter(Boolean))
|
|
}).finally(() => this.hideLoading())
|
|
},
|
|
init(siteId) {
|
|
//初始化 清空数据
|
|
this.siteId = siteId
|
|
this.timeRange = []
|
|
this.deviceId = ''
|
|
this.$refs.dateRangeSelect.init()
|
|
},
|
|
initChart() {
|
|
this.chart = echarts.init(document.querySelector('#weekChart'))
|
|
},
|
|
showLoading() {
|
|
this.chart && this.chart.showLoading()
|
|
},
|
|
hideLoading() {
|
|
this.chart && this.chart.hideLoading()
|
|
},
|
|
normalizeDateTime(value, endOfDay) {
|
|
const raw = String(value || '').trim()
|
|
if (!raw) return ''
|
|
if (raw.includes(' ')) return raw
|
|
return `${raw} ${endOfDay ? '23:59:59' : '00:00:00'}`
|
|
},
|
|
parseToTimestamp(value) {
|
|
if (!value) return null
|
|
const t = new Date(value).getTime()
|
|
return Number.isNaN(t) ? null : t
|
|
},
|
|
setOption(seriesData = []) {
|
|
this.chart && this.chart.setOption({
|
|
color: ['#4472c4', '#70ad47'],//所有充放电颜色保持统一
|
|
tooltip: {
|
|
trigger: 'axis',
|
|
axisPointer: { type: 'cross' }
|
|
},
|
|
grid: {
|
|
containLabel: true
|
|
},
|
|
legend: {
|
|
left: 'center',
|
|
bottom: '15',
|
|
},
|
|
xAxis: {
|
|
type: 'time'
|
|
},
|
|
yAxis: [{
|
|
type: 'value',
|
|
name: '充电量/放电量kWh',
|
|
axisLine: {
|
|
lineStyle: {
|
|
color: '#333333',
|
|
},
|
|
onZero: false
|
|
}
|
|
}],
|
|
series: seriesData.map(item => ({
|
|
name: item.name,
|
|
yAxisIndex: 0,
|
|
type: 'bar',
|
|
data: item.data
|
|
}))
|
|
})
|
|
}
|
|
}
|
|
}
|
|
</script>
|