2025-07-28 22:08:20 +08:00
|
|
|
|
<template>
|
|
|
|
|
|
<div class="space-y-16px">
|
2025-08-02 13:18:12 +08:00
|
|
|
|
<!-- 触发事件类型选择 -->
|
|
|
|
|
|
<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>
|
|
|
|
|
|
|
2025-07-28 22:08:20 +08:00
|
|
|
|
<!-- 设备属性条件配置 -->
|
|
|
|
|
|
<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>
|
|
|
|
|
|
|
2025-08-05 21:26:01 +08:00
|
|
|
|
<!-- 操作符选择 - 服务调用和事件上报不需要操作符 -->
|
|
|
|
|
|
<el-col
|
|
|
|
|
|
v-if="
|
|
|
|
|
|
triggerType !== IotRuleSceneTriggerTypeEnum.DEVICE_SERVICE_INVOKE &&
|
|
|
|
|
|
triggerType !== IotRuleSceneTriggerTypeEnum.DEVICE_EVENT_POST
|
|
|
|
|
|
"
|
|
|
|
|
|
:span="6"
|
|
|
|
|
|
>
|
2025-07-28 22:08:20 +08:00
|
|
|
|
<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>
|
|
|
|
|
|
|
|
|
|
|
|
<!-- 值输入 -->
|
2025-08-05 21:26:01 +08:00
|
|
|
|
<el-col
|
|
|
|
|
|
:span="
|
|
|
|
|
|
triggerType === IotRuleSceneTriggerTypeEnum.DEVICE_SERVICE_INVOKE ||
|
|
|
|
|
|
triggerType === IotRuleSceneTriggerTypeEnum.DEVICE_EVENT_POST
|
|
|
|
|
|
? 18
|
|
|
|
|
|
: 12
|
|
|
|
|
|
"
|
|
|
|
|
|
>
|
2025-08-04 15:49:53 +08:00
|
|
|
|
<el-form-item
|
|
|
|
|
|
:label="
|
|
|
|
|
|
triggerType === IotRuleSceneTriggerTypeEnum.DEVICE_SERVICE_INVOKE
|
|
|
|
|
|
? '服务参数'
|
|
|
|
|
|
: '比较值'
|
|
|
|
|
|
"
|
|
|
|
|
|
required
|
|
|
|
|
|
>
|
|
|
|
|
|
<!-- 服务调用参数配置 -->
|
2025-08-05 17:33:20 +08:00
|
|
|
|
<JsonParamsInput
|
2025-08-04 15:49:53 +08:00
|
|
|
|
v-if="triggerType === IotRuleSceneTriggerTypeEnum.DEVICE_SERVICE_INVOKE"
|
2025-08-05 22:12:19 +08:00
|
|
|
|
v-model="condition.value"
|
2025-08-05 17:33:20 +08:00
|
|
|
|
type="service"
|
2025-08-05 21:26:01 +08:00
|
|
|
|
:config="serviceConfig"
|
2025-08-05 17:33:20 +08:00
|
|
|
|
placeholder="请输入JSON格式的服务参数"
|
|
|
|
|
|
/>
|
|
|
|
|
|
<!-- 事件上报参数配置 -->
|
|
|
|
|
|
<JsonParamsInput
|
|
|
|
|
|
v-else-if="triggerType === IotRuleSceneTriggerTypeEnum.DEVICE_EVENT_POST"
|
2025-08-05 22:12:19 +08:00
|
|
|
|
v-model="condition.value"
|
2025-08-05 17:33:20 +08:00
|
|
|
|
type="event"
|
2025-08-05 21:26:01 +08:00
|
|
|
|
:config="eventConfig"
|
2025-08-05 17:33:20 +08:00
|
|
|
|
placeholder="请输入JSON格式的事件参数"
|
2025-08-04 15:49:53 +08:00
|
|
|
|
/>
|
|
|
|
|
|
<!-- 普通值输入 -->
|
2025-07-28 22:08:20 +08:00
|
|
|
|
<ValueInput
|
2025-08-04 15:49:53 +08:00
|
|
|
|
v-else
|
2025-08-02 13:18:12 +08:00
|
|
|
|
:model-value="condition.value"
|
|
|
|
|
|
@update:model-value="(value) => updateConditionField('value', value)"
|
2025-07-28 22:08:20 +08:00
|
|
|
|
: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">
|
2025-08-05 17:33:20 +08:00
|
|
|
|
<!-- 设备状态触发器使用简化的配置 -->
|
|
|
|
|
|
<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="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 label="变为在线" value="online" />
|
|
|
|
|
|
<el-option label="变为离线" value="offline" />
|
|
|
|
|
|
</el-select>
|
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
</el-col>
|
|
|
|
|
|
</el-row>
|
2025-07-28 22:08:20 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<!-- 其他触发类型的提示 -->
|
|
|
|
|
|
<div v-else class="text-center py-20px">
|
|
|
|
|
|
<p class="text-14px text-[var(--el-text-color-secondary)] mb-4px">
|
|
|
|
|
|
当前触发事件类型:{{ getTriggerTypeText(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'
|
2025-08-05 17:33:20 +08:00
|
|
|
|
import JsonParamsInput from '../inputs/JsonParamsInput.vue'
|
|
|
|
|
|
|
2025-08-07 14:29:59 +08:00
|
|
|
|
import type { Trigger } from '@/api/iot/rule/scene'
|
2025-08-02 13:18:12 +08:00
|
|
|
|
import { IotRuleSceneTriggerTypeEnum, getTriggerTypeOptions } from '@/views/iot/utils/constants'
|
2025-07-28 22:08:20 +08:00
|
|
|
|
import { useVModel } from '@vueuse/core'
|
|
|
|
|
|
|
|
|
|
|
|
/** 主条件内部配置组件 */
|
|
|
|
|
|
defineOptions({ name: 'MainConditionInnerConfig' })
|
|
|
|
|
|
|
2025-08-01 17:18:23 +08:00
|
|
|
|
const props = defineProps<{
|
2025-08-07 14:29:59 +08:00
|
|
|
|
modelValue: Trigger
|
2025-07-28 22:08:20 +08:00
|
|
|
|
triggerType: number
|
2025-08-01 17:18:23 +08:00
|
|
|
|
}>()
|
2025-07-28 22:08:20 +08:00
|
|
|
|
|
2025-08-01 17:18:23 +08:00
|
|
|
|
const emit = defineEmits<{
|
2025-08-07 14:29:59 +08:00
|
|
|
|
(e: 'update:modelValue', value: Trigger): void
|
2025-08-02 13:18:12 +08:00
|
|
|
|
(e: 'trigger-type-change', value: number): void
|
2025-08-01 17:18:23 +08:00
|
|
|
|
}>()
|
2025-07-28 22:08:20 +08:00
|
|
|
|
|
|
|
|
|
|
// 响应式数据
|
|
|
|
|
|
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
|
|
|
|
|
|
})
|
|
|
|
|
|
|
2025-08-05 21:26:01 +08:00
|
|
|
|
// 服务配置 - 用于 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
|
|
|
|
|
|
})
|
|
|
|
|
|
|
2025-07-28 22:08:20 +08:00
|
|
|
|
// 获取触发类型文本
|
2025-07-28 23:25:54 +08:00
|
|
|
|
// TODO @puhui999:是不是有枚举可以服用哈;
|
2025-07-28 22:08:20 +08:00
|
|
|
|
const getTriggerTypeText = (type: number) => {
|
|
|
|
|
|
switch (type) {
|
|
|
|
|
|
case IotRuleSceneTriggerTypeEnum.DEVICE_PROPERTY_POST:
|
|
|
|
|
|
return '设备属性上报'
|
|
|
|
|
|
case IotRuleSceneTriggerTypeEnum.DEVICE_EVENT_POST:
|
|
|
|
|
|
return '设备事件上报'
|
|
|
|
|
|
case IotRuleSceneTriggerTypeEnum.DEVICE_SERVICE_INVOKE:
|
|
|
|
|
|
return '设备服务调用'
|
|
|
|
|
|
case IotRuleSceneTriggerTypeEnum.DEVICE_STATE_UPDATE:
|
|
|
|
|
|
return '设备状态变化'
|
|
|
|
|
|
default:
|
|
|
|
|
|
return '未知类型'
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-08-02 13:18:12 +08:00
|
|
|
|
// 触发器类型选项
|
|
|
|
|
|
const triggerTypeOptions = getTriggerTypeOptions()
|
|
|
|
|
|
|
2025-07-28 22:08:20 +08:00
|
|
|
|
// 事件处理
|
2025-08-07 14:29:59 +08:00
|
|
|
|
const updateConditionField = (field: keyof Trigger, value: any) => {
|
2025-08-04 15:49:53 +08:00
|
|
|
|
;(condition.value as any)[field] = value
|
2025-07-28 22:08:20 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-08-02 13:18:12 +08:00
|
|
|
|
const handleTriggerTypeChange = (type: number) => {
|
|
|
|
|
|
emit('trigger-type-change', type)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-07-28 22:08:20 +08:00
|
|
|
|
const handleProductChange = () => {
|
|
|
|
|
|
// 产品变化时清空设备和属性
|
|
|
|
|
|
condition.value.deviceId = undefined
|
|
|
|
|
|
condition.value.identifier = ''
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const handleDeviceChange = () => {
|
|
|
|
|
|
// 设备变化时清空属性
|
|
|
|
|
|
condition.value.identifier = ''
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const handlePropertyChange = (propertyInfo: any) => {
|
|
|
|
|
|
if (propertyInfo) {
|
|
|
|
|
|
propertyType.value = propertyInfo.type
|
|
|
|
|
|
propertyConfig.value = propertyInfo.config
|
2025-08-05 21:26:01 +08:00
|
|
|
|
|
|
|
|
|
|
// 对于事件上报和服务调用,自动设置操作符为 '='
|
|
|
|
|
|
if (
|
|
|
|
|
|
props.triggerType === IotRuleSceneTriggerTypeEnum.DEVICE_EVENT_POST ||
|
|
|
|
|
|
props.triggerType === IotRuleSceneTriggerTypeEnum.DEVICE_SERVICE_INVOKE
|
|
|
|
|
|
) {
|
|
|
|
|
|
condition.value.operator = '='
|
|
|
|
|
|
}
|
2025-07-28 22:08:20 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const handleOperatorChange = () => {
|
2025-08-07 16:31:07 +08:00
|
|
|
|
// 操作符变化处理
|
2025-07-28 22:08:20 +08:00
|
|
|
|
}
|
|
|
|
|
|
</script>
|