feat: 添加库位任务相关类型定义,优化点位编辑和详细卡片的库位管理功能,增强数据处理和同步逻辑
This commit is contained in:
parent
dd6f712439
commit
0cd2a951d5
@ -158,3 +158,43 @@ export interface StorageLocationClientMessage {
|
|||||||
type: 'get_status';
|
type: 'get_status';
|
||||||
timestamp: string;
|
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[];
|
||||||
|
}
|
||||||
|
@ -1,51 +1,11 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { MapAreaType, type MapPen, type MapPointInfo, MapPointType, type Rect } from '@api/map';
|
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 type { EditorService } from '@core/editor.service';
|
||||||
import sTheme from '@core/theme.service';
|
import sTheme from '@core/theme.service';
|
||||||
import { isNil } from 'lodash-es';
|
import { isNil } from 'lodash-es';
|
||||||
import { computed, inject, type InjectionKey, type ShallowRef } from 'vue';
|
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 = {
|
type Props = {
|
||||||
token: InjectionKey<ShallowRef<EditorService>>;
|
token: InjectionKey<ShallowRef<EditorService>>;
|
||||||
current?: string;
|
current?: string;
|
||||||
|
@ -106,14 +106,33 @@ function onAddLocation() {
|
|||||||
}
|
}
|
||||||
function onRemoveLocation(i: number) {
|
function onRemoveLocation(i: number) {
|
||||||
const p = point.value!;
|
const p = point.value!;
|
||||||
p.associatedStorageLocations?.splice(i, 1);
|
if (p.associatedStorageLocations) {
|
||||||
editor.value.updatePen(props.id!, { point: { ...p } }, false);
|
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) {
|
function onChangeLocation(i: number, v: string) {
|
||||||
const p = point.value!;
|
const p = point.value!;
|
||||||
if (p.associatedStorageLocations) {
|
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);
|
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>
|
</script>
|
||||||
|
@ -13,6 +13,8 @@ import {
|
|||||||
} from '@api/map';
|
} from '@api/map';
|
||||||
import type { RobotGroup, RobotInfo, RobotRealtimeInfo, RobotType } from '@api/robot';
|
import type { RobotGroup, RobotInfo, RobotRealtimeInfo, RobotType } from '@api/robot';
|
||||||
import type {
|
import type {
|
||||||
|
BinLocationGroup,
|
||||||
|
BinLocationItem,
|
||||||
GroupSceneDetail,
|
GroupSceneDetail,
|
||||||
SceneData,
|
SceneData,
|
||||||
StandardScene,
|
StandardScene,
|
||||||
@ -106,6 +108,106 @@ export class EditorService extends Meta2d {
|
|||||||
return (this.#originalSceneData as Record<string, unknown>)?.binLocationsList;
|
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 如果库位项存在则返回true,否则返回false
|
||||||
|
*/
|
||||||
|
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 机器人组列表
|
* @param groups 机器人组列表
|
||||||
|
Loading…
x
Reference in New Issue
Block a user