refactor: 更新库位名称为关联库位,调整相关接口和组件以支持新字段

This commit is contained in:
xudan 2025-07-14 18:11:29 +08:00
parent c3181d4d37
commit 3fdd2db521
5 changed files with 57 additions and 15 deletions

View File

@ -28,7 +28,7 @@ export interface MapPointInfo {
actions?: Array<string>; // 绑定动作点id集合
isBlock?: boolean; // 是否禁行
isForbidAvoid?: boolean; // 是否禁止避让
locationNames?: string[]; // 库位名称
associatedStorageLocations?: string[]; // 库位名称
}
//#endregion
@ -49,6 +49,7 @@ export interface MapAreaInfo {
routes?: Array<string>; // 绑定线路id集合
maxAmr?: number; // 最大可容纳AMR数
inoutflag?: 1 | 2; // 库区规则
storageLocations?: Record<string, string[]>; // 动作点ID对应的库位信息内部使用
}
//#endregion

View File

@ -40,7 +40,7 @@ export interface StandardScenePoint {
type: number; // 点位类型
robots?: Array<string>; // 绑定机器人id集合
actions?: Array<string>; // 绑定动作点id集合
locationNames?: string[]; // 库位名称
associatedStorageLocations?: string[]; // 库位名称
config?: object; // 其它属性配置(可按需增加)
properties?: unknown; // 附加数据(前端不做任何处理)
}
@ -69,6 +69,7 @@ export interface StandardSceneArea {
routes?: Array<string>; // 绑定线路id集合
maxAmr?: number; // 最大可容纳AMR数
inoutflag?: 1 | 2; // 库区规则
storageLocations?: Record<string, string[]>; // 动作点对应的库位信息
config?: object; // 其它属性配置(可按需增加)
properties?: unknown; // 附加数据(前端不做任何处理)
}

View File

@ -101,10 +101,10 @@ const storageStatus = computed<string>(() => {
<a-typography-text>{{ coArea1 || $t('暂无') }}</a-typography-text>
</a-flex>
</a-list-item>
<a-list-item v-if="MapPointType.动作点 === point.type && point.locationNames?.length">
<a-list-item v-if="MapPointType.动作点 === point.type && point.associatedStorageLocations?.length">
<a-flex :gap="8" vertical>
<a-typography-text type="secondary">{{ $t('库位') }}</a-typography-text>
<a-typography-text>{{ point.locationNames.join('、') }}</a-typography-text>
<a-typography-text>{{ point.associatedStorageLocations.join('、') }}</a-typography-text>
</a-flex>
</a-list-item>
<a-list-item

View File

@ -60,19 +60,19 @@ const coArea2 = computed<MapPen[]>(() => 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) {
<a-collapse-panel v-if="MapPointType.动作点 === point.type" :header="$t('库位')">
<a-flex vertical :gap="8">
<a-flex v-for="(l, i) in point.locationNames" :key="i" :gap="8" align="center">
<a-flex v-for="(l, i) in point.associatedStorageLocations" :key="i" :gap="8" align="center">
<a-input
style="flex: 1"
:value="l"

View File

@ -153,10 +153,35 @@ export class EditorService extends Meta2d {
if (!areas?.length) return;
await Promise.all(
areas.map(async (v) => {
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)) {