diff --git a/src/components/map/controls/VehicleMovementControlRefactored.vue b/src/components/map/controls/VehicleMovementControlRefactored.vue index 5ab0af4..7df7229 100644 --- a/src/components/map/controls/VehicleMovementControlRefactored.vue +++ b/src/components/map/controls/VehicleMovementControlRefactored.vue @@ -14,12 +14,11 @@ /> - + maxAlarmCount) { + alarmList.value = alarmList.value.slice(0, maxAlarmCount); + } + + // 如果告警面板已打开,更新告警面板 + updateAlarmNotification(); + + return completeAlarm.id; // 返回告警ID,便于后续引用 +} + +// 更新告警 +function updateAlarm(alarmId, updates) { + const index = alarmList.value.findIndex(alarm => alarm.id === alarmId); + if (index !== -1) { + alarmList.value[index] = { ...alarmList.value[index], ...updates }; + updateAlarmNotification(); + return true; + } + return false; +} + +// 删除告警 +function removeAlarm(alarmId) { + const index = alarmList.value.findIndex(alarm => alarm.id === alarmId); + if (index !== -1) { + alarmList.value.splice(index, 1); + updateAlarmNotification(); + return true; + } + return false; +} + +// 清空告警列表 +function clearAlarms() { + alarmList.value = []; + updateAlarmNotification(); +} + +// 更新告警面板 +function updateAlarmNotification() { + if (alarmNotification.value) { + alarmNotification.value.updateAlarmList(alarmList.value); + } +} + +// 切换告警面板显示状态 +function toggleAlarmNotification() { + alarmVisible.value = !alarmVisible.value; + if (alarmNotification.value) { + if (alarmVisible.value) { + alarmNotification.value.show(); + } else { + alarmNotification.value.hide(); + } + } +} + +// 处理告警面板关闭事件 +function handleAlarmClose() { + alarmVisible.value = false; + console.log('告警面板已关闭'); +} + +// 格式化时间范围,例如:T10:20-10:25 +function formatTimeRange(date, durationMinutes = 5) { + const startTime = new Date(date); + const endTime = new Date(date); + endTime.setMinutes(endTime.getMinutes() + durationMinutes); + + const startHour = startTime.getHours().toString().padStart(2, '0'); + const startMinute = startTime.getMinutes().toString().padStart(2, '0'); + const endHour = endTime.getHours().toString().padStart(2, '0'); + const endMinute = endTime.getMinutes().toString().padStart(2, '0'); + + return `T${startHour}:${startMinute}-${endHour}:${endMinute}`; +} + +// 格式化日期时间,例如:2025-03-19 10:30 +function formatDateTime(date) { + const year = date.getFullYear(); + const month = (date.getMonth() + 1).toString().padStart(2, '0'); + const day = date.getDate().toString().padStart(2, '0'); + const hour = date.getHours().toString().padStart(2, '0'); + const minute = date.getMinutes().toString().padStart(2, '0'); + + return `${year}-${month}-${day} ${hour}:${minute}`; +} + // 处理告警显示 function handleAlertShow({ message, type, duration = 5000 }) { if (alertTimer) { @@ -814,6 +926,17 @@ function handlePathConflictAlert(payload) { const warningMessage = `预警:${message}`; showAlert(warningMessage, 'warning', 8000); + // 添加到告警列表 + addAlarm({ + carId: vehicleId, + carType: vehicles.value[vehicleId]?.type || '未知类型', + time: `${formatTimeRange(new Date())}与${otherVehicleId}发生冲`, + description: '突预警', + level: 'medium', + type: 'car', + rawData: payload + }); + // 在地图上标记该车辆的预警状态 if (vehicles.value[vehicleId]) { vehicles.value[vehicleId].warning = true; @@ -834,6 +957,17 @@ function handlePathConflictAlert(payload) { const alertMessage = `⚠️ 告警:${message}`; showAlert(alertMessage, 'alarm', 10000); + // 添加到告警列表 + addAlarm({ + carId: vehicleId, + carType: vehicles.value[vehicleId]?.type || '未知类型', + time: `${formatTimeRange(new Date())}与${otherVehicleId}发生冲`, + description: '突告警', + level: 'high', + type: 'car', + rawData: payload + }); + // 在地图上标记该车辆的告警状态 if (vehicles.value[vehicleId]) { vehicles.value[vehicleId].alarm = true; @@ -906,6 +1040,20 @@ function handleSpeedViolation(vehicleId, payload) { // 显示超速告警提示 showAlert(`⚠️ 超速告警:${vehicleId} ${description}`, 'warning', 8000); + // 添加到告警列表,提供更详细的信息 + addAlarm({ + carId: vehicleId, + carType: vehicles.value[vehicleId]?.type || '未知类型', + time: `${formatTimeRange(new Date())}超速行驶`, + description: `,速度达到${actualValue}km/h`, + level: actualValue > limitValue * 1.5 ? 'high' : 'medium', // 超速50%以上为高级别告警 + type: 'speed', + limitValue: limitValue, + actualValue: actualValue, + ruleName: ruleName, + rawData: payload + }); + // 在地图上标记该车辆的超速状态 if (vehicles.value[vehicleId]) { // 避免重复设置超速状态导致闪烁 @@ -1018,6 +1166,17 @@ function handleUnauthorizedEntry(vehicleId, payload) { // 显示越界告警提示 showAlert(`⚠️ 越界告警:${vehicleId} ${description}`, 'critical', 10000); + // 添加到告警列表 + addAlarm({ + carId: vehicleId, + carType: vehicles.value[vehicleId]?.type || '未知类型', + time: `${formatTimeRange(new Date())}越界`, + description: '越界告警', + level: 'high', + type: 'access', + rawData: payload + }); + // 在地图上标记该车辆的越界状态 if (vehicles.value[vehicleId]) { vehicles.value[vehicleId].critical = true; @@ -1496,6 +1655,40 @@ defineExpose({ removeAircraftRoute(flightNo) { return removeAircraftRoute(flightNo); + }, + + // 告警通知相关方法 + showAlarmNotification(message, type, duration) { + if (alarmNotification.value) { + alarmNotification.value.showNotification(message, type, duration); + } + }, + hideAlarmNotification() { + if (alarmNotification.value) { + alarmNotification.value.hideNotification(); + } + }, + handleAlarmClose() { + // 告警通知组件关闭时,可以在这里执行一些清理或状态重置 + console.log('告警通知组件已关闭'); + }, + addAlarm(alarm) { + return addAlarm(alarm); + }, + updateAlarm(alarmId, updates) { + return updateAlarm(alarmId, updates); + }, + removeAlarm(alarmId) { + return removeAlarm(alarmId); + }, + clearAlarms() { + return clearAlarms(); + }, + updateAlarmNotification() { + return updateAlarmNotification(); + }, + toggleAlarmNotification() { + return toggleAlarmNotification(); } }); diff --git a/src/components/map/info/AlarmNotification.vue b/src/components/map/info/AlarmNotification.vue index 75c31af..030ce1d 100644 --- a/src/components/map/info/AlarmNotification.vue +++ b/src/components/map/info/AlarmNotification.vue @@ -72,62 +72,7 @@ import { ref, computed } from 'vue'; const activeTab = ref('all'); // 模拟报警数据 -const alarmList = ref([ - { - carId: 'QN001', - carType: '驱鸟车', - time: 'T10:20—10: 25与JD5949发生冲', - description: '突告警', - date: '2025-03-19 10:30', - level: 'high', - type: 'car' - }, - { - carId: 'QN001', - carType: '驱鸟车', - time: 'T10:20—10: 25与JD5949发生冲', - description: '突告警', - date: '2025-03-19 10:30', - level: 'high', - type: 'car' - }, - { - carId: 'QN001', - carType: '驱鸟车', - time: 'T10:20—10: 25闯入电子围', - description: '栏监控区域,发生告警', - date: '2025-03-19 10:30', - level: 'medium', - type: 'report' - }, - { - carId: 'QN001', - carType: '驱鸟车', - time: 'T10:20—10: 25闯入电子围', - description: '栏监控区域,发生告警', - date: '2025-03-19 10:30', - level: 'medium', - type: 'report' - }, - { - carId: 'QN002', - carType: '牵引车', - time: 'T10:15—10: 18超速行驶', - description: ',速度达到85km/h', - date: '2025-03-19 10:18', - level: 'high', - type: 'speed' - }, - { - carId: 'QN003', - carType: '摆渡车', - time: 'T10:22—10: 25超速行驶', - description: ',速度达到78km/h', - date: '2025-03-19 10:25', - level: 'medium', - type: 'speed' - } -]); +const alarmList = ref([]); // 根据当前选中的标签页过滤告警数据 const filteredAlarms = computed(() => {