|
|
|
@ -23,19 +23,19 @@ export default {
|
|
|
|
|
return {
|
|
|
|
|
// WebSocket相关
|
|
|
|
|
websocket: null,
|
|
|
|
|
websocketUrl: 'ws://119.45.202.115:7181/ws',
|
|
|
|
|
websocketUrl: 'ws://10.42.0.1:7181/ws',
|
|
|
|
|
isWebSocketConnected: false,
|
|
|
|
|
reconnectTimer: null,
|
|
|
|
|
reconnectAttempts: 0,
|
|
|
|
|
maxReconnectAttempts: 5,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 告警队列管理
|
|
|
|
|
alarmQueue: [], // 告警队列
|
|
|
|
|
isProcessingAlarm: false, // 是否正在处理告警
|
|
|
|
|
maxQueueSize: 50, // 最大队列长度
|
|
|
|
|
alarmTimeout: 300000, // 5分钟自动超时
|
|
|
|
|
currentAlarmTimer: null,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 统计信息
|
|
|
|
|
totalAlarmsReceived: 0,
|
|
|
|
|
totalAlarmsProcessed: 0,
|
|
|
|
@ -45,7 +45,7 @@ export default {
|
|
|
|
|
mounted() {
|
|
|
|
|
console.log('App mounted - 初始化全局WebSocket连接')
|
|
|
|
|
this.initGlobalWebSocket()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 监听路由变化,确保WebSocket连接状态
|
|
|
|
|
this.$router.afterEach(() => {
|
|
|
|
|
this.checkWebSocketConnection()
|
|
|
|
@ -119,7 +119,7 @@ export default {
|
|
|
|
|
console.log('WebSocket异常关闭,尝试重连...')
|
|
|
|
|
this.handleReconnect()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 通知所有组件WebSocket已断开
|
|
|
|
|
this.$bus.$emit('websocket-disconnected')
|
|
|
|
|
},
|
|
|
|
@ -158,14 +158,14 @@ export default {
|
|
|
|
|
// 处理告警数据 - 队列管理
|
|
|
|
|
handleAlarmData(alarmData) {
|
|
|
|
|
this.totalAlarmsReceived++
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 检查队列是否已满
|
|
|
|
|
if (this.alarmQueue.length >= this.maxQueueSize) {
|
|
|
|
|
console.warn('告警队列已满,丢弃最旧的告警数据')
|
|
|
|
|
this.alarmQueue.shift() // 移除最旧的告警
|
|
|
|
|
this.totalAlarmsDropped++
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 添加时间戳和优先级
|
|
|
|
|
const enrichedAlarmData = {
|
|
|
|
|
...alarmData,
|
|
|
|
@ -174,16 +174,16 @@ export default {
|
|
|
|
|
priority: this.calculateAlarmPriority(alarmData),
|
|
|
|
|
processed: false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 添加到队列
|
|
|
|
|
this.alarmQueue.push(enrichedAlarmData)
|
|
|
|
|
console.log(`告警已加入队列,当前队列长度: ${this.alarmQueue.length}`)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 如果当前没有在处理告警,开始处理队列
|
|
|
|
|
if (!this.isProcessingAlarm) {
|
|
|
|
|
this.processAlarmQueue()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 打印统计信息
|
|
|
|
|
this.printAlarmStatistics()
|
|
|
|
|
},
|
|
|
|
@ -193,24 +193,24 @@ export default {
|
|
|
|
|
if (this.alarmQueue.length === 0 || this.isProcessingAlarm) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.isProcessingAlarm = true
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 按优先级排序(高优先级在前)
|
|
|
|
|
this.alarmQueue.sort((a, b) => b.priority - a.priority)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 取出最高优先级的告警
|
|
|
|
|
const currentAlarm = this.alarmQueue[0]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
console.log('开始处理告警:', currentAlarm.id, '优先级:', currentAlarm.priority)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 通过事件总线发送告警到Navbar组件
|
|
|
|
|
this.$bus.$emit('websocket-alarm-with-callback', {
|
|
|
|
|
alarm: currentAlarm,
|
|
|
|
|
onProcessed: this.onAlarmProcessed,
|
|
|
|
|
onTimeout: this.onAlarmTimeout
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 设置自动超时
|
|
|
|
|
this.currentAlarmTimer = setTimeout(() => {
|
|
|
|
|
this.onAlarmTimeout(currentAlarm)
|
|
|
|
@ -220,19 +220,19 @@ export default {
|
|
|
|
|
// 告警处理完成回调
|
|
|
|
|
onAlarmProcessed(alarmId, status) {
|
|
|
|
|
console.log('告警处理完成:', alarmId, '状态:', status)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 清除超时定时器
|
|
|
|
|
if (this.currentAlarmTimer) {
|
|
|
|
|
clearTimeout(this.currentAlarmTimer)
|
|
|
|
|
this.currentAlarmTimer = null
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 从队列中移除已处理的告警
|
|
|
|
|
this.alarmQueue = this.alarmQueue.filter(alarm => alarm.id !== alarmId)
|
|
|
|
|
this.totalAlarmsProcessed++
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.isProcessingAlarm = false
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 继续处理队列中的下一个告警
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
this.processAlarmQueue()
|
|
|
|
@ -242,13 +242,13 @@ export default {
|
|
|
|
|
// 告警超时处理
|
|
|
|
|
onAlarmTimeout(alarm) {
|
|
|
|
|
console.log('告警超时未处理:', alarm.id, '自动标记为稍后处理')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 自动保存为未处理状态
|
|
|
|
|
this.$bus.$emit('websocket-alarm-auto-save', {
|
|
|
|
|
alarm: alarm,
|
|
|
|
|
status: 1 // 1=未处理
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.onAlarmProcessed(alarm.id, 'timeout')
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
@ -260,39 +260,39 @@ export default {
|
|
|
|
|
// 计算告警优先级
|
|
|
|
|
calculateAlarmPriority(alarmData) {
|
|
|
|
|
let priority = 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 基础优先级
|
|
|
|
|
priority += 1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 根据告警规则数量增加优先级
|
|
|
|
|
if (alarmData.alarmRules && alarmData.alarmRules.length > 0) {
|
|
|
|
|
priority += alarmData.alarmRules.length * 2
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 根据告警内容数量增加优先级
|
|
|
|
|
if (alarmData.alarmContents && alarmData.alarmContents.length > 0) {
|
|
|
|
|
priority += alarmData.alarmContents.length
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 根据设备参数的异常程度计算优先级(可以根据具体业务逻辑调整)
|
|
|
|
|
if (alarmData.deviceParam) {
|
|
|
|
|
// 温度异常
|
|
|
|
|
if (alarmData.deviceParam.temperature &&
|
|
|
|
|
if (alarmData.deviceParam.temperature &&
|
|
|
|
|
(alarmData.deviceParam.temperature > 50 || alarmData.deviceParam.temperature < -20)) {
|
|
|
|
|
priority += 10 // 极端温度高优先级
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 气体浓度异常
|
|
|
|
|
if (alarmData.deviceParam.concentration && alarmData.deviceParam.concentration > 100) {
|
|
|
|
|
priority += 15 // 危险气体浓度最高优先级
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 振动异常
|
|
|
|
|
if (alarmData.deviceParam.vibrationSpeed && alarmData.deviceParam.vibrationSpeed > 50) {
|
|
|
|
|
priority += 8 // 严重振动高优先级
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return priority
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
@ -328,18 +328,18 @@ export default {
|
|
|
|
|
this.websocket.close(1000, '应用关闭')
|
|
|
|
|
this.websocket = null
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 清除定时器
|
|
|
|
|
if (this.reconnectTimer) {
|
|
|
|
|
clearInterval(this.reconnectTimer)
|
|
|
|
|
this.reconnectTimer = null
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (this.currentAlarmTimer) {
|
|
|
|
|
clearTimeout(this.currentAlarmTimer)
|
|
|
|
|
this.currentAlarmTimer = null
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 清空队列
|
|
|
|
|
this.alarmQueue = []
|
|
|
|
|
this.isWebSocketConnected = false
|
|
|
|
|