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

156 lines
4.1 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="activeChart"></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'
2026-02-13 21:46:12 +08:00
import {getPointConfigCurve} from '@/api/ems/site'
2025-09-25 17:30:16 +08:00
import intervalUpdate from "@/mixins/ems/intervalUpdate";
2025-08-06 17:34:35 +08:00
export default {
2026-01-22 17:27:03 +08:00
mixins: [resize, intervalUpdate],
2025-08-11 17:34:39 +08:00
components: {DateRangeSelect},
2026-02-15 16:24:29 +08:00
props: {
displayData: {
type: Array,
default: () => []
}
},
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: '',
isInit: true
2025-08-06 17:34:35 +08:00
}
},
2026-02-15 16:24:29 +08:00
watch: {
displayData() {
if (this.siteId && this.timeRange.length === 2) {
this.getGVQXData()
}
}
},
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-09-17 11:15:54 +08:00
!this.isInit && this.getGVQXData()
this.isInit = false
2025-08-11 17:34:39 +08:00
},
2026-01-22 17:27:03 +08:00
getGVQXData() {
const {siteId, timeRange} = this
2026-02-15 16:24:29 +08:00
const displayData = this.displayData || []
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)
})
Promise.all(tasks).then(series => {
2026-02-13 21:46:12 +08:00
this.setOption((series || []).filter(Boolean))
2026-02-15 16:24:29 +08:00
})
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
2025-09-17 11:15:54 +08:00
this.isInit = true
2026-01-22 17:27:03 +08:00
this.timeRange = []
2025-09-08 18:01:48 +08:00
this.$refs.dateRangeSelect.init(true)
2025-09-17 11:15:54 +08:00
this.getGVQXData()
2025-09-25 17:30:16 +08:00
this.updateInterval(this.getGVQXData)
2025-08-11 17:34:39 +08:00
},
2025-08-06 17:34:35 +08:00
initChart() {
this.chart = echarts.init(document.querySelector('#activeChart'))
},
2026-02-13 21:46:12 +08:00
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 = []) {
2025-08-06 17:34:35 +08:00
this.chart.setOption({
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
},
tooltip: {
trigger: 'axis',
2026-02-13 21:46:12 +08:00
axisPointer: { type: 'cross' }
2025-08-06 17:34:35 +08:00
},
2026-01-22 17:27:03 +08:00
textStyle: {
color: "#333333",
2025-08-06 17:34:35 +08:00
},
xAxis: {
2026-02-13 21:46:12 +08:00
type: 'time',
2025-08-06 17:34:35 +08:00
},
2026-02-13 21:46:12 +08:00
yAxis: [{
type: 'value',
}],
series: seriesData.map((item) => {
2025-09-17 11:15:54 +08:00
return {
2026-02-13 21:46:12 +08:00
name: item.name,
type: 'line',
2026-01-22 17:27:03 +08:00
showSymbol: false,
symbolSize: 2,
smooth: true,
areaStyle: {
opacity: 0.5,
},
2026-02-13 21:46:12 +08:00
data: item.data
2025-08-06 23:06:12 +08:00
}
2025-09-17 11:15:54 +08:00
})
2025-08-06 17:34:35 +08:00
})
2025-08-06 23:06:12 +08:00
},
2025-08-06 17:34:35 +08:00
}
}
</script>