一周充放柱状图改为电表报表的数据接口
This commit is contained in:
@ -14,12 +14,11 @@
|
|||||||
import * as echarts from 'echarts'
|
import * as echarts from 'echarts'
|
||||||
import resize from '@/mixins/ems/resize'
|
import resize from '@/mixins/ems/resize'
|
||||||
import DateRangeSelect from '@/components/Ems/DateRangeSelect/index.vue'
|
import DateRangeSelect from '@/components/Ems/DateRangeSelect/index.vue'
|
||||||
import { getPointConfigCurve } from '@/api/ems/site'
|
import { getAmmeterData } from '@/api/ems/dzjk'
|
||||||
|
|
||||||
const DAY = 24 * 60 * 60 * 1000
|
const DAY = 24 * 60 * 60 * 1000
|
||||||
const TEXT = {
|
const TEXT = {
|
||||||
cardTitle: '\u4e00\u5468\u5145\u653e\u67f1\u72b6\u56fe',
|
cardTitle: '\u4e00\u5468\u5145\u653e\u67f1\u72b6\u56fe',
|
||||||
sectionName: '\u4e00\u5468\u5145\u653e\u66f2\u7ebf',
|
|
||||||
empty: '\u6682\u65e0\u6570\u636e',
|
empty: '\u6682\u65e0\u6570\u636e',
|
||||||
date: '\u65e5\u671f',
|
date: '\u65e5\u671f',
|
||||||
charge: '\u5145\u7535\u91cf',
|
charge: '\u5145\u7535\u91cf',
|
||||||
@ -54,13 +53,6 @@ export default {
|
|||||||
cardTitle: TEXT.cardTitle
|
cardTitle: TEXT.cardTitle
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
watch: {
|
|
||||||
displayData() {
|
|
||||||
if (this.siteId && this.timeRange.length === 2) {
|
|
||||||
this.getWeekKData()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
mounted() {
|
mounted() {
|
||||||
this.$nextTick(() => {
|
this.$nextTick(() => {
|
||||||
this.initChart()
|
this.initChart()
|
||||||
@ -80,33 +72,21 @@ export default {
|
|||||||
},
|
},
|
||||||
getWeekKData() {
|
getWeekKData() {
|
||||||
const { siteId, timeRange } = this
|
const { siteId, timeRange } = this
|
||||||
const displayData = this.displayData || []
|
if (!siteId || !Array.isArray(timeRange) || timeRange.length !== 2) {
|
||||||
const sectionRows = displayData.filter(item =>
|
this.summary = createEmptySummary()
|
||||||
item && item.sectionName === TEXT.sectionName && item.useFixedDisplay !== 1 && item.dataPoint
|
this.renderEmptyState()
|
||||||
)
|
return
|
||||||
const tasks = sectionRows.map(row => {
|
}
|
||||||
const pointId = String(row.dataPoint || '').trim()
|
|
||||||
if (!pointId) return Promise.resolve(null)
|
this.queryAllAmmeterRows({
|
||||||
return getPointConfigCurve({
|
siteId,
|
||||||
siteId,
|
startTime: String(timeRange[0] || '').trim(),
|
||||||
pointId,
|
endTime: String(timeRange[1] || '').trim(),
|
||||||
pointType: 'data',
|
}).then((rows) => {
|
||||||
rangeType: 'custom',
|
this.setOption(rows || [])
|
||||||
startTime: this.normalizeDateTime(timeRange[0], false),
|
}).catch(() => {
|
||||||
endTime: this.normalizeDateTime(timeRange[1], true)
|
this.summary = createEmptySummary()
|
||||||
}).then(curveResponse => {
|
this.renderEmptyState()
|
||||||
const list = curveResponse?.data || []
|
|
||||||
return {
|
|
||||||
name: row.fieldName || row.fieldCode || pointId,
|
|
||||||
fieldCode: row.fieldCode || '',
|
|
||||||
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 => {
|
|
||||||
this.setOption((series || []).filter(Boolean))
|
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
init(siteId) {
|
init(siteId) {
|
||||||
@ -155,6 +135,24 @@ export default {
|
|||||||
const day = String(date.getDate()).padStart(2, '0')
|
const day = String(date.getDate()).padStart(2, '0')
|
||||||
return `${year}-${month}-${day}`
|
return `${year}-${month}-${day}`
|
||||||
},
|
},
|
||||||
|
queryAllAmmeterRows({ siteId, startTime, endTime, pageSize = 500, pageNum = 1, rows = [] }) {
|
||||||
|
return getAmmeterData({ siteId, startTime, endTime, pageSize, pageNum }).then((response) => {
|
||||||
|
const currentRows = Array.isArray(response?.rows) ? response.rows : []
|
||||||
|
const allRows = rows.concat(currentRows)
|
||||||
|
const total = Number(response?.total) || 0
|
||||||
|
if (allRows.length >= total || currentRows.length < pageSize) {
|
||||||
|
return allRows
|
||||||
|
}
|
||||||
|
return this.queryAllAmmeterRows({
|
||||||
|
siteId,
|
||||||
|
startTime,
|
||||||
|
endTime,
|
||||||
|
pageSize,
|
||||||
|
pageNum: pageNum + 1,
|
||||||
|
rows: allRows
|
||||||
|
})
|
||||||
|
})
|
||||||
|
},
|
||||||
buildDatasetSource(labels = [], chargeData = [], dischargeData = []) {
|
buildDatasetSource(labels = [], chargeData = [], dischargeData = []) {
|
||||||
const source = [[TEXT.date, TEXT.charge, TEXT.discharge]]
|
const source = [[TEXT.date, TEXT.charge, TEXT.discharge]]
|
||||||
labels.forEach((label, index) => {
|
labels.forEach((label, index) => {
|
||||||
@ -166,17 +164,12 @@ export default {
|
|||||||
})
|
})
|
||||||
return source
|
return source
|
||||||
},
|
},
|
||||||
resolveSeriesType(item = {}) {
|
normalizeDateOnly(value) {
|
||||||
const text = `${item?.name || ''} ${item?.fieldCode || ''}`.toLowerCase()
|
const raw = String(value || '').trim()
|
||||||
if (text.includes('\u653e') || text.includes('discharge') || text.includes('discharged')) {
|
if (!raw) return ''
|
||||||
return 'discharge'
|
return raw.includes(' ') ? raw.split(' ')[0] : raw
|
||||||
}
|
|
||||||
if (text.includes('\u5145') || text.includes('charge') || text.includes('charged')) {
|
|
||||||
return 'charge'
|
|
||||||
}
|
|
||||||
return ''
|
|
||||||
},
|
},
|
||||||
buildDailyChartData(seriesData = []) {
|
buildDailyChartData(rows = []) {
|
||||||
const normalizedRange = this.timeRange || []
|
const normalizedRange = this.timeRange || []
|
||||||
const startTime = this.parseToTimestamp(this.normalizeDateTime(normalizedRange[0], false))
|
const startTime = this.parseToTimestamp(this.normalizeDateTime(normalizedRange[0], false))
|
||||||
const endTime = this.parseToTimestamp(this.normalizeDateTime(normalizedRange[1], true))
|
const endTime = this.parseToTimestamp(this.normalizeDateTime(normalizedRange[1], true))
|
||||||
@ -197,22 +190,13 @@ export default {
|
|||||||
const chargeMap = {}
|
const chargeMap = {}
|
||||||
const dischargeMap = {}
|
const dischargeMap = {}
|
||||||
|
|
||||||
;(seriesData || []).forEach(item => {
|
;(rows || []).forEach((row) => {
|
||||||
const seriesType = this.resolveSeriesType(item)
|
const dateText = this.normalizeDateOnly(row?.dataTime)
|
||||||
if (!seriesType) return
|
const bucketStart = this.parseToTimestamp(this.normalizeDateTime(dateText, false))
|
||||||
|
if (!bucketStart || bucketStart < this.startOfDay(startTime) || bucketStart > this.startOfDay(endTime)) return
|
||||||
|
|
||||||
;(item?.data || []).forEach(([timestamp, pointValue]) => {
|
chargeMap[bucketStart] = Math.abs(Number(row?.activeTotalKwh) || 0)
|
||||||
if (!timestamp || Number.isNaN(pointValue)) return
|
dischargeMap[bucketStart] = Math.abs(Number(row?.reActiveTotalKwh) || 0)
|
||||||
if (timestamp < startTime || timestamp > endTime) return
|
|
||||||
|
|
||||||
const bucketStart = this.startOfDay(timestamp)
|
|
||||||
const normalizedValue = Math.abs(Number(pointValue) || 0)
|
|
||||||
if (seriesType === 'charge') {
|
|
||||||
chargeMap[bucketStart] = (chargeMap[bucketStart] || 0) + normalizedValue
|
|
||||||
} else if (seriesType === 'discharge') {
|
|
||||||
dischargeMap[bucketStart] = (dischargeMap[bucketStart] || 0) + normalizedValue
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
|
||||||
const labels = []
|
const labels = []
|
||||||
@ -267,13 +251,12 @@ export default {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
setOption(seriesData = []) {
|
setOption(rows = []) {
|
||||||
if (!this.chart) return
|
if (!this.chart) return
|
||||||
|
|
||||||
const { labels, chargeData, dischargeData, summary } = this.buildDailyChartData(seriesData)
|
const { labels, chargeData, dischargeData, summary } = this.buildDailyChartData(rows)
|
||||||
const hasValue = chargeData.some(item => Number(item?.value || 0) > 0) || dischargeData.some(item => Number(item?.value || 0) > 0)
|
|
||||||
|
|
||||||
if (!labels.length || !hasValue) {
|
if (!labels.length) {
|
||||||
this.summary = createEmptySummary()
|
this.summary = createEmptySummary()
|
||||||
this.renderEmptyState()
|
this.renderEmptyState()
|
||||||
return
|
return
|
||||||
|
|||||||
Reference in New Issue
Block a user