feat: 当下游设备不存在时自动解除关联
- 获取下游设备时,如果发现下游设备不存在,将静默解除关联
This commit is contained in:
@@ -144,9 +144,24 @@ const getLowerDeviceByCircuitIndex = (circuitIndex: number) => {
|
|||||||
const stationDevices = lineDevices.value[stationCode];
|
const stationDevices = lineDevices.value[stationCode];
|
||||||
if (!stationDevices) return null;
|
if (!stationDevices) return null;
|
||||||
const devices = stationDevices[deviceType];
|
const devices = stationDevices[deviceType];
|
||||||
const device = devices.find((device) => device.id === deviceDbId);
|
const lowerDevice = devices.find((device) => device.id === deviceDbId);
|
||||||
if (!device) return null;
|
if (!lowerDevice) {
|
||||||
return device;
|
// 下游设备不存在时解除关联
|
||||||
|
const modifiedUpperDevice = cloneDeep(ndmDevice.value);
|
||||||
|
const modifiedUpperLinkDescription = cloneDeep(upperDeviceLinkDescription.value);
|
||||||
|
delete modifiedUpperLinkDescription.downstream?.[circuitIndex];
|
||||||
|
modifiedUpperDevice.linkDescription = JSON.stringify(modifiedUpperLinkDescription);
|
||||||
|
// 不需要等待异步
|
||||||
|
const stationCode = station.value.code;
|
||||||
|
updateDeviceApi(modifiedUpperDevice, { stationCode }).then(() => {
|
||||||
|
detailDeviceApi(modifiedUpperDevice, { stationCode }).then((upperDevice) => {
|
||||||
|
if (!upperDevice) return;
|
||||||
|
deviceStore.patchDevice(stationCode, { ...upperDevice });
|
||||||
|
});
|
||||||
|
});
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return lowerDevice;
|
||||||
};
|
};
|
||||||
|
|
||||||
// 获取从父组件注入的selectDevice函数
|
// 获取从父组件注入的selectDevice函数
|
||||||
|
|||||||
@@ -84,19 +84,33 @@ const upperDeviceLinkDescription = computed(() => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const getLowerDeviceByPort = (port: NdmSwitchPortInfo) => {
|
const getLowerDeviceByPort = (port: NdmSwitchPortInfo) => {
|
||||||
const portName = port.portName;
|
|
||||||
if (!upperDeviceLinkDescription.value) return null;
|
if (!upperDeviceLinkDescription.value) return null;
|
||||||
const downstream = upperDeviceLinkDescription.value.downstream;
|
const downstream = upperDeviceLinkDescription.value.downstream;
|
||||||
if (!downstream) return null;
|
if (!downstream) return null;
|
||||||
const deviceStoreIndex = downstream[portName];
|
const deviceStoreIndex = downstream[port.portName];
|
||||||
if (!deviceStoreIndex) return null;
|
if (!deviceStoreIndex) return null;
|
||||||
const { stationCode, deviceType, deviceDbId } = deviceStoreIndex;
|
const { stationCode, deviceType, deviceDbId } = deviceStoreIndex;
|
||||||
const stationDevices = lineDevices.value[stationCode];
|
const stationDevices = lineDevices.value[stationCode];
|
||||||
if (!stationDevices) return null;
|
if (!stationDevices) return null;
|
||||||
const devices = stationDevices[deviceType];
|
const devices = stationDevices[deviceType];
|
||||||
const device = devices.find((device) => device.id === deviceDbId);
|
const lowerDevice = devices.find((device) => device.id === deviceDbId);
|
||||||
if (!device) return null;
|
if (!lowerDevice) {
|
||||||
return device;
|
// 下游设备不存在时解除关联
|
||||||
|
const modifiedUpperDevice = cloneDeep(ndmDevice.value);
|
||||||
|
const modifiedUpperLinkDescription = cloneDeep(upperDeviceLinkDescription.value);
|
||||||
|
delete modifiedUpperLinkDescription.downstream?.[port.portName];
|
||||||
|
modifiedUpperDevice.linkDescription = JSON.stringify(modifiedUpperLinkDescription);
|
||||||
|
// 不需要等待异步
|
||||||
|
const stationCode = station.value.code;
|
||||||
|
updateDeviceApi(modifiedUpperDevice, { stationCode }).then(() => {
|
||||||
|
detailDeviceApi(modifiedUpperDevice, { stationCode }).then((upperDevice) => {
|
||||||
|
if (!upperDevice) return;
|
||||||
|
deviceStore.patchDevice(stationCode, { ...upperDevice });
|
||||||
|
});
|
||||||
|
});
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return lowerDevice;
|
||||||
};
|
};
|
||||||
|
|
||||||
// 获取从父组件注入的selectDevice函数
|
// 获取从父组件注入的selectDevice函数
|
||||||
|
|||||||
Reference in New Issue
Block a user