From 52827ca78aed2056dfeb455ee6412845648e2ff3 Mon Sep 17 00:00:00 2001 From: puhui999 Date: Sat, 5 Jul 2025 22:05:44 +0800 Subject: [PATCH] =?UTF-8?q?perf=EF=BC=9A=E3=80=90IoT=20=E7=89=A9=E8=81=94?= =?UTF-8?q?=E7=BD=91=E3=80=91=E5=9C=BA=E6=99=AF=E8=81=94=E5=8A=A8=E5=91=8A?= =?UTF-8?q?=E8=AD=A6=E5=91=8A=E8=AD=A6=E6=81=A2=E5=A4=8D=E9=9C=80=E8=A6=81?= =?UTF-8?q?=E9=80=89=E6=8B=A9=E5=91=8A=E8=AD=A6=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/iot/rule/scene/scene.types.ts | 11 +- .../components/action/ActionExecutor.vue | 89 +++++++++++---- .../scene/components/action/AlertAction.vue | 108 ------------------ 3 files changed, 69 insertions(+), 139 deletions(-) delete mode 100644 src/views/iot/rule/scene/components/action/AlertAction.vue diff --git a/src/api/iot/rule/scene/scene.types.ts b/src/api/iot/rule/scene/scene.types.ts index bfc51e8d0..0e4158296 100644 --- a/src/api/iot/rule/scene/scene.types.ts +++ b/src/api/iot/rule/scene/scene.types.ts @@ -94,20 +94,12 @@ interface ActionDeviceControl { data: Record // 具体数据 } -// 告警执行配置 -interface ActionAlert { - receiveType: number // 接收方式 - phoneNumbers?: string[] // 手机号列表 - emails?: string[] // 邮箱列表 - content: string // 通知内容 -} - // 执行器配置 interface ActionConfig { key: any // 解决组件索引重用 TODO @puhui999:看看有没更好的解决方案呢。 type: number // 执行类型 deviceControl?: ActionDeviceControl // 设备控制 - alert?: ActionAlert // 告警执行 + alertConfigId?: number // 告警配置ID(告警恢复时需要) } // 主接口 @@ -127,7 +119,6 @@ export { TriggerConditionParameter, ActionConfig, ActionDeviceControl, - ActionAlert, IotRuleSceneTriggerTypeEnum, IotRuleSceneActionTypeEnum, IotDeviceMessageTypeEnum, diff --git a/src/views/iot/rule/scene/components/action/ActionExecutor.vue b/src/views/iot/rule/scene/components/action/ActionExecutor.vue index d945e9938..0eb8d3a5b 100644 --- a/src/views/iot/rule/scene/components/action/ActionExecutor.vue +++ b/src/views/iot/rule/scene/components/action/ActionExecutor.vue @@ -49,12 +49,42 @@ @update:model-value="(val) => (actionConfig.deviceControl = val)" /> - -
- - - {{ getAlertActionDescription(actionConfig.type) }} - + +
+ +
+ + 触发告警通知,系统将自动发送告警信息 +
+ + +
+
+ + 恢复指定的告警配置状态 +
+
+ + + + + +
+
@@ -78,6 +108,7 @@ import DeviceTableSelect from '@/views/iot/device/device/components/DeviceTableS import DeviceControlAction from './DeviceControlAction.vue' import { ProductApi, ProductVO } from '@/api/iot/product/product' import { DeviceApi, DeviceVO } from '@/api/iot/device/device' +import { AlertConfigApi, AlertConfig } from '@/api/iot/alert/config' import { ActionConfig, ActionDeviceControl, @@ -111,18 +142,6 @@ const isAlertAction = computed(() => { ].includes(actionConfig.value.type as any) }) -/** 获取告警执行器描述文本 */ -const getAlertActionDescription = (actionType: number) => { - switch (actionType) { - case IotRuleSceneActionTypeEnum.ALERT_TRIGGER: - return '触发告警通知,系统将自动发送告警信息' - case IotRuleSceneActionTypeEnum.ALERT_RECOVER: - return '恢复告警状态,系统将自动发送恢复通知' - default: - return '告警相关操作,无需额外配置' - } -} - /** 初始化执行器结构 */ const initActionConfig = () => { if (!actionConfig.value) { @@ -146,9 +165,17 @@ const initActionConfig = () => { } as ActionDeviceControl } - // 告警执行器初始化 - 无需额外配置,清空 alert 配置 + // 告警执行器初始化 if (isAlertAction.value) { - actionConfig.value.alert = undefined + if (actionConfig.value.type === IotRuleSceneActionTypeEnum.ALERT_TRIGGER) { + // 告警触发 - 无需额外配置 + actionConfig.value.alertConfigId = undefined + } else if (actionConfig.value.type === IotRuleSceneActionTypeEnum.ALERT_RECOVER) { + // 告警恢复 - 需要选择告警配置 + if (!actionConfig.value.alertConfigId) { + actionConfig.value.alertConfigId = undefined + } + } } } @@ -158,6 +185,10 @@ const deviceTableSelectRef = ref>() const product = ref() const deviceList = ref([]) +/** 告警配置相关 */ +const alertConfigList = ref([]) +const alertConfigLoading = ref(false) + /** 处理选择产品 */ const handleSelectProduct = () => { productTableSelectRef.value?.open() @@ -193,11 +224,27 @@ const handleDeviceSelect = (val: DeviceVO[]) => { } } +/** 获取告警配置列表 */ +const getAlertConfigList = async () => { + try { + alertConfigLoading.value = true + alertConfigList.value = await AlertConfigApi.getSimpleAlertConfigList() + } catch (error) { + console.error('获取告警配置列表失败:', error) + } finally { + alertConfigLoading.value = false + } +} + /** 监听执行类型变化,初始化对应配置 */ watch( () => actionConfig.value.type, - () => { + (newType) => { initActionConfig() + // 如果是告警恢复类型,需要加载告警配置列表 + if (newType === IotRuleSceneActionTypeEnum.ALERT_RECOVER) { + getAlertConfigList() + } }, { immediate: true } ) diff --git a/src/views/iot/rule/scene/components/action/AlertAction.vue b/src/views/iot/rule/scene/components/action/AlertAction.vue deleted file mode 100644 index ff964dc4c..000000000 --- a/src/views/iot/rule/scene/components/action/AlertAction.vue +++ /dev/null @@ -1,108 +0,0 @@ - - -