Browse Source

feat:设备详情明细加载慢

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

10
weapp/package/deviceBigdataGraph/deviceBigdataGraph.js

@ -47,7 +47,7 @@ Page({
*/
data: {
ec: {},
// dataList: [], //巡检记录的列表
dataList: [], //巡检记录的列表
guaranteedRate: 0, //过保率
warrantyPeriod: 0, //质保期
count: 0, //设备总数
@ -57,8 +57,10 @@ Page({
},
navigator(e) {
const res = JSON.stringify(this.deviceList)
const patrolRecord=JSON.stringify(this.data.dataList)
wx.navigateTo({
url: `/package/deviceBigdataGraph/statusDetail/statusDetail?arrayData=${encodeURIComponent(res)}`,
url: `/package/deviceBigdataGraph/statusDetail/statusDetail?arrayData=${encodeURIComponent(res)}&patrolRecord=${encodeURIComponent(patrolRecord)}`,
})
},
navigatorToLifeWarning(e) {
@ -149,7 +151,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:true})).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:false})).then(res => {
if (res) {
let normal = 0;
let abnormal = 0;
@ -229,7 +231,7 @@ Page({
break;
}
});
// that.setData({dataList:res})
that.setData({dataList:res})
var optionDevice = {
tooltip: {
trigger: 'item'

19
weapp/package/deviceBigdataGraph/statusDetail/statusDetail.js

@ -101,23 +101,24 @@ Page({
const that = this
//上次菜单传入设备列表
const complexArray = JSON.parse(decodeURIComponent(options.arrayData));
//上级菜单传入巡检记录
const patrolRecord = JSON.parse(decodeURIComponent(options.patrolRecord))
const today = moment();
const date1 = new Date('1970-01-01 00:00:00');
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=>{
if(res){
// console.log('xx111',res)
// 创建一个对象来存储每个pointId的最大inspectionTime
const maxInspectionTimeByPointId = {};
const sevenDaysAgo = moment().subtract(7, 'days'); // 获取七天前的日期
//把设备数据全部弄成未知状态
const len=complexArray.map(item=>{return {id:item.id,name:item.name,status:'unknown'}})?.length
// 过滤出近七天内的最新记录(同点位+同一天的最新记录)
const latestRecords = res.filter((record) => {
const latestRecords = patrolRecord?.filter((record) => {
const inspectionDate = moment(record.inspectionTime).format('YYYY-MM-DD');
const isWithin7Days = moment(today).diff(inspectionDate, 'days') <= 7;
if (!isWithin7Days) {
return false;
}
return res.every((r) => {
return patrolRecord?.every((r) => {
if (r.pointId === record.pointId && moment(r.inspectionTime).isSame(moment(record.inspectionTime), 'day')) {
return moment(r.inspectionTime).isSameOrBefore(moment(record.inspectionTime));
}
@ -127,7 +128,7 @@ Page({
//调用每天的函数处理每天的正常-异常-未知的个数
const sevenDays= that.calculateDailyDeviceStatusCounts(latestRecords,len)
// 遍历数据并更新maxInspectionTimeByPointId
res.forEach((item) => {
patrolRecord?.forEach((item) => {
const {pointId,inspectionTime} = item;
if (pointId in maxInspectionTimeByPointId) {
if (inspectionTime > maxInspectionTimeByPointId[pointId]) {
@ -138,7 +139,7 @@ Page({
}
});
// 过滤数据以获取相同pointId中inspectionTime最大的记录
const filteredData = res.filter((item) => {
const filteredData = patrolRecord?.filter((item) => {
const { pointId,inspectionTime} = item;
const inspectionDate = moment(inspectionTime);
if (inspectionDate.isBetween(sevenDaysAgo, today, null, '[]')) {
@ -167,8 +168,8 @@ Page({
that.initChart(normaldata,abnormaldata,xData)
}, 1000)
}
})
},
//分类统计设备,异常-正常-未知个数

Loading…
Cancel
Save