Commit 0d4b011ae50d78a495bde4bf6194338b11fac348

Authored by xp.Huang
2 parents ce1d11fc cf244343

Merge branch 'fix/device-modbus-command' into 'main_dev'

fix: 修复设备属性下发输入参数为0时,寄存器值为空

See merge request yunteng/thingskit-front!798
... ... @@ -129,7 +129,6 @@ const SingleToHexBatch = (t) => {
129 129
130 130 const formSchemasConfig = (schemas, actionType): FormSchema[] => {
131 131 const { identifier, functionName } = schemas;
132   - console.log(identifier, 'identifier', actionType, 'actionType');
133 132 if (actionType == '06') {
134 133 return [
135 134 {
... ...
... ... @@ -91,11 +91,14 @@
91 91 };
92 92
93 93 // 获取小数
94   - const getFloatPart = (number): any => {
  94 + const getFloatPart = (number: string | number) => {
  95 + const isLessZero = Number(number) < 0;
95 96 number = number.toString();
96 97 const floatPartStartIndex = number.indexOf('.');
97   - const value = ~floatPartStartIndex ? `0.${number.substring(floatPartStartIndex + 1)}` : '0';
98   - return value;
  98 + const value = ~floatPartStartIndex
  99 + ? `${isLessZero ? '-' : ''}0.${number.substring(floatPartStartIndex + 1)}`
  100 + : '0';
  101 + return Number(value);
99 102 };
100 103
101 104 const { createMessage } = useMessage();
... ... @@ -139,13 +142,16 @@
139 142 if (unref(modBUSForm).method == '16' || unref(modBUSForm).method == '10') {
140 143 const regex = /^-?\d+(\.\d{0,2})?$/;
141 144 const values =
142   - Math.floor(oldValue) * unref(zoomFactorValue) +
  145 + Math.trunc(oldValue) * unref(zoomFactorValue) +
143 146 getFloatPart(oldValue) * unref(zoomFactorValue);
  147 +
144 148 if (!regex.test(values as any)) {
145 149 createMessage.warning(`属性下发值精确到两位小数,缩放因子是${unref(zoomFactorValue)}`);
146 150 return;
147 151 }
148   - const newValue = getArray(SingleToHex(unref(isShowMultiply) ? values : oldValue));
  152 +
  153 + const newValue =
  154 + values == 0 ? [0, 0] : getArray(SingleToHex(unref(isShowMultiply) ? values : oldValue));
149 155 modBUSForm.value.registerValues = newValue;
150 156 modBUSForm.value.registerNumber = 2;
151 157 modBUSForm.value.method = '10';
... ...
... ... @@ -20,7 +20,6 @@ export const useGenDynamicForm = () => {
20 20 const { specs, type } = dataType;
21 21 const { valueRange, step } = specs! as Partial<Specs>;
22 22 const { max, min } = valueRange || {};
23   - console.log({ max, min });
24 23 return {
25 24 field: identifier,
26 25 label: functionName,
... ...