Showing
1 changed file
with
10 additions
and
2 deletions
... | ... | @@ -16273,20 +16273,28 @@ class HandleDataInteraction { |
16273 | 16273 | MODBUS: '2', |
16274 | 16274 | } |
16275 | 16275 | |
16276 | + const getNumberFloatPart = (number) => { | |
16277 | + number = number.toString() | |
16278 | + const floatIndex = number.indexOf('.') | |
16279 | + const floatPart = ~floatIndex ? `0.${number.substring(floatIndex + 1)}` : '0'; | |
16280 | + return floatPart | |
16281 | + } | |
16282 | + | |
16276 | 16283 | if (commandType == enumCommandType.MODBUS) { |
16277 | 16284 | value = data[enumActionEl.CUSTOM_TCP_COMMAND] |
16278 | 16285 | const { method, deviceCode, zoomFactor = 1 } = additional || {} |
16286 | + | |
16279 | 16287 | const validate = new Validate([ |
16280 | 16288 | { value: deviceCode, required: true, message: '未找到设备地址码' }, |
16281 | 16289 | { value: method, required: true, message: '未找到Modbus命令操作类型' }, |
16282 | 16290 | { value, required: true, message: '下发值是必填项' }, |
16283 | 16291 | ...(method == '05' ? [{ value, message: '下发类型必须为0或1', validator(value) { return value == 0 || value == 1 } }] : []), |
16284 | - ...(method == '06' ? [{ value, message: `下发类型必须为整型,缩放因子为${zoomFactor}`, validator(value) { return !isNaN(value) && Number(value) * zoomFactor % 1 === 0 } }, { value: value * zoomFactor, message: `最大值不能超过65535,缩放因子为${zoomFactor}`, validator(value) { return Number(value) <= parseInt('ffff', 16) } }] : []), | |
16292 | + ...(method == '06' ? [{ value, message: `下发类型必须为整型,缩放因子为${zoomFactor}`, validator(value) { return !isNaN(value) && getNumberFloatPart(value) * zoomFactor % 1 === 0 } }, { value: value * zoomFactor, message: `最大值不能超过65535,缩放因子为${zoomFactor}`, validator(value) { return Number(value) <= parseInt('ffff', 16) } }] : []), | |
16285 | 16293 | ...(method == '16' ? [{ value, message: '下发类型精确到两位小数', validator(value) { return /^-?\d+(\.\d{0,2})?$/.test(value * zoomFactor) } }] : []) |
16286 | 16294 | ]) |
16287 | 16295 | |
16288 | 16296 | if (method == '06' || method == '16') { |
16289 | - value = value * zoomFactor | |
16297 | + value = Math.floor(value) * zoomFactor + getNumberFloatPart(value) * zoomFactor | |
16290 | 16298 | } |
16291 | 16299 | |
16292 | 16300 | if (method == '16') { | ... | ... |