Browse Source

环控定时更新

master
xuhuajiao 2 months ago
parent
commit
a0d1fbe732
  1. 116
      src/views/environmentalScreen/index.vue

116
src/views/environmentalScreen/index.vue

@ -390,7 +390,9 @@ export default {
offlineDeviceNum: 0,
alarmStatisticsRaw: [], //
alarmChartData: [], //
alarmRefreshTimer: null //
alarmRefreshTimer: null, //
deviceConfigTimer: null,
deviceConfigRefreshInterval: 15000 // 15
}
},
computed: {
@ -440,23 +442,33 @@ export default {
// this.allDisplayConfigData = allDeviceData
// this.handleDeviceIpList()
await alarmApi.FetchYpGetSite().then((data) => {
if (data && data.length > 0) {
this.allDisplayConfigData = data
this.handleDeviceIpList()
} else {
this.allDisplayConfigData = []
}
})
// await alarmApi.FetchYpGetSite().then((data) => {
// if (data && data.length > 0) {
// this.allDisplayConfigData = data
// this.handleDeviceIpList()
// } else {
// this.allDisplayConfigData = []
// }
// })
if (this.allDeviceIds.length > 0) {
await this.getAllDevicesData()
this.calcAllAvgData() //
this.calcAQIByAvg() // AQI
} else {
console.warn('无设备IP数据')
this.hasValidData = false
}
// if (this.allDeviceIds.length > 0) {
// await this.getAllDevicesData()
// this.calcAllAvgData() //
// this.calcAQIByAvg() // AQI
// } else {
// console.warn('IP')
// this.hasValidData = false
// }
await this.fullDataRefresh()
this.deviceConfigTimer = setInterval(() => {
this.fullDataRefresh()
// this.getDeviceFlag = false
// this.totalDeviceNum = 0
// this.onlineDeviceNum = 0
// this.offlineDeviceNum = 0
this.getDevice()
}, this.deviceConfigRefreshInterval)
},
mounted() {
this.iframeWin = this.$refs.myIframe?.contentWindow
@ -474,6 +486,7 @@ export default {
//
if (this.timer) clearInterval(this.timer)
if (this.echartsTimer) clearInterval(this.echartsTimer)
if (this.deviceConfigTimer) clearInterval(this.deviceConfigTimer)
//
if (this.webRtcServer) {
this.webRtcServer.disconnect()
@ -482,6 +495,36 @@ export default {
// if (this.alarmRefreshTimer) clearInterval(this.alarmRefreshTimer)
},
methods: {
/**
* 全量数据更新设备配置 + 设备实时数据 + 计算逻辑
*/
async fullDataRefresh() {
try {
// this.allDisplayConfigData = allDeviceData
// this.handleDeviceIpList()
// 1. allDisplayConfigData
const siteData = await alarmApi.FetchYpGetSite()
this.allDisplayConfigData = siteData && siteData.length > 0 ? siteData : []
console.log('定时刷新:设备配置数据更新完成', this.allDisplayConfigData)
// 2. IP
this.handleDeviceIpList()
// 3. IP
if (this.allDeviceIds.length > 0) {
await this.getAllDevicesData()
this.calcAllAvgData() //
this.calcAQIByAvg() // AQI
console.log('定时刷新:设备实时数据及计算逻辑更新完成')
} else {
console.warn('定时刷新:无设备IP数据,跳过后续步骤')
this.hasValidData = false
}
} catch (error) {
console.error('定时刷新:全量数据更新失败', error)
}
},
getTodayHikAlarmLog() {
getTodayHikAlarmLog().then(data => {
console.log('今日海康告警日志', data)
@ -630,8 +673,8 @@ export default {
this.allDeviceIds = Array.from(ipSet)
},
/**
* 获取所有设备的实时数据
*/
* 获取所有设备的实时数据修改保留设备IP关联
*/
async getAllDevicesData() {
const allData = []
for (const ip of this.allDeviceIds) {
@ -639,12 +682,12 @@ export default {
// const data = await mockFetchDataForIP({ ip })
//
const data = await alarmApi.FetchDataForIP({ ip })
//
// IP
const filtered = data.filter(item => this.keepIndicators.includes(item.subName)).map(item => {
if (item.subName === 'CO2浓度') {
return { ...item, subName: '二氧化碳' }
}
return item
const formattedItem = item.subName === 'CO2浓度' ? { ...item, subName: '二氧化碳' } : item
// IP
formattedItem.deviceIp = ip
return formattedItem
})
if (filtered.length > 0) {
allData.push(...filtered)
@ -659,6 +702,9 @@ export default {
/**
* 计算所有设备指标的平均值适配ON/OFF告警状态保留单位
*/
/**
* 计算所有设备指标的平均值适配ON/OFF告警状态保留单位
*/
calcAllAvgData() {
if (!this.hasValidData) return
@ -675,12 +721,26 @@ export default {
fire: [], // ON/OFF
waterLeak: [] // ON/OFF
}
console.log('===== 所有设备原始数据 =====', this.newAlarm)
// 2.
// 2. + 湿
this.newAlarm.forEach(item => {
const value = parseFloat(item.value) || 0
// 使dw
const unit = item.dw || this.getDefaultUnit(item.subName)
// IP
const deviceInfo = this.allDisplayConfigData.find(dev => (dev.IP || '').trim() === item.deviceIp)
const deviceName = deviceInfo?.Name || `未知设备(IP:${item.deviceIp}`
// 湿
if (item.subName === '温度' || item.subName === '湿度') {
console.log(`${item.subName}设备】`, {
设备名称: deviceName,
设备IP: item.deviceIp,
数值: value,
单位: unit || this.getDefaultUnit(item.subName)
})
}
switch (item.subName) {
case '温度':
@ -719,7 +779,7 @@ export default {
sumMap.formaldehyde.count++
if (!sumMap.formaldehyde.unit && unit) sumMap.formaldehyde.unit = unit
break
//
//
case '红外':
sumMap.infrared.push(item.value)
break
@ -731,7 +791,7 @@ export default {
break
}
})
console.log('累加结果:', sumMap)
console.log('===== 温湿度等指标累加结果 =====', sumMap)
// 3.
this.avgData = {
@ -750,7 +810,7 @@ export default {
formaldehyde: sumMap.formaldehyde.count ? (sumMap.formaldehyde.sum / sumMap.formaldehyde.count).toFixed(2) : '0.00',
formaldehydeUnit: sumMap.formaldehyde.unit || 'ppm'
}
console.log('平均值:', this.avgData)
console.log('===== 所有设备温湿度等指标平均值 =====', this.avgData)
// 4. ON=OFF=ON
this.alarmStatus = {

Loading…
Cancel
Save