Commit 0ecd294cbf6397b4c652a79b1aed214f51d549f7

Authored by xp.Huang
2 parents 5097bab3 7680be68

Merge branch 'fix/object-model-bool' into 'main_dev'

fix: TCP Modbus bool类型物模型取值范围变更

See merge request yunteng/thingskit-front!1224
1 import { useParseOriginalDataType } from './useParseOriginalDataType'; 1 import { useParseOriginalDataType } from './useParseOriginalDataType';
2 import { OriginalDataTypeEnum } from '/@/enums/objectModelEnum'; 2 import { OriginalDataTypeEnum } from '/@/enums/objectModelEnum';
3 3
  4 +export function getBoolValueByStatus(status: boolean) {
  5 + return status ? parseInt('FF00', 16) : parseInt('0000', 16);
  6 +}
  7 +
4 export function useBaseConversion() { 8 export function useBaseConversion() {
5 function DecTo32Float(number: number) { 9 function DecTo32Float(number: number) {
6 const arr = new Uint8Array(4); 10 const arr = new Uint8Array(4);
@@ -146,7 +150,7 @@ export function useBaseConversion() { @@ -146,7 +150,7 @@ export function useBaseConversion() {
146 let result: number[]; 150 let result: number[];
147 151
148 if (type === OriginalDataTypeEnum.BOOLEAN) { 152 if (type === OriginalDataTypeEnum.BOOLEAN) {
149 - result = [value]; 153 + result = [getBoolValueByStatus(!!value)];
150 } else if (type === OriginalDataTypeEnum.STRING) { 154 } else if (type === OriginalDataTypeEnum.STRING) {
151 let buffer = StringToHEXBuffer(value); 155 let buffer = StringToHEXBuffer(value);
152 const { registerNumber = 0 } = additional || {}; 156 const { registerNumber = 0 } = additional || {};
@@ -14,7 +14,7 @@ import { @@ -14,7 +14,7 @@ import {
14 TransportTypeEnum, 14 TransportTypeEnum,
15 } from '/@/enums/deviceEnum'; 15 } from '/@/enums/deviceEnum';
16 import { FunctionTypeEnum } from '/@/enums/objectModelEnum'; 16 import { FunctionTypeEnum } from '/@/enums/objectModelEnum';
17 -import { isFunction } from '/@/utils/is'; 17 +import { isFunction, isNullOrUnDef } from '/@/utils/is';
18 import { getDeviceActiveTime } from '/@/api/alarm/position'; 18 import { getDeviceActiveTime } from '/@/api/alarm/position';
19 import { useMessage } from '../web/useMessage'; 19 import { useMessage } from '../web/useMessage';
20 20
@@ -152,7 +152,7 @@ export function useCommandDelivery() { @@ -152,7 +152,7 @@ export function useCommandDelivery() {
152 rpcCommand, 152 rpcCommand,
153 setupResult 153 setupResult
154 ); 154 );
155 - rpcCommand = _rpcCommand; 155 + !isNullOrUnDef(rpcCommand) && (rpcCommand = _rpcCommand);
156 if (_way) way = _way; 156 if (_way) way = _way;
157 } 157 }
158 158
@@ -135,6 +135,26 @@ export const useGenerateFormSchemasByObjectModel = () => { @@ -135,6 +135,26 @@ export const useGenerateFormSchemasByObjectModel = () => {
135 const { valueRange } = specs as Specs; 135 const { valueRange } = specs as Specs;
136 const { max, min } = valueRange || {}; 136 const { max, min } = valueRange || {};
137 137
  138 + if (extensionDesc?.originalDataType === OriginalDataTypeEnum.BOOLEAN) {
  139 + const options = [
  140 + { label: '闭合', value: parseInt('FF00', 16) },
  141 + { label: '断开', value: parseInt('0000', 16) },
  142 + ];
  143 +
  144 + return {
  145 + field: identifier,
  146 + label: name,
  147 + component: 'Select',
  148 + componentProps: () => {
  149 + return {
  150 + options,
  151 + placeholder: `请选择${name}`,
  152 + getPopupContainer: () => document.body,
  153 + };
  154 + },
  155 + };
  156 + }
  157 +
138 const isStringType = extensionDesc?.originalDataType === OriginalDataTypeEnum.STRING; 158 const isStringType = extensionDesc?.originalDataType === OriginalDataTypeEnum.STRING;
139 return { 159 return {
140 field: identifier, 160 field: identifier,
@@ -68,10 +68,13 @@ export const UINT32_VALUE_RANGE = { @@ -68,10 +68,13 @@ export const UINT32_VALUE_RANGE = {
68 }; 68 };
69 69
70 function getValueRangeFromOriginDataType( 70 function getValueRangeFromOriginDataType(
71 - originalDataType?: OriginalDataTypeEnum 71 + originalDataType?: OriginalDataTypeEnum,
  72 + type: 'range' | 'defaultValue' = 'range'
72 ): Record<'min' | 'max', number> { 73 ): Record<'min' | 'max', number> {
73 switch (originalDataType) { 74 switch (originalDataType) {
74 case OriginalDataTypeEnum.BOOLEAN: 75 case OriginalDataTypeEnum.BOOLEAN:
  76 + return type === 'defaultValue' ? BOOL_DEFAULT_VALUE_RANGE : UINT16_VALUE_RANGE;
  77 +
75 case OriginalDataTypeEnum.BITS: 78 case OriginalDataTypeEnum.BITS:
76 return BOOL_DEFAULT_VALUE_RANGE; 79 return BOOL_DEFAULT_VALUE_RANGE;
77 80
@@ -216,7 +219,8 @@ export const getExtendDescFormSchemas = (): FormSchema[] => { @@ -216,7 +219,8 @@ export const getExtendDescFormSchemas = (): FormSchema[] => {
216 const { setFieldsValue } = formActionType; 219 const { setFieldsValue } = formActionType;
217 setFieldsValue({ 220 setFieldsValue({
218 [FormFieldsEnum.VALUE_RANGE]: getValueRangeFromOriginDataType( 221 [FormFieldsEnum.VALUE_RANGE]: getValueRangeFromOriginDataType(
219 - value as OriginalDataTypeEnum 222 + value as OriginalDataTypeEnum,
  223 + 'defaultValue'
220 ), 224 ),
221 }); 225 });
222 }, 226 },