From 7539dd33beeae906c43128ddcc9e481a22b0c783 Mon Sep 17 00:00:00 2001 From: George Date: Sun, 23 Aug 2026 16:51:42 +0800 Subject: [PATCH] =?UTF-8?q?20260823:H5=E4=BF=AE=E5=A4=8D=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E7=BD=91=E5=85=B3=E8=AE=BE=E5=A4=87=E7=89=A9=E7=90=86=E9=87=8F?= =?UTF-8?q?bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yack-app/apis/modules/deviceLog.js | 11 +- yack-app/locale/en-US.json | 8 + yack-app/locale/zh-CN.json | 8 + .../pagesA/home/device/statistic/history.vue | 251 ++++++++++++------ 4 files changed, 197 insertions(+), 81 deletions(-) diff --git a/yack-app/apis/modules/deviceLog.js b/yack-app/apis/modules/deviceLog.js index a17f4987..bf46db17 100644 --- a/yack-app/apis/modules/deviceLog.js +++ b/yack-app/apis/modules/deviceLog.js @@ -32,7 +32,7 @@ export function getDeviceHistory (params) { return http.get('/iot/deviceLog/history', { params: params }); } -//查询历史监测数据 +//查询历史监测数据(直连设备) export function getHistoryList (data) { return http.request({ url: '/data/center/deviceHistory', @@ -41,6 +41,15 @@ export function getHistoryList (data) { }) } +// 查询网关子设备对比历史数据 +export function getSubDeviceComparativeHistory (data) { + return http.request({ + url: '/data/center/subDeviceComparativeHistory', + method: 'post', + data: data, + }) +} + // 查询设备日志详细 export function getDeviceLog (logId) { return http.request({ diff --git a/yack-app/locale/en-US.json b/yack-app/locale/en-US.json index c75992af..a287bfd8 100644 --- a/yack-app/locale/en-US.json +++ b/yack-app/locale/en-US.json @@ -812,7 +812,15 @@ }, "deviceHistory": { "lastTwoHours": "last 2 hours", + "lastFourHours": "last 4 hours", + "lastEightHours": "last 8 hours", + "lastTwelveHours": "last 12 hours", "lastOneDay": "last 1 day", + "lastTwoDays": "last 2 days", + "lastThreeDays": "last 3 days", + "lastFiveDays": "last 5 days", + "lastSevenDays": "last 7 days", + "lastFifteenDays": "last 15 days", "lastThirtyDay": "last 30 day", "custom": "custom", "inputDate": "starting time", diff --git a/yack-app/locale/zh-CN.json b/yack-app/locale/zh-CN.json index 0cf9d83e..e0ff109a 100644 --- a/yack-app/locale/zh-CN.json +++ b/yack-app/locale/zh-CN.json @@ -814,7 +814,15 @@ }, "deviceHistory": { "lastTwoHours": "最近2小时", + "lastFourHours": "最近4小时", + "lastEightHours": "最近8小时", + "lastTwelveHours": "最近12小时", "lastOneDay": "最近1天", + "lastTwoDays": "最近2天", + "lastThreeDays": "最近3天", + "lastFiveDays": "最近5天", + "lastSevenDays": "最近7天", + "lastFifteenDays": "最近15天", "lastThirtyDay": "最近30天", "custom": "自定义", "inputDate": "起始时间", diff --git a/yack-app/pagesA/home/device/statistic/history.vue b/yack-app/pagesA/home/device/statistic/history.vue index 4ae8924b..3fd3c20a 100644 --- a/yack-app/pagesA/home/device/statistic/history.vue +++ b/yack-app/pagesA/home/device/statistic/history.vue @@ -81,7 +81,7 @@ import uniPagination from '@/pagesA/components/uni-pagination/index.vue'; import { getSubGatewayList } from '@/apis/modules/gateway.js'; import { listThingsModel } from '@/apis/modules/device.js'; - import { getHistoryList } from '@/apis/modules/deviceLog.js'; + import { getHistoryList, getSubDeviceComparativeHistory } from '@/apis/modules/deviceLog.js'; export default { name: 'deviceHistory', @@ -118,27 +118,59 @@ return { deviceInfo: {}, // 设备信息 deviceId: null, - // 时间快捷数据列表 + // 时间快捷数据列表(value 为小时数,-1 表示自定义) timeShortcuts: [{ - value: 0, + value: 2, text: this.$tt('deviceHistory.lastTwoHours') }, { - value: 1, + value: 4, + text: this.$tt('deviceHistory.lastFourHours') + }, + { + value: 8, + text: this.$tt('deviceHistory.lastEightHours') + }, + { + value: 12, + text: this.$tt('deviceHistory.lastTwelveHours') + }, + { + value: 24, text: this.$tt('deviceHistory.lastOneDay') }, { - value: 2, + value: 48, + text: this.$tt('deviceHistory.lastTwoDays') + }, + { + value: 72, + text: this.$tt('deviceHistory.lastThreeDays') + }, + { + value: 120, + text: this.$tt('deviceHistory.lastFiveDays') + }, + { + value: 168, + text: this.$tt('deviceHistory.lastSevenDays') + }, + { + value: 360, + text: this.$tt('deviceHistory.lastFifteenDays') + }, + { + value: 720, text: this.$tt('deviceHistory.lastThirtyDay') }, { - value: 3, + value: -1, text: this.$tt('deviceHistory.custom') }, ], // 查询参数 queryParams: { - timeShortcut: 1, + timeShortcut: 24, strTime: `${beginTime}-${endTime}`, beginTime: beginTime, endTime: endTime, @@ -201,20 +233,13 @@ }, }, methods: { - // 快捷时间选择 + // 快捷时间选择(val 为小时数,-1 表示自定义) handleTimeShortcutChange (val) { - if (val === 3) { + if (val === -1) { return; } const endTime = new Date().getTime(); - let beginTime = null; - if (val === 0) { - beginTime = endTime - 3600 * 1000 * 2; - } else if (val === 1) { - beginTime = endTime - 3600 * 1000 * 24; - } else if (val === 2) { - beginTime = endTime - 3600 * 1000 * 24 * 30; - }; + const beginTime = endTime - 3600 * 1000 * val; this.queryParams.beginTime = beginTime; this.queryParams.endTime = endTime; this.queryParams.strTime = beginTime + '-' + endTime; @@ -263,7 +288,7 @@ this.queryParams.strTime = beginTime + '-' + e.value; this.getHistory(); this.isDateTime = false; - this.queryParams.timeShortcut = 3; + this.queryParams.timeShortcut = -1; } }, // 取消日期选择 @@ -322,9 +347,9 @@ } }); }, - // 获取物模型 + // 获取物模型(网关设备按identifier去重) getIdentifierList () { - const { deviceId } = this.deviceInfo; + const { deviceId, deviceType } = this.deviceInfo; const params = { deviceId: deviceId, pageNum: 1, @@ -341,9 +366,23 @@ type: item.type, } } - }); - this.identifierList = this.identifierList.filter(item => item !== undefined); - this.queryParams.identifiers = [this.identifierList[0].value]; + }).filter(item => item !== undefined); + + // 网关设备:按identifier去重(多个子设备可能有相同identifier) + if (deviceType === 2) { + const seen = new Set(); + this.identifierList = this.identifierList.filter(item => { + if (seen.has(item.value)) { + return false; + } + seen.add(item.value); + return true; + }); + } + + if (this.identifierList.length > 0) { + this.queryParams.identifiers = [this.identifierList[0].value]; + } } }); }, @@ -354,68 +393,120 @@ }, // 获取统计数据 getHistory () { - const { identifiers, beginTime, endTime, slaveId } = this.queryParams; - const { deviceId, serialNumber } = this.deviceInfo; + const { identifiers, beginTime, endTime } = this.queryParams; + const { deviceId, serialNumber, deviceType } = this.deviceInfo; if (identifiers.length !== 0) { - const idenList = identifiers.map((item) => { - const iden = this.identifierList.find((chil) => chil.value === item); + this.historys = []; + if (deviceType === 2) { + // 网关设备:调用多设备对比接口,数据按子设备SN存储 + const params = { + gwDeviceId: deviceId, + identifierList: identifiers, + type: 1, + beginTime: moment(beginTime).format('YYYY-MM-DD HH:mm:ss'), + endTime: moment(endTime).format('YYYY-MM-DD HH:mm:ss'), + }; + getSubDeviceComparativeHistory(params).then(res => { + if (res.code === 200) { + this.historys = res.data || []; + this.chartData = this.getChartDatas(); + this.getTableDatas(); + } + }) + } else { + // 直连设备 + const idenList = identifiers.map((item) => { + const iden = this.identifierList.find((chil) => chil.value === item); + return { + identifier: iden.value, + type: iden.type + }; + }); + const params = { + identifierList: idenList, + beginTime: moment(beginTime).format('YYYY-MM-DD HH:mm:ss'), + endTime: moment(endTime).format('YYYY-MM-DD HH:mm:ss'), + deviceId: deviceId, + serialNumber: serialNumber, + }; + getHistoryList(params).then(res => { + if (res.code === 200) { + this.historys = res.data; + this.chartData = this.getChartDatas(); + this.getTableDatas(); + } + }) + } + } + }, + // 获取折线图数据(适配两种接口响应格式) + getChartDatas () { + const { deviceType } = this.deviceInfo; + if (deviceType === 2) { + // subDeviceComparativeHistory 格式: [{ "time": "2026-08-23 10:00:00", "子设备A": "25.5", "子设备B": "26.0" }] + const categories = this.historys.map((item) => item.time); + // 获取除 time 外的所有列名作为系列 + const keys = Object.keys(this.historys[0] || {}).filter(k => k !== 'time'); + const series = keys.map((key) => { return { - identifier: iden.value, - type: iden.type + name: key, + data: this.historys.map((d) => Number(d[key]) || 0), }; }); - const params = { - identifierList: idenList, - beginTime: moment(beginTime).format('YYYY-MM-DD HH:mm:ss'), - endTime: moment(endTime).format('YYYY-MM-DD HH:mm:ss'), - deviceId: deviceId, - // slaveId: slaveId, - serialNumber: serialNumber, - }; - this.historys = []; - getHistoryList(params).then(res => { - if (res.code === 200) { - this.historys = res.data; - this.chartData = this.getChartDatas(); - this.getTableDatas(); - } - }) - } - }, - // 获取折线图数据 - getChartDatas () { - const categories = this.historys.map((item) => Object.keys(item)[0]); - const series = this.queryParams.identifiers.map((item) => { - return { - name: this.identifierList.find((chil) => chil.value === item).text, - data: this.historys.map((d) => { - const ide = Object.values(d)[0].find((f) => Object.keys(f)[0] === item); - return Number(Object.values(ide)[0]); - }), - }; - }); - return { - categories, - series - } - }, - // 获取表格数据 - getTableDatas () { - this.tableHeaders = this.queryParams.identifiers.map((item) => ({ - name: this.identifierList.find((chil) => chil.value === item).text, - value: item, - })); - this.tableComTemp = this.historys.map((item) => { - const time = Object.keys(item)[0]; - let obj = {}; - Object.values(item)[0].forEach((chil) => { - obj[Object.keys(chil)[0]] = Object.values(chil)[0]; + return { categories, series }; + } else { + // deviceHistory 格式: [{ "2026-08-23 10:00:00": [{ "temperature": "25.5" }] }] + const categories = this.historys.map((item) => Object.keys(item)[0]); + const series = this.queryParams.identifiers.map((item) => { + return { + name: this.identifierList.find((chil) => chil.value === item).text, + data: this.historys.map((d) => { + const ide = Object.values(d)[0].find((f) => Object.keys(f)[0] === item); + return Number(Object.values(ide)[0]); + }), + }; }); - return { - time, - ...obj - }; - }); + return { categories, series }; + } + }, + // 获取表格数据(适配两种接口响应格式) + getTableDatas () { + const { deviceType } = this.deviceInfo; + if (deviceType === 2) { + // subDeviceComparativeHistory 格式 + const keys = Object.keys(this.historys[0] || {}).filter(k => k !== 'time'); + this.tableHeaders = keys.map((key) => ({ + name: key, + value: key, + })); + this.tableComTemp = this.historys.map((item) => { + let obj = {}; + keys.forEach((key) => { + obj[key] = item[key]; + }); + return { + time: item.time, + ...obj + }; + }); + } else { + // deviceHistory 格式 + this.tableHeaders = this.queryParams.identifiers.map((item) => ({ + name: this.identifierList.find((chil) => chil.value === item).text, + value: item, + })); + this.tableComTemp = this.historys.map((item) => { + const time = Object.keys(item)[0]; + let obj = {}; + Object.values(item)[0].forEach((chil) => { + obj[Object.keys(chil)[0]] = Object.values(chil)[0]; + }); + return { + time, + ...obj + }; + }); + } this.devTotal = this.historys.length; }, // 获取设备列表数据