From b06ce3ebd7b4d60fcbaab9b100cbc813812e0b42 Mon Sep 17 00:00:00 2001 From: xudan Date: Fri, 5 Sep 2025 16:01:02 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E5=BA=93=E4=BD=8D?= =?UTF-8?q?=E7=8A=B6=E6=80=81=E6=9B=B4=E6=96=B0=E9=80=BB=E8=BE=91=EF=BC=8C?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E5=A2=9E=E9=87=8F=E5=88=B7=E6=96=B0=E5=92=8C?= =?UTF-8?q?=E7=8A=B6=E6=80=81=E6=AF=94=E8=BE=83=EF=BC=8C=E6=8F=90=E5=8D=87?= =?UTF-8?q?=E6=80=A7=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/services/storage-location.service.ts | 42 ++++++++++++++++++++---- 1 file changed, 35 insertions(+), 7 deletions(-) diff --git a/src/services/storage-location.service.ts b/src/services/storage-location.service.ts index a13757a..4d946e2 100644 --- a/src/services/storage-location.service.ts +++ b/src/services/storage-location.service.ts @@ -396,8 +396,21 @@ export class StorageLocationService { // 只更新有变化的点的边框颜色 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(); @@ -633,12 +646,27 @@ export class StorageLocationService { state: { occupied?: boolean; locked?: boolean } ): void { 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, { - storageLocation: updatedState, - background: this.getColorByOccupiedState(updatedState.occupied || false), - }, false); + // 若状态无变化则跳过 + 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, + background: nextBg, + }, + false, + ); } /**