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 1 import { useParseOriginalDataType } from './useParseOriginalDataType';
2 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 8 export function useBaseConversion() {
5 9 function DecTo32Float(number: number) {
6 10 const arr = new Uint8Array(4);
... ... @@ -146,7 +150,7 @@ export function useBaseConversion() {
146 150 let result: number[];
147 151
148 152 if (type === OriginalDataTypeEnum.BOOLEAN) {
149   - result = [value];
  153 + result = [getBoolValueByStatus(!!value)];
150 154 } else if (type === OriginalDataTypeEnum.STRING) {
151 155 let buffer = StringToHEXBuffer(value);
152 156 const { registerNumber = 0 } = additional || {};
... ...
... ... @@ -14,7 +14,7 @@ import {
14 14 TransportTypeEnum,
15 15 } from '/@/enums/deviceEnum';
16 16 import { FunctionTypeEnum } from '/@/enums/objectModelEnum';
17   -import { isFunction } from '/@/utils/is';
  17 +import { isFunction, isNullOrUnDef } from '/@/utils/is';
18 18 import { getDeviceActiveTime } from '/@/api/alarm/position';
19 19 import { useMessage } from '../web/useMessage';
20 20
... ... @@ -152,7 +152,7 @@ export function useCommandDelivery() {
152 152 rpcCommand,
153 153 setupResult
154 154 );
155   - rpcCommand = _rpcCommand;
  155 + !isNullOrUnDef(rpcCommand) && (rpcCommand = _rpcCommand);
156 156 if (_way) way = _way;
157 157 }
158 158
... ...
... ... @@ -135,6 +135,26 @@ export const useGenerateFormSchemasByObjectModel = () => {
135 135 const { valueRange } = specs as Specs;
136 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 158 const isStringType = extensionDesc?.originalDataType === OriginalDataTypeEnum.STRING;
139 159 return {
140 160 field: identifier,
... ...
... ... @@ -68,10 +68,13 @@ export const UINT32_VALUE_RANGE = {
68 68 };
69 69
70 70 function getValueRangeFromOriginDataType(
71   - originalDataType?: OriginalDataTypeEnum
  71 + originalDataType?: OriginalDataTypeEnum,
  72 + type: 'range' | 'defaultValue' = 'range'
72 73 ): Record<'min' | 'max', number> {
73 74 switch (originalDataType) {
74 75 case OriginalDataTypeEnum.BOOLEAN:
  76 + return type === 'defaultValue' ? BOOL_DEFAULT_VALUE_RANGE : UINT16_VALUE_RANGE;
  77 +
75 78 case OriginalDataTypeEnum.BITS:
76 79 return BOOL_DEFAULT_VALUE_RANGE;
77 80
... ... @@ -216,7 +219,8 @@ export const getExtendDescFormSchemas = (): FormSchema[] => {
216 219 const { setFieldsValue } = formActionType;
217 220 setFieldsValue({
218 221 [FormFieldsEnum.VALUE_RANGE]: getValueRangeFromOriginDataType(
219   - value as OriginalDataTypeEnum
  222 + value as OriginalDataTypeEnum,
  223 + 'defaultValue'
220 224 ),
221 225 });
222 226 },
... ...