diff --git a/src/api/iot/rule/scene/index.ts b/src/api/iot/rule/scene/index.ts index 9bbf8db6a..bd0a450d0 100644 --- a/src/api/iot/rule/scene/index.ts +++ b/src/api/iot/rule/scene/index.ts @@ -1,5 +1,46 @@ import request from '@/config/axios' -import { IotSceneRule } from './scene.types' + +// 场景联动 +export interface IotSceneRule { + id?: number // 场景编号 + name: string // 场景名称 + description?: string // 场景描述 + status: number // 场景状态:0-开启,1-关闭 + triggers: Trigger[] // 触发器数组 + actions: Action[] // 执行器数组 +} + +// 触发器结构 +export interface Trigger { + type: number // 触发类型 + productId?: number // 产品编号 + deviceId?: number // 设备编号 + identifier?: string // 物模型标识符 + operator?: string // 操作符 + value?: string // 参数值 + cronExpression?: string // CRON 表达式 + conditionGroups?: TriggerCondition[][] // 条件组(二维数组) +} + +// 触发条件结构 +export interface TriggerCondition { + type: number // 条件类型:1-设备状态,2-设备属性,3-当前时间 + productId?: number // 产品编号 + deviceId?: number // 设备编号 + identifier?: string // 标识符 + operator: string // 操作符 + param: string // 参数 +} + +// 执行器结构 +export interface Action { + type: number // 执行类型 + productId?: number // 产品编号 + deviceId?: number // 设备编号 + identifier?: string // 物模型标识符(服务调用时使用) + params?: string // 请求参数 + alertConfigId?: number // 告警配置编号 +} // IoT 场景联动 API export const RuleSceneApi = { diff --git a/src/api/iot/rule/scene/scene.types.ts b/src/api/iot/rule/scene/scene.types.ts deleted file mode 100644 index d8ba01faa..000000000 --- a/src/api/iot/rule/scene/scene.types.ts +++ /dev/null @@ -1,202 +0,0 @@ -/** - * IoT 场景联动接口定义 - */ - -// ========== IoT物模型TSL数据类型定义 ========== - -// TODO @puhui999:看看有些是不是在别的模块已经定义了。物模型的 - -/** 物模型TSL响应数据结构 */ -export interface IotThingModelTSLRespVO { - productId: number - productKey: string - properties: ThingModelProperty[] - events: ThingModelEvent[] - services: ThingModelService[] -} - -/** 物模型属性 */ -export interface ThingModelProperty { - identifier: string - name: string - accessMode: string - required?: boolean - dataType: string - description?: string - dataSpecs?: ThingModelDataSpecs - dataSpecsList?: ThingModelDataSpecs[] -} - -/** 物模型事件 */ -export interface ThingModelEvent { - identifier: string - name: string - required?: boolean - type: string - description?: string - outputParams?: ThingModelParam[] - method?: string -} - -/** 物模型服务 */ -export interface ThingModelService { - identifier: string - name: string - required?: boolean - callType: string - description?: string - inputParams?: ThingModelParam[] - outputParams?: ThingModelParam[] - method?: string -} - -/** 物模型参数 */ -export interface ThingModelParam { - identifier: string - name: string - direction: string - paraOrder?: number - dataType: string - dataSpecs?: ThingModelDataSpecs - dataSpecsList?: ThingModelDataSpecs[] -} - -/** 数值型数据规范 */ -export interface ThingModelNumericDataSpec { - dataType: 'int' | 'float' | 'double' - max: string - min: string - step: string - precise?: string - defaultValue?: string - unit?: string - unitName?: string -} - -/** 布尔/枚举型数据规范 */ -export interface ThingModelBoolOrEnumDataSpecs { - dataType: 'bool' | 'enum' - name: string - value: number -} - -/** 文本/时间型数据规范 */ -export interface ThingModelDateOrTextDataSpecs { - dataType: 'text' | 'date' - length?: number - defaultValue?: string -} - -/** 数组型数据规范 */ -export interface ThingModelArrayDataSpecs { - dataType: 'array' - size: number - childDataType: string - dataSpecsList?: ThingModelDataSpecs[] -} - -/** 结构体型数据规范 */ -export interface ThingModelStructDataSpecs { - dataType: 'struct' - identifier: string - name: string - accessMode: string - required?: boolean - childDataType: string - dataSpecs?: ThingModelDataSpecs - dataSpecsList?: ThingModelDataSpecs[] -} - -/** 数据规范联合类型 */ -export type ThingModelDataSpecs = - | ThingModelNumericDataSpec - | ThingModelBoolOrEnumDataSpecs - | ThingModelDateOrTextDataSpecs - | ThingModelArrayDataSpecs - | ThingModelStructDataSpecs - -/** 属性选择器内部使用的统一数据结构 */ -export interface PropertySelectorItem { - identifier: string - name: string - description?: string - dataType: string - type: number // IoTThingModelTypeEnum - accessMode?: string - required?: boolean - unit?: string - range?: string - eventType?: string - callType?: string - inputParams?: ThingModelParam[] - outputParams?: ThingModelParam[] - property?: ThingModelProperty - event?: ThingModelEvent - service?: ThingModelService -} - -// ========== 场景联动规则相关接口定义 ========== - -// 后端 DO 接口 - 匹配后端数据结构 -interface IotSceneRule { - id?: number // 场景编号 - name: string // 场景名称 - description?: string // 场景描述 - status: number // 场景状态:0-开启,1-关闭 - triggers: Trigger[] // 触发器数组 - actions: Action[] // 执行器数组 -} - -// 触发器 DO 结构 -interface Trigger { - type: number // 触发类型 - productId?: number // 产品编号 - deviceId?: number // 设备编号 - identifier?: string // 物模型标识符 - operator?: string // 操作符 - value?: string // 参数值 - cronExpression?: string // CRON 表达式 - conditionGroups?: TriggerCondition[][] // 条件组(二维数组) -} - -// 触发条件 DO 结构 -interface TriggerCondition { - type: number // 条件类型:1-设备状态,2-设备属性,3-当前时间 - productId?: number // 产品编号 - deviceId?: number // 设备编号 - identifier?: string // 标识符 - operator: string // 操作符 - param: string // 参数 -} - -// 执行器 DO 结构 -interface Action { - type: number // 执行类型 - productId?: number // 产品编号 - deviceId?: number // 设备编号 - identifier?: string // 物模型标识符(服务调用时使用) - params?: string // 请求参数 - alertConfigId?: number // 告警配置编号 -} - -// 表单验证规则类型 -interface ValidationRule { - required?: boolean - message?: string - trigger?: string | string[] - type?: string - min?: number - max?: number - enum?: any[] -} - -interface FormValidationRules { - [key: string]: ValidationRule[] -} - -// 表单数据类型别名 -export type TriggerFormData = Trigger - -// TODO @puhui999:这个文件,目标最终没有哈,和别的模块一致; - -export { IotSceneRule, Trigger, TriggerCondition, Action, ValidationRule, FormValidationRules } diff --git a/src/api/iot/thingmodel/index.ts b/src/api/iot/thingmodel/index.ts index 2ad37caed..bcf9e0707 100644 --- a/src/api/iot/thingmodel/index.ts +++ b/src/api/iot/thingmodel/index.ts @@ -40,7 +40,7 @@ export interface ThingModelService { } /** dataSpecs 数值型数据结构 */ -export interface DataSpecsNumberDataVO { +export interface DataSpecsNumberData { dataType: 'int' | 'float' | 'double' // 数据类型,取值为 INT、FLOAT 或 DOUBLE max: string // 最大值,必须与 dataType 设置一致,且为 STRING 类型 min: string // 最小值,必须与 dataType 设置一致,且为 STRING 类型 @@ -52,13 +52,114 @@ export interface DataSpecsNumberDataVO { } /** dataSpecs 枚举型数据结构 */ -export interface DataSpecsEnumOrBoolDataVO { +export interface DataSpecsEnumOrBoolData { dataType: 'enum' | 'bool' defaultValue?: string // 默认值,可选 name: string // 枚举项的名称 value: number | undefined // 枚举值 } +/** 物模型TSL响应数据结构 */ +export interface IotThingModelTSLResp { + productId: number + productKey: string + properties: ThingModelProperty[] + events: ThingModelEvent[] + services: ThingModelService[] +} + +/** 物模型属性 */ +export interface ThingModelProperty { + identifier: string + name: string + accessMode: string + required?: boolean + dataType: string + description?: string + dataSpecs?: ThingModelProperty + dataSpecsList?: ThingModelProperty[] +} + +/** 物模型事件 */ +export interface ThingModelEvent { + identifier: string + name: string + required?: boolean + type: string + description?: string + outputParams?: ThingModelParam[] + method?: string +} + +/** 物模型服务 */ +export interface ThingModelService { + identifier: string + name: string + required?: boolean + callType: string + description?: string + inputParams?: ThingModelParam[] + outputParams?: ThingModelParam[] + method?: string +} + +/** 物模型参数 */ +export interface ThingModelParam { + identifier: string + name: string + direction: string + paraOrder?: number + dataType: string + dataSpecs?: ThingModelProperty + dataSpecsList?: ThingModelProperty[] +} + +/** 数值型数据规范 */ +export interface ThingModelNumericDataSpec { + dataType: 'int' | 'float' | 'double' + max: string + min: string + step: string + precise?: string + defaultValue?: string + unit?: string + unitName?: string +} + +/** 布尔/枚举型数据规范 */ +export interface ThingModelBoolOrEnumDataSpecs { + dataType: 'bool' | 'enum' + name: string + value: number +} + +/** 文本/时间型数据规范 */ +export interface ThingModelDateOrTextDataSpecs { + dataType: 'text' | 'date' + length?: number + defaultValue?: string +} + +/** 数组型数据规范 */ +export interface ThingModelArrayDataSpecs { + dataType: 'array' + size: number + childDataType: string + dataSpecsList?: ThingModelProperty[] +} + +/** 结构体型数据规范 */ +export interface ThingModelStructDataSpecs { + dataType: 'struct' + identifier: string + name: string + accessMode: string + required?: boolean + childDataType: string + dataSpecs?: ThingModelProperty + dataSpecsList?: ThingModelProperty[] +} + // IoT 产品物模型 API export const ThingModelApi = { // 查询产品物模型分页 diff --git a/src/views/iot/rule/scene/form/RuleSceneForm.vue b/src/views/iot/rule/scene/form/RuleSceneForm.vue index 0362bc4bf..9abcb6981 100644 --- a/src/views/iot/rule/scene/form/RuleSceneForm.vue +++ b/src/views/iot/rule/scene/form/RuleSceneForm.vue @@ -36,7 +36,7 @@ import { useVModel } from '@vueuse/core' import BasicInfoSection from './sections/BasicInfoSection.vue' import TriggerSection from './sections/TriggerSection.vue' import ActionSection from './sections/ActionSection.vue' -import { IotSceneRule } from '@/api/iot/rule/scene/scene.types' +import { IotSceneRule } from '@/api/iot/rule/scene' import { RuleSceneApi } from '@/api/iot/rule/scene' import { IotRuleSceneTriggerTypeEnum, diff --git a/src/views/iot/rule/scene/form/configs/ConditionConfig.vue b/src/views/iot/rule/scene/form/configs/ConditionConfig.vue index 9574c58ce..8a9fcee99 100644 --- a/src/views/iot/rule/scene/form/configs/ConditionConfig.vue +++ b/src/views/iot/rule/scene/form/configs/ConditionConfig.vue @@ -123,7 +123,7 @@ 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 { TriggerCondition } from '@/api/iot/rule/scene/scene.types' +import type { TriggerCondition } from '@/api/iot/rule/scene' import { IotRuleSceneTriggerConditionTypeEnum, IotRuleSceneTriggerConditionParameterOperatorEnum diff --git a/src/views/iot/rule/scene/form/configs/CurrentTimeConditionConfig.vue b/src/views/iot/rule/scene/form/configs/CurrentTimeConditionConfig.vue index 0cf1087c8..bcf052979 100644 --- a/src/views/iot/rule/scene/form/configs/CurrentTimeConditionConfig.vue +++ b/src/views/iot/rule/scene/form/configs/CurrentTimeConditionConfig.vue @@ -94,17 +94,18 @@ - - diff --git a/src/views/iot/rule/scene/form/selectors/PropertySelector.vue b/src/views/iot/rule/scene/form/selectors/PropertySelector.vue index c8d237a4d..03c648f7f 100644 --- a/src/views/iot/rule/scene/form/selectors/PropertySelector.vue +++ b/src/views/iot/rule/scene/form/selectors/PropertySelector.vue @@ -160,12 +160,38 @@ import { useVModel } from '@vueuse/core' import { InfoFilled } from '@element-plus/icons-vue' import { IotRuleSceneTriggerTypeEnum, IoTThingModelTypeEnum } from '@/views/iot/utils/constants' +import type { + IotThingModelTSLResp, + ThingModelEvent, + ThingModelParam, + ThingModelProperty, + ThingModelService +} from '@/api/iot/thingmodel' import { ThingModelApi } from '@/api/iot/thingmodel' -import type { IotThingModelTSLRespVO, PropertySelectorItem } from '@/api/iot/rule/scene/scene.types' /** 属性选择器组件 */ defineOptions({ name: 'PropertySelector' }) +/** 属性选择器内部使用的统一数据结构 */ +export interface PropertySelectorItem { + identifier: string + name: string + description?: string + dataType: string + type: number // IoTThingModelTypeEnum + accessMode?: string + required?: boolean + unit?: string + range?: string + eventType?: string + callType?: string + inputParams?: ThingModelParam[] + outputParams?: ThingModelParam[] + property?: ThingModelProperty + event?: ThingModelEvent + service?: ThingModelService +} + const props = defineProps<{ modelValue?: string triggerType: number @@ -183,7 +209,7 @@ const localValue = useVModel(props, 'modelValue', emit) // 状态 const loading = ref(false) const propertyList = ref([]) -const thingModelTSL = ref(null) +const thingModelTSL = ref(null) // 计算属性 const propertyGroups = computed(() => { diff --git a/src/views/iot/rule/scene/index.vue b/src/views/iot/rule/scene/index.vue index 4a587072c..50200ebdf 100644 --- a/src/views/iot/rule/scene/index.vue +++ b/src/views/iot/rule/scene/index.vue @@ -239,7 +239,7 @@ import { DICT_TYPE, getIntDictOptions, getDictLabel } from '@/utils/dict' import { ContentWrap } from '@/components/ContentWrap' import RuleSceneForm from './form/RuleSceneForm.vue' -import { IotSceneRule } from '@/api/iot/rule/scene/scene.types' +import { IotSceneRule } from '@/api/iot/rule/scene' import { RuleSceneApi } from '@/api/iot/rule/scene' import { IotRuleSceneTriggerTypeEnum, diff --git a/src/views/iot/thingmodel/dataSpecs/ThingModelEnumDataSpecs.vue b/src/views/iot/thingmodel/dataSpecs/ThingModelEnumDataSpecs.vue index 2820aeac4..71d47789f 100644 --- a/src/views/iot/thingmodel/dataSpecs/ThingModelEnumDataSpecs.vue +++ b/src/views/iot/thingmodel/dataSpecs/ThingModelEnumDataSpecs.vue @@ -46,14 +46,14 @@ import { useVModel } from '@vueuse/core' import { isEmpty } from '@/utils/is' import { IoTDataSpecsDataTypeEnum } from '@/views/iot/utils/constants' -import { DataSpecsEnumOrBoolDataVO } from '@/api/iot/thingmodel' +import { DataSpecsEnumOrBoolData } from '@/api/iot/thingmodel' /** 枚举型的 dataSpecs 配置组件 */ defineOptions({ name: 'ThingModelEnumDataSpecs' }) const props = defineProps<{ modelValue: any }>() const emits = defineEmits(['update:modelValue']) -const dataSpecsList = useVModel(props, 'modelValue', emits) as Ref +const dataSpecsList = useVModel(props, 'modelValue', emits) as Ref const message = useMessage() /** 添加枚举项 */ diff --git a/src/views/iot/thingmodel/dataSpecs/ThingModelNumberDataSpecs.vue b/src/views/iot/thingmodel/dataSpecs/ThingModelNumberDataSpecs.vue index 0a8857dee..d7a47c36b 100644 --- a/src/views/iot/thingmodel/dataSpecs/ThingModelNumberDataSpecs.vue +++ b/src/views/iot/thingmodel/dataSpecs/ThingModelNumberDataSpecs.vue @@ -60,14 +60,14 @@