diff --git a/src/views/iot/rule/scene/form/RuleSceneForm.vue b/src/views/iot/rule/scene/form/RuleSceneForm.vue index 9157312e..d348046c 100644 --- a/src/views/iot/rule/scene/form/RuleSceneForm.vue +++ b/src/views/iot/rule/scene/form/RuleSceneForm.vue @@ -12,9 +12,9 @@ - + - + @@ -80,7 +85,6 @@ interface Props { interface Emits { (e: 'update:modelValue', value?: number): void - (e: 'validate', result: { valid: boolean; message: string }): void } const props = defineProps() @@ -91,8 +95,6 @@ const localValue = useVModel(props, 'modelValue', emit) // 状态 const loading = ref(false) const alertConfigs = ref([]) -const validationMessage = ref('') -const isValid = ref(true) // 计算属性 const selectedConfig = computed(() => { @@ -110,40 +112,6 @@ const getNotifyTypeName = (type: number) => { return typeMap[type] || '未知' } -// 事件处理 -const handleChange = () => { - updateValidationResult() -} - -const updateValidationResult = () => { - if (!localValue.value) { - isValid.value = false - validationMessage.value = '请选择告警配置' - emit('validate', { valid: false, message: validationMessage.value }) - return - } - - const config = selectedConfig.value - if (!config) { - isValid.value = false - validationMessage.value = '告警配置不存在' - emit('validate', { valid: false, message: validationMessage.value }) - return - } - - if (!config.enabled) { - isValid.value = false - validationMessage.value = '选择的告警配置已禁用' - emit('validate', { valid: false, message: validationMessage.value }) - return - } - - // 验证通过 - isValid.value = true - validationMessage.value = '告警配置验证通过' - emit('validate', { valid: true, message: validationMessage.value }) -} - // API 调用 const getAlertConfigs = async () => { loading.value = true @@ -184,20 +152,9 @@ const getAlertConfigs = async () => { } } -// 监听值变化 -watch( - () => localValue.value, - () => { - updateValidationResult() - } -) - // 初始化 onMounted(() => { getAlertConfigs() - if (localValue.value) { - updateValidationResult() - } }) diff --git a/src/views/iot/rule/scene/form/configs/DeviceControlConfig.vue b/src/views/iot/rule/scene/form/configs/DeviceControlConfig.vue index 9782869b..7885a915 100644 --- a/src/views/iot/rule/scene/form/configs/DeviceControlConfig.vue +++ b/src/views/iot/rule/scene/form/configs/DeviceControlConfig.vue @@ -39,16 +39,6 @@ - - -
- -
@@ -66,21 +56,17 @@ const props = defineProps<{ const emit = defineEmits<{ (e: 'update:modelValue', value: ActionFormData): void - (e: 'validate', result: { valid: boolean; message: string }): void }>() const action = useVModel(props, 'modelValue', emit) // 状态 const paramsJson = ref('') -const validationMessage = ref('') -const isValid = ref(true) // 事件处理 const handleDeviceChange = ({ productId, deviceId }: { productId?: number; deviceId?: number }) => { action.value.productId = productId action.value.deviceId = deviceId - updateValidationResult() } const handleParamsChange = () => { @@ -90,42 +76,16 @@ const handleParamsChange = () => { } else { action.value.params = {} } - updateValidationResult() } catch (error) { - isValid.value = false - validationMessage.value = 'JSON格式错误' - emit('validate', { valid: false, message: validationMessage.value }) + console.error('JSON格式错误:', error) } } -const updateValidationResult = () => { - // 基础验证 - if (!action.value.productId || !action.value.deviceId) { - isValid.value = false - validationMessage.value = '请选择产品和设备' - emit('validate', { valid: false, message: validationMessage.value }) - return - } - - if (!action.value.params || Object.keys(action.value.params).length === 0) { - isValid.value = false - validationMessage.value = '请配置控制参数' - emit('validate', { valid: false, message: validationMessage.value }) - return - } - - // 验证通过 - isValid.value = true - validationMessage.value = '设备控制配置验证通过' - emit('validate', { valid: true, message: validationMessage.value }) -} - // 初始化 onMounted(() => { if (action.value.params) { paramsJson.value = JSON.stringify(action.value.params, null, 2) } - updateValidationResult() }) // 监听参数变化 diff --git a/src/views/iot/rule/scene/form/configs/DeviceTriggerConfig.vue b/src/views/iot/rule/scene/form/configs/DeviceTriggerConfig.vue index 69ab5052..350a6cee 100644 --- a/src/views/iot/rule/scene/form/configs/DeviceTriggerConfig.vue +++ b/src/views/iot/rule/scene/form/configs/DeviceTriggerConfig.vue @@ -6,7 +6,6 @@ @@ -17,7 +16,6 @@ @@ -48,14 +46,6 @@ const emit = defineEmits<{ const trigger = useVModel(props, 'modelValue', emit) -// 验证状态 -const mainConditionValidation = ref<{ valid: boolean; message: string }>({ - valid: true, - message: '' -}) -const validationMessage = ref('') -const isValid = ref(true) - // 初始化主条件 const initMainCondition = () => { // TODO @puhui999: 等到编辑回显时联调 @@ -80,76 +70,12 @@ watch( { immediate: true } ) -const handleMainConditionValidate = (result: { valid: boolean; message: string }) => { - mainConditionValidation.value = result - updateValidationResult() -} - const handleTriggerTypeChange = (type: number) => { trigger.value.type = type emit('trigger-type-change', type) } -// 事件处理 -const handleConditionGroupValidate = () => { - updateValidationResult() -} - const removeConditionGroup = () => { trigger.value.conditionGroups = undefined } - -const updateValidationResult = () => { - // 主条件验证 - if (!mainConditionValidation.value.valid) { - isValid.value = false - validationMessage.value = mainConditionValidation.value.message - emit('validate', { valid: false, message: validationMessage.value }) - return - } - - // 设备状态变更不需要条件验证 - if (trigger.value.type === TriggerTypeEnum.DEVICE_STATE_UPDATE) { - isValid.value = true - validationMessage.value = '设备触发配置验证通过' - emit('validate', { valid: true, message: validationMessage.value }) - return - } - - // 主条件验证 - if (!trigger.value.value) { - isValid.value = false - validationMessage.value = '请配置主条件' - emit('validate', { valid: false, message: validationMessage.value }) - return - } - - // 主条件详细验证 - if (!mainConditionValidation.value.valid) { - isValid.value = false - validationMessage.value = `主条件配置错误: ${mainConditionValidation.value.message}` - emit('validate', { valid: false, message: validationMessage.value }) - return - } - - isValid.value = true - validationMessage.value = '设备触发配置验证通过' - emit('validate', { valid: isValid.value, message: validationMessage.value }) -} - -// 监听触发器类型变化 -watch( - () => trigger.value.type, - () => { - updateValidationResult() - } -) - -// 监听产品设备变化 -watch( - () => [trigger.value.productId, trigger.value.deviceId], - () => { - updateValidationResult() - } -) diff --git a/src/views/iot/rule/scene/form/sections/ActionSection.vue b/src/views/iot/rule/scene/form/sections/ActionSection.vue index 4535be7e..7fac9a15 100644 --- a/src/views/iot/rule/scene/form/sections/ActionSection.vue +++ b/src/views/iot/rule/scene/form/sections/ActionSection.vue @@ -76,7 +76,6 @@ v-if="isDeviceAction(action.type)" :model-value="action" @update:model-value="(value) => updateAction(index, value)" - @validate="(result) => handleActionValidate(index, result)" /> @@ -84,7 +83,6 @@ v-if="isAlertAction(action.type)" :model-value="action.alertConfigId" @update:model-value="(value) => updateActionAlertConfig(index, value)" - @validate="(result) => handleActionValidate(index, result)" /> @@ -100,16 +98,6 @@ 最多可添加 {{ maxActions }} 个执行器 - - -
- -
@@ -131,7 +119,6 @@ interface Props { interface Emits { (e: 'update:actions', value: ActionFormData[]): void - (e: 'validate', result: { valid: boolean; message: string }): void } const props = defineProps() @@ -155,11 +142,6 @@ const createDefaultActionData = (): ActionFormData => { // 配置常量 const maxActions = 5 -// 验证状态 -const actionValidations = ref<{ [key: number]: { valid: boolean; message: string } }>({}) -const validationMessage = ref('') -const isValid = ref(true) - // 执行器类型映射 const actionTypeNames = { [ActionTypeEnum.DEVICE_PROPERTY_SET]: '属性设置', @@ -206,21 +188,6 @@ const addAction = () => { const removeAction = (index: number) => { actions.value.splice(index, 1) - delete actionValidations.value[index] - - // 重新索引验证结果 - const newValidations: { [key: number]: { valid: boolean; message: string } } = {} - Object.keys(actionValidations.value).forEach((key) => { - const numKey = parseInt(key) - if (numKey > index) { - newValidations[numKey - 1] = actionValidations.value[numKey] - } else if (numKey < index) { - newValidations[numKey] = actionValidations.value[numKey] - } - }) - actionValidations.value = newValidations - - updateValidationResult() } const updateActionType = (index: number, type: number) => { @@ -249,37 +216,4 @@ const onActionTypeChange = (action: ActionFormData, type: number) => { action.params = undefined } } - -const handleActionValidate = (index: number, result: { valid: boolean; message: string }) => { - actionValidations.value[index] = result - updateValidationResult() -} - -const updateValidationResult = () => { - const validations = Object.values(actionValidations.value) - const allValid = validations.every((v) => v.valid) - const hasValidations = validations.length > 0 - - if (!hasValidations) { - isValid.value = true - validationMessage.value = '' - } else if (allValid) { - isValid.value = true - validationMessage.value = '所有执行器配置验证通过' - } else { - isValid.value = false - const errorMessages = validations.filter((v) => !v.valid).map((v) => v.message) - validationMessage.value = `执行器配置错误: ${errorMessages.join('; ')}` - } - - emit('validate', { valid: isValid.value, message: validationMessage.value }) -} - -// 监听执行器数量变化 -watch( - () => actions.value.length, - () => { - updateValidationResult() - } -)