diff --git a/src/views/iot/rule/scene/form/configs/CurrentTimeConditionConfig.vue b/src/views/iot/rule/scene/form/configs/CurrentTimeConditionConfig.vue
index bcf052979..79ccf42b4 100644
--- a/src/views/iot/rule/scene/form/configs/CurrentTimeConditionConfig.vue
+++ b/src/views/iot/rule/scene/form/configs/CurrentTimeConditionConfig.vue
@@ -106,7 +106,6 @@ const props = defineProps<{
const emit = defineEmits<{
(e: 'update:modelValue', value: TriggerCondition): void
- (e: 'validate', result: { valid: boolean; message: string }): void
}>()
const condition = useVModel(props, 'modelValue', emit)
@@ -155,10 +154,6 @@ const timeOperatorOptions = [
}
]
-// 状态
-const validationMessage = ref('')
-const isValid = ref(true)
-
// 计算属性
const needsTimeInput = computed(() => {
const timeOnlyOperators = [
@@ -181,62 +176,16 @@ const needsSecondTimeInput = computed(() => {
// 事件处理
const updateConditionField = (field: keyof TriggerCondition, value: any) => {
condition.value[field] = value
- updateValidationResult()
}
-const updateValidationResult = () => {
- if (!condition.value.operator) {
- isValid.value = false
- validationMessage.value = '请选择时间条件'
- emit('validate', { valid: false, message: validationMessage.value })
- return
- }
-
- // 今日条件不需要时间值
- if (condition.value.operator === IotRuleSceneTriggerTimeOperatorEnum.TODAY.value) {
- isValid.value = true
- validationMessage.value = '当前时间条件配置验证通过'
- emit('validate', { valid: true, message: validationMessage.value })
- return
- }
-
- if (needsTimeInput.value && !condition.value.timeValue) {
- isValid.value = false
- validationMessage.value = '请设置时间值'
- emit('validate', { valid: false, message: validationMessage.value })
- return
- }
-
- if (needsSecondTimeInput.value && !condition.value.timeValue2) {
- 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 })
-}
-
-// 监听变化
-watch(
- () => [condition.value.operator, condition.value.timeValue, condition.value.timeValue2],
- () => {
- updateValidationResult()
- },
- { immediate: true }
-)
-
// 监听操作符变化,清理不相关的时间值
watch(
() => condition.value.operator,
(newOperator) => {
if (newOperator === IotRuleSceneTriggerTimeOperatorEnum.TODAY.value) {
- condition.value.timeValue = undefined
- condition.value.timeValue2 = undefined
+ ;(condition.value as any).timeValue = undefined(condition.value as any).timeValue2 = undefined
} else if (!needsSecondTimeInput.value) {
- condition.value.timeValue2 = undefined
+ ;(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 b911b0833..a90c7874b 100644
--- a/src/views/iot/rule/scene/form/configs/DeviceControlConfig.vue
+++ b/src/views/iot/rule/scene/form/configs/DeviceControlConfig.vue
@@ -55,7 +55,6 @@
type="service"
:config="{ service: selectedService }"
placeholder="请输入JSON格式的服务参数"
- @validate="handleParamsValidate"
/>
@@ -70,7 +69,6 @@
type="property"
:config="{ properties: thingModelProperties }"
placeholder="请输入JSON格式的控制参数"
- @validate="handleParamsValidate"
/>
@@ -86,7 +84,8 @@ import type { Action } from '@/api/iot/rule/scene'
import type { ThingModelProperty, ThingModelService } from '@/api/iot/thingmodel'
import {
IotRuleSceneActionTypeEnum,
- IoTThingModelAccessModeEnum
+ IoTThingModelAccessModeEnum,
+ IoTDataSpecsDataTypeEnum
} from '@/views/iot/utils/constants'
import { ThingModelApi } from '@/api/iot/thingmodel'
@@ -126,12 +125,6 @@ const paramsValue = computed({
}
})
-// 参数验证处理
-const handleParamsValidate = (result: { valid: boolean; message: string }) => {
- // 可以在这里处理验证结果,比如显示错误信息
- console.log('参数验证结果:', result)
-}
-
const isPropertySetAction = computed(() => {
// 是否为属性设置类型
return action.value.type === IotRuleSceneActionTypeEnum.DEVICE_PROPERTY_SET
@@ -301,16 +294,16 @@ const loadServiceFromTSL = async (productId: number, serviceIdentifier: string)
*/
const getDefaultValueForParam = (param: any) => {
switch (param.dataType) {
- case 'int':
+ case IoTDataSpecsDataTypeEnum.INT:
return 0
- case 'float':
- case 'double':
+ case IoTDataSpecsDataTypeEnum.FLOAT:
+ case IoTDataSpecsDataTypeEnum.DOUBLE:
return 0.0
- case 'bool':
+ case IoTDataSpecsDataTypeEnum.BOOL:
return false
- case 'text':
+ case IoTDataSpecsDataTypeEnum.TEXT:
return ''
- case 'enum':
+ case IoTDataSpecsDataTypeEnum.ENUM:
// 如果有枚举值,使用第一个
if (param.dataSpecs?.dataSpecsList && param.dataSpecs.dataSpecsList.length > 0) {
return param.dataSpecs.dataSpecsList[0].value
diff --git a/src/views/iot/rule/scene/form/configs/DeviceTriggerConfig.vue b/src/views/iot/rule/scene/form/configs/DeviceTriggerConfig.vue
index d3f39ee66..d38c6ec8b 100644
--- a/src/views/iot/rule/scene/form/configs/DeviceTriggerConfig.vue
+++ b/src/views/iot/rule/scene/form/configs/DeviceTriggerConfig.vue
@@ -29,7 +29,6 @@
:model-value="trigger"
@update:model-value="updateCondition"
:trigger-type="trigger.type"
- @validate="handleValidate"
@trigger-type-change="handleTriggerTypeChange"
/>
@@ -123,7 +122,6 @@
@update:model-value="(value) => updateSubGroup(subGroupIndex, value)"
:trigger-type="trigger.type"
:max-conditions="maxConditionsPerGroup"
- @validate="(result) => handleSubGroupValidate(subGroupIndex, result)"
/>
@@ -182,7 +180,6 @@ const props = defineProps<{
const emit = defineEmits<{
(e: 'update:modelValue', value: Trigger): void
- (e: 'validate', value: { valid: boolean; message: string }): void
(e: 'trigger-type-change', type: number): void
}>()
@@ -192,18 +189,11 @@ const trigger = useVModel(props, 'modelValue', emit)
const maxSubGroups = 3 // 最多 3 个子条件组
const maxConditionsPerGroup = 3 // 每组最多 3 个条件
-// 验证状态
-const subGroupValidations = ref<{ [key: number]: { valid: boolean; message: string } }>({})
-
// 事件处理
const updateCondition = (condition: Trigger) => {
trigger.value = condition
}
-const handleValidate = (result: { valid: boolean; message: string }) => {
- emit('validate', result)
-}
-
const handleTriggerTypeChange = (type: number) => {
trigger.value.type = type
emit('trigger-type-change', type)
@@ -231,21 +221,6 @@ const addSubGroup = () => {
const removeSubGroup = (index: number) => {
if (trigger.value.conditionGroups) {
trigger.value.conditionGroups.splice(index, 1)
- delete subGroupValidations.value[index]
-
- // 重新索引验证结果
- const newValidations: { [key: number]: { valid: boolean; message: string } } = {}
- Object.keys(subGroupValidations.value).forEach((key) => {
- const numKey = parseInt(key)
- if (numKey > index) {
- newValidations[numKey - 1] = subGroupValidations.value[numKey]
- } else if (numKey < index) {
- newValidations[numKey] = subGroupValidations.value[numKey]
- }
- })
- subGroupValidations.value = newValidations
-
- updateValidationResult()
}
}
@@ -258,35 +233,4 @@ const updateSubGroup = (index: number, subGroup: any) => {
const removeConditionGroup = () => {
trigger.value.conditionGroups = undefined
}
-
-const handleSubGroupValidate = (index: number, result: { valid: boolean; message: string }) => {
- subGroupValidations.value[index] = result
- updateValidationResult()
-}
-
-const updateValidationResult = () => {
- if (!trigger.value.conditionGroups || trigger.value.conditionGroups.length === 0) {
- emit('validate', { valid: true, message: '条件组容器为空,验证通过' })
- return
- }
-
- const validations = Object.values(subGroupValidations.value)
- const allValid = validations.every((v: any) => v.valid)
-
- if (allValid) {
- emit('validate', { valid: true, message: '条件组容器配置验证通过' })
- } else {
- const errorMessages = validations.filter((v: any) => !v.valid).map((v: any) => v.message)
- emit('validate', { valid: false, message: `子条件组配置错误: ${errorMessages.join('; ')}` })
- }
-}
-
-// 监听变化
-watch(
- () => trigger.value.conditionGroups,
- () => {
- updateValidationResult()
- },
- { deep: true, immediate: true }
-)
diff --git a/src/views/iot/rule/scene/form/configs/MainConditionInnerConfig.vue b/src/views/iot/rule/scene/form/configs/MainConditionInnerConfig.vue
index 55012f8b9..9066a0064 100644
--- a/src/views/iot/rule/scene/form/configs/MainConditionInnerConfig.vue
+++ b/src/views/iot/rule/scene/form/configs/MainConditionInnerConfig.vue
@@ -100,7 +100,6 @@
type="service"
:config="serviceConfig"
placeholder="请输入JSON格式的服务参数"
- @validate="handleValueValidate"
/>
@@ -202,15 +199,11 @@ const props = defineProps<{
const emit = defineEmits<{
(e: 'update:modelValue', value: Trigger): void
- (e: 'validate', result: { valid: boolean; message: string }): void
(e: 'trigger-type-change', value: number): void
}>()
// 响应式数据
const condition = useVModel(props, 'modelValue', emit)
-// TODO @puhui999:是不是 validationMessage 非空,就是不通过哈;
-const isValid = ref(true)
-const validationMessage = ref('')
const propertyType = ref('')
const propertyConfig = ref(null)
@@ -279,7 +272,6 @@ const triggerTypeOptions = getTriggerTypeOptions()
// 事件处理
const updateConditionField = (field: keyof Trigger, value: any) => {
;(condition.value as any)[field] = value
- updateValidationResult()
}
const handleTriggerTypeChange = (type: number) => {
@@ -290,13 +282,11 @@ const handleProductChange = () => {
// 产品变化时清空设备和属性
condition.value.deviceId = undefined
condition.value.identifier = ''
- updateValidationResult()
}
const handleDeviceChange = () => {
// 设备变化时清空属性
condition.value.identifier = ''
- updateValidationResult()
}
const handlePropertyChange = (propertyInfo: any) => {
@@ -312,88 +302,9 @@ const handlePropertyChange = (propertyInfo: any) => {
condition.value.operator = '='
}
}
- updateValidationResult()
}
const handleOperatorChange = () => {
- updateValidationResult()
+ // 操作符变化处理
}
-
-// 处理参数验证结果
-const handleValueValidate = (result: { valid: boolean; message: string }) => {
- isValid.value = result.valid
- validationMessage.value = result.message
- emit('validate', result)
- updateValidationResult()
-}
-
-// 验证逻辑
-// TODO @puhui999:这个校验,是不是用更原生的 validator 哈。项目风格更统一点。
-const updateValidationResult = () => {
- if (isDevicePropertyTrigger.value) {
- // 设备属性触发验证
- if (!condition.value.productId) {
- isValid.value = false
- validationMessage.value = '请选择产品'
- emit('validate', { valid: false, message: validationMessage.value })
- return
- }
-
- if (!condition.value.deviceId) {
- isValid.value = false
- validationMessage.value = '请选择设备'
- emit('validate', { valid: false, message: validationMessage.value })
- return
- }
-
- if (!condition.value.identifier) {
- isValid.value = false
- validationMessage.value = '请选择监控项'
- emit('validate', { valid: false, message: validationMessage.value })
- return
- }
-
- // 服务调用和事件上报不需要操作符
- if (
- props.triggerType !== IotRuleSceneTriggerTypeEnum.DEVICE_SERVICE_INVOKE &&
- props.triggerType !== IotRuleSceneTriggerTypeEnum.DEVICE_EVENT_POST &&
- !condition.value.operator
- ) {
- isValid.value = false
- validationMessage.value = '请选择操作符'
- emit('validate', { valid: false, message: validationMessage.value })
- return
- }
-
- if (!condition.value.value) {
- 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 })
-}
-
-// 监听变化
-watch(
- () => [
- condition.value.productId,
- condition.value.deviceId,
- condition.value.identifier,
- // 服务调用和事件上报不需要监听操作符
- props.triggerType !== IotRuleSceneTriggerTypeEnum.DEVICE_SERVICE_INVOKE &&
- props.triggerType !== IotRuleSceneTriggerTypeEnum.DEVICE_EVENT_POST
- ? condition.value.operator
- : null,
- condition.value.value
- ],
- () => {
- updateValidationResult()
- },
- { immediate: true }
-)
diff --git a/src/views/iot/rule/scene/form/configs/SubConditionGroupConfig.vue b/src/views/iot/rule/scene/form/configs/SubConditionGroupConfig.vue
index b33193293..976870537 100644
--- a/src/views/iot/rule/scene/form/configs/SubConditionGroupConfig.vue
+++ b/src/views/iot/rule/scene/form/configs/SubConditionGroupConfig.vue
@@ -56,7 +56,6 @@
:model-value="condition"
@update:model-value="(value) => updateCondition(conditionIndex, value)"
:trigger-type="triggerType"
- @validate="(result) => handleConditionValidate(conditionIndex, result)"
/>
@@ -100,7 +99,6 @@ const props = defineProps<{
const emit = defineEmits<{
(e: 'update:modelValue', value: TriggerCondition[]): void
- (e: 'validate', result: { valid: boolean; message: string }): void
}>()
const subGroup = useVModel(props, 'modelValue', emit)
@@ -108,9 +106,6 @@ const subGroup = useVModel(props, 'modelValue', emit)
// 配置常量
const maxConditions = computed(() => props.maxConditions || 3)
-// 验证状态
-const conditionValidations = ref<{ [key: number]: { valid: boolean; message: string } }>({})
-
// 事件处理
const addCondition = () => {
// 确保 subGroup.value 是一个数组
@@ -143,21 +138,6 @@ const addCondition = () => {
const removeCondition = (index: number) => {
if (subGroup.value) {
subGroup.value.splice(index, 1)
- delete conditionValidations.value[index]
-
- // 重新索引验证结果
- const newValidations: { [key: number]: { valid: boolean; message: string } } = {}
- Object.keys(conditionValidations.value).forEach((key) => {
- const numKey = parseInt(key)
- if (numKey > index) {
- newValidations[numKey - 1] = conditionValidations.value[numKey]
- } else if (numKey < index) {
- newValidations[numKey] = conditionValidations.value[numKey]
- }
- })
- conditionValidations.value = newValidations
-
- updateValidationResult()
}
}
@@ -166,35 +146,4 @@ const updateCondition = (index: number, condition: TriggerCondition) => {
subGroup.value[index] = condition
}
}
-
-const handleConditionValidate = (index: number, result: { valid: boolean; message: string }) => {
- conditionValidations.value[index] = result
- updateValidationResult()
-}
-
-const updateValidationResult = () => {
- if (!subGroup.value || subGroup.value.length === 0) {
- emit('validate', { valid: false, message: '子条件组至少需要一个条件' })
- return
- }
-
- const validations = Object.values(conditionValidations.value)
- const allValid = validations.every((v: any) => v.valid)
-
- if (allValid) {
- emit('validate', { valid: true, message: '子条件组配置验证通过' })
- } else {
- const errorMessages = validations.filter((v: any) => !v.valid).map((v: any) => v.message)
- emit('validate', { valid: false, message: `条件配置错误: ${errorMessages.join('; ')}` })
- }
-}
-
-// 监听变化
-watch(
- () => subGroup.value,
- () => {
- updateValidationResult()
- },
- { deep: true, immediate: true }
-)
diff --git a/src/views/iot/rule/scene/form/inputs/JsonParamsInput.vue b/src/views/iot/rule/scene/form/inputs/JsonParamsInput.vue
index b7001f6a9..3dbb30428 100644
--- a/src/views/iot/rule/scene/form/inputs/JsonParamsInput.vue
+++ b/src/views/iot/rule/scene/form/inputs/JsonParamsInput.vue
@@ -136,6 +136,7 @@
diff --git a/src/views/iot/rule/scene/form/selectors/OperatorSelector.vue b/src/views/iot/rule/scene/form/selectors/OperatorSelector.vue
index 71e0b5690..b8ae1b44c 100644
--- a/src/views/iot/rule/scene/form/selectors/OperatorSelector.vue
+++ b/src/views/iot/rule/scene/form/selectors/OperatorSelector.vue
@@ -35,7 +35,10 @@