From a1d7e81859f554f3a53680cc35f0f49bf1f77098 Mon Sep 17 00:00:00 2001
From: wwf <1971391498@qq.com>
Date: 星期四, 14 五月 2026 14:37:02 +0800
Subject: [PATCH] 导入项目
---
src/views/iot/rule/scene/form/configs/SubConditionGroupConfig.vue | 156 ++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 156 insertions(+), 0 deletions(-)
diff --git a/src/views/iot/rule/scene/form/configs/SubConditionGroupConfig.vue b/src/views/iot/rule/scene/form/configs/SubConditionGroupConfig.vue
new file mode 100644
index 0000000..3097fdc
--- /dev/null
+++ b/src/views/iot/rule/scene/form/configs/SubConditionGroupConfig.vue
@@ -0,0 +1,156 @@
+<template>
+ <div class="p-16px">
+ <!-- 绌虹姸鎬� -->
+ <div v-if="!subGroup || subGroup.length === 0" class="text-center py-24px">
+ <div class="flex flex-col items-center gap-12px">
+ <Icon icon="ep:plus" class="text-32px text-[var(--el-text-color-placeholder)]" />
+ <div class="text-[var(--el-text-color-secondary)]">
+ <p class="text-14px font-500 mb-4px">鏆傛棤鏉′欢</p>
+ <p class="text-12px">鐐瑰嚮涓嬫柟鎸夐挳娣诲姞绗竴涓潯浠�</p>
+ </div>
+ <el-button type="primary" @click="addCondition">
+ <Icon icon="ep:plus" />
+ 娣诲姞鏉′欢
+ </el-button>
+ </div>
+ </div>
+
+ <!-- 鏉′欢鍒楄〃 -->
+ <div v-else class="space-y-16px">
+ <div
+ v-for="(condition, conditionIndex) in subGroup"
+ :key="`condition-${conditionIndex}`"
+ class="relative"
+ >
+ <!-- 鏉′欢閰嶇疆 -->
+ <div
+ class="border border-[var(--el-border-color-lighter)] rounded-6px bg-[var(--el-fill-color-blank)] shadow-sm"
+ >
+ <div
+ class="flex items-center justify-between p-12px bg-[var(--el-fill-color-light)] border-b border-[var(--el-border-color-lighter)] rounded-t-4px"
+ >
+ <div class="flex items-center gap-8px">
+ <div
+ class="w-20px h-20px bg-blue-500 text-white rounded-full flex items-center justify-center text-10px font-bold"
+ >
+ {{ conditionIndex + 1 }}
+ </div>
+ <span class="text-12px font-500 text-[var(--el-text-color-primary)]"
+ >鏉′欢 {{ conditionIndex + 1 }}</span
+ >
+ </div>
+ <el-button
+ type="danger"
+ size="small"
+ text
+ @click="removeCondition(conditionIndex)"
+ v-if="subGroup!.length > 1"
+ class="hover:bg-red-50"
+ >
+ <Icon icon="ep:delete" />
+ </el-button>
+ </div>
+
+ <div class="p-12px">
+ <ConditionConfig
+ :model-value="condition"
+ @update:model-value="(value) => updateCondition(conditionIndex, value)"
+ :trigger-type="triggerType"
+ />
+ </div>
+ </div>
+ </div>
+
+ <!-- 娣诲姞鏉′欢鎸夐挳 -->
+ <div
+ v-if="subGroup && subGroup.length > 0 && subGroup.length < maxConditions"
+ class="text-center py-16px"
+ >
+ <el-button type="primary" plain @click="addCondition">
+ <Icon icon="ep:plus" />
+ 缁х画娣诲姞鏉′欢
+ </el-button>
+ <span class="block mt-8px text-12px text-[var(--el-text-color-secondary)]">
+ 鏈�澶氬彲娣诲姞 {{ maxConditions }} 涓潯浠�
+ </span>
+ </div>
+ </div>
+ </div>
+</template>
+
+<script setup lang="ts">
+import { nextTick } from 'vue'
+import { useVModel } from '@vueuse/core'
+import ConditionConfig from './ConditionConfig.vue'
+import type { TriggerCondition } from '@/api/iot/rule/scene'
+import {
+ IotRuleSceneTriggerConditionTypeEnum,
+ IotRuleSceneTriggerConditionParameterOperatorEnum
+} from '@/views/iot/utils/constants'
+
+/** 瀛愭潯浠剁粍閰嶇疆缁勪欢 */
+defineOptions({ name: 'SubConditionGroupConfig' })
+
+const props = defineProps<{
+ modelValue: TriggerCondition[]
+ triggerType: number
+ maxConditions?: number
+}>()
+
+const emit = defineEmits<{
+ (e: 'update:modelValue', value: TriggerCondition[]): void
+}>()
+
+const subGroup = useVModel(props, 'modelValue', emit)
+
+const maxConditions = computed(() => props.maxConditions || 3) // 鏈�澶ф潯浠舵暟閲�
+
+/** 娣诲姞鏉′欢 */
+const addCondition = async () => {
+ // 纭繚 subGroup.value 鏄竴涓暟缁�
+ if (!subGroup.value) {
+ subGroup.value = []
+ }
+
+ // 妫�鏌ユ槸鍚﹁揪鍒版渶澶ф潯浠舵暟閲忛檺鍒�
+ if (subGroup.value?.length >= maxConditions.value) {
+ return
+ }
+
+ const newCondition: TriggerCondition = {
+ type: IotRuleSceneTriggerConditionTypeEnum.DEVICE_PROPERTY, // 榛樿涓鸿澶囧睘鎬�
+ productId: undefined,
+ deviceId: undefined,
+ identifier: '',
+ operator: IotRuleSceneTriggerConditionParameterOperatorEnum.EQUALS.value, // 浣跨敤鏋氫妇榛樿鍊�
+ param: ''
+ }
+
+ // 浣跨敤 nextTick 纭繚鍝嶅簲寮忔洿鏂板畬鎴愬悗鍐嶆坊鍔犳柊鏉′欢
+ await nextTick()
+ if (subGroup.value) {
+ subGroup.value.push(newCondition)
+ }
+}
+
+/**
+ * 绉婚櫎鏉′欢
+ * @param index 鏉′欢绱㈠紩
+ */
+const removeCondition = (index: number) => {
+ if (subGroup.value) {
+ subGroup.value.splice(index, 1)
+ }
+}
+
+/**
+ * 鏇存柊鏉′欢
+ * @param index 鏉′欢绱㈠紩
+ * @param condition 鏉′欢瀵硅薄
+ */
+const updateCondition = (index: number, condition: TriggerCondition) => {
+ if (subGroup.value) {
+ subGroup.value[index] = condition
+ }
+}
+</script>
--
Gitblit v1.8.0