|
|
@@ -1,5 +1,23 @@
|
|
|
<template>
|
|
|
<div class="space-y-16px">
|
|
|
+ <!-- 触发事件类型选择 -->
|
|
|
+ <el-form-item label="触发事件类型" required>
|
|
|
+ <el-select
|
|
|
+ :model-value="triggerType"
|
|
|
+ @update:model-value="handleTriggerTypeChange"
|
|
|
+ placeholder="请选择触发事件类型"
|
|
|
+ class="w-full"
|
|
|
+ style="width: 100%"
|
|
|
+ >
|
|
|
+ <el-option
|
|
|
+ v-for="option in triggerTypeOptions"
|
|
|
+ :key="option.value"
|
|
|
+ :label="option.label"
|
|
|
+ :value="option.value"
|
|
|
+ />
|
|
|
+ </el-select>
|
|
|
+ </el-form-item>
|
|
|
+
|
|
|
<!-- 设备属性条件配置 -->
|
|
|
<div v-if="isDevicePropertyTrigger" class="space-y-16px">
|
|
|
<!-- 产品设备选择 -->
|
|
|
@@ -57,8 +75,8 @@
|
|
|
<el-col :span="12">
|
|
|
<el-form-item label="比较值" required>
|
|
|
<ValueInput
|
|
|
- :model-value="condition.param"
|
|
|
- @update:model-value="(value) => updateConditionField('param', value)"
|
|
|
+ :model-value="condition.value"
|
|
|
+ @update:model-value="(value) => updateConditionField('value', value)"
|
|
|
:property-type="propertyType"
|
|
|
:operator="condition.operator"
|
|
|
:property-config="propertyConfig"
|
|
|
@@ -97,21 +115,22 @@ import PropertySelector from '../selectors/PropertySelector.vue'
|
|
|
import OperatorSelector from '../selectors/OperatorSelector.vue'
|
|
|
import ValueInput from '../inputs/ValueInput.vue'
|
|
|
import DeviceStatusConditionConfig from './DeviceStatusConditionConfig.vue'
|
|
|
-import { ConditionFormData } from '@/api/iot/rule/scene/scene.types'
|
|
|
-import { IotRuleSceneTriggerTypeEnum } from '@/views/iot/utils/constants'
|
|
|
+import { TriggerFormData } from '@/api/iot/rule/scene/scene.types'
|
|
|
+import { IotRuleSceneTriggerTypeEnum, getTriggerTypeOptions } from '@/views/iot/utils/constants'
|
|
|
import { useVModel } from '@vueuse/core'
|
|
|
|
|
|
/** 主条件内部配置组件 */
|
|
|
defineOptions({ name: 'MainConditionInnerConfig' })
|
|
|
|
|
|
const props = defineProps<{
|
|
|
- modelValue: ConditionFormData
|
|
|
+ modelValue: TriggerFormData
|
|
|
triggerType: number
|
|
|
}>()
|
|
|
|
|
|
const emit = defineEmits<{
|
|
|
- (e: 'update:modelValue', value: ConditionFormData): void
|
|
|
+ (e: 'update:modelValue', value: TriggerFormData): void
|
|
|
(e: 'validate', result: { valid: boolean; message: string }): void
|
|
|
+ (e: 'trigger-type-change', value: number): void
|
|
|
}>()
|
|
|
|
|
|
// 响应式数据
|
|
|
@@ -152,17 +171,24 @@ const getTriggerTypeText = (type: number) => {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+// 触发器类型选项
|
|
|
+const triggerTypeOptions = getTriggerTypeOptions()
|
|
|
+
|
|
|
// 事件处理
|
|
|
-const updateConditionField = (field: keyof ConditionFormData, value: any) => {
|
|
|
+const updateConditionField = (field: keyof TriggerFormData, value: any) => {
|
|
|
condition.value[field] = value
|
|
|
updateValidationResult()
|
|
|
}
|
|
|
|
|
|
-const updateCondition = (value: ConditionFormData) => {
|
|
|
+const updateCondition = (value: TriggerFormData) => {
|
|
|
emit('update:modelValue', value)
|
|
|
updateValidationResult()
|
|
|
}
|
|
|
|
|
|
+const handleTriggerTypeChange = (type: number) => {
|
|
|
+ emit('trigger-type-change', type)
|
|
|
+}
|
|
|
+
|
|
|
const handleProductChange = () => {
|
|
|
// 产品变化时清空设备和属性
|
|
|
condition.value.deviceId = undefined
|
|
|
@@ -231,7 +257,7 @@ const updateValidationResult = () => {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- if (!condition.value.param) {
|
|
|
+ if (!condition.value.value) {
|
|
|
isValid.value = false
|
|
|
validationMessage.value = '请输入比较值'
|
|
|
emit('validate', { valid: false, message: validationMessage.value })
|
|
|
@@ -251,7 +277,7 @@ watch(
|
|
|
condition.value.deviceId,
|
|
|
condition.value.identifier,
|
|
|
condition.value.operator,
|
|
|
- condition.value.param
|
|
|
+ condition.value.value
|
|
|
],
|
|
|
() => {
|
|
|
updateValidationResult()
|