feat: 添加优化的库位数据变化检查和边框颜色更新功能

This commit is contained in:
xudan 2025-09-05 11:16:16 +08:00
parent d105719a07
commit 32a8e04635

View File

@ -274,6 +274,82 @@ export class StorageLocationService {
}
}
/**
*
* @param changedPointIds ID列表
*/
private updatePointBorderColorsOptimized(changedPointIds: Set<string>) {
for (const pointId of changedPointIds) {
this.updatePointBorderColor(pointId);
}
}
/**
*
* @param newLocationsByPointId
* @returns
*/
private hasStorageLocationDataChanged(newLocationsByPointId: Map<string, StorageLocationInfo[]>): boolean {
const currentData = this.storageLocations.value;
// 如果数据量不同,肯定有变化
if (currentData.size !== newLocationsByPointId.size) {
return true;
}
// 检查每个点的数据是否有变化
for (const [pointId, newLocations] of newLocationsByPointId.entries()) {
const currentLocations = currentData.get(pointId);
if (!currentLocations || currentLocations.length !== newLocations.length) {
return true;
}
// 检查每个库位的状态是否有变化
for (const newLocation of newLocations) {
const currentLocation = currentLocations.find(loc => loc.id === newLocation.id);
if (!currentLocation ||
currentLocation.is_occupied !== newLocation.is_occupied ||
currentLocation.is_locked !== newLocation.is_locked) {
return true;
}
}
}
return false;
}
/**
* ID列表
* @param newLocationsByPointId
* @returns ID列表
*/
private getChangedPointIds(newLocationsByPointId: Map<string, StorageLocationInfo[]>): Set<string> {
const changedPointIds = new Set<string>();
const currentData = this.storageLocations.value;
// 检查每个点的数据是否有变化
for (const [pointId, newLocations] of newLocationsByPointId.entries()) {
const currentLocations = currentData.get(pointId);
if (!currentLocations || currentLocations.length !== newLocations.length) {
changedPointIds.add(pointId);
continue;
}
// 检查每个库位的状态是否有变化
for (const newLocation of newLocations) {
const currentLocation = currentLocations.find(loc => loc.id === newLocation.id);
if (!currentLocation ||
currentLocation.is_occupied !== newLocation.is_occupied ||
currentLocation.is_locked !== newLocation.is_locked) {
changedPointIds.add(pointId);
break;
}
}
}
return changedPointIds;
}
/**
*
* @param message
@ -299,6 +375,12 @@ export class StorageLocationService {
}
});
// 检查数据是否有变化,避免不必要的更新
const changedPointIds = this.getChangedPointIds(locationsByPointId);
if (changedPointIds.size === 0) {
return; // 数据没有变化,跳过更新
}
this.storageLocations.value = locationsByPointId;
// 同步维护 storageStateMap
@ -307,16 +389,12 @@ export class StorageLocationService {
const inner = new Map<string, StorageState>();
list.forEach((loc) => {
inner.set(loc.layer_name, { occupied: loc.is_occupied, locked: loc.is_locked });
// console.log(`更新库位状态映射: ${pointId} - ${loc.layer_name}`, {
// occupied: loc.is_occupied,
// locked: loc.is_locked
// });
});
storageStateMap.set(pointId, inner);
}
// 更新动作点的边框颜色
this.updatePointBorderColors();
// 只更新有变化的点的边框颜色
this.updatePointBorderColorsOptimized(changedPointIds);
// 重新创建所有动作点的库位pen对象以反映最新状态
this.createAll();