feat: fix:15071

This commit is contained in:
XieYongHong 2023-06-07 17:46:12 +08:00
parent 5efd20a863
commit 7a8340d3e8
1 changed files with 34 additions and 13 deletions

View File

@ -23,7 +23,12 @@
<j-form-item <j-form-item
label="功能码" label="功能码"
:name="['configuration', 'function']" :name="['configuration', 'function']"
:rules="ModBusRules.function" :rules="[
...ModBusRules.function,
{
validator: checkFunction
}
]"
> >
<j-select <j-select
style="width: 100%" style="width: 100%"
@ -43,7 +48,8 @@
</j-form-item> </j-form-item>
<j-form-item <j-form-item
label="地址" label="地址"
:name="['pointKey']" name="address"
:validateFirst="true"
:rules="[ :rules="[
...ModBusRules.pointKey, ...ModBusRules.pointKey,
{ {
@ -55,17 +61,14 @@
<j-input-number <j-input-number
style="width: 100%" style="width: 100%"
placeholder="请输入地址" placeholder="请输入地址"
v-model:value="formData.pointKey" v-model:value="formData.address"
:min="0" :min="0"
:max="999999999" :max="999999999"
:precision="0" :precision="0"
/> />
</j-form-item> </j-form-item>
<p style="color: #616161" v-if="formData.configuration.function"> <p style="color: #616161" v-if="formData.configuration.function">
PLC地址: {{ PLC地址: {{ plc }}
InitAddress[formData.configuration.function] +
Number(formData.pointKey) || 0
}}
</p> </p>
<j-form-item <j-form-item
label="寄存器数量" label="寄存器数量"
@ -287,7 +290,7 @@ const formRef = ref<FormInstance>();
const id = props.data.id; const id = props.data.id;
const collectorId = props.data.collectorId; const collectorId = props.data.collectorId;
const provider = props.data.provider; const provider = props.data.provider;
const oldPointKey = props.data.pointKey; const oldPointKey = props.data?.configuration?.parameter?.address;
const InitAddress = { const InitAddress = {
Coils: 1, Coils: 1,
@ -305,7 +308,7 @@ const formData = ref({
quantity: 1, quantity: 1,
writeByteCount: '', writeByteCount: '',
byteCount: 2, byteCount: 2,
address: '', address: undefined,
}, },
codec: { codec: {
provider: undefined, provider: undefined,
@ -315,6 +318,7 @@ const formData = ref({
}, },
}, },
}, },
address: undefined,
pointKey: undefined, pointKey: undefined,
accessModes: [], accessModes: [],
nspwc: false, nspwc: false,
@ -322,6 +326,11 @@ const formData = ref({
description: '', description: '',
}); });
const plc = computed(() =>{
const configuration = formData.value.configuration
return configuration.function !== undefined && formData.value.address !== undefined ? InitAddress[configuration.function] + Number(formData.value.address) : 0
})
const handleOk = async () => { const handleOk = async () => {
const data = await formRef.value?.validate(); const data = await formRef.value?.validate();
delete data?.nspwc; delete data?.nspwc;
@ -337,15 +346,16 @@ const handleOk = async () => {
provider, provider,
collectorId, collectorId,
interval, interval,
pointKey: plc.value,
}; };
// addressreact使
params.configuration.parameter = { params.configuration.parameter = {
...params.configuration.parameter, ...params.configuration.parameter,
address: data?.pointKey, address: data?.address,
}; };
loading.value = true; loading.value = true;
const response = !id const response = !id
? await savePointBatch(params).catch(() => {}) ? await savePointBatch(params).catch(() => {})
: await updatePoint(id, { ...props.data, ...params }).catch(() => {}); : await updatePoint(id, { ...props.data, ...params }).catch(() => {});
@ -394,13 +404,23 @@ const checkProvider = (_rule: Rule, value: string): Promise<any> =>
} }
}); });
const checkFunction = (_: any, value: string) => {
if (value) {
formRef.value!.validateFields('address')
}
return Promise.resolve('');
}
const checkPointKey = (_rule: Rule, value: string): Promise<any> => const checkPointKey = (_rule: Rule, value: string): Promise<any> =>
new Promise(async (resolve, reject) => { new Promise(async (resolve, reject) => {
console.log(value, formData.value!.configuration?.function)
if (value || Number(value) === 0) { if (value || Number(value) === 0) {
if (Number(oldPointKey) === Number(value)) return resolve(''); if (Number(oldPointKey) === Number(value)) return resolve('');
if (typeof value === 'object') return resolve(''); if (typeof value === 'object') return resolve('');
if (!formData.value!.configuration?.function) return resolve('');
const plc = InitAddress[formData.value!.configuration?.function] + Number(value)
const res: any = await _validateField(collectorId, { const res: any = await _validateField(collectorId, {
pointKey: value, pointKey: plc,
}); });
return res.result?.passed ? resolve('') : reject(res.result.reason); return res.result?.passed ? resolve('') : reject(res.result.reason);
} else { } else {
@ -443,6 +463,7 @@ watch(
const { writeByteCount, byteCount } = const { writeByteCount, byteCount } =
_value.configuration.parameter; _value.configuration.parameter;
formData.value = _value; formData.value = _value;
formData.value.address = _value.configuration?.parameter?.address
if (!!_value.accessModes[0]?.value) { if (!!_value.accessModes[0]?.value) {
formData.value.accessModes = value.accessModes.map( formData.value.accessModes = value.accessModes.map(
(i: any) => i.value, (i: any) => i.value,