|
@@ -1,10 +1,7 @@
|
|
|
<template>
|
|
<template>
|
|
|
<div class="p-16px">
|
|
<div class="p-16px">
|
|
|
<!-- 空状态 -->
|
|
<!-- 空状态 -->
|
|
|
- <div
|
|
|
|
|
- v-if="!subGroup.conditions || subGroup.conditions.length === 0"
|
|
|
|
|
- class="text-center py-24px"
|
|
|
|
|
- >
|
|
|
|
|
|
|
+ <div v-if="!subGroup || subGroup.length === 0" class="text-center py-24px">
|
|
|
<div class="flex flex-col items-center gap-12px">
|
|
<div class="flex flex-col items-center gap-12px">
|
|
|
<Icon icon="ep:plus" class="text-32px text-[var(--el-text-color-placeholder)]" />
|
|
<Icon icon="ep:plus" class="text-32px text-[var(--el-text-color-placeholder)]" />
|
|
|
<div class="text-[var(--el-text-color-secondary)]">
|
|
<div class="text-[var(--el-text-color-secondary)]">
|
|
@@ -21,7 +18,7 @@
|
|
|
<!-- 条件列表 -->
|
|
<!-- 条件列表 -->
|
|
|
<div v-else class="space-y-16px">
|
|
<div v-else class="space-y-16px">
|
|
|
<div
|
|
<div
|
|
|
- v-for="(condition, conditionIndex) in subGroup.conditions"
|
|
|
|
|
|
|
+ v-for="(condition, conditionIndex) in subGroup"
|
|
|
:key="`condition-${conditionIndex}`"
|
|
:key="`condition-${conditionIndex}`"
|
|
|
class="relative"
|
|
class="relative"
|
|
|
>
|
|
>
|
|
@@ -47,7 +44,7 @@
|
|
|
size="small"
|
|
size="small"
|
|
|
text
|
|
text
|
|
|
@click="removeCondition(conditionIndex)"
|
|
@click="removeCondition(conditionIndex)"
|
|
|
- v-if="subGroup.conditions!.length > 1"
|
|
|
|
|
|
|
+ v-if="subGroup!.length > 1"
|
|
|
class="hover:bg-red-50"
|
|
class="hover:bg-red-50"
|
|
|
>
|
|
>
|
|
|
<Icon icon="ep:delete" />
|
|
<Icon icon="ep:delete" />
|
|
@@ -67,11 +64,7 @@
|
|
|
|
|
|
|
|
<!-- 添加条件按钮 -->
|
|
<!-- 添加条件按钮 -->
|
|
|
<div
|
|
<div
|
|
|
- v-if="
|
|
|
|
|
- subGroup.conditions &&
|
|
|
|
|
- subGroup.conditions.length > 0 &&
|
|
|
|
|
- subGroup.conditions.length < maxConditions
|
|
|
|
|
- "
|
|
|
|
|
|
|
+ v-if="subGroup && subGroup.length > 0 && subGroup.length < maxConditions"
|
|
|
class="text-center py-16px"
|
|
class="text-center py-16px"
|
|
|
>
|
|
>
|
|
|
<el-button type="primary" plain @click="addCondition">
|
|
<el-button type="primary" plain @click="addCondition">
|
|
@@ -90,22 +83,21 @@
|
|
|
import { useVModel } from '@vueuse/core'
|
|
import { useVModel } from '@vueuse/core'
|
|
|
import ConditionConfig from './ConditionConfig.vue'
|
|
import ConditionConfig from './ConditionConfig.vue'
|
|
|
import {
|
|
import {
|
|
|
- ConditionFormData,
|
|
|
|
|
IotRuleSceneTriggerConditionTypeEnum,
|
|
IotRuleSceneTriggerConditionTypeEnum,
|
|
|
- SubConditionGroupFormData
|
|
|
|
|
|
|
+ TriggerConditionFormData
|
|
|
} from '@/api/iot/rule/scene/scene.types'
|
|
} from '@/api/iot/rule/scene/scene.types'
|
|
|
|
|
|
|
|
/** 子条件组配置组件 */
|
|
/** 子条件组配置组件 */
|
|
|
defineOptions({ name: 'SubConditionGroupConfig' })
|
|
defineOptions({ name: 'SubConditionGroupConfig' })
|
|
|
|
|
|
|
|
const props = defineProps<{
|
|
const props = defineProps<{
|
|
|
- modelValue: SubConditionGroupFormData
|
|
|
|
|
|
|
+ modelValue: TriggerConditionFormData[]
|
|
|
triggerType: number
|
|
triggerType: number
|
|
|
maxConditions?: number
|
|
maxConditions?: number
|
|
|
}>()
|
|
}>()
|
|
|
|
|
|
|
|
const emit = defineEmits<{
|
|
const emit = defineEmits<{
|
|
|
- (e: 'update:modelValue', value: SubConditionGroupFormData): void
|
|
|
|
|
|
|
+ (e: 'update:modelValue', value: TriggerConditionFormData[]): void
|
|
|
(e: 'validate', result: { valid: boolean; message: string }): void
|
|
(e: 'validate', result: { valid: boolean; message: string }): void
|
|
|
}>()
|
|
}>()
|
|
|
|
|
|
|
@@ -119,15 +111,13 @@ const conditionValidations = ref<{ [key: number]: { valid: boolean; message: str
|
|
|
|
|
|
|
|
// 事件处理
|
|
// 事件处理
|
|
|
const addCondition = () => {
|
|
const addCondition = () => {
|
|
|
- if (!subGroup.value.conditions) {
|
|
|
|
|
- subGroup.value.conditions = []
|
|
|
|
|
|
|
+ if (!subGroup.value) {
|
|
|
|
|
+ subGroup.value = []
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- if (subGroup.value.conditions.length >= maxConditions.value) {
|
|
|
|
|
|
|
+ if (subGroup.value.length >= maxConditions.value) {
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- const newCondition: ConditionFormData = {
|
|
|
|
|
|
|
+ const newCondition: TriggerConditionFormData = {
|
|
|
type: IotRuleSceneTriggerConditionTypeEnum.DEVICE_PROPERTY, // 默认为设备属性
|
|
type: IotRuleSceneTriggerConditionTypeEnum.DEVICE_PROPERTY, // 默认为设备属性
|
|
|
productId: undefined,
|
|
productId: undefined,
|
|
|
deviceId: undefined,
|
|
deviceId: undefined,
|
|
@@ -135,13 +125,12 @@ const addCondition = () => {
|
|
|
operator: '=',
|
|
operator: '=',
|
|
|
param: ''
|
|
param: ''
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- subGroup.value.conditions.push(newCondition)
|
|
|
|
|
|
|
+ subGroup.value.push(newCondition)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const removeCondition = (index: number) => {
|
|
const removeCondition = (index: number) => {
|
|
|
- if (subGroup.value.conditions) {
|
|
|
|
|
- subGroup.value.conditions.splice(index, 1)
|
|
|
|
|
|
|
+ if (subGroup.value) {
|
|
|
|
|
+ subGroup.value.splice(index, 1)
|
|
|
delete conditionValidations.value[index]
|
|
delete conditionValidations.value[index]
|
|
|
|
|
|
|
|
// 重新索引验证结果
|
|
// 重新索引验证结果
|
|
@@ -160,9 +149,9 @@ const removeCondition = (index: number) => {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-const updateCondition = (index: number, condition: ConditionFormData) => {
|
|
|
|
|
- if (subGroup.value.conditions) {
|
|
|
|
|
- subGroup.value.conditions[index] = condition
|
|
|
|
|
|
|
+const updateCondition = (index: number, condition: TriggerConditionFormData) => {
|
|
|
|
|
+ if (subGroup.value) {
|
|
|
|
|
+ subGroup.value[index] = condition
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -172,7 +161,7 @@ const handleConditionValidate = (index: number, result: { valid: boolean; messag
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const updateValidationResult = () => {
|
|
const updateValidationResult = () => {
|
|
|
- if (!subGroup.value.conditions || subGroup.value.conditions.length === 0) {
|
|
|
|
|
|
|
+ if (!subGroup.value || subGroup.value.length === 0) {
|
|
|
emit('validate', { valid: false, message: '子条件组至少需要一个条件' })
|
|
emit('validate', { valid: false, message: '子条件组至少需要一个条件' })
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
@@ -190,7 +179,7 @@ const updateValidationResult = () => {
|
|
|
|
|
|
|
|
// 监听变化
|
|
// 监听变化
|
|
|
watch(
|
|
watch(
|
|
|
- () => subGroup.value.conditions,
|
|
|
|
|
|
|
+ () => subGroup.value,
|
|
|
() => {
|
|
() => {
|
|
|
updateValidationResult()
|
|
updateValidationResult()
|
|
|
},
|
|
},
|