fix: bug#11200、11201、11206、11207

This commit is contained in:
jackhoo_98 2023-03-29 21:49:50 +08:00
parent a1affe20a8
commit a422769c2f
2 changed files with 63 additions and 35 deletions

View File

@ -81,11 +81,9 @@
@blur="changeQuantity" @blur="changeQuantity"
/> />
</j-form-item> </j-form-item>
<j-form-item <j-form-item
v-if=" v-if="formData.configuration.function === 'HoldingRegisters'"
formData.configuration.function === 'HoldingRegisters' ||
formData.configuration.function === 'InputRegisters'
"
label="数据类型" label="数据类型"
:name="['configuration', 'codec', 'provider']" :name="['configuration', 'codec', 'provider']"
:rules="[ :rules="[
@ -124,15 +122,23 @@
" "
/> />
</j-form-item> </j-form-item>
<j-form-item label="访问类型" name="accessModes"> <j-form-item
v-if="formData.configuration.function"
label="访问类型"
name="accessModes"
>
<j-card-select <j-card-select
multiple multiple
:showImage="false" :showImage="false"
v-model:value="formData.accessModes" v-model:value="formData.accessModes"
:options="[ :options="
{ label: '读', value: 'read' }, formData.configuration.function === 'InputRegisters'
{ label: '写', value: 'write' }, ? [{ label: '读', value: 'read' }]
]" : [
{ label: '读', value: 'read' },
{ label: '写', value: 'write' },
]
"
:column="2" :column="2"
/> />
</j-form-item> </j-form-item>
@ -144,7 +150,10 @@
" "
> >
<span style="margin-right: 10px">非标准协议写入配置</span> <span style="margin-right: 10px">非标准协议写入配置</span>
<j-switch v-model:checked="formData.nspwc" /> <j-switch
@change="changeNspwc"
v-model:checked="formData.nspwc"
/>
</j-form-item> </j-form-item>
<j-form-item <j-form-item
v-if=" v-if="
@ -262,7 +271,6 @@ 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.pointKey;
console.log(22, props.data);
const InitAddress = { const InitAddress = {
Coils: 1, Coils: 1,
@ -329,9 +337,21 @@ const handleCancel = () => {
}; };
const changeQuantity = () => { const changeQuantity = () => {
if (formData.value.configuration.function === 'HoldingRegisters') { const { configuration, nspwc } = formData.value;
if (configuration.function === 'HoldingRegisters') {
formRef.value?.validate(); formRef.value?.validate();
} }
if (nspwc) {
configuration.parameter.byteCount =
Number(configuration.parameter.quantity) * 2;
}
};
const changeNspwc = (value: boolean) => {
const { configuration } = formData.value;
if (value) {
configuration.parameter.byteCount =
Number(configuration.parameter.quantity || 0) * 2;
}
}; };
const changeWriteByteCount = (value: Array<string>) => { const changeWriteByteCount = (value: Array<string>) => {
formData.value.configuration.parameter.writeByteCount = value[0]; formData.value.configuration.parameter.writeByteCount = value[0];
@ -357,12 +377,13 @@ const checkPointKey = (_rule: Rule, value: string): Promise<any> =>
new Promise(async (resolve, reject) => { new Promise(async (resolve, reject) => {
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('');
const res: any = await _validateField(collectorId, { const res: any = await _validateField(collectorId, {
pointKey: value, pointKey: value,
}); });
return res.result?.passed ? resolve('') : reject(res.result.reason); return res.result?.passed ? resolve('') : reject(res.result.reason);
} else { } else {
return reject(''); return reject('请输入地址');
} }
}); });
@ -392,13 +413,6 @@ const setProviderList = (value: string | undefined) => {
); );
}; };
watch(
() => formData.value.configuration.parameter.quantity,
(value) => {
formData.value.configuration.parameter.byteCount = Number(value) * 2;
},
{ immediate: true, deep: true },
);
watch( watch(
() => formData.value.configuration.function, () => formData.value.configuration.function,
(value) => { (value) => {

View File

@ -506,7 +506,7 @@ const clickRedo = async (data: any) => {
const getQuantity = (item: Partial<Record<string, any>>) => { const getQuantity = (item: Partial<Record<string, any>>) => {
const { quantity } = item.configuration?.parameter || ''; const { quantity } = item.configuration?.parameter || '';
return !!quantity ? quantity + '(读取寄存器)' : ''; return !!quantity ? quantity + '(寄存器数量)' : '';
}; };
const getAddress = (item: Partial<Record<string, any>>) => { const getAddress = (item: Partial<Record<string, any>>) => {
const { address } = item.configuration?.parameter || ''; const { address } = item.configuration?.parameter || '';
@ -571,21 +571,35 @@ const handleClick = (dt: any) => {
} }
}; };
//
let timer: any = null;
function throttle(fn: any, delay = 1000) {
if (timer == null) {
timer = setTimeout(() => {
fn();
clearTimeout(timer);
timer = null;
}, delay);
}
}
const subscribeProperty = (value: any) => { const subscribeProperty = (value: any) => {
// const list = value.map((item: any) => item.id); const list = value.map((item: any) => item.id);
// const id = `collector-${props.data?.channelId || 'channel'}-${ const id = `collector-${props.data?.channelId || 'channel'}-${
// props.data?.id || 'point' props.data?.id || 'point'
// }-data-${list.join('-')}`; }-data-${list.join('-')}`;
// const topic = `/collector/${props.data?.channelId || '*'}/${ const topic = `/collector/${props.data?.channelId || '*'}/${
// props.data?.id || '*' props.data?.id || '*'
// }/data`; }/data`;
// subRef.value = getWebSocket(id, topic, { subRef.value = getWebSocket(id, topic, {
// pointId: list.join(','), pointId: list.join(','),
// }) })
// ?.pipe(map((res: any) => res.payload)) ?.pipe(map((res: any) => res.payload))
// .subscribe((payload: any) => { .subscribe((payload: any) => {
// propertyValue.value.set(payload.pointId, payload); //
// }); throttle(() => {
propertyValue.value.set(payload.pointId, payload);
});
});
}; };
const onCheckAllChange = (e: any) => { const onCheckAllChange = (e: any) => {