feat: 更新库位管理逻辑,支持延迟渲染以防止点位失焦,并优化库位pen对象创建逻辑

This commit is contained in:
xudan 2025-09-09 15:16:31 +08:00
parent 1be4280495
commit 3223e8e16f
4 changed files with 61 additions and 13 deletions

View File

@ -4,5 +4,5 @@ ENV_WEBSOCKET_BASE=/ws
ENV_STORAGE_WEBSOCKET_BASE=/vwedWs
# 开发环境token配置 - 可以手动设置或从另一个项目获取后填入
ENV_DEV_TOKEN=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE3NTc0NDc3NzMsInVzZXJuYW1lIjoiYWRtaW4ifQ.kCwSuHfYWZS5uVZLL912gTT2OrCEO4dyHJAjkDz7hE0
ENV_DEV_TOKEN=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE3NTc1Mjc0NTksInVzZXJuYW1lIjoiYWRtaW4ifQ.MionV2RtdoIm085NYLRQxCNHxmgB9HGCvYXlsAERkG4
ENV_DEV_TENANT_ID=1000

View File

@ -72,6 +72,9 @@ function onAddLocation() {
const p = point.value!;
if (!p.associatedStorageLocations) p.associatedStorageLocations = [];
// ID
const currentPointId = props.id!;
// "AP1" -> "AP1"
const pointName = pen.value?.label || '';
@ -105,12 +108,21 @@ function onAddLocation() {
p.associatedStorageLocations.push(defaultName);
editor.value.updatePen(props.id!, { point: { ...p } }, false);
// pen
editor.value.createStorageLocationPens(props.id!, p.associatedStorageLocations);
// pen
editor.value.createStorageLocationPens(props.id!, p.associatedStorageLocations, false);
//
requestAnimationFrame(() => {
editor.value.render();
//
editor.value.active(currentPointId);
});
}
function onRemoveLocation(i: number) {
const p = point.value!;
if (p.associatedStorageLocations) {
// ID
const currentPointId = props.id!;
const removedLocationName = p.associatedStorageLocations[i];
const pointName = pen.value?.label || pen.value?.id || '';
@ -131,13 +143,20 @@ function onRemoveLocation(i: number) {
p.associatedStorageLocations.splice(i, 1);
editor.value.updatePen(props.id!, { point: { ...p } }, false);
// pen
editor.value.createStorageLocationPens(props.id!, p.associatedStorageLocations);
// pen
editor.value.createStorageLocationPens(props.id!, p.associatedStorageLocations, false);
// binLocationList
if (pointName && removedLocationName) {
editor.value.removeBinLocation(pointName, removedLocationName);
}
//
requestAnimationFrame(() => {
editor.value.render();
//
editor.value.active(currentPointId);
});
}
},
});
@ -147,13 +166,20 @@ function onRemoveLocation(i: number) {
p.associatedStorageLocations.splice(i, 1);
editor.value.updatePen(props.id!, { point: { ...p } }, false);
// pen
editor.value.createStorageLocationPens(props.id!, p.associatedStorageLocations);
// pen
editor.value.createStorageLocationPens(props.id!, p.associatedStorageLocations, false);
// binLocationList
if (pointName && removedLocationName) {
editor.value.removeBinLocation(pointName, removedLocationName);
}
//
requestAnimationFrame(() => {
editor.value.render();
//
editor.value.active(currentPointId);
});
}
}
}
@ -161,6 +187,8 @@ function onRemoveLocation(i: number) {
function onChangeLocation(i: number, v: string) {
const p = point.value!;
if (p.associatedStorageLocations) {
// ID
const currentPointId = props.id!;
const oldLocationName = p.associatedStorageLocations[i];
const newLocationName = v;
@ -168,14 +196,21 @@ function onChangeLocation(i: number, v: string) {
p.associatedStorageLocations[i] = newLocationName;
editor.value.updatePen(props.id!, { point: { ...p } }, false);
// pen
editor.value.createStorageLocationPens(props.id!, p.associatedStorageLocations);
// pen
editor.value.createStorageLocationPens(props.id!, p.associatedStorageLocations, false);
// binLocationList
const pointName = pen.value?.label || pen.value?.id || '';
if (pointName && oldLocationName !== newLocationName) {
editor.value.updateBinLocationName(pointName, oldLocationName, newLocationName);
}
//
requestAnimationFrame(() => {
editor.value.render();
//
editor.value.active(currentPointId);
});
}
}
</script>

View File

@ -892,9 +892,10 @@ export class EditorService extends Meta2d {
* pen对象
* @param pointId ID
* @param storageLocations
* @param render true
*/
public createStorageLocationPens(pointId: string, storageLocations: string[]): void {
this.storageLocationService?.create(pointId, storageLocations);
public createStorageLocationPens(pointId: string, storageLocations: string[], render = true): void {
this.storageLocationService?.create(pointId, storageLocations, render);
}
/**
@ -1263,6 +1264,12 @@ export class EditorService extends Meta2d {
const pen = this.getPenById(id);
const rect = this.getPointRect(pen);
if (isNil(rect)) return;
// 如果原点位是动作点,需要先删除相关的库位元素
if (pen?.point?.type === MapPointType.) {
this.removeStorageLocationPens(id);
}
const point = this.#mapPoint(type);
const pointInfo: MapPointInfo = { type };

View File

@ -508,8 +508,9 @@ export class StorageLocationService {
* pen对象
* @param pointId ID
* @param storageLocations
* @param render true
*/
public create(pointId: string, storageLocations: string[]): void {
public create(pointId: string, storageLocations: string[], render = true): void {
if (!this.editor) return;
const pointPen = this.editor.getPenById(pointId);
@ -525,10 +526,15 @@ export class StorageLocationService {
const pointRect = this.editor.getPointRect(pointPen) ?? { x: 0, y: 0, width: 0, height: 0 };
const pens = createStorageLocationPens(pointId, storageLocations, pointRect, storageStateMap);
// 添加所有pen对象到编辑器
// 添加所有pen对象到编辑器,但不立即渲染
pens.forEach(pen => {
this.editor!.addPen(pen, false, true, true);
});
// 如果需要渲染,统一渲染一次
if (render) {
this.editor!.render();
}
}
/**