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/ConditionConfig.vue | 301 ++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 301 insertions(+), 0 deletions(-)
diff --git a/src/views/iot/rule/scene/form/configs/ConditionConfig.vue b/src/views/iot/rule/scene/form/configs/ConditionConfig.vue
new file mode 100644
index 0000000..7cb9bdb
--- /dev/null
+++ b/src/views/iot/rule/scene/form/configs/ConditionConfig.vue
@@ -0,0 +1,301 @@
+<!-- 鍗曚釜鏉′欢閰嶇疆缁勪欢 -->
+<template>
+ <div class="flex flex-col gap-16px">
+ <!-- 鏉′欢绫诲瀷閫夋嫨 -->
+ <el-row :gutter="16">
+ <el-col :span="8">
+ <el-form-item label="鏉′欢绫诲瀷" required>
+ <el-select
+ :model-value="condition.type"
+ @update:model-value="(value) => updateConditionField('type', value)"
+ @change="handleConditionTypeChange"
+ placeholder="璇烽�夋嫨鏉′欢绫诲瀷"
+ class="w-full"
+ >
+ <el-option
+ v-for="option in getConditionTypeOptions()"
+ :key="option.value"
+ :label="option.label"
+ :value="option.value"
+ />
+ </el-select>
+ </el-form-item>
+ </el-col>
+ </el-row>
+
+ <!-- 浜у搧璁惧閫夋嫨 - 璁惧鐩稿叧鏉′欢鐨勫叕鍏遍儴鍒� -->
+ <el-row v-if="isDeviceCondition" :gutter="16">
+ <el-col :span="12">
+ <el-form-item label="浜у搧" required>
+ <ProductSelector
+ :model-value="condition.productId"
+ @update:model-value="(value) => updateConditionField('productId', value)"
+ @change="handleProductChange"
+ />
+ </el-form-item>
+ </el-col>
+ <el-col :span="12">
+ <el-form-item label="璁惧" required>
+ <DeviceSelector
+ :model-value="condition.deviceId"
+ @update:model-value="(value) => updateConditionField('deviceId', value)"
+ :product-id="condition.productId"
+ @change="handleDeviceChange"
+ />
+ </el-form-item>
+ </el-col>
+ </el-row>
+
+ <!-- 璁惧鐘舵�佹潯浠堕厤缃� -->
+ <div
+ v-if="condition.type === IotRuleSceneTriggerConditionTypeEnum.DEVICE_STATUS"
+ class="flex flex-col gap-16px"
+ >
+ <!-- 鐘舵�佸拰鎿嶄綔绗﹂�夋嫨 -->
+ <el-row :gutter="16">
+ <!-- 鎿嶄綔绗﹂�夋嫨 -->
+ <el-col :span="12">
+ <el-form-item label="鎿嶄綔绗�" required>
+ <el-select
+ :model-value="condition.operator"
+ @update:model-value="(value) => updateConditionField('operator', value)"
+ placeholder="璇烽�夋嫨鎿嶄綔绗�"
+ class="w-full"
+ >
+ <el-option
+ v-for="option in statusOperatorOptions"
+ :key="option.value"
+ :label="option.label"
+ :value="option.value"
+ />
+ </el-select>
+ </el-form-item>
+ </el-col>
+
+ <!-- 鐘舵�侀�夋嫨 -->
+ <el-col :span="12">
+ <el-form-item label="璁惧鐘舵��" required>
+ <el-select
+ :model-value="condition.param"
+ @update:model-value="(value) => updateConditionField('param', value)"
+ placeholder="璇烽�夋嫨璁惧鐘舵��"
+ class="w-full"
+ >
+ <el-option
+ v-for="option in deviceStatusOptions"
+ :key="option.value"
+ :label="option.label"
+ :value="option.value"
+ />
+ </el-select>
+ </el-form-item>
+ </el-col>
+ </el-row>
+ </div>
+
+ <!-- 璁惧灞炴�ф潯浠堕厤缃� -->
+ <div
+ v-else-if="condition.type === IotRuleSceneTriggerConditionTypeEnum.DEVICE_PROPERTY"
+ class="space-y-16px"
+ >
+ <!-- 灞炴�ч厤缃� -->
+ <el-row :gutter="16">
+ <!-- 灞炴��/浜嬩欢/鏈嶅姟閫夋嫨 -->
+ <el-col :span="6">
+ <el-form-item label="鐩戞帶椤�" required>
+ <PropertySelector
+ :model-value="condition.identifier"
+ @update:model-value="(value) => updateConditionField('identifier', value)"
+ :trigger-type="triggerType"
+ :product-id="condition.productId"
+ :device-id="condition.deviceId"
+ @change="handlePropertyChange"
+ />
+ </el-form-item>
+ </el-col>
+
+ <!-- 鎿嶄綔绗﹂�夋嫨 -->
+ <el-col :span="6">
+ <el-form-item label="鎿嶄綔绗�" required>
+ <OperatorSelector
+ :model-value="condition.operator"
+ @update:model-value="(value) => updateConditionField('operator', value)"
+ :property-type="propertyType"
+ @change="handleOperatorChange"
+ />
+ </el-form-item>
+ </el-col>
+
+ <!-- 鍊艰緭鍏� -->
+ <el-col :span="12">
+ <el-form-item label="姣旇緝鍊�" required>
+ <ValueInput
+ :model-value="condition.param"
+ @update:model-value="(value) => updateConditionField('param', value)"
+ :property-type="propertyType"
+ :operator="condition.operator"
+ :property-config="propertyConfig"
+ />
+ </el-form-item>
+ </el-col>
+ </el-row>
+ </div>
+
+ <!-- 褰撳墠鏃堕棿鏉′欢閰嶇疆 -->
+ <CurrentTimeConditionConfig
+ v-else-if="condition.type === IotRuleSceneTriggerConditionTypeEnum.CURRENT_TIME"
+ :model-value="condition"
+ @update:model-value="updateCondition"
+ />
+ </div>
+</template>
+
+<script setup lang="ts">
+import { useVModel } from '@vueuse/core'
+import CurrentTimeConditionConfig from './CurrentTimeConditionConfig.vue'
+import ProductSelector from '../selectors/ProductSelector.vue'
+import DeviceSelector from '../selectors/DeviceSelector.vue'
+import PropertySelector from '../selectors/PropertySelector.vue'
+import OperatorSelector from '../selectors/OperatorSelector.vue'
+import ValueInput from '../inputs/ValueInput.vue'
+import type { TriggerCondition } from '@/api/iot/rule/scene'
+import {
+ IotRuleSceneTriggerConditionTypeEnum,
+ IotRuleSceneTriggerConditionParameterOperatorEnum,
+ getConditionTypeOptions,
+ IoTDeviceStatusEnum
+} from '@/views/iot/utils/constants'
+
+/** 鍗曚釜鏉′欢閰嶇疆缁勪欢 */
+defineOptions({ name: 'ConditionConfig' })
+
+const props = defineProps<{
+ modelValue: TriggerCondition
+ triggerType: number
+}>()
+
+const emit = defineEmits<{
+ (e: 'update:modelValue', value: TriggerCondition): void
+}>()
+
+/** 鑾峰彇璁惧鐘舵�侀�夐」 */
+const deviceStatusOptions = [
+ {
+ value: IoTDeviceStatusEnum.ONLINE.value,
+ label: IoTDeviceStatusEnum.ONLINE.label
+ },
+ {
+ value: IoTDeviceStatusEnum.OFFLINE.value,
+ label: IoTDeviceStatusEnum.OFFLINE.label
+ }
+]
+
+/** 鑾峰彇鐘舵�佹搷浣滅閫夐」 */
+const statusOperatorOptions = [
+ {
+ value: IotRuleSceneTriggerConditionParameterOperatorEnum.EQUALS.value,
+ label: IotRuleSceneTriggerConditionParameterOperatorEnum.EQUALS.name
+ },
+ {
+ value: IotRuleSceneTriggerConditionParameterOperatorEnum.NOT_EQUALS.value,
+ label: IotRuleSceneTriggerConditionParameterOperatorEnum.NOT_EQUALS.name
+ }
+]
+
+const condition = useVModel(props, 'modelValue', emit)
+
+const propertyType = ref<string>('string') // 灞炴�х被鍨�
+const propertyConfig = ref<any>(null) // 灞炴�ч厤缃�
+const isDeviceCondition = computed(() => {
+ return (
+ condition.value.type === IotRuleSceneTriggerConditionTypeEnum.DEVICE_STATUS ||
+ condition.value.type === IotRuleSceneTriggerConditionTypeEnum.DEVICE_PROPERTY
+ )
+}) // 璁$畻灞炴�э細鍒ゆ柇鏄惁涓鸿澶囩浉鍏虫潯浠�
+
+/**
+ * 鏇存柊鏉′欢瀛楁
+ * @param field 瀛楁鍚�
+ * @param value 瀛楁鍊�
+ */
+const updateConditionField = (field: any, value: any) => {
+ ;(condition.value as any)[field] = value
+ emit('update:modelValue', condition.value)
+}
+
+/**
+ * 鏇存柊鏁翠釜鏉′欢瀵硅薄
+ * @param newCondition 鏂扮殑鏉′欢瀵硅薄
+ */
+const updateCondition = (newCondition: TriggerCondition) => {
+ condition.value = newCondition
+ emit('update:modelValue', condition.value)
+}
+
+/**
+ * 澶勭悊鏉′欢绫诲瀷鍙樺寲浜嬩欢
+ * @param type 鏉′欢绫诲瀷
+ */
+const handleConditionTypeChange = (type: number) => {
+ // 鏍规嵁鏉′欢绫诲瀷娓呯悊瀛楁
+ const isCurrentTime = type === IotRuleSceneTriggerConditionTypeEnum.CURRENT_TIME
+ const isDeviceStatus = type === IotRuleSceneTriggerConditionTypeEnum.DEVICE_STATUS
+
+ // 娓呯悊鏍囪瘑绗﹀瓧娈碉紙鏃堕棿鏉′欢鍜岃澶囩姸鎬佹潯浠堕兘涓嶉渶瑕侊級
+ if (isCurrentTime || isDeviceStatus) {
+ condition.value.identifier = undefined
+ }
+
+ // 娓呯悊璁惧鐩稿叧瀛楁锛堜粎鏃堕棿鏉′欢闇�瑕侊級
+ if (isCurrentTime) {
+ condition.value.productId = undefined
+ condition.value.deviceId = undefined
+ }
+
+ // 璁剧疆榛樿鎿嶄綔绗�
+ condition.value.operator = isCurrentTime
+ ? 'at_time'
+ : IotRuleSceneTriggerConditionParameterOperatorEnum.EQUALS.value
+
+ // 娓呯┖鍙傛暟鍊�
+ condition.value.param = ''
+}
+
+/** 澶勭悊浜у搧鍙樺寲浜嬩欢 */
+const handleProductChange = (_: number) => {
+ // 浜у搧鍙樺寲鏃舵竻绌鸿澶囧拰灞炴��
+ condition.value.deviceId = undefined
+ condition.value.identifier = ''
+}
+
+/** 澶勭悊璁惧鍙樺寲浜嬩欢 */
+const handleDeviceChange = (_: number) => {
+ // 璁惧鍙樺寲鏃舵竻绌哄睘鎬�
+ condition.value.identifier = ''
+}
+
+/**
+ * 澶勭悊灞炴�у彉鍖栦簨浠�
+ * @param propertyInfo 灞炴�т俊鎭璞�
+ */
+const handlePropertyChange = (propertyInfo: { type: string; config: any }) => {
+ propertyType.value = propertyInfo.type
+ propertyConfig.value = propertyInfo.config
+
+ // 閲嶇疆鎿嶄綔绗﹀拰鍊�
+ condition.value.operator = IotRuleSceneTriggerConditionParameterOperatorEnum.EQUALS.value
+ condition.value.param = ''
+}
+
+/** 澶勭悊鎿嶄綔绗﹀彉鍖栦簨浠� */
+const handleOperatorChange = () => {
+ // 閲嶇疆鍊�
+ condition.value.param = ''
+}
+</script>
+
+<style scoped>
+:deep(.el-form-item) {
+ margin-bottom: 0;
+}
+</style>
--
Gitblit v1.8.0