From 9380fd1ad524f8205934f05281efdcb1da3d7f55 Mon Sep 17 00:00:00 2001 From: xiaoyang <17515057146@163.com> Date: Tue, 21 Apr 2026 14:54:29 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=80=E5=91=A8=E5=85=85=E6=94=BE=E6=9F=B1?= =?UTF-8?q?=E7=8A=B6=E5=9B=BE=E6=94=B9=E4=B8=BA=E7=94=B5=E8=A1=A8=E6=8A=A5?= =?UTF-8?q?=E8=A1=A8=E7=9A=84=E6=95=B0=E6=8D=AE=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/ems/dzjk/home/WeekChart.vue | 113 +++++++++++--------------- 1 file changed, 48 insertions(+), 65 deletions(-) diff --git a/src/views/ems/dzjk/home/WeekChart.vue b/src/views/ems/dzjk/home/WeekChart.vue index 6441707..5b2303c 100644 --- a/src/views/ems/dzjk/home/WeekChart.vue +++ b/src/views/ems/dzjk/home/WeekChart.vue @@ -14,12 +14,11 @@ import * as echarts from 'echarts' import resize from '@/mixins/ems/resize' 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 TEXT = { cardTitle: '\u4e00\u5468\u5145\u653e\u67f1\u72b6\u56fe', - sectionName: '\u4e00\u5468\u5145\u653e\u66f2\u7ebf', empty: '\u6682\u65e0\u6570\u636e', date: '\u65e5\u671f', charge: '\u5145\u7535\u91cf', @@ -54,13 +53,6 @@ export default { cardTitle: TEXT.cardTitle } }, - watch: { - displayData() { - if (this.siteId && this.timeRange.length === 2) { - this.getWeekKData() - } - } - }, mounted() { this.$nextTick(() => { this.initChart() @@ -80,33 +72,21 @@ export default { }, getWeekKData() { const { siteId, timeRange } = this - const displayData = this.displayData || [] - const sectionRows = displayData.filter(item => - item && item.sectionName === TEXT.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, - 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)) + if (!siteId || !Array.isArray(timeRange) || timeRange.length !== 2) { + this.summary = createEmptySummary() + this.renderEmptyState() + return + } + + this.queryAllAmmeterRows({ + siteId, + startTime: String(timeRange[0] || '').trim(), + endTime: String(timeRange[1] || '').trim(), + }).then((rows) => { + this.setOption(rows || []) + }).catch(() => { + this.summary = createEmptySummary() + this.renderEmptyState() }) }, init(siteId) { @@ -155,6 +135,24 @@ export default { const day = String(date.getDate()).padStart(2, '0') 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 = []) { const source = [[TEXT.date, TEXT.charge, TEXT.discharge]] labels.forEach((label, index) => { @@ -166,17 +164,12 @@ export default { }) return source }, - resolveSeriesType(item = {}) { - const text = `${item?.name || ''} ${item?.fieldCode || ''}`.toLowerCase() - if (text.includes('\u653e') || text.includes('discharge') || text.includes('discharged')) { - return 'discharge' - } - if (text.includes('\u5145') || text.includes('charge') || text.includes('charged')) { - return 'charge' - } - return '' + normalizeDateOnly(value) { + const raw = String(value || '').trim() + if (!raw) return '' + return raw.includes(' ') ? raw.split(' ')[0] : raw }, - buildDailyChartData(seriesData = []) { + buildDailyChartData(rows = []) { const normalizedRange = this.timeRange || [] const startTime = this.parseToTimestamp(this.normalizeDateTime(normalizedRange[0], false)) const endTime = this.parseToTimestamp(this.normalizeDateTime(normalizedRange[1], true)) @@ -197,22 +190,13 @@ export default { const chargeMap = {} const dischargeMap = {} - ;(seriesData || []).forEach(item => { - const seriesType = this.resolveSeriesType(item) - if (!seriesType) return + ;(rows || []).forEach((row) => { + const dateText = this.normalizeDateOnly(row?.dataTime) + const bucketStart = this.parseToTimestamp(this.normalizeDateTime(dateText, false)) + if (!bucketStart || bucketStart < this.startOfDay(startTime) || bucketStart > this.startOfDay(endTime)) return - ;(item?.data || []).forEach(([timestamp, pointValue]) => { - if (!timestamp || Number.isNaN(pointValue)) return - 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 - } - }) + chargeMap[bucketStart] = Math.abs(Number(row?.activeTotalKwh) || 0) + dischargeMap[bucketStart] = Math.abs(Number(row?.reActiveTotalKwh) || 0) }) const labels = [] @@ -267,13 +251,12 @@ export default { } }) }, - setOption(seriesData = []) { + setOption(rows = []) { if (!this.chart) return - const { labels, chargeData, dischargeData, summary } = this.buildDailyChartData(seriesData) - const hasValue = chargeData.some(item => Number(item?.value || 0) > 0) || dischargeData.some(item => Number(item?.value || 0) > 0) + const { labels, chargeData, dischargeData, summary } = this.buildDailyChartData(rows) - if (!labels.length || !hasValue) { + if (!labels.length) { this.summary = createEmptySummary() this.renderEmptyState() return