diff --git a/src/apis/map/type.ts b/src/apis/map/type.ts index 2a02c65..a56a362 100644 --- a/src/apis/map/type.ts +++ b/src/apis/map/type.ts @@ -28,7 +28,7 @@ export interface MapPointInfo { actions?: Array; // 绑定动作点id集合 isBlock?: boolean; // 是否禁行 isForbidAvoid?: boolean; // 是否禁止避让 - locationNames?: string[]; // 库位名称 + associatedStorageLocations?: string[]; // 库位名称 } //#endregion @@ -49,6 +49,7 @@ export interface MapAreaInfo { routes?: Array; // 绑定线路id集合 maxAmr?: number; // 最大可容纳AMR数 inoutflag?: 1 | 2; // 库区规则 + storageLocations?: Record; // 动作点ID对应的库位信息(内部使用) } //#endregion diff --git a/src/apis/scene/type.ts b/src/apis/scene/type.ts index 91e3df2..46ecbb8 100644 --- a/src/apis/scene/type.ts +++ b/src/apis/scene/type.ts @@ -40,7 +40,7 @@ export interface StandardScenePoint { type: number; // 点位类型 robots?: Array; // 绑定机器人id集合 actions?: Array; // 绑定动作点id集合 - locationNames?: string[]; // 库位名称 + associatedStorageLocations?: string[]; // 库位名称 config?: object; // 其它属性配置(可按需增加) properties?: unknown; // 附加数据(前端不做任何处理) } @@ -69,6 +69,7 @@ export interface StandardSceneArea { routes?: Array; // 绑定线路id集合 maxAmr?: number; // 最大可容纳AMR数 inoutflag?: 1 | 2; // 库区规则 + storageLocations?: Record; // 动作点对应的库位信息 config?: object; // 其它属性配置(可按需增加) properties?: unknown; // 附加数据(前端不做任何处理) } diff --git a/src/components/card/point-detail-card.vue b/src/components/card/point-detail-card.vue index 516305c..c255596 100644 --- a/src/components/card/point-detail-card.vue +++ b/src/components/card/point-detail-card.vue @@ -101,10 +101,10 @@ const storageStatus = computed(() => { {{ coArea1 || $t('暂无') }} - + {{ $t('库位') }} - {{ point.locationNames.join('、') }} + {{ point.associatedStorageLocations.join('、') }} (() => editor.value.getBoundAreas(props.id, 'p function onAddLocation() { const p = point.value!; - if (!p.locationNames) p.locationNames = []; - p.locationNames.push(''); + if (!p.associatedStorageLocations) p.associatedStorageLocations = []; + p.associatedStorageLocations.push(''); editor.value.updatePen(props.id!, { point: { ...p } }, false); } function onRemoveLocation(i: number) { const p = point.value!; - p.locationNames?.splice(i, 1); + p.associatedStorageLocations?.splice(i, 1); editor.value.updatePen(props.id!, { point: { ...p } }, false); } function onChangeLocation(i: number, v: string) { const p = point.value!; - if (p.locationNames) { - p.locationNames[i] = v; + if (p.associatedStorageLocations) { + p.associatedStorageLocations[i] = v; editor.value.updatePen(props.id!, { point: { ...p } }, false); } } @@ -209,7 +209,7 @@ function onChangeLocation(i: number, v: string) { - + { - const { id, name, desc, x, y, w, h, type, points, routes, maxAmr, inoutflag, properties } = v; + const { id, name, desc, x, y, w, h, type, points, routes, maxAmr, inoutflag, storageLocations, properties } = v; await this.addArea({ x, y }, { x: x + w, y: y + h }, type, id); + + // 对于库区类型,需要将点位名称数组转换为点位ID数组,并更新动作点的库位信息 + let processedPoints = points; + if (type === MapAreaType.库区 && points?.length) { + // 将点位名称数组转换为点位ID数组 + const actionPoints = this.find('point').filter( + (pen: MapPen) => pen.point?.type === MapPointType.动作点 && points.includes(pen.label || pen.id!), + ); + + processedPoints = actionPoints.map((pen) => pen.id!); + + // 如果有storageLocations数据,更新对应动作点的库位信息 + if (storageLocations) { + actionPoints.forEach((pen) => { + const pointName = pen.label || pen.id!; + if (storageLocations[pointName]) { + this.setValue( + { id: pen.id, point: { ...pen.point, associatedStorageLocations: storageLocations[pointName] } }, + { render: false, history: false, doEvent: false }, + ); + } + }); + } + } + this.setValue( - { id, label: name, desc, properties, area: { type, points, routes, maxAmr, inoutflag } }, + { id, label: name, desc, properties, area: { type, points: processedPoints, routes, maxAmr, inoutflag } }, { render: false, history: false, doEvent: false }, ); }), @@ -166,7 +191,7 @@ export class EditorService extends Meta2d { #mapScenePoint(pen?: MapPen): StandardScenePoint | null { if (!pen?.id || isEmpty(pen?.point)) return null; const { id, label, desc, properties } = pen; - const { type, robots, actions, locationNames } = pen.point; + const { type, robots, actions, associatedStorageLocations } = pen.point; const { x = 0, y = 0 } = this.getPointRect(pen) ?? {}; // 进行坐标转换:左上角原点 -> 中心点原点,同时应用ratio缩放 @@ -189,7 +214,7 @@ export class EditorService extends Meta2d { point.actions = actions?.filter((v) => this.getPenById(v)?.point?.type === MapPointType.动作点); } if (MapPointType.动作点 === type) { - point.locationNames = locationNames; + point.associatedStorageLocations = associatedStorageLocations; } return point; } @@ -255,7 +280,22 @@ export class EditorService extends Meta2d { area.maxAmr = maxAmr; } if (MapAreaType.库区 === type) { - area.points = points?.filter((v) => this.getPenById(v)?.point?.type === MapPointType.动作点); + // 获取库区内的动作点 + const actionPoints = + points + ?.map((id) => this.getPenById(id)) + .filter((pen): pen is MapPen => !!pen && pen.point?.type === MapPointType.动作点) ?? []; + + // 保存动作点名称 + area.points = actionPoints.map((pen) => pen.label || pen.id!); + + // 构建storageLocations映射:动作点名称 -> 库位列表 + area.storageLocations = {}; + actionPoints.forEach((pen) => { + const pointName = pen.label || pen.id!; + area.storageLocations![pointName] = pen.point?.associatedStorageLocations ?? []; + }); + area.inoutflag = inoutflag; } if ([MapAreaType.互斥区, MapAreaType.非互斥区, MapAreaType.约束区].includes(type)) {