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/MainConditionInnerConfig.vue | 340 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 340 insertions(+), 0 deletions(-)
diff --git a/src/views/iot/rule/scene/form/configs/MainConditionInnerConfig.vue b/src/views/iot/rule/scene/form/configs/MainConditionInnerConfig.vue
new file mode 100644
index 0000000..4c61d31
--- /dev/null
+++ b/src/views/iot/rule/scene/form/configs/MainConditionInnerConfig.vue
@@ -0,0 +1,340 @@
+<template>
+ <div class="space-y-16px">
+ <!-- 瑙﹀彂浜嬩欢绫诲瀷閫夋嫨 -->
+ <el-form-item label="瑙﹀彂浜嬩欢绫诲瀷" required>
+ <el-select
+ :model-value="triggerType"
+ @update:model-value="handleTriggerTypeChange"
+ placeholder="璇烽�夋嫨瑙﹀彂浜嬩欢绫诲瀷"
+ class="w-full"
+ >
+ <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">
+ <!-- 浜у搧璁惧閫夋嫨 -->
+ <el-row :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>
+
+ <!-- 灞炴�ч厤缃� -->
+ <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 v-if="needsOperatorSelector" :span="6">
+ <el-form-item label="鎿嶄綔绗�" required>
+ <OperatorSelector
+ :model-value="condition.operator"
+ @update:model-value="(value) => updateConditionField('operator', value)"
+ :property-type="propertyType"
+ />
+ </el-form-item>
+ </el-col>
+
+ <!-- 鍊艰緭鍏� -->
+ <el-col :span="isWideValueColumn ? 18 : 12">
+ <el-form-item :label="valueInputLabel" required>
+ <!-- 鏈嶅姟璋冪敤鍙傛暟閰嶇疆 -->
+ <JsonParamsInput
+ v-if="triggerType === IotRuleSceneTriggerTypeEnum.DEVICE_SERVICE_INVOKE"
+ v-model="condition.value"
+ type="service"
+ :config="serviceConfig"
+ placeholder="璇疯緭鍏� JSON 鏍煎紡鐨勬湇鍔″弬鏁�"
+ />
+ <!-- 浜嬩欢涓婃姤鍙傛暟閰嶇疆 -->
+ <JsonParamsInput
+ v-else-if="triggerType === IotRuleSceneTriggerTypeEnum.DEVICE_EVENT_POST"
+ v-model="condition.value"
+ type="event"
+ :config="eventConfig"
+ placeholder="璇疯緭鍏� JSON 鏍煎紡鐨勪簨浠跺弬鏁�"
+ />
+ <!-- 鏅�氬�艰緭鍏� -->
+ <ValueInput
+ v-else
+ :model-value="condition.value"
+ @update:model-value="(value) => updateConditionField('value', value)"
+ :property-type="propertyType"
+ :operator="condition.operator"
+ :property-config="propertyConfig"
+ />
+ </el-form-item>
+ </el-col>
+ </el-row>
+ </div>
+
+ <!-- 璁惧鐘舵�佹潯浠堕厤缃� -->
+ <div v-else-if="isDeviceStatusTrigger" class="space-y-16px">
+ <!-- 璁惧鐘舵�佽Е鍙戝櫒浣跨敤绠�鍖栫殑閰嶇疆 -->
+ <el-row :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>
+ <el-row :gutter="16">
+ <el-col :span="6">
+ <el-form-item label="鎿嶄綔绗�" required>
+ <el-select
+ :model-value="condition.operator"
+ @update:model-value="(value) => updateConditionField('operator', value)"
+ placeholder="璇烽�夋嫨鎿嶄綔绗�"
+ class="w-full"
+ >
+ <el-option
+ :label="IotRuleSceneTriggerConditionParameterOperatorEnum.EQUALS.name"
+ :value="IotRuleSceneTriggerConditionParameterOperatorEnum.EQUALS.value"
+ />
+ </el-select>
+ </el-form-item>
+ </el-col>
+ <el-col :span="6">
+ <el-form-item label="鍙傛暟" required>
+ <el-select
+ :model-value="condition.value"
+ @update:model-value="(value) => updateConditionField('value', value)"
+ placeholder="璇烽�夋嫨鎿嶄綔绗�"
+ class="w-full"
+ >
+ <el-option
+ v-for="option in deviceStatusChangeOptions"
+ :key="option.value"
+ :label="option.label"
+ :value="option.value"
+ />
+ </el-select>
+ </el-form-item>
+ </el-col>
+ </el-row>
+ </div>
+
+ <!-- 鍏朵粬瑙﹀彂绫诲瀷鐨勬彁绀� -->
+ <div v-else class="text-center py-20px">
+ <p class="text-14px text-[var(--el-text-color-secondary)] mb-4px">
+ 褰撳墠瑙﹀彂浜嬩欢绫诲瀷锛歿{ getTriggerTypeLabel(triggerType) }}
+ </p>
+ <p class="text-12px text-[var(--el-text-color-placeholder)]">
+ 姝よЕ鍙戠被鍨嬫殏涓嶉渶瑕侀厤缃澶栨潯浠�
+ </p>
+ </div>
+ </div>
+</template>
+
+<script setup lang="ts">
+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 JsonParamsInput from '../inputs/JsonParamsInput.vue'
+
+import type { Trigger } from '@/api/iot/rule/scene'
+import {
+ IotRuleSceneTriggerTypeEnum,
+ triggerTypeOptions,
+ getTriggerTypeLabel,
+ IotRuleSceneTriggerConditionParameterOperatorEnum,
+ IoTDeviceStatusEnum
+} from '@/views/iot/utils/constants'
+import { useVModel } from '@vueuse/core'
+
+/** 涓绘潯浠跺唴閮ㄩ厤缃粍浠� */
+defineOptions({ name: 'MainConditionInnerConfig' })
+
+const props = defineProps<{
+ modelValue: Trigger
+ triggerType: number
+}>()
+
+const emit = defineEmits<{
+ (e: 'update:modelValue', value: Trigger): void
+ (e: 'trigger-type-change', value: number): void
+}>()
+
+/** 鑾峰彇璁惧鐘舵�佸彉鏇撮�夐」锛堢敤浜庤Е鍙戝櫒閰嶇疆锛� */
+const deviceStatusChangeOptions = [
+ {
+ label: IoTDeviceStatusEnum.ONLINE.label,
+ value: IoTDeviceStatusEnum.ONLINE.value
+ },
+ {
+ label: IoTDeviceStatusEnum.OFFLINE.label,
+ value: IoTDeviceStatusEnum.OFFLINE.value
+ }
+]
+
+const condition = useVModel(props, 'modelValue', emit)
+const propertyType = ref('') // 灞炴�х被鍨�
+const propertyConfig = ref<any>(null) // 灞炴�ч厤缃�
+
+// 璁$畻灞炴�э細鏄惁涓鸿澶囧睘鎬цЕ鍙戝櫒
+const isDevicePropertyTrigger = computed(() => {
+ return (
+ props.triggerType === IotRuleSceneTriggerTypeEnum.DEVICE_PROPERTY_POST ||
+ props.triggerType === IotRuleSceneTriggerTypeEnum.DEVICE_EVENT_POST ||
+ props.triggerType === IotRuleSceneTriggerTypeEnum.DEVICE_SERVICE_INVOKE
+ )
+})
+
+// 璁$畻灞炴�э細鏄惁涓鸿澶囩姸鎬佽Е鍙戝櫒
+const isDeviceStatusTrigger = computed(() => {
+ return props.triggerType === IotRuleSceneTriggerTypeEnum.DEVICE_STATE_UPDATE
+})
+
+// 璁$畻灞炴�э細鏄惁闇�瑕佹搷浣滅閫夋嫨锛堟湇鍔¤皟鐢ㄥ拰浜嬩欢涓婃姤涓嶉渶瑕佹搷浣滅锛�
+const needsOperatorSelector = computed(() => {
+ const noOperatorTriggerTypes = [
+ IotRuleSceneTriggerTypeEnum.DEVICE_SERVICE_INVOKE,
+ IotRuleSceneTriggerTypeEnum.DEVICE_EVENT_POST
+ ] as number[]
+ return !noOperatorTriggerTypes.includes(props.triggerType)
+})
+
+// 璁$畻灞炴�э細鏄惁闇�瑕佸鍒楀竷灞�锛堟湇鍔¤皟鐢ㄥ拰浜嬩欢涓婃姤涓嶉渶瑕佹搷浣滅鍒楋紝鎵�浠ュ�艰緭鍏ュ垪鏇村锛�
+const isWideValueColumn = computed(() => {
+ const wideColumnTriggerTypes = [
+ IotRuleSceneTriggerTypeEnum.DEVICE_SERVICE_INVOKE,
+ IotRuleSceneTriggerTypeEnum.DEVICE_EVENT_POST
+ ] as number[]
+ return wideColumnTriggerTypes.includes(props.triggerType)
+})
+
+// 璁$畻灞炴�э細鍊艰緭鍏ュ瓧娈电殑鏍囩鏂囨湰
+const valueInputLabel = computed(() => {
+ return props.triggerType === IotRuleSceneTriggerTypeEnum.DEVICE_SERVICE_INVOKE
+ ? '鏈嶅姟鍙傛暟'
+ : '姣旇緝鍊�'
+})
+
+// 璁$畻灞炴�э細鏈嶅姟閰嶇疆 - 鐢ㄤ簬 JsonParamsInput
+const serviceConfig = computed(() => {
+ if (
+ propertyConfig.value &&
+ props.triggerType === IotRuleSceneTriggerTypeEnum.DEVICE_SERVICE_INVOKE
+ ) {
+ return {
+ service: {
+ name: propertyConfig.value.name || '鏈嶅姟',
+ inputParams: propertyConfig.value.inputParams || []
+ }
+ }
+ }
+ return undefined
+})
+
+// 璁$畻灞炴�э細浜嬩欢閰嶇疆 - 鐢ㄤ簬 JsonParamsInput
+const eventConfig = computed(() => {
+ if (propertyConfig.value && props.triggerType === IotRuleSceneTriggerTypeEnum.DEVICE_EVENT_POST) {
+ return {
+ event: {
+ name: propertyConfig.value.name || '浜嬩欢',
+ outputParams: propertyConfig.value.outputParams || []
+ }
+ }
+ }
+ return undefined
+})
+
+/**
+ * 鏇存柊鏉′欢瀛楁
+ * @param field 瀛楁鍚�
+ * @param value 瀛楁鍊�
+ */
+const updateConditionField = (field: any, value: any) => {
+ condition.value[field] = value
+}
+
+/**
+ * 澶勭悊瑙﹀彂鍣ㄧ被鍨嬪彉鍖栦簨浠�
+ * @param type 瑙﹀彂鍣ㄧ被鍨�
+ */
+const handleTriggerTypeChange = (type: number) => {
+ emit('trigger-type-change', type)
+}
+
+/** 澶勭悊浜у搧鍙樺寲浜嬩欢 */
+const handleProductChange = () => {
+ // 浜у搧鍙樺寲鏃舵竻绌鸿澶囧拰灞炴��
+ condition.value.deviceId = undefined
+ condition.value.identifier = ''
+}
+
+/** 澶勭悊璁惧鍙樺寲浜嬩欢 */
+const handleDeviceChange = () => {
+ // 璁惧鍙樺寲鏃舵竻绌哄睘鎬�
+ condition.value.identifier = ''
+}
+
+/**
+ * 澶勭悊灞炴�у彉鍖栦簨浠�
+ * @param propertyInfo 灞炴�т俊鎭璞�
+ */
+const handlePropertyChange = (propertyInfo: any) => {
+ if (propertyInfo) {
+ propertyType.value = propertyInfo.type
+ propertyConfig.value = propertyInfo.config
+
+ // 瀵逛簬浜嬩欢涓婃姤鍜屾湇鍔¤皟鐢紝鑷姩璁剧疆鎿嶄綔绗︿负 '='
+ if (
+ props.triggerType === IotRuleSceneTriggerTypeEnum.DEVICE_EVENT_POST ||
+ props.triggerType === IotRuleSceneTriggerTypeEnum.DEVICE_SERVICE_INVOKE
+ ) {
+ condition.value.operator = IotRuleSceneTriggerConditionParameterOperatorEnum.EQUALS.value
+ }
+ }
+}
+</script>
--
Gitblit v1.8.0