From a0d1fbe7329910eba634127b549961228dded055 Mon Sep 17 00:00:00 2001 From: xuhuajiao <13476289682@163.com> Date: Tue, 23 Dec 2025 17:32:27 +0800 Subject: [PATCH] =?UTF-8?q?=E7=8E=AF=E6=8E=A7=E5=AE=9A=E6=97=B6=E6=9B=B4?= =?UTF-8?q?=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/environmentalScreen/index.vue | 116 ++++++++++++++++++------ 1 file changed, 88 insertions(+), 28 deletions(-) diff --git a/src/views/environmentalScreen/index.vue b/src/views/environmentalScreen/index.vue index d91a117..fa9d181 100644 --- a/src/views/environmentalScreen/index.vue +++ b/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 = {