Browse Source

feat:小程序闪退+首屏渲染时间过长问题

master
zhaobing’ 1 year ago
parent
commit
3a4d4d7075
  1. 4
      api/app/lib/controllers/patrolManage/patrolRecord.js
  2. 78
      weapp/package/deviceBigdataGraph/deviceBigdataGraph.js
  3. 1
      weapp/package/deviceBigdataGraph/lifeWarning/lifeWarning.js
  4. 20
      weapp/package/deviceBigdataGraph/statusDetail/statusDetail.js

4
api/app/lib/controllers/patrolManage/patrolRecord.js

@ -54,7 +54,9 @@ async function findPatrolRecord(ctx, next) {
}
// 小程序首页优化(只查对应数据条数,不需要详细数据)
if(home=='true'){
option.attributes=['id', 'alarm','inspection_time','project_id']
option.attributes={
exclude:['points']
}
}
rslt = await models.PatrolRecord.findAll(option)
} else {

78
weapp/package/deviceBigdataGraph/deviceBigdataGraph.js

@ -54,7 +54,7 @@ Page({
const res = JSON.stringify(this.data.deviceList)
const patrolRecord=JSON.stringify(this.data.dataList)
wx.navigateTo({
url: `/package/deviceBigdataGraph/statusDetail/statusDetail?arrayData=${encodeURIComponent(res)}&patrolRecord=${encodeURIComponent(patrolRecord)}`,
url: `/package/deviceBigdataGraph/statusDetail/statusDetail?arrayData=${encodeURIComponent(res)}`,
})
},
navigatorToLifeWarning(e) {
@ -72,29 +72,34 @@ Page({
that.ecDeviceComponent = that.selectComponent('#mychart-device-pie');
const date1 = new Date('1970-01-01 00:00:00');
Request.get(getDevices()).then(res => {
const currentDate = moment();
let guaranteedRate = 0;
let warrantyPeriod = 0;
if (res && res.length) {
//总的
const count = res.length
//过期的
const guaranteedRate = res.filter(item => moment(item.dateGuarantee).isBefore(moment()))?.length || 0
//没过期的
const warrantyPeriod = res.filter(item => moment(item.dateGuarantee).isAfter(moment()))?.length || 0
const typeGroups = {};
res.forEach(item => {
const itemDate = moment(item.dateGuarantee);
if (itemDate.isBefore(currentDate)) {
guaranteedRate++;
} else {
warrantyPeriod++;
}
// 处理类型分组逻辑
const type = item.type;
if (!typeGroups[type]) {
typeGroups[type] = [];
}
typeGroups[type].push(item)
});
that.setData({
guaranteedRate: Math.round((guaranteedRate / count) * 100),
warrantyPeriod: Math.round((warrantyPeriod / count) * 100),
count: res.length,
deviceList:res
})
const typeGroups = {};
res.forEach((item) => {
const type = item.type;
// 如果 typeGroups 中没有这个类型的数组,就初始化一个空数组
if (!typeGroups[type]) {
typeGroups[type] = [];
}
// 将对象添加到相应类型的数组中
typeGroups[type].push(item);
});
// 格式转换成指定格式
const result = Object.keys(typeGroups).map((type) => ({
name: type,
@ -105,18 +110,27 @@ Page({
trigger: 'item'
},
backgroundColor: "#ffffff",
// grid: {
// left: 10,
// // right: 10,
// // bottom: 10,
// top: 10,
// // containLabel: true,
// },
legend: {
bottom: 10,
left: 'center',
bottom: 0,
// left: 'right',
},
series: [{
label: {
normal: {
fontSize: 14
}
show:false,
// normal: {
// fontSize: 14
// }
},
type: 'pie',
center: ['50%', '50%'],
center:['50%','30%'],
radius: ['20%', '40%'],
data: result
@ -130,7 +144,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;
let abnormal = 0;
@ -155,7 +169,7 @@ Page({
});
//获取设备信息
const devices=that.data.deviceList.map(item=>{return {id:item.id,name:item.name,status:'unknown'}})
filteredData.forEach((item) => {
filteredData?.forEach((item) => {
const inspectContent =item.alarm?(item?.points?.inspectContent || []):[];
if (inspectContent && inspectContent.length&&Array.isArray(inspectContent)&&inspectContent.some(o=>o.deviceId)) {
inspectContent.forEach((p) => {
@ -184,7 +198,7 @@ Page({
}
});
//更新devices
devices.forEach(device => {
devices?.forEach(device => {
if (normal > 0) {
device.status = 'normal';
normal -= 1;
@ -197,9 +211,19 @@ Page({
}
});
//重新给三个状态的值赋值
normal=devices.filter(device => device.status === 'normal').length||0
abnormal=devices.filter(device => device.status === 'abnormal').length||0
unknown=devices.filter(device => device.status === 'unknown').length||0
devices.forEach(device => {
switch (device.status) {
case 'normal':
normal += 1;
break;
case 'abnormal':
abnormal += 1;
break;
case 'unknown':
unknown += 1;
break;
}
});
that.setData({dataList:res})
var optionDevice = {
tooltip: {

1
weapp/package/deviceBigdataGraph/lifeWarning/lifeWarning.js

@ -166,7 +166,6 @@ Page({
"10": "Nov",
"11": "Dec"
}[month]
console.log('月', month_);
xAxisLabels.push(month_);
}
//过期的

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

@ -1,6 +1,8 @@
// package/deviceBigdataGraph/detail/detail.js
import * as echarts from '../../components/ec-canvas/echarts';
const moment = require("../../../utils/moment");
import {getPatrolRecord} from "../../../utils/getApiUrl";
import { Request } from "../../../common";
function setOption(chart, data1, data2,xdata) {
const option = {
@ -100,22 +102,23 @@ Page({
const that = this
//上次菜单传入设备列表
const complexArray = JSON.parse(decodeURIComponent(options.arrayData));
//上级菜单传入巡检记录
const patrolRecord = JSON.parse(decodeURIComponent(options.patrolRecord))
const today = moment();
// 创建一个对象来存储每个pointId的最大inspectionTime
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){
// 创建一个对象来存储每个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 = 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));
}
@ -125,7 +128,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]) {
@ -136,7 +139,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, '[]')) {
@ -163,6 +166,9 @@ Page({
that.initChart(normaldata,abnormaldata,xData)
}, 1000)
}
})
},
//分类统计设备,异常-正常-未知个数
classifiedStatistics:function(list,len){

Loading…
Cancel
Save