diff --git a/src/views/iot/device/components/DeviceAttributeForm.vue b/src/views/iot/device/components/DeviceAttributeForm.vue index 3d72a2da..e1fe54fc 100644 --- a/src/views/iot/device/components/DeviceAttributeForm.vue +++ b/src/views/iot/device/components/DeviceAttributeForm.vue @@ -44,7 +44,7 @@ - + @@ -104,6 +104,33 @@ const formData = ref({ deviceId: undefined as number | undefined }) +const ratioEnabledTypes = new Set([ + 'uint8', + 'uint16', + 'uint32', + 'uint64', + 'int8', + 'int16', + 'int32', + 'float32', + 'float64' +]) + +const ratioEnabled = computed(() => { + const v = formData.value.dataType + if (!v) return false + return ratioEnabledTypes.has(v) +}) + +watch( + () => formData.value.dataType, + () => { + if (!ratioEnabled.value) { + formData.value.ratio = undefined + } + } +) + const handleAttributeCodeInput = (val: string) => { formData.value.attributeCode = val?.replace(/[\u4e00-\u9fa5]/g, '') } @@ -190,7 +217,7 @@ const buildSubmitData = () => { dataType, address, dataUnit, - ratio, + ratio: ratioEnabled.value ? ratio : undefined, sort: parsedSort, remark, deviceId