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

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

@ -23,19 +23,19 @@ export default {
return { return {
// WebSocket // WebSocket
websocket: null, websocket: null,
websocketUrl: 'ws://119.45.202.115:7181/ws', websocketUrl: 'ws://10.42.0.1:7181/ws',
isWebSocketConnected: false, isWebSocketConnected: false,
reconnectTimer: null, reconnectTimer: null,
reconnectAttempts: 0, reconnectAttempts: 0,
maxReconnectAttempts: 5, maxReconnectAttempts: 5,
// //
alarmQueue: [], // alarmQueue: [], //
isProcessingAlarm: false, // isProcessingAlarm: false, //
maxQueueSize: 50, // maxQueueSize: 50, //
alarmTimeout: 300000, // 5 alarmTimeout: 300000, // 5
currentAlarmTimer: null, currentAlarmTimer: null,
// //
totalAlarmsReceived: 0, totalAlarmsReceived: 0,
totalAlarmsProcessed: 0, totalAlarmsProcessed: 0,
@ -45,7 +45,7 @@ export default {
mounted() { mounted() {
console.log('App mounted - 初始化全局WebSocket连接') console.log('App mounted - 初始化全局WebSocket连接')
this.initGlobalWebSocket() this.initGlobalWebSocket()
// WebSocket // WebSocket
this.$router.afterEach(() => { this.$router.afterEach(() => {
this.checkWebSocketConnection() this.checkWebSocketConnection()
@ -119,7 +119,7 @@ export default {
console.log('WebSocket异常关闭尝试重连...') console.log('WebSocket异常关闭尝试重连...')
this.handleReconnect() this.handleReconnect()
} }
// WebSocket // WebSocket
this.$bus.$emit('websocket-disconnected') this.$bus.$emit('websocket-disconnected')
}, },
@ -158,14 +158,14 @@ export default {
// - // -
handleAlarmData(alarmData) { handleAlarmData(alarmData) {
this.totalAlarmsReceived++ this.totalAlarmsReceived++
// //
if (this.alarmQueue.length >= this.maxQueueSize) { if (this.alarmQueue.length >= this.maxQueueSize) {
console.warn('告警队列已满,丢弃最旧的告警数据') console.warn('告警队列已满,丢弃最旧的告警数据')
this.alarmQueue.shift() // this.alarmQueue.shift() //
this.totalAlarmsDropped++ this.totalAlarmsDropped++
} }
// //
const enrichedAlarmData = { const enrichedAlarmData = {
...alarmData, ...alarmData,
@ -174,16 +174,16 @@ export default {
priority: this.calculateAlarmPriority(alarmData), priority: this.calculateAlarmPriority(alarmData),
processed: false processed: false
} }
// //
this.alarmQueue.push(enrichedAlarmData) this.alarmQueue.push(enrichedAlarmData)
console.log(`告警已加入队列,当前队列长度: ${this.alarmQueue.length}`) console.log(`告警已加入队列,当前队列长度: ${this.alarmQueue.length}`)
// //
if (!this.isProcessingAlarm) { if (!this.isProcessingAlarm) {
this.processAlarmQueue() this.processAlarmQueue()
} }
// //
this.printAlarmStatistics() this.printAlarmStatistics()
}, },
@ -193,24 +193,24 @@ export default {
if (this.alarmQueue.length === 0 || this.isProcessingAlarm) { if (this.alarmQueue.length === 0 || this.isProcessingAlarm) {
return return
} }
this.isProcessingAlarm = true this.isProcessingAlarm = true
// //
this.alarmQueue.sort((a, b) => b.priority - a.priority) this.alarmQueue.sort((a, b) => b.priority - a.priority)
// //
const currentAlarm = this.alarmQueue[0] const currentAlarm = this.alarmQueue[0]
console.log('开始处理告警:', currentAlarm.id, '优先级:', currentAlarm.priority) console.log('开始处理告警:', currentAlarm.id, '优先级:', currentAlarm.priority)
// 线Navbar // 线Navbar
this.$bus.$emit('websocket-alarm-with-callback', { this.$bus.$emit('websocket-alarm-with-callback', {
alarm: currentAlarm, alarm: currentAlarm,
onProcessed: this.onAlarmProcessed, onProcessed: this.onAlarmProcessed,
onTimeout: this.onAlarmTimeout onTimeout: this.onAlarmTimeout
}) })
// //
this.currentAlarmTimer = setTimeout(() => { this.currentAlarmTimer = setTimeout(() => {
this.onAlarmTimeout(currentAlarm) this.onAlarmTimeout(currentAlarm)
@ -220,19 +220,19 @@ export default {
// //
onAlarmProcessed(alarmId, status) { onAlarmProcessed(alarmId, status) {
console.log('告警处理完成:', alarmId, '状态:', status) console.log('告警处理完成:', alarmId, '状态:', status)
// //
if (this.currentAlarmTimer) { if (this.currentAlarmTimer) {
clearTimeout(this.currentAlarmTimer) clearTimeout(this.currentAlarmTimer)
this.currentAlarmTimer = null this.currentAlarmTimer = null
} }
// //
this.alarmQueue = this.alarmQueue.filter(alarm => alarm.id !== alarmId) this.alarmQueue = this.alarmQueue.filter(alarm => alarm.id !== alarmId)
this.totalAlarmsProcessed++ this.totalAlarmsProcessed++
this.isProcessingAlarm = false this.isProcessingAlarm = false
// //
setTimeout(() => { setTimeout(() => {
this.processAlarmQueue() this.processAlarmQueue()
@ -242,13 +242,13 @@ export default {
// //
onAlarmTimeout(alarm) { onAlarmTimeout(alarm) {
console.log('告警超时未处理:', alarm.id, '自动标记为稍后处理') console.log('告警超时未处理:', alarm.id, '自动标记为稍后处理')
// //
this.$bus.$emit('websocket-alarm-auto-save', { this.$bus.$emit('websocket-alarm-auto-save', {
alarm: alarm, alarm: alarm,
status: 1 // 1= status: 1 // 1=
}) })
this.onAlarmProcessed(alarm.id, 'timeout') this.onAlarmProcessed(alarm.id, 'timeout')
}, },
@ -260,39 +260,39 @@ export default {
// //
calculateAlarmPriority(alarmData) { calculateAlarmPriority(alarmData) {
let priority = 0 let priority = 0
// //
priority += 1 priority += 1
// //
if (alarmData.alarmRules && alarmData.alarmRules.length > 0) { if (alarmData.alarmRules && alarmData.alarmRules.length > 0) {
priority += alarmData.alarmRules.length * 2 priority += alarmData.alarmRules.length * 2
} }
// //
if (alarmData.alarmContents && alarmData.alarmContents.length > 0) { if (alarmData.alarmContents && alarmData.alarmContents.length > 0) {
priority += alarmData.alarmContents.length priority += alarmData.alarmContents.length
} }
// //
if (alarmData.deviceParam) { if (alarmData.deviceParam) {
// //
if (alarmData.deviceParam.temperature && if (alarmData.deviceParam.temperature &&
(alarmData.deviceParam.temperature > 50 || alarmData.deviceParam.temperature < -20)) { (alarmData.deviceParam.temperature > 50 || alarmData.deviceParam.temperature < -20)) {
priority += 10 // priority += 10 //
} }
// //
if (alarmData.deviceParam.concentration && alarmData.deviceParam.concentration > 100) { if (alarmData.deviceParam.concentration && alarmData.deviceParam.concentration > 100) {
priority += 15 // priority += 15 //
} }
// //
if (alarmData.deviceParam.vibrationSpeed && alarmData.deviceParam.vibrationSpeed > 50) { if (alarmData.deviceParam.vibrationSpeed && alarmData.deviceParam.vibrationSpeed > 50) {
priority += 8 // priority += 8 //
} }
} }
return priority return priority
}, },
@ -328,18 +328,18 @@ export default {
this.websocket.close(1000, '应用关闭') this.websocket.close(1000, '应用关闭')
this.websocket = null this.websocket = null
} }
// //
if (this.reconnectTimer) { if (this.reconnectTimer) {
clearInterval(this.reconnectTimer) clearInterval(this.reconnectTimer)
this.reconnectTimer = null this.reconnectTimer = null
} }
if (this.currentAlarmTimer) { if (this.currentAlarmTimer) {
clearTimeout(this.currentAlarmTimer) clearTimeout(this.currentAlarmTimer)
this.currentAlarmTimer = null this.currentAlarmTimer = null
} }
// //
this.alarmQueue = [] this.alarmQueue = []
this.isWebSocketConnected = false this.isWebSocketConnected = false

Loading…
Cancel
Save