20260823:H5修复查询网关设备物理量bug

This commit is contained in:
George 2026-08-23 16:51:42 +08:00
parent 3f5bba9a02
commit 7539dd33be
4 changed files with 197 additions and 81 deletions

View File

@ -32,7 +32,7 @@ export function getDeviceHistory (params) {
return http.get('/iot/deviceLog/history', { params: params }); return http.get('/iot/deviceLog/history', { params: params });
} }
//查询历史监测数据 //查询历史监测数据(直连设备)
export function getHistoryList (data) { export function getHistoryList (data) {
return http.request({ return http.request({
url: '/data/center/deviceHistory', 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) { export function getDeviceLog (logId) {
return http.request({ return http.request({

View File

@ -812,7 +812,15 @@
}, },
"deviceHistory": { "deviceHistory": {
"lastTwoHours": "last 2 hours", "lastTwoHours": "last 2 hours",
"lastFourHours": "last 4 hours",
"lastEightHours": "last 8 hours",
"lastTwelveHours": "last 12 hours",
"lastOneDay": "last 1 day", "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", "lastThirtyDay": "last 30 day",
"custom": "custom", "custom": "custom",
"inputDate": "starting time", "inputDate": "starting time",

View File

@ -814,7 +814,15 @@
}, },
"deviceHistory": { "deviceHistory": {
"lastTwoHours": "最近2小时", "lastTwoHours": "最近2小时",
"lastFourHours": "最近4小时",
"lastEightHours": "最近8小时",
"lastTwelveHours": "最近12小时",
"lastOneDay": "最近1天", "lastOneDay": "最近1天",
"lastTwoDays": "最近2天",
"lastThreeDays": "最近3天",
"lastFiveDays": "最近5天",
"lastSevenDays": "最近7天",
"lastFifteenDays": "最近15天",
"lastThirtyDay": "最近30天", "lastThirtyDay": "最近30天",
"custom": "自定义", "custom": "自定义",
"inputDate": "起始时间", "inputDate": "起始时间",

View File

@ -81,7 +81,7 @@
import uniPagination from '@/pagesA/components/uni-pagination/index.vue'; import uniPagination from '@/pagesA/components/uni-pagination/index.vue';
import { getSubGatewayList } from '@/apis/modules/gateway.js'; import { getSubGatewayList } from '@/apis/modules/gateway.js';
import { listThingsModel } from '@/apis/modules/device.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 { export default {
name: 'deviceHistory', name: 'deviceHistory',
@ -118,27 +118,59 @@
return { return {
deviceInfo: {}, // 设备信息 deviceInfo: {}, // 设备信息
deviceId: null, deviceId: null,
// 时间快捷数据列表 // 时间快捷数据列表(value 为小时数,-1 表示自定义)
timeShortcuts: [{ timeShortcuts: [{
value: 0, value: 2,
text: this.$tt('deviceHistory.lastTwoHours') 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') 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') text: this.$tt('deviceHistory.lastThirtyDay')
}, },
{ {
value: 3, value: -1,
text: this.$tt('deviceHistory.custom') text: this.$tt('deviceHistory.custom')
}, },
], ],
// 查询参数 // 查询参数
queryParams: { queryParams: {
timeShortcut: 1, timeShortcut: 24,
strTime: `${beginTime}-${endTime}`, strTime: `${beginTime}-${endTime}`,
beginTime: beginTime, beginTime: beginTime,
endTime: endTime, endTime: endTime,
@ -201,20 +233,13 @@
}, },
}, },
methods: { methods: {
// 快捷时间选择 // 快捷时间选择(val 为小时数,-1 表示自定义)
handleTimeShortcutChange (val) { handleTimeShortcutChange (val) {
if (val === 3) { if (val === -1) {
return; return;
} }
const endTime = new Date().getTime(); const endTime = new Date().getTime();
let beginTime = null; const beginTime = endTime - 3600 * 1000 * val;
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;
};
this.queryParams.beginTime = beginTime; this.queryParams.beginTime = beginTime;
this.queryParams.endTime = endTime; this.queryParams.endTime = endTime;
this.queryParams.strTime = beginTime + '-' + endTime; this.queryParams.strTime = beginTime + '-' + endTime;
@ -263,7 +288,7 @@
this.queryParams.strTime = beginTime + '-' + e.value; this.queryParams.strTime = beginTime + '-' + e.value;
this.getHistory(); this.getHistory();
this.isDateTime = false; this.isDateTime = false;
this.queryParams.timeShortcut = 3; this.queryParams.timeShortcut = -1;
} }
}, },
// 取消日期选择 // 取消日期选择
@ -322,9 +347,9 @@
} }
}); });
}, },
// 获取物模型 // 获取物模型(网关设备按identifier去重)
getIdentifierList () { getIdentifierList () {
const { deviceId } = this.deviceInfo; const { deviceId, deviceType } = this.deviceInfo;
const params = { const params = {
deviceId: deviceId, deviceId: deviceId,
pageNum: 1, pageNum: 1,
@ -341,10 +366,24 @@
type: item.type, type: item.type,
} }
} }
}).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;
}); });
this.identifierList = this.identifierList.filter(item => item !== undefined); }
if (this.identifierList.length > 0) {
this.queryParams.identifiers = [this.identifierList[0].value]; this.queryParams.identifiers = [this.identifierList[0].value];
} }
}
}); });
}, },
// 获取统计数据 // 获取统计数据
@ -354,9 +393,28 @@
}, },
// 获取统计数据 // 获取统计数据
getHistory () { getHistory () {
const { identifiers, beginTime, endTime, slaveId } = this.queryParams; const { identifiers, beginTime, endTime } = this.queryParams;
const { deviceId, serialNumber } = this.deviceInfo; const { deviceId, serialNumber, deviceType } = this.deviceInfo;
if (identifiers.length !== 0) { if (identifiers.length !== 0) {
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 idenList = identifiers.map((item) => {
const iden = this.identifierList.find((chil) => chil.value === item); const iden = this.identifierList.find((chil) => chil.value === item);
return { return {
@ -369,10 +427,8 @@
beginTime: moment(beginTime).format('YYYY-MM-DD HH:mm:ss'), beginTime: moment(beginTime).format('YYYY-MM-DD HH:mm:ss'),
endTime: moment(endTime).format('YYYY-MM-DD HH:mm:ss'), endTime: moment(endTime).format('YYYY-MM-DD HH:mm:ss'),
deviceId: deviceId, deviceId: deviceId,
// slaveId: slaveId,
serialNumber: serialNumber, serialNumber: serialNumber,
}; };
this.historys = [];
getHistoryList(params).then(res => { getHistoryList(params).then(res => {
if (res.code === 200) { if (res.code === 200) {
this.historys = res.data; this.historys = res.data;
@ -381,9 +437,25 @@
} }
}) })
} }
}
}, },
// 获取折线图数据 // 获取折线图数据(适配两种接口响应格式)
getChartDatas () { 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 {
name: key,
data: this.historys.map((d) => Number(d[key]) || 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 categories = this.historys.map((item) => Object.keys(item)[0]);
const series = this.queryParams.identifiers.map((item) => { const series = this.queryParams.identifiers.map((item) => {
return { return {
@ -394,13 +466,31 @@
}), }),
}; };
}); });
return { return { categories, series };
categories,
series
} }
}, },
// 获取表格数据 // 获取表格数据(适配两种接口响应格式)
getTableDatas () { 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) => ({ this.tableHeaders = this.queryParams.identifiers.map((item) => ({
name: this.identifierList.find((chil) => chil.value === item).text, name: this.identifierList.find((chil) => chil.value === item).text,
value: item, value: item,
@ -416,6 +506,7 @@
...obj ...obj
}; };
}); });
}
this.devTotal = this.historys.length; this.devTotal = this.historys.length;
}, },
// 获取设备列表数据 // 获取设备列表数据