fix: 添加防止设备自关联的校验

This commit is contained in:
yangsy
2026-01-04 10:30:30 +08:00
parent 286449b831
commit c259eabc22
2 changed files with 6 additions and 2 deletions

View File

@@ -68,7 +68,9 @@ const { mutate: linkPortToDevice, isPending: linking } = useMutation({
const lowerDeviceDbId = lowerDevice.value?.id;
if (!lowerDeviceDbId) throw new Error('该设备没有ID');
// 0. 检查上游设备的linkDescription的downstream字段是否存在某个端口已经关联下游设备
// 0. 检查是否会导致循环关联,
if (upperDeviceDbId === lowerDeviceDbId) throw new Error('不能关联到自身');
// 以及检查上游设备的linkDescription的downstream字段是否存在某个端口已经关联下游设备
const duplicated = Object.entries(upperDeviceLinkDescription.value?.downstream ?? {}).find(([, deviceStoreIndex]) => {
return deviceStoreIndex.deviceDbId === lowerDeviceDbId;
});

View File

@@ -78,7 +78,9 @@ const { mutate: linkPortToDevice, isPending: linking } = useMutation({
const lowerDeviceDbId = lowerDevice.value?.id;
if (!lowerDeviceDbId) throw new Error('该设备没有ID');
// 0. 检查上游设备的linkDescription的downstream字段是否存在某个端口已经关联下游设备
// 0. 检查是否会导致循环关联,
if (upperDeviceDbId === lowerDeviceDbId) throw new Error('不能关联到自身');
// 以及检查上游设备的linkDescription的downstream字段是否存在某个端口已经关联下游设备
const duplicated = Object.entries(upperDeviceLinkDescription.value?.downstream ?? {}).find(([, deviceStoreIndex]) => {
return deviceStoreIndex.deviceDbId === lowerDeviceDbId;
});