|
@@ -6,7 +6,7 @@ import { useDictData } from '@/hooks/dict-data';
|
|
import { useRequest } from '@/hooks/request';
|
|
import { useRequest } from '@/hooks/request';
|
|
import { useViewVisible } from '@/hooks/view-visible';
|
|
import { useViewVisible } from '@/hooks/view-visible';
|
|
import { t } from '@/i18n';
|
|
import { t } from '@/i18n';
|
|
-import { addProtocolParam } from '@/api';
|
|
|
|
|
|
+import { addProtocolParam, updateProtocolParam } from '@/api';
|
|
import { DictCode } from '@/constants';
|
|
import { DictCode } from '@/constants';
|
|
|
|
|
|
import type { FormInstance } from 'ant-design-vue';
|
|
import type { FormInstance } from 'ant-design-vue';
|
|
@@ -15,6 +15,7 @@ import type { FormRules, ProtocolParamInfo } from '@/types';
|
|
|
|
|
|
interface Props {
|
|
interface Props {
|
|
protocolId?: number;
|
|
protocolId?: number;
|
|
|
|
+ paramId?: number;
|
|
isModbusRtuProtocol?: boolean;
|
|
isModbusRtuProtocol?: boolean;
|
|
isModbusTcpProtocol?: boolean;
|
|
isModbusTcpProtocol?: boolean;
|
|
isS7Protocol?: boolean;
|
|
isS7Protocol?: boolean;
|
|
@@ -135,6 +136,16 @@ const isModbusProtocol = computed(() => {
|
|
return props.isModbusRtuProtocol || props.isModbusTcpProtocol;
|
|
return props.isModbusRtuProtocol || props.isModbusTcpProtocol;
|
|
});
|
|
});
|
|
|
|
|
|
|
|
+const isAddParams = ref(true);
|
|
|
|
+
|
|
|
|
+const modalTitle = computed(() => {
|
|
|
|
+ return isAddParams.value ? t('setupProtocol.addCustomParams') : t('setupProtocol.updateCustomParams');
|
|
|
|
+});
|
|
|
|
+
|
|
|
|
+const setIsAddParams = (isAdd: boolean) => {
|
|
|
|
+ isAddParams.value = isAdd;
|
|
|
|
+};
|
|
|
|
+
|
|
onMounted(() => {
|
|
onMounted(() => {
|
|
handleRequest(async () => {
|
|
handleRequest(async () => {
|
|
await getReadWriteTypes();
|
|
await getReadWriteTypes();
|
|
@@ -174,12 +185,22 @@ const handleOk = () => {
|
|
?.validate()
|
|
?.validate()
|
|
.then(() => {
|
|
.then(() => {
|
|
handleRequest(async () => {
|
|
handleRequest(async () => {
|
|
- await addProtocolParam({
|
|
|
|
- baseInfoId: props.protocolId,
|
|
|
|
- ...customParamsForm,
|
|
|
|
- });
|
|
|
|
|
|
+ if (isAddParams.value) {
|
|
|
|
+ await addProtocolParam({
|
|
|
|
+ baseInfoId: props.protocolId,
|
|
|
|
+ ...customParamsForm,
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ message.success(t('setupProtocol.addCustomParamsSuccessful'));
|
|
|
|
+ } else {
|
|
|
|
+ await updateProtocolParam({
|
|
|
|
+ ...customParamsForm,
|
|
|
|
+ id: props.paramId,
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ message.success(t('setupProtocol.updateCustomParamsSuccessful'));
|
|
|
|
+ }
|
|
|
|
|
|
- message.success(t('setupProtocol.addCustomParamsSuccessful'));
|
|
|
|
hideView();
|
|
hideView();
|
|
emit('refreshList');
|
|
emit('refreshList');
|
|
});
|
|
});
|
|
@@ -196,18 +217,12 @@ const handleClose = () => {
|
|
defineExpose({
|
|
defineExpose({
|
|
showView,
|
|
showView,
|
|
hideView,
|
|
hideView,
|
|
|
|
+ setIsAddParams,
|
|
});
|
|
});
|
|
</script>
|
|
</script>
|
|
|
|
|
|
<template>
|
|
<template>
|
|
- <AModal
|
|
|
|
- v-model:open="visible"
|
|
|
|
- :title="$t('setupProtocol.addCustomParams')"
|
|
|
|
- :width="920"
|
|
|
|
- centered
|
|
|
|
- :after-close="handleClose"
|
|
|
|
- @ok="handleOk"
|
|
|
|
- >
|
|
|
|
|
|
+ <AModal v-model:open="visible" :title="modalTitle" :width="920" centered :after-close="handleClose" @ok="handleOk">
|
|
<AForm ref="formRef" :model="customParamsForm" :rules="rules" layout="vertical">
|
|
<AForm ref="formRef" :model="customParamsForm" :rules="rules" layout="vertical">
|
|
<ARow :gutter="30">
|
|
<ARow :gutter="30">
|
|
<ACol :span="8">
|
|
<ACol :span="8">
|