feat: 添加库位任务相关类型定义,优化点位编辑和详细卡片的库位管理功能,增强数据处理和同步逻辑

This commit is contained in:
xudan 2025-08-07 16:17:05 +08:00
parent dd6f712439
commit 0cd2a951d5
4 changed files with 165 additions and 44 deletions

View File

@ -158,3 +158,43 @@ export interface StorageLocationClientMessage {
type: 'get_status';
timestamp: string;
}
// 库位任务相关类型定义
export interface BinTaskOperation {
operation: string;
recfile?: string;
recognize?: boolean;
use_down_pgv?: boolean;
use_pgv?: boolean;
pgv_x_adjust?: boolean;
}
export interface BinTaskItem {
Load?: BinTaskOperation;
Unload?: BinTaskOperation;
}
export interface BinLocationProperty {
key: string;
type: string;
stringValue: string;
}
export interface BinLocationItem {
className: string;
instanceName: string;
pointName: string;
pos: {
x: number;
y: number;
};
property: BinLocationProperty[];
}
export interface BinLocationGroup {
binLocationList: BinLocationItem[];
}
export interface BinLocationsList {
binLocationsList: BinLocationGroup[];
}

View File

@ -1,51 +1,11 @@
<script setup lang="ts">
import { MapAreaType, type MapPen, type MapPointInfo, MapPointType, type Rect } from '@api/map';
import type { StorageLocationInfo } from '@api/scene';
import type { BinLocationGroup, BinLocationsList, BinTaskItem, StorageLocationInfo } from '@api/scene';
import type { EditorService } from '@core/editor.service';
import sTheme from '@core/theme.service';
import { isNil } from 'lodash-es';
import { computed, inject, type InjectionKey, type ShallowRef } from 'vue';
//
interface BinTaskOperation {
operation: string;
recfile?: string;
recognize?: boolean;
use_down_pgv?: boolean;
use_pgv?: boolean;
pgv_x_adjust?: boolean;
}
interface BinTaskItem {
Load?: BinTaskOperation;
Unload?: BinTaskOperation;
}
interface BinLocationProperty {
key: string;
type: string;
stringValue: string;
}
interface BinLocationItem {
className: string;
instanceName: string;
pointName: string;
pos: {
x: number;
y: number;
};
property: BinLocationProperty[];
}
interface BinLocationGroup {
binLocationList: BinLocationItem[];
}
interface BinLocationsList {
binLocationsList: BinLocationGroup[];
}
type Props = {
token: InjectionKey<ShallowRef<EditorService>>;
current?: string;

View File

@ -106,14 +106,33 @@ function onAddLocation() {
}
function onRemoveLocation(i: number) {
const p = point.value!;
p.associatedStorageLocations?.splice(i, 1);
editor.value.updatePen(props.id!, { point: { ...p } }, false);
if (p.associatedStorageLocations) {
const removedLocationName = p.associatedStorageLocations[i];
p.associatedStorageLocations.splice(i, 1);
editor.value.updatePen(props.id!, { point: { ...p } }, false);
// binLocationList
const pointName = pen.value?.label || pen.value?.id || '';
if (pointName && removedLocationName) {
editor.value.removeBinLocation(pointName, removedLocationName);
}
}
}
function onChangeLocation(i: number, v: string) {
const p = point.value!;
if (p.associatedStorageLocations) {
p.associatedStorageLocations[i] = v;
const oldLocationName = p.associatedStorageLocations[i];
const newLocationName = v;
//
p.associatedStorageLocations[i] = newLocationName;
editor.value.updatePen(props.id!, { point: { ...p } }, false);
// binLocationList
const pointName = pen.value?.label || pen.value?.id || '';
if (pointName && oldLocationName !== newLocationName) {
editor.value.updateBinLocationName(pointName, oldLocationName, newLocationName);
}
}
}
</script>

View File

@ -13,6 +13,8 @@ import {
} from '@api/map';
import type { RobotGroup, RobotInfo, RobotRealtimeInfo, RobotType } from '@api/robot';
import type {
BinLocationGroup,
BinLocationItem,
GroupSceneDetail,
SceneData,
StandardScene,
@ -106,6 +108,106 @@ export class EditorService extends Meta2d {
return (this.#originalSceneData as Record<string, unknown>)?.binLocationsList;
}
/**
*
* @returns
*/
private getBinLocationGroups(): BinLocationGroup[] {
const rawData = this.getBinLocationsList();
if (!rawData) return [];
const binLocationGroups = Array.isArray(rawData)
? (rawData as BinLocationGroup[])
: (rawData as { binLocationsList: BinLocationGroup[] })?.binLocationsList;
return Array.isArray(binLocationGroups) ? binLocationGroups : [];
}
/**
*
* @param pointName
* @param locationName
* @returns truefalse
*/
private checkBinLocationExists(pointName: string, locationName: string): boolean {
const binLocationGroups = this.getBinLocationGroups();
return binLocationGroups.some(
(group) =>
group &&
Array.isArray(group.binLocationList) &&
group.binLocationList.some(
(item) => item && item.pointName === pointName && item.instanceName === locationName,
),
);
}
/**
*
* @param pointName
* @param oldLocationName
* @param newLocationName
*/
public updateBinLocationName(pointName: string, oldLocationName: string, newLocationName: string): void {
// 预检查:确保要更新的库位项存在
if (!this.checkBinLocationExists(pointName, oldLocationName)) {
return;
}
const binLocationGroups = this.getBinLocationGroups();
if (binLocationGroups.length === 0) return;
// 遍历所有库位组,查找匹配的库位并更新名称
binLocationGroups.forEach((group) => {
if (group && Array.isArray(group.binLocationList)) {
group.binLocationList.forEach((item: BinLocationItem) => {
if (item && item.pointName === pointName && item.instanceName === oldLocationName) {
item.instanceName = newLocationName;
}
});
}
});
// 更新原始场景数据
if (!this.#originalSceneData) {
this.#originalSceneData = {};
}
(this.#originalSceneData as Record<string, unknown>).binLocationsList = binLocationGroups;
}
/**
*
* @param pointName
* @param locationName
*/
public removeBinLocation(pointName: string, locationName: string): void {
// 预检查:确保要删除的库位项存在
if (!this.checkBinLocationExists(pointName, locationName)) {
return;
}
const binLocationGroups = this.getBinLocationGroups();
if (binLocationGroups.length === 0) return;
// 遍历所有库位组,查找匹配的库位并删除
binLocationGroups.forEach((group) => {
if (group && Array.isArray(group.binLocationList)) {
const index = group.binLocationList.findIndex(
(item: BinLocationItem) => item && item.pointName === pointName && item.instanceName === locationName,
);
if (index !== -1) {
group.binLocationList.splice(index, 1);
}
}
});
// 更新原始场景数据
if (!this.#originalSceneData) {
this.#originalSceneData = {};
}
(this.#originalSceneData as Record<string, unknown>).binLocationsList = binLocationGroups;
}
/**
*
* @param groups