Browse Source

feat:大数据图谱,设备状态详情界面优化

master
zhaobing’ 10 months ago
parent
commit
a1e4a264b5
  1. 20
      weapp/package/deviceBigdataGraph/deviceBigdataGraph.js
  2. 20
      weapp/package/deviceBigdataGraph/statusDetail/statusDetail.js

20
weapp/package/deviceBigdataGraph/deviceBigdataGraph.js

@ -55,11 +55,15 @@ Page({
// unknownCount: 0, //未知数量
},
navigator(e) {
const res = JSON.stringify(this.deviceList)
const patrolRecord=JSON.stringify(this.data.dataList)
const devices = this.deviceList.map(({ id, name }) => ({ id, name }))
const res = JSON.stringify(devices)
// const patrolRecord=JSON.stringify(this.data.dataList)
// wx.navigateTo({
// url: `/package/deviceBigdataGraph/statusDetail/statusDetail?arrayData=${encodeURIComponent(res)}&patrolRecord=${encodeURIComponent(patrolRecord)}`,
// })
wx.navigateTo({
url: `/package/deviceBigdataGraph/statusDetail/statusDetail?arrayData=${encodeURIComponent(res)}&patrolRecord=${encodeURIComponent(patrolRecord)}`,
url: `/package/deviceBigdataGraph/statusDetail/statusDetail?arrayData=${encodeURIComponent(res)}`,
})
},
navigatorToLifeWarning(e) {
@ -149,7 +153,7 @@ Page({
}
})
Request.get(getPatrolRecord('all', moment(date1).format('YYYY-MM-DD') + ' 00:00:00', moment('2099-12-31').format('YYYY-MM-DD') + ' 23:59:59', 'null', 'null',{home:false})).then(res => {
Request.get(getPatrolRecord('all', moment(date1).format('YYYY-MM-DD') + ' 00:00:00', moment('2099-12-31').format('YYYY-MM-DD') + ' 23:59:59', 'null', 'null',{home:true})).then(res => {
if (res) {
let normal = 0;
@ -158,6 +162,7 @@ Page({
// 创建一个对象来存储每个pointId的最大inspectionTime
const maxInspectionTimeByPointId = {};
// 遍历数据并更新maxInspectionTimeByPointId
res.forEach((item) => {
const {pointId,inspectionTime} = item;
if (pointId in maxInspectionTimeByPointId) {
@ -173,6 +178,8 @@ Page({
const {pointId,inspectionTime} = item;
return inspectionTime == maxInspectionTimeByPointId[pointId]
});
// console.log('xx2122222',filteredData)
//获取设备信息
const devices=that.deviceList.map(item=>{return {id:item.id,name:item.name,status:'unknown'}})
filteredData?.forEach((item) => {
@ -265,12 +272,11 @@ Page({
}]
};
that.setData({dataList:res},()=>{
that.timeoutId2= setTimeout(() => {
that.initDeviceECharts(optionDevice);
}, 1000)
})
} else {
}

20
weapp/package/deviceBigdataGraph/statusDetail/statusDetail.js

@ -100,11 +100,13 @@ Page({
wx.showLoading({ title: '加载中...' });
const that = this
//上次菜单传入设备列表
const complexArray = JSON.parse(decodeURIComponent(options.arrayData));
const complexArray = JSON.parse(decodeURIComponent(options.arrayData))
//上级菜单传入巡检记录
const patrolRecord = JSON.parse(decodeURIComponent(options.patrolRecord))
const today = moment();
// const patrolRecord = JSON.parse(decodeURIComponent(options.patrolRecord))
const today = moment().format('YYYY-MM-DD HH:mm:ss')
const sevenDaysAgos = moment().subtract(7, 'days').format('YYYY-MM-DD HH:mm:ss')
Request.get(getPatrolRecord('all',today, sevenDaysAgos, 'null', 'null',{home:false})).then(res=>{
if(res){
// console.log('xx111',res)
// 创建一个对象来存储每个pointId的最大inspectionTime
const maxInspectionTimeByPointId = {};
@ -112,13 +114,13 @@ Page({
//把设备数据全部弄成未知状态
const len=complexArray.map(item=>{return {id:item.id,name:item.name,status:'unknown'}})?.length
// 过滤出近七天内的最新记录(同点位+同一天的最新记录)
const latestRecords = patrolRecord?.filter((record) => {
const latestRecords = res?.filter((record) => {
const inspectionDate = moment(record.inspectionTime).format('YYYY-MM-DD');
const isWithin7Days = moment(today).diff(inspectionDate, 'days') <= 7;
if (!isWithin7Days) {
return false;
}
return patrolRecord?.every((r) => {
return res?.every((r) => {
if (r.pointId === record.pointId && moment(r.inspectionTime).isSame(moment(record.inspectionTime), 'day')) {
return moment(r.inspectionTime).isSameOrBefore(moment(record.inspectionTime));
}
@ -128,7 +130,7 @@ Page({
//调用每天的函数处理每天的正常-异常-未知的个数
const sevenDays= that.calculateDailyDeviceStatusCounts(latestRecords,len)
// 遍历数据并更新maxInspectionTimeByPointId
patrolRecord?.forEach((item) => {
res?.forEach((item) => {
const {pointId,inspectionTime} = item;
if (pointId in maxInspectionTimeByPointId) {
if (inspectionTime > maxInspectionTimeByPointId[pointId]) {
@ -139,7 +141,7 @@ Page({
}
});
// 过滤数据以获取相同pointId中inspectionTime最大的记录
const filteredData = patrolRecord?.filter((item) => {
const filteredData = res?.filter((item) => {
const { pointId,inspectionTime} = item;
const inspectionDate = moment(inspectionTime);
if (inspectionDate.isBetween(sevenDaysAgo, today, null, '[]')) {
@ -169,6 +171,8 @@ Page({
}, 1000)
}})
},

Loading…
Cancel
Save