diff --git a/src/api/iot/rule/scene/scene.types.ts b/src/api/iot/rule/scene/scene.types.ts index 5d3d59a46999fc9f4e4e58e7e6a6d176957eabc7..0e41582963aa8b0915eace2bf963be661568f856 100644 --- a/src/api/iot/rule/scene/scene.types.ts +++ b/src/api/iot/rule/scene/scene.types.ts @@ -4,13 +4,18 @@ // 枚举定义 const IotRuleSceneTriggerTypeEnum = { - DEVICE: 1, // 设备触发 - TIMER: 2 // 定时触发 + DEVICE_STATE_UPDATE: 1, // 设备上下线变更 + DEVICE_PROPERTY_POST: 2, // 物模型属性上报 + DEVICE_EVENT_POST: 3, // 设备事件上报 + DEVICE_SERVICE_INVOKE: 4, // 设备服务调用 + TIMER: 100 // 定时触发 } as const const IotRuleSceneActionTypeEnum = { - DEVICE_CONTROL: 1, // 设备执行 - ALERT: 2 // 告警执行 + DEVICE_PROPERTY_SET: 1, // 设备属性设置, + DEVICE_SERVICE_INVOKE: 2, // 设备服务调用 + ALERT_TRIGGER: 100, // 告警触发 + ALERT_RECOVER: 101 // 告警恢复 } as const const IotDeviceMessageTypeEnum = { @@ -89,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(告警恢复时需要) } // 主接口 @@ -122,7 +119,6 @@ export { TriggerConditionParameter, ActionConfig, ActionDeviceControl, - ActionAlert, IotRuleSceneTriggerTypeEnum, IotRuleSceneActionTypeEnum, IotDeviceMessageTypeEnum, diff --git a/src/views/iot/rule/scene/RuleSceneForm.vue b/src/views/iot/rule/scene/RuleSceneForm.vue index 5c0c8e3337b53d40704a4a2743cc959f558b6c89..b79b6b4d489462e7b0374f9b635f70714634105e 100644 --- a/src/views/iot/rule/scene/RuleSceneForm.vue +++ b/src/views/iot/rule/scene/RuleSceneForm.vue @@ -33,17 +33,36 @@ 触发器配置 - - - - - + + + 添加触发器 @@ -77,6 +96,7 @@ import { DICT_TYPE, getIntDictOptions } from '@/utils/dict' import { RuleSceneApi } from '@/api/iot/rule/scene' import DeviceListener from './components/listener/DeviceListener.vue' +import DeviceStateListener from './components/listener/DeviceStateListener.vue' import { CommonStatusEnum } from '@/utils/constants' import { ActionConfig, @@ -117,7 +137,7 @@ const formRef = ref() // 表单 Ref const addTrigger = () => { formData.value.triggers.push({ key: generateUUID(), // 解决组件索引重用 - type: IotRuleSceneTriggerTypeEnum.DEVICE, + type: IotRuleSceneTriggerTypeEnum.DEVICE_PROPERTY_POST, // 默认为物模型属性上报 productKey: '', deviceNames: [], conditions: [ @@ -138,7 +158,7 @@ const removeTrigger = (index: number) => { const addAction = () => { formData.value.actions.push({ key: generateUUID(), // 解决组件索引重用 - type: IotRuleSceneActionTypeEnum.DEVICE_CONTROL + type: IotRuleSceneActionTypeEnum.DEVICE_PROPERTY_SET } as ActionConfig) } /** 移除执行器 */ diff --git a/src/views/iot/rule/scene/components/action/ActionExecutor.vue b/src/views/iot/rule/scene/components/action/ActionExecutor.vue index a3644c49ce2c97a913d742ccb2726dae45fcf9bf..0eb8d3a5bff34ecb8ba9e53687eeb599c8d51acc 100644 --- a/src/views/iot/rule/scene/components/action/ActionExecutor.vue +++ b/src/views/iot/rule/scene/components/action/ActionExecutor.vue @@ -19,19 +19,13 @@ /> -
+
产品 {{ product ? product.name : '选择产品' }}
-
+
设备 {{ isEmpty(deviceList) ? '选择设备' : deviceList.map((d) => d.deviceName).join(',') }} @@ -47,7 +41,8 @@ - +
+ +
+ + 触发告警通知,系统将自动发送告警信息 +
+ + +
+
+ + 恢复指定的告警配置状态 +
+
+ + + + + +
+
+
@@ -80,11 +106,10 @@ import { DICT_TYPE, getIntDictOptions } from '@/utils/dict' import ProductTableSelect from '@/views/iot/product/product/components/ProductTableSelect.vue' import DeviceTableSelect from '@/views/iot/device/device/components/DeviceTableSelect.vue' import DeviceControlAction from './DeviceControlAction.vue' -import AlertAction from './AlertAction.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 { - ActionAlert, ActionConfig, ActionDeviceControl, IotDeviceMessageIdentifierEnum, @@ -101,29 +126,56 @@ const actionConfig = useVModel(props, 'modelValue', emits) as Ref const message = useMessage() +/** 计算属性:判断是否为设备相关执行类型 */ +const isDeviceAction = computed(() => { + return [ + IotRuleSceneActionTypeEnum.DEVICE_PROPERTY_SET, + IotRuleSceneActionTypeEnum.DEVICE_SERVICE_INVOKE + ].includes(actionConfig.value.type as any) +}) + +/** 计算属性:判断是否为告警相关执行类型 */ +const isAlertAction = computed(() => { + return [ + IotRuleSceneActionTypeEnum.ALERT_TRIGGER, + IotRuleSceneActionTypeEnum.ALERT_RECOVER + ].includes(actionConfig.value.type as any) +}) + /** 初始化执行器结构 */ const initActionConfig = () => { if (!actionConfig.value) { - actionConfig.value = { type: IotRuleSceneActionTypeEnum.DEVICE_CONTROL } as ActionConfig + actionConfig.value = { type: IotRuleSceneActionTypeEnum.DEVICE_PROPERTY_SET } as ActionConfig } // 设备控制执行器初始化 - if ( - actionConfig.value.type === IotRuleSceneActionTypeEnum.DEVICE_CONTROL && - !actionConfig.value.deviceControl - ) { + if (isDeviceAction.value && !actionConfig.value.deviceControl) { actionConfig.value.deviceControl = { productKey: '', deviceNames: [], - type: IotDeviceMessageTypeEnum.PROPERTY, - identifier: IotDeviceMessageIdentifierEnum.PROPERTY_SET, + type: + actionConfig.value.type === IotRuleSceneActionTypeEnum.DEVICE_PROPERTY_SET + ? IotDeviceMessageTypeEnum.PROPERTY + : IotDeviceMessageTypeEnum.SERVICE, + identifier: + actionConfig.value.type === IotRuleSceneActionTypeEnum.DEVICE_PROPERTY_SET + ? IotDeviceMessageIdentifierEnum.PROPERTY_SET + : IotDeviceMessageIdentifierEnum.SERVICE_INVOKE, data: {} } as ActionDeviceControl } // 告警执行器初始化 - if (actionConfig.value.type === IotRuleSceneActionTypeEnum.ALERT && !actionConfig.value.alert) { - actionConfig.value.alert = {} as ActionAlert + if (isAlertAction.value) { + 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 + } + } } } @@ -133,6 +185,10 @@ const deviceTableSelectRef = ref>() const product = ref() const deviceList = ref([]) +/** 告警配置相关 */ +const alertConfigList = ref([]) +const alertConfigLoading = ref(false) + /** 处理选择产品 */ const handleSelectProduct = () => { productTableSelectRef.value?.open() @@ -168,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 d2fa7e4547a3af99ea6cdd77a3b0a65196821dca..0000000000000000000000000000000000000000 --- a/src/views/iot/rule/scene/components/action/AlertAction.vue +++ /dev/null @@ -1,91 +0,0 @@ - - - diff --git a/src/views/iot/rule/scene/components/action/DeviceControlAction.vue b/src/views/iot/rule/scene/components/action/DeviceControlAction.vue index f3db4583d4fc0b6659ab95be6d4b3e21c832bdd4..9e0b4b65012cbd55f0790afa6bfd438a376631fb 100644 --- a/src/views/iot/rule/scene/components/action/DeviceControlAction.vue +++ b/src/views/iot/rule/scene/components/action/DeviceControlAction.vue @@ -1,11 +1,5 @@