Commit e12050867762f1060b893e770671f44855c1a0a4

Authored by loveumiko
1 parent ab4c93f6

fix: 修复设备填写设备地址

... ... @@ -202,6 +202,13 @@ export const step1Schemas: FormSchema[] = [
202 202 },
203 203 },
204 204 {
  205 + field: 'addressType',
  206 + label: '',
  207 + component: 'Input',
  208 + show: false,
  209 + defaultValue: 'HEX',
  210 + },
  211 + {
205 212 field: 'addressCode',
206 213 label: '地址码',
207 214 dynamicRules({ values }) {
... ... @@ -211,7 +218,7 @@ export const step1Schemas: FormSchema[] = [
211 218 values?.transportType === TransportTypeEnum.TCP &&
212 219 values?.tcpDeviceProtocol === TCPProtocolTypeEnum.MODBUS_RTU,
213 220 message: '地址码范围为00~FF',
214   - pattern: /^[0-9A-Fa-f]{1,2}$/,
  221 + pattern: values?.addressType === 'HEX' ? /^[0-9A-Fa-f]{2}$/ : /^[0-9A-Fa-f]{1,2}$/,
215 222 },
216 223 ];
217 224 },
... ... @@ -219,10 +226,15 @@ export const step1Schemas: FormSchema[] = [
219 226 component: 'HexInput',
220 227 changeEvent: 'update:value',
221 228 valueField: 'value',
222   - componentProps: {
223   - type: InputTypeEnum.HEX,
224   - maxValue: parseInt('FF', 16),
225   - placeholder: '请输入寄存器地址',
  229 + componentProps: ({ formModel }) => {
  230 + return {
  231 + type: InputTypeEnum.HEX,
  232 + maxValue: parseInt('FF', 16),
  233 + placeholder: '请输入寄存器地址',
  234 + onHexChange: (e) => {
  235 + formModel.addressType = e;
  236 + },
  237 + };
226 238 },
227 239 ifShow: ({ values }) => {
228 240 return (
... ...
... ... @@ -23,7 +23,7 @@
23 23 }
24 24 );
25 25
26   - const emits = defineEmits(['update:value', 'change']);
  26 + const emits = defineEmits(['update:value', 'change', 'hexChange']);
27 27
28 28 const typOptions = Object.values(InputTypeEnum).map((value) => ({ label: value, value }));
29 29
... ... @@ -114,6 +114,10 @@
114 114 ? getHexToDec(unref(getInputValue)!)
115 115 : `${hexWithPrefix ? '0x' : ''}${Number(unref(getInputValue)).toString(16).toUpperCase()}`;
116 116 });
  117 +
  118 + const handleInputTypeChange = (e) => {
  119 + emits('hexChange', e);
  120 + };
117 121 </script>
118 122
119 123 <template>
... ... @@ -124,6 +128,7 @@
124 128 class="min-w-20"
125 129 :options="typOptions"
126 130 :disabled="disabled"
  131 + @change="handleInputTypeChange"
127 132 />
128 133 <Input v-bind="$attrs" v-model:value="getInputValue" class="!w-full" :disabled="disabled" />
129 134 <div class="min-w-14 h-full px-2 flex-grow flex-shrink-0 text-center leading-8 bg-gray-200">
... ...