diff --git a/src/services/context-menu.service.ts b/src/services/context-menu.service.ts index 93e7bf8..bfa81d2 100644 --- a/src/services/context-menu.service.ts +++ b/src/services/context-menu.service.ts @@ -3,6 +3,8 @@ * 提供纯函数和状态管理工具,避免单例模式的问题 */ +import { MapPointType } from '@api/map'; + export interface ParsedEventData { type: 'robot' | 'point' | 'area' | 'storage' | 'storage-background' | 'default'; id?: string; @@ -408,14 +410,26 @@ export function getMenuConfig(type: string, data: ParsedEventData, storageLocati }; } case 'point': { - // 点区域:显示该点关联的库位信息 + // 点区域:只有动作点且有库位信息时才显示库位菜单 console.log(`处理点区域类型,点ID: ${data.pointId}`); - const pointStorageLocations = getStorageLocationsForPoint(data, storageLocationService); - console.log(`找到 ${pointStorageLocations.length} 个库位:`, pointStorageLocations); - return { - menuType: 'storage-background' as const, - storageLocations: pointStorageLocations, - }; + + // 检查是否为动作点且有库位信息 + const isActionPointWithStorage = checkIfActionPointWithStorage(data); + + if (isActionPointWithStorage) { + const pointStorageLocations = getStorageLocationsForPoint(data, storageLocationService); + console.log(`动作点找到 ${pointStorageLocations.length} 个库位:`, pointStorageLocations); + return { + menuType: 'storage-background' as const, + storageLocations: pointStorageLocations, + }; + } else { + console.log('非动作点或无库位信息,显示默认菜单'); + return { + menuType: 'default' as const, + storageLocations: [], + }; + } } default: return { @@ -426,6 +440,42 @@ export function getMenuConfig(type: string, data: ParsedEventData, storageLocati } +/** + * 检查是否为动作点且有库位信息 + * @param data 事件数据 + * @returns 是否为动作点且有库位信息 + */ +function checkIfActionPointWithStorage(data: ParsedEventData): boolean { + // 从pen数据中获取点信息 + const pen = data.pen; + if (!pen) { + console.log('无pen数据,不是动作点'); + return false; + } + + const pointInfo = pen.point as any; + if (!pointInfo) { + console.log('无point信息,不是动作点'); + return false; + } + + // 检查是否为动作点 + const isActionPoint = pointInfo.type === MapPointType.动作点; + if (!isActionPoint) { + console.log(`点类型为 ${pointInfo.type},不是动作点`); + return false; + } + + // 检查是否有库位信息 + const hasStorageLocations = pointInfo.associatedStorageLocations && + Array.isArray(pointInfo.associatedStorageLocations) && + pointInfo.associatedStorageLocations.length > 0; + + console.log(`动作点检查结果: 是动作点=${isActionPoint}, 有库位信息=${hasStorageLocations}`); + + return isActionPoint && hasStorageLocations; +} + /** * 查找指定点ID的所有库位信息 * @param pointId 点ID