Browse Source

perf(components): 优化“协议自定义参数”组件

1. 添加 S7 协议参数字段
2. 根据协议类型动态显示相关字段
wangcong 2 tháng trước cách đây
mục cha
commit
f2f875076b

+ 4 - 0
src/i18n/locales/zh.json

@@ -361,6 +361,7 @@
     "protocolDisplayName": "{name}协议",
     "protocolName": "协议名称",
     "protocolParamFields": {
+      "addrNumber": "地址编号",
       "addressLength": "地址长度",
       "coefficient": "系数",
       "customParamName": "客户参数名称",
@@ -375,12 +376,15 @@
       "parsingType": "解析类型",
       "platformParamCode": "平台参数编码",
       "platformParamName": "平台参数名称",
+      "quantity": "数量",
       "readCalculationFormula": "读计算公式",
       "readFunctionCode": "读功能码",
       "readWriteType": "读写类型",
       "registerAddress": "寄存器地址",
+      "registerType": "寄存器类型",
       "result": "结果",
       "unit": "单位",
+      "wordLength": "字长",
       "writeCalculationFormula": "写计算公式",
       "writeFunctionCode": "写功能码"
     },

+ 94 - 3
src/views/setup-protocol/CustomParams.vue

@@ -29,6 +29,8 @@ const emit = defineEmits<{
 const { visible, showView, hideView } = useViewVisible();
 const { handleRequest } = useRequest();
 const { dictData: readWriteTypes, getDictData: getReadWriteTypes } = useDictData(DictCode.ReadWriteType);
+const { dictData: registerTypes, getDictData: getRegisterTypes } = useDictData(DictCode.RegisterType);
+const { dictData: wordLength, getDictData: getWordLength } = useDictData(DictCode.WordLength);
 const { dictData: parsingTypes, getDictData: getParsingTypes } = useDictData(DictCode.ParsingType);
 const { dictData: writeFuncCode, getDictData: getWriteFuncCode } = useDictData(DictCode.WriteFuncCode);
 const { dictData: readFuncCode, getDictData: getReadFuncCode } = useDictData(DictCode.ReadFuncCode);
@@ -46,7 +48,13 @@ const customParamsForm = reactive<Partial<ProtocolParamInfo>>({
   writeFuncCode: undefined,
   readFuncCode: undefined,
   addrLength: undefined,
+  addrNumber: '',
   registerAddr: '',
+  registerType: undefined,
+  registerTypeCode: undefined,
+  wordLength: undefined,
+  wordLengthCode: undefined,
+  quantity: undefined,
   coefficient: undefined,
   isHighFreqParam: undefined,
   isHighFreqParamCode: undefined,
@@ -92,6 +100,20 @@ const rules = computed<FormRules<ProtocolParamInfo>>(() => {
         trigger: 'blur',
       },
     ],
+    addrNumber: [
+      {
+        required: true,
+        message: t('common.plzEnter', { name: t('setupProtocol.protocolParamFields.addrNumber') }),
+        trigger: 'blur',
+      },
+    ],
+    registerType: [
+      {
+        required: true,
+        message: t('common.plzSelect', { name: t('setupProtocol.protocolParamFields.registerType') }),
+        trigger: 'blur',
+      },
+    ],
     registerAddr: [
       {
         required: true,
@@ -99,12 +121,25 @@ const rules = computed<FormRules<ProtocolParamInfo>>(() => {
         trigger: 'blur',
       },
     ],
+    wordLength: [
+      {
+        required: true,
+        message: t('common.plzSelect', { name: t('setupProtocol.protocolParamFields.wordLength') }),
+        trigger: 'blur',
+      },
+    ],
   };
 });
 
+const isModbusProtocol = computed(() => {
+  return props.isModbusRtuProtocol || props.isModbusTcpProtocol;
+});
+
 onMounted(() => {
   handleRequest(async () => {
     await getReadWriteTypes();
+    await getRegisterTypes();
+    await getWordLength();
     await getParsingTypes();
     await getWriteFuncCode();
     await getReadFuncCode();
@@ -116,6 +151,14 @@ const handleReadWriteTypeChange = (_value: SelectValue, option: DefaultOptionTyp
   customParamsForm.readWriteTypeCode = option.key;
 };
 
+const handleRegisterTypeChange = (_value: SelectValue, option: DefaultOptionType) => {
+  customParamsForm.registerTypeCode = option.key;
+};
+
+const handleWordLengthChange = (_value: SelectValue, option: DefaultOptionType) => {
+  customParamsForm.wordLengthCode = option.key;
+};
+
 const handleParsingTypeChange = (_value: SelectValue, option: DefaultOptionType) => {
   customParamsForm.parsingTypeCode = option.key;
 };
@@ -227,7 +270,7 @@ defineExpose({
             </ASelect>
           </AFormItem>
         </ACol>
-        <ACol :span="8">
+        <ACol v-if="isModbusProtocol" :span="8">
           <AFormItem :label="$t('setupProtocol.protocolParamFields.writeFunctionCode')" name="writeFuncCode">
             <ASelect
               v-model:value="customParamsForm.writeFuncCode"
@@ -240,7 +283,7 @@ defineExpose({
             </ASelect>
           </AFormItem>
         </ACol>
-        <ACol :span="8">
+        <ACol v-if="isModbusProtocol" :span="8">
           <AFormItem :label="$t('setupProtocol.protocolParamFields.readFunctionCode')" name="readFuncCode">
             <ASelect
               v-model:value="customParamsForm.readFuncCode"
@@ -253,7 +296,7 @@ defineExpose({
             </ASelect>
           </AFormItem>
         </ACol>
-        <ACol :span="8">
+        <ACol v-if="isModbusProtocol" :span="8">
           <AFormItem :label="$t('setupProtocol.protocolParamFields.addressLength')" name="addrLength">
             <AInputNumber
               v-model:value="customParamsForm.addrLength"
@@ -264,6 +307,29 @@ defineExpose({
             />
           </AFormItem>
         </ACol>
+        <ACol v-if="isS7Protocol" :span="8">
+          <AFormItem :label="$t('setupProtocol.protocolParamFields.addrNumber')" name="addrNumber">
+            <AInput
+              v-model:value="customParamsForm.addrNumber"
+              class="protocol-input"
+              :placeholder="$t('common.plzEnter')"
+            />
+          </AFormItem>
+        </ACol>
+        <ACol v-if="isS7Protocol" :span="8">
+          <AFormItem :label="$t('setupProtocol.protocolParamFields.registerType')" name="registerType">
+            <ASelect
+              v-model:value="customParamsForm.registerType"
+              class="protocol-input"
+              :placeholder="$t('common.plzSelect')"
+              @change="handleRegisterTypeChange"
+            >
+              <ASelectOption v-for="item in registerTypes" :key="item.dictEngValue" :value="item.dictValue">
+                {{ item.dictValue }}
+              </ASelectOption>
+            </ASelect>
+          </AFormItem>
+        </ACol>
         <ACol :span="8">
           <AFormItem :label="$t('setupProtocol.protocolParamFields.registerAddress')" name="registerAddr">
             <AInput
@@ -273,6 +339,31 @@ defineExpose({
             />
           </AFormItem>
         </ACol>
+        <ACol v-if="isS7Protocol" :span="8">
+          <AFormItem :label="$t('setupProtocol.protocolParamFields.wordLength')" name="wordLength">
+            <ASelect
+              v-model:value="customParamsForm.wordLength"
+              class="protocol-input"
+              :placeholder="$t('common.plzSelect')"
+              @change="handleWordLengthChange"
+            >
+              <ASelectOption v-for="item in wordLength" :key="item.dictEngValue" :value="item.dictValue">
+                {{ item.dictValue }}
+              </ASelectOption>
+            </ASelect>
+          </AFormItem>
+        </ACol>
+        <ACol v-if="isS7Protocol" :span="8">
+          <AFormItem :label="$t('setupProtocol.protocolParamFields.quantity')" name="quantity">
+            <AInputNumber
+              v-model:value="customParamsForm.quantity"
+              class="protocol-input"
+              :placeholder="$t('common.plzEnter')"
+              :min="0"
+              :precision="0"
+            />
+          </AFormItem>
+        </ACol>
         <ACol :span="8">
           <AFormItem :label="$t('setupProtocol.protocolParamFields.coefficient')" name="coefficient">
             <AInputNumber

+ 1 - 1
src/views/setup-protocol/ProtocolContent.vue

@@ -533,7 +533,7 @@ defineExpose({
     <CustomParams
       ref="customParams"
       :protocol-id="info.id"
-      :is-modbus-rtu-protocol="isModbusTcpProtocol"
+      :is-modbus-rtu-protocol="isModbusRtuProtocol"
       :is-modbus-tcp-protocol="isModbusTcpProtocol"
       :is-s7-protocol="isS7Protocol"
       @refresh-list="getCurrentProtocolParams"