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,7 +129,6 @@ const SingleToHexBatch = (t) => {
129 129
130 const formSchemasConfig = (schemas, actionType): FormSchema[] => { 130 const formSchemasConfig = (schemas, actionType): FormSchema[] => {
131 const { identifier, functionName } = schemas; 131 const { identifier, functionName } = schemas;
132 - console.log(identifier, 'identifier', actionType, 'actionType');  
133 if (actionType == '06') { 132 if (actionType == '06') {
134 return [ 133 return [
135 { 134 {
@@ -91,11 +91,14 @@ @@ -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 number = number.toString(); 96 number = number.toString();
96 const floatPartStartIndex = number.indexOf('.'); 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 const { createMessage } = useMessage(); 104 const { createMessage } = useMessage();
@@ -139,13 +142,16 @@ @@ -139,13 +142,16 @@
139 if (unref(modBUSForm).method == '16' || unref(modBUSForm).method == '10') { 142 if (unref(modBUSForm).method == '16' || unref(modBUSForm).method == '10') {
140 const regex = /^-?\d+(\.\d{0,2})?$/; 143 const regex = /^-?\d+(\.\d{0,2})?$/;
141 const values = 144 const values =
142 - Math.floor(oldValue) * unref(zoomFactorValue) + 145 + Math.trunc(oldValue) * unref(zoomFactorValue) +
143 getFloatPart(oldValue) * unref(zoomFactorValue); 146 getFloatPart(oldValue) * unref(zoomFactorValue);
  147 +
144 if (!regex.test(values as any)) { 148 if (!regex.test(values as any)) {
145 createMessage.warning(`属性下发值精确到两位小数,缩放因子是${unref(zoomFactorValue)}`); 149 createMessage.warning(`属性下发值精确到两位小数,缩放因子是${unref(zoomFactorValue)}`);
146 return; 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 modBUSForm.value.registerValues = newValue; 155 modBUSForm.value.registerValues = newValue;
150 modBUSForm.value.registerNumber = 2; 156 modBUSForm.value.registerNumber = 2;
151 modBUSForm.value.method = '10'; 157 modBUSForm.value.method = '10';
@@ -20,7 +20,6 @@ export const useGenDynamicForm = () => { @@ -20,7 +20,6 @@ export const useGenDynamicForm = () => {
20 const { specs, type } = dataType; 20 const { specs, type } = dataType;
21 const { valueRange, step } = specs! as Partial<Specs>; 21 const { valueRange, step } = specs! as Partial<Specs>;
22 const { max, min } = valueRange || {}; 22 const { max, min } = valueRange || {};
23 - console.log({ max, min });  
24 return { 23 return {
25 field: identifier, 24 field: identifier,
26 label: functionName, 25 label: functionName,