feat: 优化库位状态更新逻辑,支持增量刷新和状态比较,提升性能
This commit is contained in:
parent
7708bcfaa1
commit
b06ce3ebd7
@ -396,8 +396,21 @@ export class StorageLocationService {
|
|||||||
// 只更新有变化的点的边框颜色
|
// 只更新有变化的点的边框颜色
|
||||||
this.updatePointBorderColorsOptimized(changedPointIds);
|
this.updatePointBorderColorsOptimized(changedPointIds);
|
||||||
|
|
||||||
// 重新创建所有动作点的库位pen对象以反映最新状态
|
// 仅对发生变化的点位做增量刷新:存在则批量更新状态,不存在则创建
|
||||||
this.createAll();
|
for (const pointId of changedPointIds) {
|
||||||
|
const pointPen = this.editor?.getPenById(pointId);
|
||||||
|
const storageNames = pointPen?.point?.associatedStorageLocations;
|
||||||
|
if (pointPen && Array.isArray(storageNames) && storageNames.length > 0) {
|
||||||
|
const existing = this.getStorageLocationPens(pointId);
|
||||||
|
if (existing.length > 0) {
|
||||||
|
// 已有库位图元:按名称列表从 storageStateMap 取状态并批量更新
|
||||||
|
this.update(pointId, storageNames);
|
||||||
|
} else {
|
||||||
|
// 不存在库位图元:为该点创建一次
|
||||||
|
this.create(pointId, storageNames);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 批量更新后触发一次重绘
|
// 批量更新后触发一次重绘
|
||||||
this.scheduleRender();
|
this.scheduleRender();
|
||||||
@ -633,12 +646,27 @@ export class StorageLocationService {
|
|||||||
state: { occupied?: boolean; locked?: boolean }
|
state: { occupied?: boolean; locked?: boolean }
|
||||||
): void {
|
): void {
|
||||||
if (!this.editor) return;
|
if (!this.editor) return;
|
||||||
|
// 计算新旧状态,用于比较与更新
|
||||||
|
const prevOccupied = !!storageLocation.occupied;
|
||||||
|
const prevLocked = !!storageLocation.locked;
|
||||||
|
const nextOccupied = state.occupied ?? prevOccupied;
|
||||||
|
const nextLocked = state.locked ?? prevLocked;
|
||||||
|
|
||||||
const updatedState = { ...storageLocation, ...state };
|
// 若状态无变化则跳过
|
||||||
this.editor.updatePen(penId, {
|
if (prevOccupied === nextOccupied && prevLocked === nextLocked) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const updatedState = { ...storageLocation, occupied: nextOccupied, locked: nextLocked };
|
||||||
|
const nextBg = this.getColorByOccupiedState(updatedState.occupied || false);
|
||||||
|
this.editor.updatePen(
|
||||||
|
penId,
|
||||||
|
{
|
||||||
storageLocation: updatedState,
|
storageLocation: updatedState,
|
||||||
background: this.getColorByOccupiedState(updatedState.occupied || false),
|
background: nextBg,
|
||||||
}, false);
|
},
|
||||||
|
false,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user