diff --git a/src/views/iot/rule/scene/form/RuleSceneForm.vue b/src/views/iot/rule/scene/form/RuleSceneForm.vue index 0a96dce33..09a316576 100644 --- a/src/views/iot/rule/scene/form/RuleSceneForm.vue +++ b/src/views/iot/rule/scene/form/RuleSceneForm.vue @@ -63,9 +63,12 @@ const emit = defineEmits<{ (e: 'success'): void }>() -const drawerVisible = useVModel(props, 'modelValue', emit) // 是否可见 +const drawerVisible = useVModel(props, 'modelValue', emit) // 抽屉显示状态 -/** 创建默认的表单数据 */ +/** + * 创建默认的表单数据 + * @returns 默认表单数据对象 + */ const createDefaultFormData = (): IotSceneRule => { return { name: '', @@ -87,10 +90,15 @@ const createDefaultFormData = (): IotSceneRule => { } } -// 表单数据和状态 -const formRef = ref() -const formData = ref(createDefaultFormData()) -// 自定义校验器 +const formRef = ref() // 表单引用 +const formData = ref(createDefaultFormData()) // 表单数据 + +/** + * 触发器校验器 + * @param _rule 校验规则(未使用) + * @param value 校验值 + * @param callback 回调函数 + */ const validateTriggers = (_rule: any, value: any, callback: any) => { if (!value || !Array.isArray(value) || value.length === 0) { callback(new Error('至少需要一个触发器')) @@ -142,6 +150,12 @@ const validateTriggers = (_rule: any, value: any, callback: any) => { callback() } +/** + * 执行器校验器 + * @param _rule 校验规则(未使用) + * @param value 校验值 + * @param callback 回调函数 + */ const validateActions = (_rule: any, value: any, callback: any) => { if (!value || !Array.isArray(value) || value.length === 0) { callback(new Error('至少需要一个执行器')) @@ -201,6 +215,7 @@ const validateActions = (_rule: any, value: any, callback: any) => { } const formRules = reactive({ + // 表单校验规则 name: [ { required: true, message: '场景名称不能为空', trigger: 'blur' }, { type: 'string', min: 1, max: 50, message: '场景名称长度应在1-50个字符之间', trigger: 'blur' } @@ -221,13 +236,15 @@ const formRules = reactive({ actions: [{ required: true, validator: validateActions, trigger: 'change' }] }) -const submitLoading = ref(false) +const submitLoading = ref(false) // 提交加载状态 +const isEdit = ref(false) // 是否为编辑模式 -// 计算属性 -const isEdit = ref(false) +// 计算属性:抽屉标题 const drawerTitle = computed(() => (isEdit.value ? '编辑场景联动规则' : '新增场景联动规则')) -/** 提交表单 */ +/** + * 提交表单 + */ const handleSubmit = async () => { // 校验表单 if (!formRef.value) return @@ -258,11 +275,16 @@ const handleSubmit = async () => { } } +/** + * 处理抽屉关闭事件 + */ const handleClose = () => { drawerVisible.value = false } -/** 初始化表单数据 */ +/** + * 初始化表单数据 + */ const initFormData = () => { if (props.ruleScene) { // 编辑模式:数据结构已对齐,直接使用后端数据 diff --git a/src/views/iot/rule/scene/form/configs/ConditionConfig.vue b/src/views/iot/rule/scene/form/configs/ConditionConfig.vue index 41e82d5a2..b712bbc9f 100644 --- a/src/views/iot/rule/scene/form/configs/ConditionConfig.vue +++ b/src/views/iot/rule/scene/form/configs/ConditionConfig.vue @@ -181,9 +181,8 @@ const emit = defineEmits<{ const condition = useVModel(props, 'modelValue', emit) -// 状态 -const propertyType = ref('string') -const propertyConfig = ref(null) +const propertyType = ref('string') // 属性类型 +const propertyConfig = ref(null) // 属性配置 // 计算属性:判断是否为设备相关条件 const isDeviceCondition = computed(() => { @@ -193,17 +192,29 @@ const isDeviceCondition = computed(() => { ) }) -// 事件处理 +/** + * 更新条件字段 + * @param field 字段名 + * @param value 字段值 + */ const updateConditionField = (field: keyof TriggerCondition, value: any) => { ;(condition.value as any)[field] = value emit('update:modelValue', condition.value) } +/** + * 更新整个条件对象 + * @param newCondition 新的条件对象 + */ const updateCondition = (newCondition: TriggerCondition) => { condition.value = newCondition emit('update:modelValue', condition.value) } +/** + * 处理条件类型变化事件 + * @param type 条件类型 + */ const handleConditionTypeChange = (type: number) => { // 清理不相关的字段 if (type === IotRuleSceneTriggerConditionTypeEnum.DEVICE_STATUS) { @@ -234,17 +245,29 @@ const handleConditionTypeChange = (type: number) => { condition.value.param = '' } +/** + * 处理产品变化事件 + * @param _ 产品ID(未使用) + */ const handleProductChange = (_: number) => { // 产品变化时清空设备和属性 condition.value.deviceId = undefined condition.value.identifier = '' } +/** + * 处理设备变化事件 + * @param _ 设备ID(未使用) + */ const handleDeviceChange = (_: number) => { // 设备变化时清空属性 condition.value.identifier = '' } +/** + * 处理属性变化事件 + * @param propertyInfo 属性信息对象 + */ const handlePropertyChange = (propertyInfo: { type: string; config: any }) => { propertyType.value = propertyInfo.type propertyConfig.value = propertyInfo.config @@ -254,6 +277,9 @@ const handlePropertyChange = (propertyInfo: { type: string; config: any }) => { condition.value.param = '' } +/** + * 处理操作符变化事件 + */ const handleOperatorChange = () => { // 重置值 condition.value.param = '' diff --git a/src/views/iot/rule/scene/form/configs/CurrentTimeConditionConfig.vue b/src/views/iot/rule/scene/form/configs/CurrentTimeConditionConfig.vue index 79ccf42b4..6d591b55c 100644 --- a/src/views/iot/rule/scene/form/configs/CurrentTimeConditionConfig.vue +++ b/src/views/iot/rule/scene/form/configs/CurrentTimeConditionConfig.vue @@ -154,7 +154,7 @@ const timeOperatorOptions = [ } ] -// 计算属性 +// 计算属性:是否需要时间输入 const needsTimeInput = computed(() => { const timeOnlyOperators = [ IotRuleSceneTriggerTimeOperatorEnum.BEFORE_TIME.value, @@ -165,15 +165,21 @@ const needsTimeInput = computed(() => { return timeOnlyOperators.includes(condition.value.operator) }) +// 计算属性:是否需要日期输入 const needsDateInput = computed(() => { return false // 暂时不支持日期输入,只支持时间 }) +// 计算属性:是否需要第二个时间输入 const needsSecondTimeInput = computed(() => { return condition.value.operator === IotRuleSceneTriggerTimeOperatorEnum.BETWEEN_TIME.value }) -// 事件处理 +/** + * 更新条件字段 + * @param field 字段名 + * @param value 字段值 + */ const updateConditionField = (field: keyof TriggerCondition, value: any) => { condition.value[field] = value } @@ -183,7 +189,8 @@ watch( () => condition.value.operator, (newOperator) => { if (newOperator === IotRuleSceneTriggerTimeOperatorEnum.TODAY.value) { - ;(condition.value as any).timeValue = undefined(condition.value as any).timeValue2 = undefined + ;(condition.value as any).timeValue = undefined + ;(condition.value as any).timeValue2 = undefined } else if (!needsSecondTimeInput.value) { ;(condition.value as any).timeValue2 = undefined } diff --git a/src/views/iot/rule/scene/form/configs/DeviceControlConfig.vue b/src/views/iot/rule/scene/form/configs/DeviceControlConfig.vue index a90c7874b..e1f5068ce 100644 --- a/src/views/iot/rule/scene/form/configs/DeviceControlConfig.vue +++ b/src/views/iot/rule/scene/form/configs/DeviceControlConfig.vue @@ -102,7 +102,6 @@ const emit = defineEmits<{ const action = useVModel(props, 'modelValue', emit) -// 简化后的状态变量 const thingModelProperties = ref([]) // 物模型属性列表 const loadingThingModel = ref(false) // 物模型加载状态 const selectedService = ref(null) // 选中的服务对象 @@ -125,13 +124,13 @@ const paramsValue = computed({ } }) +// 计算属性:是否为属性设置类型 const isPropertySetAction = computed(() => { - // 是否为属性设置类型 return action.value.type === IotRuleSceneActionTypeEnum.DEVICE_PROPERTY_SET }) +// 计算属性:是否为服务调用类型 const isServiceInvokeAction = computed(() => { - // 是否为服务调用类型 return action.value.type === IotRuleSceneActionTypeEnum.DEVICE_SERVICE_INVOKE }) @@ -314,8 +313,7 @@ const getDefaultValueForParam = (param: any) => { } } -// 防止重复初始化的标志 -const isInitialized = ref(false) +const isInitialized = ref(false) // 防止重复初始化的标志 /** * 初始化组件数据 @@ -347,7 +345,7 @@ onMounted(() => { initializeComponent() }) -// 只监听关键字段的变化,避免深度监听导致的性能问题 +// 监听关键字段的变化,避免深度监听导致的性能问题 watch( () => [action.value.productId, action.value.type, action.value.identifier], async ([newProductId, , newIdentifier], [oldProductId, , oldIdentifier]) => { diff --git a/src/views/iot/rule/scene/form/configs/DeviceTriggerConfig.vue b/src/views/iot/rule/scene/form/configs/DeviceTriggerConfig.vue index c307578e2..1cba70e7d 100644 --- a/src/views/iot/rule/scene/form/configs/DeviceTriggerConfig.vue +++ b/src/views/iot/rule/scene/form/configs/DeviceTriggerConfig.vue @@ -185,21 +185,29 @@ const emit = defineEmits<{ const trigger = useVModel(props, 'modelValue', emit) -// 配置常量 const maxSubGroups = 3 // 最多 3 个子条件组 const maxConditionsPerGroup = 3 // 每组最多 3 个条件 -// 事件处理 +/** + * 更新条件 + * @param condition 条件对象 + */ const updateCondition = (condition: Trigger) => { trigger.value = condition } +/** + * 处理触发器类型变化事件 + * @param type 触发器类型 + */ const handleTriggerTypeChange = (type: number) => { trigger.value.type = type emit('trigger-type-change', type) } -// 条件组相关方法 +/** + * 添加子条件组 + */ const addSubGroup = async () => { if (!trigger.value.conditionGroups) { trigger.value.conditionGroups = [] @@ -217,18 +225,30 @@ const addSubGroup = async () => { } } +/** + * 移除子条件组 + * @param index 子条件组索引 + */ const removeSubGroup = (index: number) => { if (trigger.value.conditionGroups) { trigger.value.conditionGroups.splice(index, 1) } } +/** + * 更新子条件组 + * @param index 子条件组索引 + * @param subGroup 子条件组数据 + */ const updateSubGroup = (index: number, subGroup: any) => { if (trigger.value.conditionGroups) { trigger.value.conditionGroups[index] = subGroup } } +/** + * 移除整个条件组 + */ const removeConditionGroup = () => { trigger.value.conditionGroups = undefined } diff --git a/src/views/iot/rule/scene/form/configs/MainConditionInnerConfig.vue b/src/views/iot/rule/scene/form/configs/MainConditionInnerConfig.vue index 780696d62..5d9e07a93 100644 --- a/src/views/iot/rule/scene/form/configs/MainConditionInnerConfig.vue +++ b/src/views/iot/rule/scene/form/configs/MainConditionInnerConfig.vue @@ -211,12 +211,11 @@ const emit = defineEmits<{ (e: 'trigger-type-change', value: number): void }>() -// 响应式数据 const condition = useVModel(props, 'modelValue', emit) -const propertyType = ref('') -const propertyConfig = ref(null) +const propertyType = ref('') // 属性类型 +const propertyConfig = ref(null) // 属性配置 -// 计算属性 +// 计算属性:是否为设备属性触发器 const isDevicePropertyTrigger = computed(() => { return ( props.triggerType === IotRuleSceneTriggerTypeEnum.DEVICE_PROPERTY_POST || @@ -225,11 +224,12 @@ const isDevicePropertyTrigger = computed(() => { ) }) +// 计算属性:是否为设备状态触发器 const isDeviceStatusTrigger = computed(() => { return props.triggerType === IotRuleSceneTriggerTypeEnum.DEVICE_STATE_UPDATE }) -// 服务配置 - 用于 JsonParamsInput +// 计算属性:服务配置 - 用于 JsonParamsInput const serviceConfig = computed(() => { if ( propertyConfig.value && @@ -245,7 +245,7 @@ const serviceConfig = computed(() => { return undefined }) -// 事件配置 - 用于 JsonParamsInput +// 计算属性:事件配置 - 用于 JsonParamsInput const eventConfig = computed(() => { if (propertyConfig.value && props.triggerType === IotRuleSceneTriggerTypeEnum.DEVICE_EVENT_POST) { return { @@ -258,30 +258,47 @@ const eventConfig = computed(() => { return undefined }) -// 使用标准化的选项获取函数 -const triggerTypeOptions = getTriggerTypeOptions() -const deviceStatusChangeOptions = getDeviceStatusChangeOptions() +const triggerTypeOptions = getTriggerTypeOptions() // 触发器类型选项 +const deviceStatusChangeOptions = getDeviceStatusChangeOptions() // 设备状态变化选项 -// 事件处理 +/** + * 更新条件字段 + * @param field 字段名 + * @param value 字段值 + */ const updateConditionField = (field: keyof Trigger, value: any) => { ;(condition.value as any)[field] = value } +/** + * 处理触发器类型变化事件 + * @param type 触发器类型 + */ const handleTriggerTypeChange = (type: number) => { emit('trigger-type-change', type) } +/** + * 处理产品变化事件 + */ const handleProductChange = () => { // 产品变化时清空设备和属性 condition.value.deviceId = undefined condition.value.identifier = '' } +/** + * 处理设备变化事件 + */ const handleDeviceChange = () => { // 设备变化时清空属性 condition.value.identifier = '' } +/** + * 处理属性变化事件 + * @param propertyInfo 属性信息对象 + */ const handlePropertyChange = (propertyInfo: any) => { if (propertyInfo) { propertyType.value = propertyInfo.type @@ -297,6 +314,9 @@ const handlePropertyChange = (propertyInfo: any) => { } } +/** + * 处理操作符变化事件 + */ const handleOperatorChange = () => { // 操作符变化处理 } diff --git a/src/views/iot/rule/scene/form/configs/SubConditionGroupConfig.vue b/src/views/iot/rule/scene/form/configs/SubConditionGroupConfig.vue index 710af0004..cb8f2762a 100644 --- a/src/views/iot/rule/scene/form/configs/SubConditionGroupConfig.vue +++ b/src/views/iot/rule/scene/form/configs/SubConditionGroupConfig.vue @@ -103,10 +103,11 @@ const emit = defineEmits<{ const subGroup = useVModel(props, 'modelValue', emit) -// 配置常量 -const maxConditions = computed(() => props.maxConditions || 3) +const maxConditions = computed(() => props.maxConditions || 3) // 最大条件数量 -// 事件处理 +/** + * 添加条件 + */ const addCondition = async () => { // 确保 subGroup.value 是一个数组 if (!subGroup.value) { @@ -134,12 +135,21 @@ const addCondition = async () => { } } +/** + * 移除条件 + * @param index 条件索引 + */ const removeCondition = (index: number) => { if (subGroup.value) { subGroup.value.splice(index, 1) } } +/** + * 更新条件 + * @param index 条件索引 + * @param condition 条件对象 + */ const updateCondition = (index: number, condition: TriggerCondition) => { if (subGroup.value) { subGroup.value[index] = condition diff --git a/src/views/iot/rule/scene/form/inputs/JsonParamsInput.vue b/src/views/iot/rule/scene/form/inputs/JsonParamsInput.vue index b8bfcb314..ae93feed1 100644 --- a/src/views/iot/rule/scene/form/inputs/JsonParamsInput.vue +++ b/src/views/iot/rule/scene/form/inputs/JsonParamsInput.vue @@ -204,11 +204,10 @@ const localValue = useVModel(props, 'modelValue', emit, { defaultValue: '' }) -// 状态 -const paramsJson = ref('') -const jsonError = ref('') +const paramsJson = ref('') // JSON参数字符串 +const jsonError = ref('') // JSON验证错误信息 -// 计算属性 +// 计算属性:是否有配置 const hasConfig = computed(() => { // TODO @puhui999: 后续统一处理 console.log(props.config) @@ -221,6 +220,7 @@ const hasConfig = computed(() => { return true }) +// 计算属性:参数列表 const paramsList = computed(() => { switch (props.type) { case JsonParamsInputTypeEnum.SERVICE: @@ -236,6 +236,7 @@ const paramsList = computed(() => { } }) +// 计算属性:标题 const title = computed(() => { switch (props.type) { case JsonParamsInputTypeEnum.SERVICE: @@ -251,6 +252,7 @@ const title = computed(() => { } }) +// 计算属性:标题图标 const titleIcon = computed(() => { switch (props.type) { case JsonParamsInputTypeEnum.SERVICE: @@ -266,6 +268,7 @@ const titleIcon = computed(() => { } }) +// 计算属性:参数图标 const paramsIcon = computed(() => { switch (props.type) { case JsonParamsInputTypeEnum.SERVICE: @@ -281,6 +284,7 @@ const paramsIcon = computed(() => { } }) +// 计算属性:参数标签 const paramsLabel = computed(() => { switch (props.type) { case JsonParamsInputTypeEnum.SERVICE: @@ -296,6 +300,7 @@ const paramsLabel = computed(() => { } }) +// 计算属性:空状态消息 const emptyMessage = computed(() => { switch (props.type) { case JsonParamsInputTypeEnum.SERVICE: @@ -311,6 +316,7 @@ const emptyMessage = computed(() => { } }) +// 计算属性:无配置消息 const noConfigMessage = computed(() => { switch (props.type) { case JsonParamsInputTypeEnum.SERVICE: @@ -326,7 +332,9 @@ const noConfigMessage = computed(() => { } }) -// 事件处理 +/** + * 处理参数变化事件 + */ const handleParamsChange = () => { try { jsonError.value = '' // 清除之前的错误 @@ -361,20 +369,28 @@ const handleParamsChange = () => { } } -// 快速填充示例数据 +/** + * 快速填充示例数据 + */ const fillExampleJson = () => { paramsJson.value = generateExampleJson() handleParamsChange() } -// 清空参数 +/** + * 清空参数 + */ const clearParams = () => { paramsJson.value = '' localValue.value = '' jsonError.value = '' } -// 工具函数 +/** + * 获取参数类型名称 + * @param dataType 数据类型 + * @returns 类型名称 + */ const getParamTypeName = (dataType: string) => { // 使用 constants.ts 中已有的 getDataTypeName 函数逻辑 const typeMap = { @@ -391,6 +407,11 @@ const getParamTypeName = (dataType: string) => { return typeMap[dataType] || dataType } +/** + * 获取参数类型标签样式 + * @param dataType 数据类型 + * @returns 标签样式 + */ const getParamTypeTag = (dataType: string) => { const tagMap = { [IoTDataSpecsDataTypeEnum.INT]: 'primary', @@ -406,12 +427,21 @@ const getParamTypeTag = (dataType: string) => { return tagMap[dataType] || 'info' } +/** + * 获取示例值 + * @param param 参数对象 + * @returns 示例值 + */ const getExampleValue = (param: any) => { const exampleConfig = JSON_PARAMS_EXAMPLE_VALUES[param.dataType] || JSON_PARAMS_EXAMPLE_VALUES.DEFAULT return exampleConfig.display } +/** + * 生成示例JSON + * @returns JSON字符串 + */ const generateExampleJson = () => { if (paramsList.value.length === 0) { return '{}' @@ -427,7 +457,10 @@ const generateExampleJson = () => { return JSON.stringify(example, null, 2) } -// 处理数据回显的函数 +/** + * 处理数据回显 + * @param value 值字符串 + */ const handleDataDisplay = (value: string) => { if (!value || !value.trim()) { paramsJson.value = '' diff --git a/src/views/iot/rule/scene/form/inputs/ValueInput.vue b/src/views/iot/rule/scene/form/inputs/ValueInput.vue index 5ce7a981a..27c067a0d 100644 --- a/src/views/iot/rule/scene/form/inputs/ValueInput.vue +++ b/src/views/iot/rule/scene/form/inputs/ValueInput.vue @@ -160,13 +160,12 @@ const localValue = useVModel(props, 'modelValue', emit, { defaultValue: '' }) -// 状态 -const rangeStart = ref('') -const rangeEnd = ref('') -const dateValue = ref('') -const numberValue = ref() +const rangeStart = ref('') // 范围开始值 +const rangeEnd = ref('') // 范围结束值 +const dateValue = ref('') // 日期值 +const numberValue = ref() // 数字值 -// 计算属性 +// 计算属性:枚举选项 const enumOptions = computed(() => { if (props.propertyConfig?.enum) { return props.propertyConfig.enum.map((item: any) => ({ @@ -177,6 +176,7 @@ const enumOptions = computed(() => { return [] }) +// 计算属性:列表预览 const listPreview = computed(() => { if (props.operator === 'in' && localValue.value) { return localValue.value @@ -187,7 +187,10 @@ const listPreview = computed(() => { return [] }) -// 工具函数 +/** + * 判断是否为数字类型 + * @returns 是否为数字类型 + */ const isNumericType = () => { return [ IoTDataSpecsDataTypeEnum.INT, @@ -196,6 +199,10 @@ const isNumericType = () => { ].includes(props.propertyType || '') } +/** + * 获取输入框类型 + * @returns 输入框类型 + */ const getInputType = () => { switch (props.propertyType) { case IoTDataSpecsDataTypeEnum.INT: @@ -207,6 +214,10 @@ const getInputType = () => { } } +/** + * 获取占位符文本 + * @returns 占位符文本 + */ const getPlaceholder = () => { const typeMap = { [IoTDataSpecsDataTypeEnum.TEXT]: '请输入字符串', @@ -219,27 +230,48 @@ const getPlaceholder = () => { return typeMap[props.propertyType || ''] || '请输入值' } +/** + * 获取数字精度 + * @returns 数字精度 + */ const getPrecision = () => { return props.propertyType === IoTDataSpecsDataTypeEnum.INT ? 0 : 2 } +/** + * 获取数字步长 + * @returns 数字步长 + */ const getStep = () => { return props.propertyType === IoTDataSpecsDataTypeEnum.INT ? 1 : 0.1 } +/** + * 获取最小值 + * @returns 最小值 + */ const getMin = () => { return props.propertyConfig?.min || undefined } +/** + * 获取最大值 + * @returns 最大值 + */ const getMax = () => { return props.propertyConfig?.max || undefined } -// 事件处理 +/** + * 处理值变化事件 + */ const handleChange = () => { // 值变化处理 } +/** + * 处理范围变化事件 + */ const handleRangeChange = () => { if (rangeStart.value && rangeEnd.value) { localValue.value = `${rangeStart.value},${rangeEnd.value}` @@ -248,10 +280,18 @@ const handleRangeChange = () => { } } +/** + * 处理日期变化事件 + * @param value 日期值 + */ const handleDateChange = (value: string) => { localValue.value = value || '' } +/** + * 处理数字变化事件 + * @param value 数字值 + */ const handleNumberChange = (value: number | undefined) => { localValue.value = value?.toString() || '' } diff --git a/src/views/iot/rule/scene/form/sections/ActionSection.vue b/src/views/iot/rule/scene/form/sections/ActionSection.vue index 7bc6597d0..d61d25dae 100644 --- a/src/views/iot/rule/scene/form/sections/ActionSection.vue +++ b/src/views/iot/rule/scene/form/sections/ActionSection.vue @@ -157,8 +157,11 @@ const emit = defineEmits<{ const actions = useVModel(props, 'actions', emit) +const maxActions = SCENE_RULE_CONFIG.MAX_ACTIONS // 最大执行器数量 + /** * 创建默认的执行器数据 + * @returns 默认执行器对象 */ const createDefaultActionData = (): Action => { return { @@ -171,10 +174,9 @@ const createDefaultActionData = (): Action => { } } -// 使用标准化的常量和函数 -const maxActions = SCENE_RULE_CONFIG.MAX_ACTIONS - -/** 添加执行器 */ +/** + * 添加执行器 + */ const addAction = () => { if (actions.value.length >= maxActions) { return @@ -184,28 +186,47 @@ const addAction = () => { actions.value.push(newAction) } -/** 删除执行器 */ +/** + * 删除执行器 + * @param index 执行器索引 + */ const removeAction = (index: number) => { actions.value.splice(index, 1) } -/** 更新执行器类型 */ +/** + * 更新执行器类型 + * @param index 执行器索引 + * @param type 执行器类型 + */ const updateActionType = (index: number, type: number) => { actions.value[index].type = type onActionTypeChange(actions.value[index], type) } -/** 更新执行器 */ +/** + * 更新执行器 + * @param index 执行器索引 + * @param action 执行器对象 + */ const updateAction = (index: number, action: Action) => { actions.value[index] = action } -/** 更新告警配置 */ +/** + * 更新告警配置 + * @param index 执行器索引 + * @param alertConfigId 告警配置ID + */ const updateActionAlertConfig = (index: number, alertConfigId?: number) => { actions.value[index].alertConfigId = alertConfigId } -/** 监听执行器类型变化 */ +/** + * 监听执行器类型变化 + * @param action 执行器对象 + * @param type 执行器类型 + */ const onActionTypeChange = (action: Action, type: number) => { // 清理不相关的配置,确保数据结构干净 if (isDeviceAction(type)) { diff --git a/src/views/iot/rule/scene/form/sections/BasicInfoSection.vue b/src/views/iot/rule/scene/form/sections/BasicInfoSection.vue index 7490e58cb..4e77053e4 100644 --- a/src/views/iot/rule/scene/form/sections/BasicInfoSection.vue +++ b/src/views/iot/rule/scene/form/sections/BasicInfoSection.vue @@ -67,11 +67,12 @@ const props = defineProps<{ modelValue: IotSceneRule rules?: any }>() + const emit = defineEmits<{ (e: 'update:modelValue', value: IotSceneRule): void }>() -const formData = useVModel(props, 'modelValue', emit) +const formData = useVModel(props, 'modelValue', emit) // 表单数据