From 081603788abee613c8258b893bc0dd5c8e5c3bce Mon Sep 17 00:00:00 2001 From: puhui999 Date: Fri, 1 Aug 2025 16:56:22 +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=E8=A7=A6?= =?UTF-8?q?=E5=8F=91=E5=99=A8=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../scene/form/configs/ConditionConfig.vue | 63 +++---------------- .../configs/ConditionGroupContainerConfig.vue | 23 ++----- .../configs/CurrentTimeConditionConfig.vue | 52 +-------------- .../form/configs/DeviceTriggerConfig.vue | 2 +- .../form/configs/MainConditionInnerConfig.vue | 15 ----- .../form/configs/SubConditionGroupConfig.vue | 23 +------ .../scene/form/selectors/PropertySelector.vue | 12 ++-- 7 files changed, 21 insertions(+), 169 deletions(-) diff --git a/src/views/iot/rule/scene/form/configs/ConditionConfig.vue b/src/views/iot/rule/scene/form/configs/ConditionConfig.vue index 8b20ec3e9..6bd932052 100644 --- a/src/views/iot/rule/scene/form/configs/ConditionConfig.vue +++ b/src/views/iot/rule/scene/form/configs/ConditionConfig.vue @@ -89,24 +89,6 @@ - - - -
-
- - 条件预览 -
-
- {{ conditionPreview }} -
-
@@ -147,18 +129,15 @@ import { /** 单个条件配置组件 */ defineOptions({ name: 'ConditionConfig' }) -interface Props { +const props = defineProps<{ modelValue: ConditionFormData triggerType: number -} +}>() -interface Emits { +const emit = defineEmits<{ (e: 'update:modelValue', value: ConditionFormData): void (e: 'validate', result: { valid: boolean; message: string }): void -} - -const props = defineProps() -const emit = defineEmits() +}>() const condition = useVModel(props, 'modelValue', emit) @@ -172,34 +151,6 @@ const validationMessage = ref('') const isValid = ref(true) const valueValidation = ref({ valid: true, message: '' }) -// 计算属性 -const conditionPreview = computed(() => { - if (!condition.value.identifier || !condition.value.operator || !condition.value.param) { - return '' - } - - const propertyName = propertyConfig.value?.name || condition.value.identifier - const operatorText = getOperatorText(condition.value.operator) - const value = condition.value.param - - return `当 ${propertyName} ${operatorText} ${value} 时触发` -}) - -// 工具函数 -const getOperatorText = (operator: string) => { - const operatorMap = { - '=': '等于', - '!=': '不等于', - '>': '大于', - '>=': '大于等于', - '<': '小于', - '<=': '小于等于', - in: '包含于', - between: '介于' - } - return operatorMap[operator] || operator -} - // 事件处理 const updateConditionField = (field: keyof ConditionFormData, value: any) => { ;(condition.value as any)[field] = value @@ -241,18 +192,20 @@ const handleValidate = (result: { valid: boolean; message: string }) => { const handleProductChange = (productId: number) => { // 产品变化时清空设备和属性 - condition.value.deviceId = undefined + condition.value.productId = productId condition.value.identifier = '' updateValidationResult() } const handleDeviceChange = (deviceId: number) => { // 设备变化时清空属性 - condition.value.identifier = '' + condition.value.deviceId = deviceId updateValidationResult() } const handlePropertyChange = (propertyInfo: { type: string; config: any }) => { + debugger + console.log(propertyInfo) propertyType.value = propertyInfo.type propertyConfig.value = propertyInfo.config diff --git a/src/views/iot/rule/scene/form/configs/ConditionGroupContainerConfig.vue b/src/views/iot/rule/scene/form/configs/ConditionGroupContainerConfig.vue index 0c8821343..60c4d3902 100644 --- a/src/views/iot/rule/scene/form/configs/ConditionGroupContainerConfig.vue +++ b/src/views/iot/rule/scene/form/configs/ConditionGroupContainerConfig.vue @@ -1,7 +1,6 @@ @@ -136,6 +108,7 @@ interface Props { interface Emits { (e: 'update:modelValue', value: ConditionFormData): void + (e: 'validate', result: { valid: boolean; message: string }): void } @@ -211,29 +184,6 @@ const needsSecondTimeInput = computed(() => { return condition.value.operator === IotRuleSceneTriggerTimeOperatorEnum.BETWEEN_TIME.value }) -const conditionPreview = computed(() => { - if (!condition.value.operator) { - return '' - } - - const operatorOption = timeOperatorOptions.find((opt) => opt.value === condition.value.operator) - const operatorLabel = operatorOption?.label || condition.value.operator - - if (condition.value.operator === IotRuleSceneTriggerTimeOperatorEnum.TODAY.value) { - return `当前时间 ${operatorLabel}` - } - - if (!condition.value.timeValue) { - return `当前时间 ${operatorLabel} [未设置时间]` - } - - if (needsSecondTimeInput.value && condition.value.timeValue2) { - return `当前时间 ${operatorLabel} ${condition.value.timeValue} 和 ${condition.value.timeValue2}` - } - - return `当前时间 ${operatorLabel} ${condition.value.timeValue}` -}) - // 事件处理 const updateConditionField = (field: keyof ConditionFormData, value: any) => { condition.value[field] = value diff --git a/src/views/iot/rule/scene/form/configs/DeviceTriggerConfig.vue b/src/views/iot/rule/scene/form/configs/DeviceTriggerConfig.vue index c0d860468..5e41a5f00 100644 --- a/src/views/iot/rule/scene/form/configs/DeviceTriggerConfig.vue +++ b/src/views/iot/rule/scene/form/configs/DeviceTriggerConfig.vue @@ -12,7 +12,7 @@
-
+
附加条件组 与主条件为且关系 diff --git a/src/views/iot/rule/scene/form/configs/MainConditionInnerConfig.vue b/src/views/iot/rule/scene/form/configs/MainConditionInnerConfig.vue index 23c492a91..709cf7356 100644 --- a/src/views/iot/rule/scene/form/configs/MainConditionInnerConfig.vue +++ b/src/views/iot/rule/scene/form/configs/MainConditionInnerConfig.vue @@ -67,14 +67,6 @@ - - - -
-
- 预览:{{ conditionPreview }} -
-
@@ -147,13 +139,6 @@ const isDeviceStatusTrigger = computed(() => { return props.triggerType === IotRuleSceneTriggerTypeEnum.DEVICE_STATE_UPDATE }) -const conditionPreview = computed(() => { - if (!condition.value.productId || !condition.value.deviceId || !condition.value.identifier) { - return '' - } - return `设备[${condition.value.deviceId}]的${condition.value.identifier} ${condition.value.operator} ${condition.value.param}` -}) - // 获取触发类型文本 // TODO @puhui999:是不是有枚举可以服用哈; const getTriggerTypeText = (type: number) => { diff --git a/src/views/iot/rule/scene/form/configs/SubConditionGroupConfig.vue b/src/views/iot/rule/scene/form/configs/SubConditionGroupConfig.vue index ffc2d5fe6..3cd8167e7 100644 --- a/src/views/iot/rule/scene/form/configs/SubConditionGroupConfig.vue +++ b/src/views/iot/rule/scene/form/configs/SubConditionGroupConfig.vue @@ -63,24 +63,6 @@ />
- - - -
-
- -
- -
- -
- -
-
-
@@ -108,9 +90,9 @@ import { useVModel } from '@vueuse/core' import ConditionConfig from './ConditionConfig.vue' import { - SubConditionGroupFormData, ConditionFormData, - IotRuleSceneTriggerConditionTypeEnum + IotRuleSceneTriggerConditionTypeEnum, + SubConditionGroupFormData } from '@/api/iot/rule/scene/scene.types' /** 子条件组配置组件 */ @@ -124,6 +106,7 @@ interface Props { interface Emits { (e: 'update:modelValue', value: SubConditionGroupFormData): void + (e: 'validate', result: { valid: boolean; message: string }): void } diff --git a/src/views/iot/rule/scene/form/selectors/PropertySelector.vue b/src/views/iot/rule/scene/form/selectors/PropertySelector.vue index 188d8f044..a8afbf28c 100644 --- a/src/views/iot/rule/scene/form/selectors/PropertySelector.vue +++ b/src/views/iot/rule/scene/form/selectors/PropertySelector.vue @@ -134,21 +134,17 @@ import type { IotThingModelTSLRespVO, PropertySelectorItem } from './types' /** 属性选择器组件 */ defineOptions({ name: 'PropertySelector' }) -interface Props { +const props = defineProps<{ modelValue?: string triggerType: number productId?: number deviceId?: number -} +}>() -interface Emits { +const emit = defineEmits<{ (e: 'update:modelValue', value: string): void - (e: 'change', value: { type: string; config: any }): void -} - -const props = defineProps() -const emit = defineEmits() +}>() const localValue = useVModel(props, 'modelValue', emit)