Commit 7f9724f4624be88eed89fe37357a40e976c3f9b5

Authored by xp.Huang
2 parents c53e457b a7e72454

Merge branch 'perf/command-delivery' into 'main_dev'

perf: 优化任务列表与物模型TCP命令移除空白字符

See merge request yunteng/thingskit-front!1299
... ... @@ -26,7 +26,7 @@
26 26 import { CommandDeliveryFormFieldType, CommandFieldsEnum, CommandSchemas } from './config';
27 27 import { useMessage } from '/@/hooks/web/useMessage';
28 28 import { DeviceRecord } from '/@/api/device/model/deviceModel';
29   - import { CommandDeliveryWayEnum, TCPProtocolTypeEnum } from '/@/enums/deviceEnum';
  29 + import { CommandDeliveryWayEnum } from '/@/enums/deviceEnum';
30 30 import { CommandTypeEnum, RPCCommandMethodEnum, TransportTypeEnum } from '/@/enums/deviceEnum';
31 31 import { BasicModal, useModalInner } from '/@/components/Modal';
32 32 import { getDeviceActiveTime } from '/@/api/alarm/position';
... ... @@ -88,13 +88,7 @@
88 88 if (commandType === CommandTypeEnum.CUSTOM) {
89 89 if (isTcpDevice) {
90 90 const value = values.tcpCommandValue;
91   - if (
92   - unref(props.deviceDetail).deviceProfile.profileData.transportConfiguration.protocol ===
93   - TCPProtocolTypeEnum.MODBUS_RTU
94   - ) {
95   - return value?.replaceAll(/\s/g, '');
96   - }
97   - return value;
  91 + return value?.replaceAll(/\s/g, '');
98 92 }
99 93 return parseStringToJSON(values.commandValue!).json;
100 94 } else {
... ...
... ... @@ -130,7 +130,11 @@ function handleServiceType(
130 130 functionJson: {
131 131 inputData:
132 132 transportType === TransportTypeEnum.TCP
133   - ? [{ [FormFieldsEnum.SERVICE_COMMAND]: serviceCommand } as unknown as StructJSON]
  133 + ? [
  134 + {
  135 + [FormFieldsEnum.SERVICE_COMMAND]: serviceCommand?.replaceAll(/\s/g, ''),
  136 + } as unknown as StructJSON,
  137 + ]
134 138 : inputData,
135 139 outputData,
136 140 },
... ...
... ... @@ -14,6 +14,7 @@ import { dateUtil } from '/@/utils/dateUtil';
14 14 import { ProductPicker, validateProductPicker } from '../ProductPicker';
15 15 import { useGlobSetting } from '/@/hooks/setting';
16 16 import { TransportTypeEnum } from '/@/enums/deviceEnum';
  17 +import { validateTCPCustomCommand } from '/@/components/Form/src/components/ThingsModelForm';
17 18
18 19 useComponentRegister('DevicePicker', DevicePicker);
19 20 useComponentRegister('ProductPicker', ProductPicker);
... ... @@ -218,7 +219,7 @@ export const formSchemas: FormSchema[] = [
218 219 const rules: Rule[] = [{ required: true, message: '请输入自定义数据流' }];
219 220 return model[FormFieldsEnum.PUSH_WAY] === PushWayEnum.MQTT
220 221 ? [...rules, ...JSONEditorValidator()]
221   - : rules;
  222 + : [...rules, { validator: validateTCPCustomCommand }];
222 223 },
223 224 ifShow: ({ model }) => model[FormFieldsEnum.EXECUTE_CONTENT_TYPE] === TaskTypeEnum.CUSTOM,
224 225 valueField: 'value',
... ...
... ... @@ -95,7 +95,8 @@ export const composeData = (result: Required<FormValueType>): CreateTaskRecordTy
95 95 targetType,
96 96 executeContent: {
97 97 pushContent: {
98   - rpcCommand: pushWay === PushWayEnum.MQTT ? JSON.parse(rpcCommand) : rpcCommand,
  98 + rpcCommand:
  99 + pushWay === PushWayEnum.TCP ? rpcCommand.replaceAll(/\s/g, '') : JSON.parse(rpcCommand),
99 100 },
100 101 pushWay,
101 102 type: executeContentType,
... ...