refactor(JDAirPort.Ems.UI): 修改 WebSocket 连接地址并优化告警处理逻辑

- 更新 WebSocket 连接地址为局域网 IP
- 优化告警数据处理和优先级计算逻辑
- 调整 JWT令牌有效期配置
boardTest
zch 3 weeks ago
parent b2c4446745
commit 5b04aff359

@ -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

Loading…
Cancel
Save