perf: 【IoT 物联网】场景联动注释优化

pull/808/head
puhui999 2025-08-07 21:36:27 +08:00
parent 85ba03b0ea
commit fd85c4d682
16 changed files with 338 additions and 91 deletions

View File

@ -63,9 +63,12 @@ const emit = defineEmits<{
(e: 'success'): void (e: 'success'): void
}>() }>()
const drawerVisible = useVModel(props, 'modelValue', emit) // const drawerVisible = useVModel(props, 'modelValue', emit) //
/** 创建默认的表单数据 */ /**
* 创建默认的表单数据
* @returns 默认表单数据对象
*/
const createDefaultFormData = (): IotSceneRule => { const createDefaultFormData = (): IotSceneRule => {
return { return {
name: '', name: '',
@ -87,10 +90,15 @@ const createDefaultFormData = (): IotSceneRule => {
} }
} }
// const formRef = ref() //
const formRef = ref() const formData = ref<IotSceneRule>(createDefaultFormData()) //
const formData = ref<IotSceneRule>(createDefaultFormData())
// /**
* 触发器校验器
* @param _rule 校验规则未使用
* @param value 校验值
* @param callback 回调函数
*/
const validateTriggers = (_rule: any, value: any, callback: any) => { const validateTriggers = (_rule: any, value: any, callback: any) => {
if (!value || !Array.isArray(value) || value.length === 0) { if (!value || !Array.isArray(value) || value.length === 0) {
callback(new Error('至少需要一个触发器')) callback(new Error('至少需要一个触发器'))
@ -142,6 +150,12 @@ const validateTriggers = (_rule: any, value: any, callback: any) => {
callback() callback()
} }
/**
* 执行器校验器
* @param _rule 校验规则未使用
* @param value 校验值
* @param callback 回调函数
*/
const validateActions = (_rule: any, value: any, callback: any) => { const validateActions = (_rule: any, value: any, callback: any) => {
if (!value || !Array.isArray(value) || value.length === 0) { if (!value || !Array.isArray(value) || value.length === 0) {
callback(new Error('至少需要一个执行器')) callback(new Error('至少需要一个执行器'))
@ -201,6 +215,7 @@ const validateActions = (_rule: any, value: any, callback: any) => {
} }
const formRules = reactive({ const formRules = reactive({
//
name: [ name: [
{ required: true, message: '场景名称不能为空', trigger: 'blur' }, { required: true, message: '场景名称不能为空', trigger: 'blur' },
{ type: 'string', min: 1, max: 50, message: '场景名称长度应在1-50个字符之间', trigger: 'blur' } { type: 'string', min: 1, max: 50, message: '场景名称长度应在1-50个字符之间', trigger: 'blur' }
@ -221,13 +236,15 @@ const formRules = reactive({
actions: [{ required: true, validator: validateActions, trigger: 'change' }] actions: [{ required: true, validator: validateActions, trigger: 'change' }]
}) })
const submitLoading = ref(false) const submitLoading = ref(false) //
const isEdit = ref(false) //
// //
const isEdit = ref(false)
const drawerTitle = computed(() => (isEdit.value ? '编辑场景联动规则' : '新增场景联动规则')) const drawerTitle = computed(() => (isEdit.value ? '编辑场景联动规则' : '新增场景联动规则'))
/** 提交表单 */ /**
* 提交表单
*/
const handleSubmit = async () => { const handleSubmit = async () => {
// //
if (!formRef.value) return if (!formRef.value) return
@ -258,11 +275,16 @@ const handleSubmit = async () => {
} }
} }
/**
* 处理抽屉关闭事件
*/
const handleClose = () => { const handleClose = () => {
drawerVisible.value = false drawerVisible.value = false
} }
/** 初始化表单数据 */ /**
* 初始化表单数据
*/
const initFormData = () => { const initFormData = () => {
if (props.ruleScene) { if (props.ruleScene) {
// 使 // 使

View File

@ -181,9 +181,8 @@ const emit = defineEmits<{
const condition = useVModel(props, 'modelValue', emit) const condition = useVModel(props, 'modelValue', emit)
// const propertyType = ref<string>('string') //
const propertyType = ref<string>('string') const propertyConfig = ref<any>(null) //
const propertyConfig = ref<any>(null)
// //
const isDeviceCondition = computed(() => { const isDeviceCondition = computed(() => {
@ -193,17 +192,29 @@ const isDeviceCondition = computed(() => {
) )
}) })
// /**
* 更新条件字段
* @param field 字段名
* @param value 字段值
*/
const updateConditionField = (field: keyof TriggerCondition, value: any) => { const updateConditionField = (field: keyof TriggerCondition, value: any) => {
;(condition.value as any)[field] = value ;(condition.value as any)[field] = value
emit('update:modelValue', condition.value) emit('update:modelValue', condition.value)
} }
/**
* 更新整个条件对象
* @param newCondition 新的条件对象
*/
const updateCondition = (newCondition: TriggerCondition) => { const updateCondition = (newCondition: TriggerCondition) => {
condition.value = newCondition condition.value = newCondition
emit('update:modelValue', condition.value) emit('update:modelValue', condition.value)
} }
/**
* 处理条件类型变化事件
* @param type 条件类型
*/
const handleConditionTypeChange = (type: number) => { const handleConditionTypeChange = (type: number) => {
// //
if (type === IotRuleSceneTriggerConditionTypeEnum.DEVICE_STATUS) { if (type === IotRuleSceneTriggerConditionTypeEnum.DEVICE_STATUS) {
@ -234,17 +245,29 @@ const handleConditionTypeChange = (type: number) => {
condition.value.param = '' condition.value.param = ''
} }
/**
* 处理产品变化事件
* @param _ 产品ID未使用
*/
const handleProductChange = (_: number) => { const handleProductChange = (_: number) => {
// //
condition.value.deviceId = undefined condition.value.deviceId = undefined
condition.value.identifier = '' condition.value.identifier = ''
} }
/**
* 处理设备变化事件
* @param _ 设备ID未使用
*/
const handleDeviceChange = (_: number) => { const handleDeviceChange = (_: number) => {
// //
condition.value.identifier = '' condition.value.identifier = ''
} }
/**
* 处理属性变化事件
* @param propertyInfo 属性信息对象
*/
const handlePropertyChange = (propertyInfo: { type: string; config: any }) => { const handlePropertyChange = (propertyInfo: { type: string; config: any }) => {
propertyType.value = propertyInfo.type propertyType.value = propertyInfo.type
propertyConfig.value = propertyInfo.config propertyConfig.value = propertyInfo.config
@ -254,6 +277,9 @@ const handlePropertyChange = (propertyInfo: { type: string; config: any }) => {
condition.value.param = '' condition.value.param = ''
} }
/**
* 处理操作符变化事件
*/
const handleOperatorChange = () => { const handleOperatorChange = () => {
// //
condition.value.param = '' condition.value.param = ''

View File

@ -154,7 +154,7 @@ const timeOperatorOptions = [
} }
] ]
// //
const needsTimeInput = computed(() => { const needsTimeInput = computed(() => {
const timeOnlyOperators = [ const timeOnlyOperators = [
IotRuleSceneTriggerTimeOperatorEnum.BEFORE_TIME.value, IotRuleSceneTriggerTimeOperatorEnum.BEFORE_TIME.value,
@ -165,15 +165,21 @@ const needsTimeInput = computed(() => {
return timeOnlyOperators.includes(condition.value.operator) return timeOnlyOperators.includes(condition.value.operator)
}) })
//
const needsDateInput = computed(() => { const needsDateInput = computed(() => {
return false // return false //
}) })
//
const needsSecondTimeInput = computed(() => { const needsSecondTimeInput = computed(() => {
return condition.value.operator === IotRuleSceneTriggerTimeOperatorEnum.BETWEEN_TIME.value return condition.value.operator === IotRuleSceneTriggerTimeOperatorEnum.BETWEEN_TIME.value
}) })
// /**
* 更新条件字段
* @param field 字段名
* @param value 字段值
*/
const updateConditionField = (field: keyof TriggerCondition, value: any) => { const updateConditionField = (field: keyof TriggerCondition, value: any) => {
condition.value[field] = value condition.value[field] = value
} }
@ -183,7 +189,8 @@ watch(
() => condition.value.operator, () => condition.value.operator,
(newOperator) => { (newOperator) => {
if (newOperator === IotRuleSceneTriggerTimeOperatorEnum.TODAY.value) { if (newOperator === IotRuleSceneTriggerTimeOperatorEnum.TODAY.value) {
;(condition.value as any).timeValue = undefined(condition.value as any).timeValue2 = undefined ;(condition.value as any).timeValue = undefined
;(condition.value as any).timeValue2 = undefined
} else if (!needsSecondTimeInput.value) { } else if (!needsSecondTimeInput.value) {
;(condition.value as any).timeValue2 = undefined ;(condition.value as any).timeValue2 = undefined
} }

View File

@ -102,7 +102,6 @@ const emit = defineEmits<{
const action = useVModel(props, 'modelValue', emit) const action = useVModel(props, 'modelValue', emit)
//
const thingModelProperties = ref<ThingModelProperty[]>([]) // const thingModelProperties = ref<ThingModelProperty[]>([]) //
const loadingThingModel = ref(false) // const loadingThingModel = ref(false) //
const selectedService = ref<ThingModelService | null>(null) // const selectedService = ref<ThingModelService | null>(null) //
@ -125,13 +124,13 @@ const paramsValue = computed({
} }
}) })
//
const isPropertySetAction = computed(() => { const isPropertySetAction = computed(() => {
//
return action.value.type === IotRuleSceneActionTypeEnum.DEVICE_PROPERTY_SET return action.value.type === IotRuleSceneActionTypeEnum.DEVICE_PROPERTY_SET
}) })
//
const isServiceInvokeAction = computed(() => { const isServiceInvokeAction = computed(() => {
//
return action.value.type === IotRuleSceneActionTypeEnum.DEVICE_SERVICE_INVOKE return action.value.type === IotRuleSceneActionTypeEnum.DEVICE_SERVICE_INVOKE
}) })
@ -314,8 +313,7 @@ const getDefaultValueForParam = (param: any) => {
} }
} }
// const isInitialized = ref(false) //
const isInitialized = ref(false)
/** /**
* 初始化组件数据 * 初始化组件数据
@ -347,7 +345,7 @@ onMounted(() => {
initializeComponent() initializeComponent()
}) })
// //
watch( watch(
() => [action.value.productId, action.value.type, action.value.identifier], () => [action.value.productId, action.value.type, action.value.identifier],
async ([newProductId, , newIdentifier], [oldProductId, , oldIdentifier]) => { async ([newProductId, , newIdentifier], [oldProductId, , oldIdentifier]) => {

View File

@ -185,21 +185,29 @@ const emit = defineEmits<{
const trigger = useVModel(props, 'modelValue', emit) const trigger = useVModel(props, 'modelValue', emit)
//
const maxSubGroups = 3 // 3 const maxSubGroups = 3 // 3
const maxConditionsPerGroup = 3 // 3 const maxConditionsPerGroup = 3 // 3
// /**
* 更新条件
* @param condition 条件对象
*/
const updateCondition = (condition: Trigger) => { const updateCondition = (condition: Trigger) => {
trigger.value = condition trigger.value = condition
} }
/**
* 处理触发器类型变化事件
* @param type 触发器类型
*/
const handleTriggerTypeChange = (type: number) => { const handleTriggerTypeChange = (type: number) => {
trigger.value.type = type trigger.value.type = type
emit('trigger-type-change', type) emit('trigger-type-change', type)
} }
// /**
* 添加子条件组
*/
const addSubGroup = async () => { const addSubGroup = async () => {
if (!trigger.value.conditionGroups) { if (!trigger.value.conditionGroups) {
trigger.value.conditionGroups = [] trigger.value.conditionGroups = []
@ -217,18 +225,30 @@ const addSubGroup = async () => {
} }
} }
/**
* 移除子条件组
* @param index 子条件组索引
*/
const removeSubGroup = (index: number) => { const removeSubGroup = (index: number) => {
if (trigger.value.conditionGroups) { if (trigger.value.conditionGroups) {
trigger.value.conditionGroups.splice(index, 1) trigger.value.conditionGroups.splice(index, 1)
} }
} }
/**
* 更新子条件组
* @param index 子条件组索引
* @param subGroup 子条件组数据
*/
const updateSubGroup = (index: number, subGroup: any) => { const updateSubGroup = (index: number, subGroup: any) => {
if (trigger.value.conditionGroups) { if (trigger.value.conditionGroups) {
trigger.value.conditionGroups[index] = subGroup trigger.value.conditionGroups[index] = subGroup
} }
} }
/**
* 移除整个条件组
*/
const removeConditionGroup = () => { const removeConditionGroup = () => {
trigger.value.conditionGroups = undefined trigger.value.conditionGroups = undefined
} }

View File

@ -211,12 +211,11 @@ const emit = defineEmits<{
(e: 'trigger-type-change', value: number): void (e: 'trigger-type-change', value: number): void
}>() }>()
//
const condition = useVModel(props, 'modelValue', emit) const condition = useVModel(props, 'modelValue', emit)
const propertyType = ref('') const propertyType = ref('') //
const propertyConfig = ref<any>(null) const propertyConfig = ref<any>(null) //
// //
const isDevicePropertyTrigger = computed(() => { const isDevicePropertyTrigger = computed(() => {
return ( return (
props.triggerType === IotRuleSceneTriggerTypeEnum.DEVICE_PROPERTY_POST || props.triggerType === IotRuleSceneTriggerTypeEnum.DEVICE_PROPERTY_POST ||
@ -225,11 +224,12 @@ const isDevicePropertyTrigger = computed(() => {
) )
}) })
//
const isDeviceStatusTrigger = computed(() => { const isDeviceStatusTrigger = computed(() => {
return props.triggerType === IotRuleSceneTriggerTypeEnum.DEVICE_STATE_UPDATE return props.triggerType === IotRuleSceneTriggerTypeEnum.DEVICE_STATE_UPDATE
}) })
// - JsonParamsInput // - JsonParamsInput
const serviceConfig = computed(() => { const serviceConfig = computed(() => {
if ( if (
propertyConfig.value && propertyConfig.value &&
@ -245,7 +245,7 @@ const serviceConfig = computed(() => {
return undefined return undefined
}) })
// - JsonParamsInput // - JsonParamsInput
const eventConfig = computed(() => { const eventConfig = computed(() => {
if (propertyConfig.value && props.triggerType === IotRuleSceneTriggerTypeEnum.DEVICE_EVENT_POST) { if (propertyConfig.value && props.triggerType === IotRuleSceneTriggerTypeEnum.DEVICE_EVENT_POST) {
return { return {
@ -258,30 +258,47 @@ const eventConfig = computed(() => {
return undefined return undefined
}) })
// 使 const triggerTypeOptions = getTriggerTypeOptions() //
const triggerTypeOptions = getTriggerTypeOptions() const deviceStatusChangeOptions = getDeviceStatusChangeOptions() //
const deviceStatusChangeOptions = getDeviceStatusChangeOptions()
// /**
* 更新条件字段
* @param field 字段名
* @param value 字段值
*/
const updateConditionField = (field: keyof Trigger, value: any) => { const updateConditionField = (field: keyof Trigger, value: any) => {
;(condition.value as any)[field] = value ;(condition.value as any)[field] = value
} }
/**
* 处理触发器类型变化事件
* @param type 触发器类型
*/
const handleTriggerTypeChange = (type: number) => { const handleTriggerTypeChange = (type: number) => {
emit('trigger-type-change', type) emit('trigger-type-change', type)
} }
/**
* 处理产品变化事件
*/
const handleProductChange = () => { const handleProductChange = () => {
// //
condition.value.deviceId = undefined condition.value.deviceId = undefined
condition.value.identifier = '' condition.value.identifier = ''
} }
/**
* 处理设备变化事件
*/
const handleDeviceChange = () => { const handleDeviceChange = () => {
// //
condition.value.identifier = '' condition.value.identifier = ''
} }
/**
* 处理属性变化事件
* @param propertyInfo 属性信息对象
*/
const handlePropertyChange = (propertyInfo: any) => { const handlePropertyChange = (propertyInfo: any) => {
if (propertyInfo) { if (propertyInfo) {
propertyType.value = propertyInfo.type propertyType.value = propertyInfo.type
@ -297,6 +314,9 @@ const handlePropertyChange = (propertyInfo: any) => {
} }
} }
/**
* 处理操作符变化事件
*/
const handleOperatorChange = () => { const handleOperatorChange = () => {
// //
} }

View File

@ -103,10 +103,11 @@ const emit = defineEmits<{
const subGroup = useVModel(props, 'modelValue', emit) const subGroup = useVModel(props, 'modelValue', emit)
// const maxConditions = computed(() => props.maxConditions || 3) //
const maxConditions = computed(() => props.maxConditions || 3)
// /**
* 添加条件
*/
const addCondition = async () => { const addCondition = async () => {
// subGroup.value // subGroup.value
if (!subGroup.value) { if (!subGroup.value) {
@ -134,12 +135,21 @@ const addCondition = async () => {
} }
} }
/**
* 移除条件
* @param index 条件索引
*/
const removeCondition = (index: number) => { const removeCondition = (index: number) => {
if (subGroup.value) { if (subGroup.value) {
subGroup.value.splice(index, 1) subGroup.value.splice(index, 1)
} }
} }
/**
* 更新条件
* @param index 条件索引
* @param condition 条件对象
*/
const updateCondition = (index: number, condition: TriggerCondition) => { const updateCondition = (index: number, condition: TriggerCondition) => {
if (subGroup.value) { if (subGroup.value) {
subGroup.value[index] = condition subGroup.value[index] = condition

View File

@ -204,11 +204,10 @@ const localValue = useVModel(props, 'modelValue', emit, {
defaultValue: '' defaultValue: ''
}) })
// const paramsJson = ref('') // JSON
const paramsJson = ref('') const jsonError = ref('') // JSON
const jsonError = ref('')
// //
const hasConfig = computed(() => { const hasConfig = computed(() => {
// TODO @puhui999: // TODO @puhui999:
console.log(props.config) console.log(props.config)
@ -221,6 +220,7 @@ const hasConfig = computed(() => {
return true return true
}) })
//
const paramsList = computed(() => { const paramsList = computed(() => {
switch (props.type) { switch (props.type) {
case JsonParamsInputTypeEnum.SERVICE: case JsonParamsInputTypeEnum.SERVICE:
@ -236,6 +236,7 @@ const paramsList = computed(() => {
} }
}) })
//
const title = computed(() => { const title = computed(() => {
switch (props.type) { switch (props.type) {
case JsonParamsInputTypeEnum.SERVICE: case JsonParamsInputTypeEnum.SERVICE:
@ -251,6 +252,7 @@ const title = computed(() => {
} }
}) })
//
const titleIcon = computed(() => { const titleIcon = computed(() => {
switch (props.type) { switch (props.type) {
case JsonParamsInputTypeEnum.SERVICE: case JsonParamsInputTypeEnum.SERVICE:
@ -266,6 +268,7 @@ const titleIcon = computed(() => {
} }
}) })
//
const paramsIcon = computed(() => { const paramsIcon = computed(() => {
switch (props.type) { switch (props.type) {
case JsonParamsInputTypeEnum.SERVICE: case JsonParamsInputTypeEnum.SERVICE:
@ -281,6 +284,7 @@ const paramsIcon = computed(() => {
} }
}) })
//
const paramsLabel = computed(() => { const paramsLabel = computed(() => {
switch (props.type) { switch (props.type) {
case JsonParamsInputTypeEnum.SERVICE: case JsonParamsInputTypeEnum.SERVICE:
@ -296,6 +300,7 @@ const paramsLabel = computed(() => {
} }
}) })
//
const emptyMessage = computed(() => { const emptyMessage = computed(() => {
switch (props.type) { switch (props.type) {
case JsonParamsInputTypeEnum.SERVICE: case JsonParamsInputTypeEnum.SERVICE:
@ -311,6 +316,7 @@ const emptyMessage = computed(() => {
} }
}) })
//
const noConfigMessage = computed(() => { const noConfigMessage = computed(() => {
switch (props.type) { switch (props.type) {
case JsonParamsInputTypeEnum.SERVICE: case JsonParamsInputTypeEnum.SERVICE:
@ -326,7 +332,9 @@ const noConfigMessage = computed(() => {
} }
}) })
// /**
* 处理参数变化事件
*/
const handleParamsChange = () => { const handleParamsChange = () => {
try { try {
jsonError.value = '' // jsonError.value = '' //
@ -361,20 +369,28 @@ const handleParamsChange = () => {
} }
} }
// /**
* 快速填充示例数据
*/
const fillExampleJson = () => { const fillExampleJson = () => {
paramsJson.value = generateExampleJson() paramsJson.value = generateExampleJson()
handleParamsChange() handleParamsChange()
} }
// /**
* 清空参数
*/
const clearParams = () => { const clearParams = () => {
paramsJson.value = '' paramsJson.value = ''
localValue.value = '' localValue.value = ''
jsonError.value = '' jsonError.value = ''
} }
// /**
* 获取参数类型名称
* @param dataType 数据类型
* @returns 类型名称
*/
const getParamTypeName = (dataType: string) => { const getParamTypeName = (dataType: string) => {
// 使 constants.ts getDataTypeName // 使 constants.ts getDataTypeName
const typeMap = { const typeMap = {
@ -391,6 +407,11 @@ const getParamTypeName = (dataType: string) => {
return typeMap[dataType] || dataType return typeMap[dataType] || dataType
} }
/**
* 获取参数类型标签样式
* @param dataType 数据类型
* @returns 标签样式
*/
const getParamTypeTag = (dataType: string) => { const getParamTypeTag = (dataType: string) => {
const tagMap = { const tagMap = {
[IoTDataSpecsDataTypeEnum.INT]: 'primary', [IoTDataSpecsDataTypeEnum.INT]: 'primary',
@ -406,12 +427,21 @@ const getParamTypeTag = (dataType: string) => {
return tagMap[dataType] || 'info' return tagMap[dataType] || 'info'
} }
/**
* 获取示例值
* @param param 参数对象
* @returns 示例值
*/
const getExampleValue = (param: any) => { const getExampleValue = (param: any) => {
const exampleConfig = const exampleConfig =
JSON_PARAMS_EXAMPLE_VALUES[param.dataType] || JSON_PARAMS_EXAMPLE_VALUES.DEFAULT JSON_PARAMS_EXAMPLE_VALUES[param.dataType] || JSON_PARAMS_EXAMPLE_VALUES.DEFAULT
return exampleConfig.display return exampleConfig.display
} }
/**
* 生成示例JSON
* @returns JSON字符串
*/
const generateExampleJson = () => { const generateExampleJson = () => {
if (paramsList.value.length === 0) { if (paramsList.value.length === 0) {
return '{}' return '{}'
@ -427,7 +457,10 @@ const generateExampleJson = () => {
return JSON.stringify(example, null, 2) return JSON.stringify(example, null, 2)
} }
// /**
* 处理数据回显
* @param value 值字符串
*/
const handleDataDisplay = (value: string) => { const handleDataDisplay = (value: string) => {
if (!value || !value.trim()) { if (!value || !value.trim()) {
paramsJson.value = '' paramsJson.value = ''

View File

@ -160,13 +160,12 @@ const localValue = useVModel(props, 'modelValue', emit, {
defaultValue: '' defaultValue: ''
}) })
// const rangeStart = ref('') //
const rangeStart = ref('') const rangeEnd = ref('') //
const rangeEnd = ref('') const dateValue = ref('') //
const dateValue = ref('') const numberValue = ref<number>() //
const numberValue = ref<number>()
// //
const enumOptions = computed(() => { const enumOptions = computed(() => {
if (props.propertyConfig?.enum) { if (props.propertyConfig?.enum) {
return props.propertyConfig.enum.map((item: any) => ({ return props.propertyConfig.enum.map((item: any) => ({
@ -177,6 +176,7 @@ const enumOptions = computed(() => {
return [] return []
}) })
//
const listPreview = computed(() => { const listPreview = computed(() => {
if (props.operator === 'in' && localValue.value) { if (props.operator === 'in' && localValue.value) {
return localValue.value return localValue.value
@ -187,7 +187,10 @@ const listPreview = computed(() => {
return [] return []
}) })
// /**
* 判断是否为数字类型
* @returns 是否为数字类型
*/
const isNumericType = () => { const isNumericType = () => {
return [ return [
IoTDataSpecsDataTypeEnum.INT, IoTDataSpecsDataTypeEnum.INT,
@ -196,6 +199,10 @@ const isNumericType = () => {
].includes(props.propertyType || '') ].includes(props.propertyType || '')
} }
/**
* 获取输入框类型
* @returns 输入框类型
*/
const getInputType = () => { const getInputType = () => {
switch (props.propertyType) { switch (props.propertyType) {
case IoTDataSpecsDataTypeEnum.INT: case IoTDataSpecsDataTypeEnum.INT:
@ -207,6 +214,10 @@ const getInputType = () => {
} }
} }
/**
* 获取占位符文本
* @returns 占位符文本
*/
const getPlaceholder = () => { const getPlaceholder = () => {
const typeMap = { const typeMap = {
[IoTDataSpecsDataTypeEnum.TEXT]: '请输入字符串', [IoTDataSpecsDataTypeEnum.TEXT]: '请输入字符串',
@ -219,27 +230,48 @@ const getPlaceholder = () => {
return typeMap[props.propertyType || ''] || '请输入值' return typeMap[props.propertyType || ''] || '请输入值'
} }
/**
* 获取数字精度
* @returns 数字精度
*/
const getPrecision = () => { const getPrecision = () => {
return props.propertyType === IoTDataSpecsDataTypeEnum.INT ? 0 : 2 return props.propertyType === IoTDataSpecsDataTypeEnum.INT ? 0 : 2
} }
/**
* 获取数字步长
* @returns 数字步长
*/
const getStep = () => { const getStep = () => {
return props.propertyType === IoTDataSpecsDataTypeEnum.INT ? 1 : 0.1 return props.propertyType === IoTDataSpecsDataTypeEnum.INT ? 1 : 0.1
} }
/**
* 获取最小值
* @returns 最小值
*/
const getMin = () => { const getMin = () => {
return props.propertyConfig?.min || undefined return props.propertyConfig?.min || undefined
} }
/**
* 获取最大值
* @returns 最大值
*/
const getMax = () => { const getMax = () => {
return props.propertyConfig?.max || undefined return props.propertyConfig?.max || undefined
} }
// /**
* 处理值变化事件
*/
const handleChange = () => { const handleChange = () => {
// //
} }
/**
* 处理范围变化事件
*/
const handleRangeChange = () => { const handleRangeChange = () => {
if (rangeStart.value && rangeEnd.value) { if (rangeStart.value && rangeEnd.value) {
localValue.value = `${rangeStart.value},${rangeEnd.value}` localValue.value = `${rangeStart.value},${rangeEnd.value}`
@ -248,10 +280,18 @@ const handleRangeChange = () => {
} }
} }
/**
* 处理日期变化事件
* @param value 日期值
*/
const handleDateChange = (value: string) => { const handleDateChange = (value: string) => {
localValue.value = value || '' localValue.value = value || ''
} }
/**
* 处理数字变化事件
* @param value 数字值
*/
const handleNumberChange = (value: number | undefined) => { const handleNumberChange = (value: number | undefined) => {
localValue.value = value?.toString() || '' localValue.value = value?.toString() || ''
} }

View File

@ -157,8 +157,11 @@ const emit = defineEmits<{
const actions = useVModel(props, 'actions', emit) const actions = useVModel(props, 'actions', emit)
const maxActions = SCENE_RULE_CONFIG.MAX_ACTIONS //
/** /**
* 创建默认的执行器数据 * 创建默认的执行器数据
* @returns 默认执行器对象
*/ */
const createDefaultActionData = (): Action => { const createDefaultActionData = (): Action => {
return { return {
@ -171,10 +174,9 @@ const createDefaultActionData = (): Action => {
} }
} }
// 使 /**
const maxActions = SCENE_RULE_CONFIG.MAX_ACTIONS * 添加执行器
*/
/** 添加执行器 */
const addAction = () => { const addAction = () => {
if (actions.value.length >= maxActions) { if (actions.value.length >= maxActions) {
return return
@ -184,28 +186,47 @@ const addAction = () => {
actions.value.push(newAction) actions.value.push(newAction)
} }
/** 删除执行器 */ /**
* 删除执行器
* @param index 执行器索引
*/
const removeAction = (index: number) => { const removeAction = (index: number) => {
actions.value.splice(index, 1) actions.value.splice(index, 1)
} }
/** 更新执行器类型 */ /**
* 更新执行器类型
* @param index 执行器索引
* @param type 执行器类型
*/
const updateActionType = (index: number, type: number) => { const updateActionType = (index: number, type: number) => {
actions.value[index].type = type actions.value[index].type = type
onActionTypeChange(actions.value[index], type) onActionTypeChange(actions.value[index], type)
} }
/** 更新执行器 */ /**
* 更新执行器
* @param index 执行器索引
* @param action 执行器对象
*/
const updateAction = (index: number, action: Action) => { const updateAction = (index: number, action: Action) => {
actions.value[index] = action actions.value[index] = action
} }
/** 更新告警配置 */ /**
* 更新告警配置
* @param index 执行器索引
* @param alertConfigId 告警配置ID
*/
const updateActionAlertConfig = (index: number, alertConfigId?: number) => { const updateActionAlertConfig = (index: number, alertConfigId?: number) => {
actions.value[index].alertConfigId = alertConfigId actions.value[index].alertConfigId = alertConfigId
} }
/** 监听执行器类型变化 */ /**
* 监听执行器类型变化
* @param action 执行器对象
* @param type 执行器类型
*/
const onActionTypeChange = (action: Action, type: number) => { const onActionTypeChange = (action: Action, type: number) => {
// //
if (isDeviceAction(type)) { if (isDeviceAction(type)) {

View File

@ -67,11 +67,12 @@ const props = defineProps<{
modelValue: IotSceneRule modelValue: IotSceneRule
rules?: any rules?: any
}>() }>()
const emit = defineEmits<{ const emit = defineEmits<{
(e: 'update:modelValue', value: IotSceneRule): void (e: 'update:modelValue', value: IotSceneRule): void
}>() }>()
const formData = useVModel(props, 'modelValue', emit) const formData = useVModel(props, 'modelValue', emit) //
</script> </script>
<style scoped> <style scoped>

View File

@ -137,7 +137,9 @@ const emit = defineEmits<{
const triggers = useVModel(props, 'triggers', emit) const triggers = useVModel(props, 'triggers', emit)
// /**
* 添加触发器
*/
const addTrigger = () => { const addTrigger = () => {
const newTrigger: Trigger = { const newTrigger: Trigger = {
type: TriggerTypeEnum.DEVICE_STATE_UPDATE, type: TriggerTypeEnum.DEVICE_STATE_UPDATE,
@ -152,25 +154,49 @@ const addTrigger = () => {
triggers.value.push(newTrigger) triggers.value.push(newTrigger)
} }
/**
* 删除触发器
* @param index 触发器索引
*/
const removeTrigger = (index: number) => { const removeTrigger = (index: number) => {
if (triggers.value.length > 1) { if (triggers.value.length > 1) {
triggers.value.splice(index, 1) triggers.value.splice(index, 1)
} }
} }
/**
* 更新触发器类型
* @param index 触发器索引
* @param type 触发器类型
*/
const updateTriggerType = (index: number, type: number) => { const updateTriggerType = (index: number, type: number) => {
triggers.value[index].type = type triggers.value[index].type = type
onTriggerTypeChange(index, type) onTriggerTypeChange(index, type)
} }
/**
* 更新触发器设备配置
* @param index 触发器索引
* @param newTrigger 新的触发器对象
*/
const updateTriggerDeviceConfig = (index: number, newTrigger: Trigger) => { const updateTriggerDeviceConfig = (index: number, newTrigger: Trigger) => {
triggers.value[index] = newTrigger triggers.value[index] = newTrigger
} }
/**
* 更新触发器CRON配置
* @param index 触发器索引
* @param cronExpression CRON表达式
*/
const updateTriggerCronConfig = (index: number, cronExpression?: string) => { const updateTriggerCronConfig = (index: number, cronExpression?: string) => {
triggers.value[index].cronExpression = cronExpression triggers.value[index].cronExpression = cronExpression
} }
/**
* 处理触发器类型变化事件
* @param index 触发器索引
* @param _ 触发器类型未使用
*/
const onTriggerTypeChange = (index: number, _: number) => { const onTriggerTypeChange = (index: number, _: number) => {
const triggerItem = triggers.value[index] const triggerItem = triggers.value[index]
triggerItem.productId = undefined triggerItem.productId = undefined

View File

@ -58,17 +58,21 @@ const emit = defineEmits<{
(e: 'change', value?: number): void (e: 'change', value?: number): void
}>() }>()
// const deviceLoading = ref(false) //
const deviceLoading = ref(false) const deviceList = ref<any[]>([]) //
const deviceList = ref<any[]>([])
// /**
* 处理选择变化事件
* @param value 选中的设备ID
*/
const handleChange = (value?: number) => { const handleChange = (value?: number) => {
emit('update:modelValue', value) emit('update:modelValue', value)
emit('change', value) emit('change', value)
} }
// /**
* 获取设备列表
*/
const getDeviceList = async () => { const getDeviceList = async () => {
if (!props.productId) { if (!props.productId) {
deviceList.value = [] deviceList.value = []
@ -88,8 +92,6 @@ const getDeviceList = async () => {
} }
} }
// constants.ts
// //
watch( watch(
() => props.productId, () => props.productId,

View File

@ -217,7 +217,7 @@ const allOperators = [
} }
] ]
// //
const availableOperators = computed(() => { const availableOperators = computed(() => {
if (!props.propertyType) { if (!props.propertyType) {
return allOperators return allOperators
@ -226,11 +226,15 @@ const availableOperators = computed(() => {
return allOperators.filter((op) => op.supportedTypes.includes(props.propertyType!)) return allOperators.filter((op) => op.supportedTypes.includes(props.propertyType!))
}) })
//
const selectedOperator = computed(() => { const selectedOperator = computed(() => {
return allOperators.find((op) => op.value === localValue.value) return allOperators.find((op) => op.value === localValue.value)
}) })
// /**
* 处理选择变化事件
* @param value 选中的操作符值
*/
const handleChange = (value: string) => { const handleChange = (value: string) => {
emit('change', value) emit('change', value)
} }

View File

@ -46,17 +46,21 @@ const emit = defineEmits<{
(e: 'change', value?: number): void (e: 'change', value?: number): void
}>() }>()
// const productLoading = ref(false) //
const productLoading = ref(false) const productList = ref<any[]>([]) //
const productList = ref<any[]>([])
// /**
* 处理选择变化事件
* @param value 选中的产品ID
*/
const handleChange = (value?: number) => { const handleChange = (value?: number) => {
emit('update:modelValue', value) emit('update:modelValue', value)
emit('change', value) emit('change', value)
} }
// /**
* 获取产品列表
*/
const getProductList = async () => { const getProductList = async () => {
try { try {
productLoading.value = true productLoading.value = true

View File

@ -212,12 +212,11 @@ const emit = defineEmits<{
const localValue = useVModel(props, 'modelValue', emit) const localValue = useVModel(props, 'modelValue', emit)
// const loading = ref(false) //
const loading = ref(false) const propertyList = ref<PropertySelectorItem[]>([]) //
const propertyList = ref<PropertySelectorItem[]>([]) const thingModelTSL = ref<IotThingModelTSLResp | null>(null) // TSL
const thingModelTSL = ref<IotThingModelTSLResp | null>(null)
// //
const propertyGroups = computed(() => { const propertyGroups = computed(() => {
const groups: { label: string; options: any[] }[] = [] const groups: { label: string; options: any[] }[] = []
@ -245,11 +244,15 @@ const propertyGroups = computed(() => {
return groups.filter((group) => group.options.length > 0) return groups.filter((group) => group.options.length > 0)
}) })
//
const selectedProperty = computed(() => { const selectedProperty = computed(() => {
return propertyList.value.find((p) => p.identifier === localValue.value) return propertyList.value.find((p) => p.identifier === localValue.value)
}) })
// /**
* 处理选择变化事件
* @param value 选中的属性标识符
*/
const handleChange = (value: string) => { const handleChange = (value: string) => {
const property = propertyList.value.find((p) => p.identifier === value) const property = propertyList.value.find((p) => p.identifier === value)
if (property) { if (property) {
@ -289,7 +292,9 @@ const getThingModelTSL = async () => {
} }
} }
// TSL /**
* 解析物模型TSL数据
*/
const parseThingModelData = () => { const parseThingModelData = () => {
const tsl = thingModelTSL.value const tsl = thingModelTSL.value
const properties: PropertySelectorItem[] = [] const properties: PropertySelectorItem[] = []
@ -352,7 +357,11 @@ const parseThingModelData = () => {
propertyList.value = properties propertyList.value = properties
} }
// /**
* 获取属性单位
* @param property 属性对象
* @returns 属性单位
*/
const getPropertyUnit = (property: any) => { const getPropertyUnit = (property: any) => {
if (!property) return undefined if (!property) return undefined
@ -364,7 +373,11 @@ const getPropertyUnit = (property: any) => {
return undefined return undefined
} }
// /**
* 获取属性范围描述
* @param property 属性对象
* @returns 属性范围描述
*/
const getPropertyRange = (property: any) => { const getPropertyRange = (property: any) => {
if (!property) return undefined if (!property) return undefined