Commit 6fdcb5ca4ec0ab9eebf3a316646e6d56b5e14b87
Merge branch 'fix/device-things-model-send-command' into 'main_dev'
fix: 修复自定义TCP设备物模型界面下发命令不正确 See merge request yunteng/thingskit-front!904
Showing
2 changed files
with
36 additions
and
9 deletions
@@ -121,7 +121,7 @@ export const step1Schemas: FormSchema[] = [ | @@ -121,7 +121,7 @@ export const step1Schemas: FormSchema[] = [ | ||
121 | { | 121 | { |
122 | field: 'codeType', | 122 | field: 'codeType', |
123 | label: '标识符类型', | 123 | label: '标识符类型', |
124 | - component: 'Select', | 124 | + component: 'RadioGroup', |
125 | dynamicRules({ values }) { | 125 | dynamicRules({ values }) { |
126 | return [ | 126 | return [ |
127 | { | 127 | { |
@@ -13,6 +13,7 @@ | @@ -13,6 +13,7 @@ | ||
13 | import { genModbusCommand } from '/@/api/task'; | 13 | import { genModbusCommand } from '/@/api/task'; |
14 | import { TaskTypeEnum } from '/@/views/task/center/config'; | 14 | import { TaskTypeEnum } from '/@/views/task/center/config'; |
15 | import { SingleToHex, formSchemasConfig } from './config'; | 15 | import { SingleToHex, formSchemasConfig } from './config'; |
16 | + import { TransportTypeEnum } from '/@/views/device/profiles/components/TransportDescript/const'; | ||
16 | 17 | ||
17 | defineEmits(['register']); | 18 | defineEmits(['register']); |
18 | const props = defineProps<{ deviceId: string; deviceName: string }>(); | 19 | const props = defineProps<{ deviceId: string; deviceName: string }>(); |
@@ -33,6 +34,7 @@ | @@ -33,6 +34,7 @@ | ||
33 | const formField = ref(''); //存一个表单取值的field | 34 | const formField = ref(''); //存一个表单取值的field |
34 | const zoomFactorValue = ref<number>(1); //缩放因子 | 35 | const zoomFactorValue = ref<number>(1); //缩放因子 |
35 | const isShowMultiply = ref<Boolean>(false); // 只有tcp --> int和double类型才相乘缩放因子 | 36 | const isShowMultiply = ref<Boolean>(false); // 只有tcp --> int和double类型才相乘缩放因子 |
37 | + const deviceTransportType = ref<string>(); | ||
36 | 38 | ||
37 | const [register] = useModalInner(async (params: ModalParamsType<DeviceModelOfMatterAttrs>) => { | 39 | const [register] = useModalInner(async (params: ModalParamsType<DeviceModelOfMatterAttrs>) => { |
38 | const { record } = params; | 40 | const { record } = params; |
@@ -45,6 +47,7 @@ | @@ -45,6 +47,7 @@ | ||
45 | formField.value = identifier; | 47 | formField.value = identifier; |
46 | zoomFactorValue.value = zoomFactor ? Number(zoomFactor) : 1; | 48 | zoomFactorValue.value = zoomFactor ? Number(zoomFactor) : 1; |
47 | isShowMultiply.value = type == 'INT' || type == 'DOUBLE' ? true : false; | 49 | isShowMultiply.value = type == 'INT' || type == 'DOUBLE' ? true : false; |
50 | + deviceTransportType.value = transportType; | ||
48 | 51 | ||
49 | let schemas = [{ dataType: dataType, identifier, functionName: name } as StructJSON]; | 52 | let schemas = [{ dataType: dataType, identifier, functionName: name } as StructJSON]; |
50 | 53 | ||
@@ -59,7 +62,7 @@ | @@ -59,7 +62,7 @@ | ||
59 | 62 | ||
60 | //是modBUS类型的就用另外的表单 | 63 | //是modBUS类型的就用另外的表单 |
61 | //判断是否是TCP ==> modBus的下发命令 | 64 | //判断是否是TCP ==> modBus的下发命令 |
62 | - if (codeType == TaskTypeEnum.MODBUS_RTU && transportType == 'TCP') { | 65 | + if (codeType === TaskTypeEnum.MODBUS_RTU && transportType == TransportTypeEnum.TCP) { |
63 | isShowModBUS.value = true; | 66 | isShowModBUS.value = true; |
64 | modBUSForm.value = { | 67 | modBUSForm.value = { |
65 | crc: 'CRC_16_LOWER', | 68 | crc: 'CRC_16_LOWER', |
@@ -72,8 +75,31 @@ | @@ -72,8 +75,31 @@ | ||
72 | setProps({ schemas: formSchemasConfig(schemas[0], actionType) }); | 75 | setProps({ schemas: formSchemasConfig(schemas[0], actionType) }); |
73 | } else { | 76 | } else { |
74 | isShowModBUS.value = false; | 77 | isShowModBUS.value = false; |
75 | - const formSchemas = genForm(schemas); | ||
76 | - setProps({ schemas: formSchemas }); | 78 | + if (transportType === TransportTypeEnum.TCP) { |
79 | + setProps({ | ||
80 | + schemas: [ | ||
81 | + { | ||
82 | + field: 'command', | ||
83 | + label: name, | ||
84 | + component: 'Input', | ||
85 | + required: true, | ||
86 | + rules: [ | ||
87 | + { | ||
88 | + pattern: /^[\s0-9a-fA-F]+$/, | ||
89 | + required: true, | ||
90 | + message: '请输入ASCII或HEX服务命令(0~9/A~F)', | ||
91 | + }, | ||
92 | + ], | ||
93 | + componentProps: { | ||
94 | + placeholder: `请输入${name}`, | ||
95 | + }, | ||
96 | + }, | ||
97 | + ], | ||
98 | + }); | ||
99 | + } else { | ||
100 | + const formSchemas = genForm(schemas); | ||
101 | + setProps({ schemas: formSchemas }); | ||
102 | + } | ||
77 | } | 103 | } |
78 | 104 | ||
79 | resetFields(); | 105 | resetFields(); |
@@ -164,6 +190,11 @@ | @@ -164,6 +190,11 @@ | ||
164 | sendValue.value = unref(keys).reduce((prev, next) => { | 190 | sendValue.value = unref(keys).reduce((prev, next) => { |
165 | return { ...prev, [next]: _value[next] }; | 191 | return { ...prev, [next]: _value[next] }; |
166 | }, {}); | 192 | }, {}); |
193 | + | ||
194 | + // tcp 设备下发字符串 | ||
195 | + if (unref(deviceTransportType) === TransportTypeEnum.TCP) { | ||
196 | + sendValue.value = Object.values(_value).join('').replaceAll(/\s/g, ''); | ||
197 | + } | ||
167 | } | 198 | } |
168 | 199 | ||
169 | await sendCommandOneway({ | 200 | await sendCommandOneway({ |
@@ -171,11 +202,7 @@ | @@ -171,11 +202,7 @@ | ||
171 | value: { | 202 | value: { |
172 | persistent: true, | 203 | persistent: true, |
173 | method: 'methodThingskit', | 204 | method: 'methodThingskit', |
174 | - params: unref(isShowModBUS) | ||
175 | - ? unref(sendValue) | ||
176 | - : { | ||
177 | - ...unref(sendValue), | ||
178 | - }, | 205 | + params: unref(sendValue), |
179 | }, | 206 | }, |
180 | }); | 207 | }); |
181 | createMessage.success('属性下发成功~'); | 208 | createMessage.success('属性下发成功~'); |