|
|
@ -390,7 +390,9 @@ export default { |
|
|
offlineDeviceNum: 0, |
|
|
offlineDeviceNum: 0, |
|
|
alarmStatisticsRaw: [], // 原始告警统计数据 |
|
|
alarmStatisticsRaw: [], // 原始告警统计数据 |
|
|
alarmChartData: [], // 格式化后给饼图的数据源 |
|
|
alarmChartData: [], // 格式化后给饼图的数据源 |
|
|
alarmRefreshTimer: null // 告警数据刷新定时器 |
|
|
|
|
|
|
|
|
alarmRefreshTimer: null, // 告警数据刷新定时器 |
|
|
|
|
|
deviceConfigTimer: null, |
|
|
|
|
|
deviceConfigRefreshInterval: 15000 // 15秒刷新一次设备配置 |
|
|
} |
|
|
} |
|
|
}, |
|
|
}, |
|
|
computed: { |
|
|
computed: { |
|
|
@ -440,23 +442,33 @@ export default { |
|
|
// this.allDisplayConfigData = allDeviceData |
|
|
// this.allDisplayConfigData = allDeviceData |
|
|
// this.handleDeviceIpList() |
|
|
// 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() { |
|
|
mounted() { |
|
|
this.iframeWin = this.$refs.myIframe?.contentWindow |
|
|
this.iframeWin = this.$refs.myIframe?.contentWindow |
|
|
@ -474,6 +486,7 @@ export default { |
|
|
// 清理所有定时器 |
|
|
// 清理所有定时器 |
|
|
if (this.timer) clearInterval(this.timer) |
|
|
if (this.timer) clearInterval(this.timer) |
|
|
if (this.echartsTimer) clearInterval(this.echartsTimer) |
|
|
if (this.echartsTimer) clearInterval(this.echartsTimer) |
|
|
|
|
|
if (this.deviceConfigTimer) clearInterval(this.deviceConfigTimer) |
|
|
// 销毁视频流 |
|
|
// 销毁视频流 |
|
|
if (this.webRtcServer) { |
|
|
if (this.webRtcServer) { |
|
|
this.webRtcServer.disconnect() |
|
|
this.webRtcServer.disconnect() |
|
|
@ -482,6 +495,36 @@ export default { |
|
|
// if (this.alarmRefreshTimer) clearInterval(this.alarmRefreshTimer) |
|
|
// if (this.alarmRefreshTimer) clearInterval(this.alarmRefreshTimer) |
|
|
}, |
|
|
}, |
|
|
methods: { |
|
|
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() { |
|
|
getTodayHikAlarmLog().then(data => { |
|
|
getTodayHikAlarmLog().then(data => { |
|
|
console.log('今日海康告警日志', data) |
|
|
console.log('今日海康告警日志', data) |
|
|
@ -630,7 +673,7 @@ export default { |
|
|
this.allDeviceIds = Array.from(ipSet) |
|
|
this.allDeviceIds = Array.from(ipSet) |
|
|
}, |
|
|
}, |
|
|
/** |
|
|
/** |
|
|
* 获取所有设备的实时数据 |
|
|
|
|
|
|
|
|
* 获取所有设备的实时数据(修改:保留设备IP关联) |
|
|
*/ |
|
|
*/ |
|
|
async getAllDevicesData() { |
|
|
async getAllDevicesData() { |
|
|
const allData = [] |
|
|
const allData = [] |
|
|
@ -639,12 +682,12 @@ export default { |
|
|
// const data = await mockFetchDataForIP({ ip }) |
|
|
// const data = await mockFetchDataForIP({ ip }) |
|
|
// 真实请求 |
|
|
// 真实请求 |
|
|
const data = await alarmApi.FetchDataForIP({ ip }) |
|
|
const data = await alarmApi.FetchDataForIP({ ip }) |
|
|
// 过滤需要的指标并添加到总数据 |
|
|
|
|
|
|
|
|
// 过滤需要的指标并添加到总数据(新增:携带设备IP) |
|
|
const filtered = data.filter(item => this.keepIndicators.includes(item.subName)).map(item => { |
|
|
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) { |
|
|
if (filtered.length > 0) { |
|
|
allData.push(...filtered) |
|
|
allData.push(...filtered) |
|
|
@ -658,6 +701,9 @@ export default { |
|
|
}, |
|
|
}, |
|
|
/** |
|
|
/** |
|
|
* 计算所有设备指标的平均值(适配ON/OFF告警状态,保留单位) |
|
|
* 计算所有设备指标的平均值(适配ON/OFF告警状态,保留单位) |
|
|
|
|
|
*/ |
|
|
|
|
|
/** |
|
|
|
|
|
* 计算所有设备指标的平均值(适配ON/OFF告警状态,保留单位) |
|
|
*/ |
|
|
*/ |
|
|
calcAllAvgData() { |
|
|
calcAllAvgData() { |
|
|
if (!this.hasValidData) return |
|
|
if (!this.hasValidData) return |
|
|
@ -675,12 +721,26 @@ export default { |
|
|
fire: [], // 消防状态(ON/OFF) |
|
|
fire: [], // 消防状态(ON/OFF) |
|
|
waterLeak: [] // 漏水状态(ON/OFF) |
|
|
waterLeak: [] // 漏水状态(ON/OFF) |
|
|
} |
|
|
} |
|
|
|
|
|
console.log('===== 所有设备原始数据 =====', this.newAlarm) |
|
|
|
|
|
|
|
|
// 2. 遍历所有数据累加,同时记录单位 |
|
|
|
|
|
|
|
|
// 2. 遍历所有数据累加,同时记录单位 + 打印温湿度设备详情 |
|
|
this.newAlarm.forEach(item => { |
|
|
this.newAlarm.forEach(item => { |
|
|
const value = parseFloat(item.value) || 0 |
|
|
const value = parseFloat(item.value) || 0 |
|
|
// 提取单位(优先使用数据中的dw字段,无则用默认值) |
|
|
// 提取单位(优先使用数据中的dw字段,无则用默认值) |
|
|
const unit = item.dw || this.getDefaultUnit(item.subName) |
|
|
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) { |
|
|
switch (item.subName) { |
|
|
case '温度': |
|
|
case '温度': |
|
|
@ -731,7 +791,7 @@ export default { |
|
|
break |
|
|
break |
|
|
} |
|
|
} |
|
|
}) |
|
|
}) |
|
|
console.log('累加结果:', sumMap) |
|
|
|
|
|
|
|
|
console.log('===== 温湿度等指标累加结果 =====', sumMap) |
|
|
|
|
|
|
|
|
// 3. 计算平均值(保留两位小数),并赋值单位 |
|
|
// 3. 计算平均值(保留两位小数),并赋值单位 |
|
|
this.avgData = { |
|
|
this.avgData = { |
|
|
@ -750,7 +810,7 @@ export default { |
|
|
formaldehyde: sumMap.formaldehyde.count ? (sumMap.formaldehyde.sum / sumMap.formaldehyde.count).toFixed(2) : '0.00', |
|
|
formaldehyde: sumMap.formaldehyde.count ? (sumMap.formaldehyde.sum / sumMap.formaldehyde.count).toFixed(2) : '0.00', |
|
|
formaldehydeUnit: sumMap.formaldehyde.unit || 'ppm' |
|
|
formaldehydeUnit: sumMap.formaldehyde.unit || 'ppm' |
|
|
} |
|
|
} |
|
|
console.log('平均值:', this.avgData) |
|
|
|
|
|
|
|
|
console.log('===== 所有设备温湿度等指标平均值 =====', this.avgData) |
|
|
|
|
|
|
|
|
// 4. 处理告警状态(ON=告警,OFF=正常;只要有一个ON就显示告警) |
|
|
// 4. 处理告警状态(ON=告警,OFF=正常;只要有一个ON就显示告警) |
|
|
this.alarmStatus = { |
|
|
this.alarmStatus = { |
|
|
|