fix(context-menu): 修复上下文菜单项的格式,确保每个操作的成功状态后面添加逗号

This commit is contained in:
xudan 2025-10-24 11:43:20 +08:00
parent 4576ed4e77
commit 093b48d714
3 changed files with 119 additions and 109 deletions

View File

@ -4,12 +4,12 @@
<span class="menu-icon">🔄</span> <span class="menu-icon">🔄</span>
<span>刷新</span> <span>刷新</span>
</div> </div>
<div class="context-menu-item" @click="handleViewInfo"> <div class="context-menu-item" @click="handleViewInfo">
<span class="menu-icon"></span> <span class="menu-icon"></span>
<span>查看信息</span> <span>查看信息</span>
</div> </div>
<div class="context-menu-item" @click="handleSettings"> <div class="context-menu-item" @click="handleSettings">
<span class="menu-icon"></span> <span class="menu-icon"></span>
<span>设置</span> <span>设置</span>
@ -34,7 +34,7 @@ const handleRefresh = () => {
console.log('刷新操作'); console.log('刷新操作');
emit('actionComplete', { emit('actionComplete', {
action: 'refresh', action: 'refresh',
success: true success: true,
}); });
}; };
@ -43,7 +43,7 @@ const handleViewInfo = () => {
console.log('查看信息操作'); console.log('查看信息操作');
emit('actionComplete', { emit('actionComplete', {
action: 'view_info', action: 'view_info',
success: true success: true,
}); });
}; };
@ -52,7 +52,7 @@ const handleSettings = () => {
console.log('设置操作'); console.log('设置操作');
emit('actionComplete', { emit('actionComplete', {
action: 'settings', action: 'settings',
success: true success: true,
}); });
}; };
</script> </script>

View File

@ -37,12 +37,12 @@ export type MenuConfig = StorageMenuConfig | RobotMenuConfig | PointMenuConfig |
* @returns * @returns
*/ */
export function getMenuConfig( export function getMenuConfig(
type: string, type: string,
data: ParsedEventData, data: ParsedEventData,
services?: { services?: {
storageLocationService?: any; storageLocationService?: any;
robotService?: any; robotService?: any;
} },
): MenuConfig { ): MenuConfig {
switch (type) { switch (type) {
case 'storage-background': case 'storage-background':
@ -50,7 +50,7 @@ export function getMenuConfig(
case 'point': case 'point':
// 库位相关类型,包括点区域(如果是动作点且有库位信息) // 库位相关类型,包括点区域(如果是动作点且有库位信息)
return getStorageMenuConfig(type, data, services?.storageLocationService); return getStorageMenuConfig(type, data, services?.storageLocationService);
case 'robot': { case 'robot': {
// 机器人类型 - 直接获取机器人信息 // 机器人类型 - 直接获取机器人信息
const robotInfo = services?.robotService?.getRobotById?.(data.id); const robotInfo = services?.robotService?.getRobotById?.(data.id);
@ -64,12 +64,14 @@ export function getMenuConfig(
menuType: 'default' as const, menuType: 'default' as const,
}; };
} }
case 'area': case 'area':
// 区域类型 // 区域类型
return getAreaMenuConfig(data); return getAreaMenuConfig(data);
default: default:
// 对于默认情况,我们不希望显示任何菜单,
// 因此返回一个可以被 processContextMenu 识别并关闭菜单的配置
return { return {
menuType: 'default' as const, menuType: 'default' as const,
}; };
@ -83,7 +85,7 @@ export function getMenuConfig(
*/ */
function getAreaMenuConfig(data: ParsedEventData): AreaMenuConfig { function getAreaMenuConfig(data: ParsedEventData): AreaMenuConfig {
console.log(`处理区域类型区域ID: ${data.id}`); console.log(`处理区域类型区域ID: ${data.id}`);
if (data.id && data.name) { if (data.id && data.name) {
return { return {
menuType: 'area' as const, menuType: 'area' as const,
@ -94,7 +96,7 @@ function getAreaMenuConfig(data: ParsedEventData): AreaMenuConfig {
}, },
}; };
} }
return { return {
menuType: 'default' as const, menuType: 'default' as const,
}; };
@ -112,7 +114,7 @@ function processContextMenu(
services?: { services?: {
storageLocationService?: any; storageLocationService?: any;
robotService?: any; robotService?: any;
} },
) { ) {
// 获取菜单配置 // 获取菜单配置
const menuConfig = getMenuConfig(parsedData.type, parsedData, services); const menuConfig = getMenuConfig(parsedData.type, parsedData, services);
@ -143,12 +145,12 @@ function processContextMenu(
* @param services * @param services
*/ */
export function handleContextMenu( export function handleContextMenu(
event: MouseEvent | PointerEvent, event: MouseEvent | PointerEvent,
manager: any, manager: any,
services?: { services?: {
storageLocationService?: any; storageLocationService?: any;
robotService?: any; robotService?: any;
} },
) { ) {
// 阻止默认右键菜单 // 阻止默认右键菜单
event.preventDefault(); event.preventDefault();
@ -171,7 +173,7 @@ export function handleContextMenuFromPenData(
services?: { services?: {
storageLocationService?: any; storageLocationService?: any;
robotService?: any; robotService?: any;
} },
) { ) {
// 解析penData并处理 // 解析penData并处理
const parsedData = parsePenData(penData); const parsedData = parsePenData(penData);

View File

@ -4,7 +4,7 @@ import type { StorageLocationInfo, StorageLocationMessage } from '@api/scene';
import { monitorStorageLocationById } from '@api/scene'; import { monitorStorageLocationById } from '@api/scene';
import type { EditorService } from '@core/editor.service'; import type { EditorService } from '@core/editor.service';
import { isNil } from 'lodash-es'; import { isNil } from 'lodash-es';
import { type Ref, ref } from 'vue'; import { reactive, type Ref, ref } from 'vue';
import { createStorageLocationPens } from './draw/storage-location-drawer'; import { createStorageLocationPens } from './draw/storage-location-drawer';
@ -14,9 +14,9 @@ import { createStorageLocationPens } from './draw/storage-location-drawer';
* *
*/ */
const COLORS = { const COLORS = {
OCCUPIED: '#ff4d4f', // 占用状态 - 红色 OCCUPIED: '#ff4d4f', // 占用状态 - 红色
AVAILABLE: '#52c41a', // 可用状态 - 绿色 AVAILABLE: '#52c41a', // 可用状态 - 绿色
DEFAULT: '#f5f5f5' // 默认状态 - 浅灰色 DEFAULT: '#f5f5f5', // 默认状态 - 浅灰色
} as const; } as const;
/** /**
@ -25,15 +25,15 @@ const COLORS = {
const MESSAGE_TYPES = { const MESSAGE_TYPES = {
BATCH_UPDATE: 'storage_location_update', BATCH_UPDATE: 'storage_location_update',
SINGLE_UPDATE: 'storage_location_status_change', SINGLE_UPDATE: 'storage_location_status_change',
GET_STATUS: 'get_status' GET_STATUS: 'get_status',
} as const; } as const;
/** /**
* *
*/ */
const DEFAULT_CONFIG = { const DEFAULT_CONFIG = {
MONITOR_INTERVAL: 3, // 默认监控间隔(秒) MONITOR_INTERVAL: 3, // 默认监控间隔(秒)
POINT_TYPE_ACTION: 15 // 动作点类型 POINT_TYPE_ACTION: 15, // 动作点类型
} as const; } as const;
/** /**
@ -43,14 +43,14 @@ const PEN_TYPES = {
POINT: 'point', POINT: 'point',
STORAGE_LOCATION: 'storage-location', STORAGE_LOCATION: 'storage-location',
STORAGE_MORE: 'storage-more', STORAGE_MORE: 'storage-more',
STORAGE_BACKGROUND: 'storage-background' STORAGE_BACKGROUND: 'storage-background',
} as const; } as const;
/** /**
* *
*/ */
const TAGS = { const TAGS = {
POINT_PREFIX: 'point-' POINT_PREFIX: 'point-',
} as const; } as const;
/** /**
@ -83,25 +83,25 @@ const DEFAULT_STORAGE_CONFIG: StorageLocationConfig = {
colors: { colors: {
occupied: COLORS.OCCUPIED, occupied: COLORS.OCCUPIED,
available: COLORS.AVAILABLE, available: COLORS.AVAILABLE,
default: COLORS.DEFAULT default: COLORS.DEFAULT,
}, },
penTypes: { penTypes: {
point: PEN_TYPES.POINT, point: PEN_TYPES.POINT,
storageLocation: PEN_TYPES.STORAGE_LOCATION, storageLocation: PEN_TYPES.STORAGE_LOCATION,
storageMore: PEN_TYPES.STORAGE_MORE, storageMore: PEN_TYPES.STORAGE_MORE,
storageBackground: PEN_TYPES.STORAGE_BACKGROUND storageBackground: PEN_TYPES.STORAGE_BACKGROUND,
}, },
tags: { tags: {
pointPrefix: TAGS.POINT_PREFIX pointPrefix: TAGS.POINT_PREFIX,
}, },
monitoring: { monitoring: {
defaultInterval: DEFAULT_CONFIG.MONITOR_INTERVAL defaultInterval: DEFAULT_CONFIG.MONITOR_INTERVAL,
} },
}; };
// 提供给绘制层快速查询的全局状态映射pointId -> (layerName -> { occupied, locked }) // 提供给绘制层快速查询的全局状态映射pointId -> (layerName -> { occupied, locked, disabled })
export type StorageState = { occupied?: boolean; locked?: boolean }; export type StorageState = { occupied?: boolean; locked?: boolean; disabled?: boolean };
export const storageStateMap = new Map<string, Map<string, StorageState>>(); export const storageStateMap = reactive(new Map<string, Map<string, StorageState>>());
/** /**
* *
@ -127,12 +127,12 @@ export class StorageLocationService {
*/ */
private mergeConfig(userConfig?: Partial<StorageLocationConfig>): StorageLocationConfig { private mergeConfig(userConfig?: Partial<StorageLocationConfig>): StorageLocationConfig {
if (!userConfig) return DEFAULT_STORAGE_CONFIG; if (!userConfig) return DEFAULT_STORAGE_CONFIG;
return { return {
colors: { ...DEFAULT_STORAGE_CONFIG.colors, ...userConfig.colors }, colors: { ...DEFAULT_STORAGE_CONFIG.colors, ...userConfig.colors },
penTypes: { ...DEFAULT_STORAGE_CONFIG.penTypes, ...userConfig.penTypes }, penTypes: { ...DEFAULT_STORAGE_CONFIG.penTypes, ...userConfig.penTypes },
tags: { ...DEFAULT_STORAGE_CONFIG.tags, ...userConfig.tags }, tags: { ...DEFAULT_STORAGE_CONFIG.tags, ...userConfig.tags },
monitoring: { ...DEFAULT_STORAGE_CONFIG.monitoring, ...userConfig.monitoring } monitoring: { ...DEFAULT_STORAGE_CONFIG.monitoring, ...userConfig.monitoring },
}; };
} }
@ -179,9 +179,9 @@ export class StorageLocationService {
if (!this.editor) return stationToPointIdMap; if (!this.editor) return stationToPointIdMap;
// 获取所有动作点 // 获取所有动作点
const actionPoints = this.editor.find(this.config.penTypes.point).filter( const actionPoints = this.editor
(pen) => pen.point?.type === DEFAULT_CONFIG.POINT_TYPE_ACTION .find(this.config.penTypes.point)
); .filter((pen) => pen.point?.type === DEFAULT_CONFIG.POINT_TYPE_ACTION);
actionPoints.forEach((pen) => { actionPoints.forEach((pen) => {
const stationName = pen.label; // 如 "AP9" const stationName = pen.label; // 如 "AP9"
@ -241,7 +241,6 @@ export class StorageLocationService {
return this.config.colors.default; return this.config.colors.default;
} }
/** /**
* *
* @param pointId ID * @param pointId ID
@ -291,7 +290,7 @@ export class StorageLocationService {
*/ */
private hasStorageLocationDataChanged(newLocationsByPointId: Map<string, StorageLocationInfo[]>): boolean { private hasStorageLocationDataChanged(newLocationsByPointId: Map<string, StorageLocationInfo[]>): boolean {
const currentData = this.storageLocations.value; const currentData = this.storageLocations.value;
// 如果数据量不同,肯定有变化 // 如果数据量不同,肯定有变化
if (currentData.size !== newLocationsByPointId.size) { if (currentData.size !== newLocationsByPointId.size) {
return true; return true;
@ -306,10 +305,13 @@ export class StorageLocationService {
// 检查每个库位的状态是否有变化 // 检查每个库位的状态是否有变化
for (const newLocation of newLocations) { for (const newLocation of newLocations) {
const currentLocation = currentLocations.find(loc => loc.id === newLocation.id); const currentLocation = currentLocations.find((loc) => loc.id === newLocation.id);
if (!currentLocation || if (
currentLocation.is_occupied !== newLocation.is_occupied || !currentLocation ||
currentLocation.is_locked !== newLocation.is_locked) { currentLocation.is_occupied !== newLocation.is_occupied ||
currentLocation.is_locked !== newLocation.is_locked ||
currentLocation.is_disabled !== newLocation.is_disabled
) {
return true; return true;
} }
} }
@ -326,7 +328,7 @@ export class StorageLocationService {
private getChangedPointIds(newLocationsByPointId: Map<string, StorageLocationInfo[]>): Set<string> { private getChangedPointIds(newLocationsByPointId: Map<string, StorageLocationInfo[]>): Set<string> {
const changedPointIds = new Set<string>(); const changedPointIds = new Set<string>();
const currentData = this.storageLocations.value; const currentData = this.storageLocations.value;
// 检查每个点的数据是否有变化 // 检查每个点的数据是否有变化
for (const [pointId, newLocations] of newLocationsByPointId.entries()) { for (const [pointId, newLocations] of newLocationsByPointId.entries()) {
const currentLocations = currentData.get(pointId); const currentLocations = currentData.get(pointId);
@ -337,10 +339,13 @@ export class StorageLocationService {
// 检查每个库位的状态是否有变化 // 检查每个库位的状态是否有变化
for (const newLocation of newLocations) { for (const newLocation of newLocations) {
const currentLocation = currentLocations.find(loc => loc.id === newLocation.id); const currentLocation = currentLocations.find((loc) => loc.id === newLocation.id);
if (!currentLocation || if (
currentLocation.is_occupied !== newLocation.is_occupied || !currentLocation ||
currentLocation.is_locked !== newLocation.is_locked) { currentLocation.is_occupied !== newLocation.is_occupied ||
currentLocation.is_locked !== newLocation.is_locked ||
currentLocation.is_disabled !== newLocation.is_disabled
) {
changedPointIds.add(pointId); changedPointIds.add(pointId);
break; break;
} }
@ -388,14 +393,18 @@ export class StorageLocationService {
for (const [pointId, list] of locationsByPointId.entries()) { for (const [pointId, list] of locationsByPointId.entries()) {
const inner = new Map<string, StorageState>(); const inner = new Map<string, StorageState>();
list.forEach((loc) => { list.forEach((loc) => {
inner.set(loc.layer_name, { occupied: loc.is_occupied, locked: loc.is_locked }); inner.set(loc.layer_name, {
occupied: loc.is_occupied,
locked: loc.is_locked,
disabled: loc.is_disabled,
});
}); });
storageStateMap.set(pointId, inner); storageStateMap.set(pointId, inner);
} }
// 只更新有变化的点的边框颜色 // 只更新有变化的点的边框颜色
this.updatePointBorderColorsOptimized(changedPointIds); this.updatePointBorderColorsOptimized(changedPointIds);
// 仅对发生变化的点位做增量刷新:存在则批量更新状态,不存在则创建 // 仅对发生变化的点位做增量刷新:存在则批量更新状态,不存在则创建
for (const pointId of changedPointIds) { for (const pointId of changedPointIds) {
const pointPen = this.editor?.getPenById(pointId); const pointPen = this.editor?.getPenById(pointId);
@ -411,7 +420,7 @@ export class StorageLocationService {
} }
} }
} }
// 批量更新后触发一次重绘 // 批量更新后触发一次重绘
this.scheduleRender(); this.scheduleRender();
} else if (message.type === MESSAGE_TYPES.SINGLE_UPDATE) { } else if (message.type === MESSAGE_TYPES.SINGLE_UPDATE) {
@ -438,9 +447,10 @@ export class StorageLocationService {
inner.set(layerName, { inner.set(layerName, {
occupied: new_status.is_occupied, occupied: new_status.is_occupied,
locked: new_status.is_locked, locked: new_status.is_locked,
disabled: new_status.is_disabled,
}); });
storageStateMap.set(pointId, inner); storageStateMap.set(pointId, inner);
// 重新创建该动作点的库位pen对象以反映最新状态 // 重新创建该动作点的库位pen对象以反映最新状态
const pointPen = this.editor?.getPenById(pointId); const pointPen = this.editor?.getPenById(pointId);
if (pointPen?.point?.associatedStorageLocations) { if (pointPen?.point?.associatedStorageLocations) {
@ -461,8 +471,8 @@ export class StorageLocationService {
this.stopMonitoring(); this.stopMonitoring();
// 监控库位状态 // 监控库位状态
const ws = await monitorStorageLocationById(this.sceneId, { const ws = await monitorStorageLocationById(this.sceneId, {
interval: options.interval || this.config.monitoring.defaultInterval interval: options.interval || this.config.monitoring.defaultInterval,
}); });
if (isNil(ws)) return; if (isNil(ws)) return;
@ -525,12 +535,12 @@ export class StorageLocationService {
// 创建新的库位pen对象 // 创建新的库位pen对象
const pointRect = this.editor.getPointRect(pointPen) ?? { x: 0, y: 0, width: 0, height: 0 }; const pointRect = this.editor.getPointRect(pointPen) ?? { x: 0, y: 0, width: 0, height: 0 };
const pens = createStorageLocationPens(pointId, storageLocations, pointRect, storageStateMap); const pens = createStorageLocationPens(pointId, storageLocations, pointRect, storageStateMap);
// 添加所有pen对象到编辑器但不立即渲染 // 添加所有pen对象到编辑器但不立即渲染
pens.forEach(pen => { pens.forEach((pen) => {
this.editor!.addPen(pen, false, true, true); this.editor!.addPen(pen, false, true, true);
}); });
// 如果需要渲染,统一渲染一次 // 如果需要渲染,统一渲染一次
if (render) { if (render) {
this.editor!.render(); this.editor!.render();
@ -546,17 +556,20 @@ export class StorageLocationService {
public update( public update(
pointId: string, pointId: string,
updates: string | Record<string, { occupied?: boolean; locked?: boolean }> | string[], updates: string | Record<string, { occupied?: boolean; locked?: boolean }> | string[],
state?: { occupied?: boolean; locked?: boolean } state?: { occupied?: boolean; locked?: boolean },
): void { ): void {
if (!this.editor) return; if (!this.editor) return;
// 处理库位名称列表更新(用于重新创建时更新状态) // 处理库位名称列表更新(用于重新创建时更新状态)
if (Array.isArray(updates)) { if (Array.isArray(updates)) {
const states = updates.reduce((acc, locationName) => { const states = updates.reduce(
const state = storageStateMap.get(pointId)?.get(locationName) || { occupied: false, locked: false }; (acc, locationName) => {
acc[locationName] = { occupied: !!state.occupied, locked: !!state.locked }; const state = storageStateMap.get(pointId)?.get(locationName) || { occupied: false, locked: false };
return acc; acc[locationName] = { occupied: !!state.occupied, locked: !!state.locked };
}, {} as Record<string, { occupied: boolean; locked: boolean }>); return acc;
},
{} as Record<string, { occupied: boolean; locked: boolean }>,
);
this.update(pointId, states); this.update(pointId, states);
return; return;
} }
@ -566,7 +579,7 @@ export class StorageLocationService {
// 同步到storageStateMap // 同步到storageStateMap
this.syncStorageStateToMap(pointId, updates, { this.syncStorageStateToMap(pointId, updates, {
occupied: state.occupied || false, occupied: state.occupied || false,
locked: state.locked || false locked: state.locked || false,
}); });
// 查找并更新pen对象 // 查找并更新pen对象
@ -584,11 +597,11 @@ export class StorageLocationService {
// 批量更新pen对象 // 批量更新pen对象
const storagePens = this.getStorageLocationPens(pointId); const storagePens = this.getStorageLocationPens(pointId);
storagePens.forEach(pen => { storagePens.forEach((pen) => {
if (pen.storageLocation && pen.id) { if (pen.storageLocation && pen.id) {
const locationName = pen.storageLocation.locationName; const locationName = pen.storageLocation.locationName;
const state = updates[locationName]; const state = updates[locationName];
if (state) { if (state) {
this.updatePenStorageState(pen.id, pen.storageLocation, state); this.updatePenStorageState(pen.id, pen.storageLocation, state);
} }
@ -605,22 +618,22 @@ export class StorageLocationService {
if (!this.editor) return; if (!this.editor) return;
const { penTypes, tags } = this.config; const { penTypes, tags } = this.config;
// 分别查找每种类型的库位pen对象 // 分别查找每种类型的库位pen对象
const storageLocationPens = this.editor.find(penTypes.storageLocation).filter( const storageLocationPens = this.editor
(pen) => pen.tags?.includes(`${tags.pointPrefix}${pointId}`) .find(penTypes.storageLocation)
); .filter((pen) => pen.tags?.includes(`${tags.pointPrefix}${pointId}`));
const storageMorePens = this.editor.find(penTypes.storageMore).filter( const storageMorePens = this.editor
(pen) => pen.tags?.includes(`${tags.pointPrefix}${pointId}`) .find(penTypes.storageMore)
); .filter((pen) => pen.tags?.includes(`${tags.pointPrefix}${pointId}`));
const storageBackgroundPens = this.editor.find(penTypes.storageBackground).filter( const storageBackgroundPens = this.editor
(pen) => pen.tags?.includes(`${tags.pointPrefix}${pointId}`) .find(penTypes.storageBackground)
); .filter((pen) => pen.tags?.includes(`${tags.pointPrefix}${pointId}`));
const allStoragePens = [...storageLocationPens, ...storageMorePens, ...storageBackgroundPens]; const allStoragePens = [...storageLocationPens, ...storageMorePens, ...storageBackgroundPens];
if (allStoragePens.length > 0) { if (allStoragePens.length > 0) {
this.editor.delete(allStoragePens, true, true); this.editor.delete(allStoragePens, true, true);
} }
@ -635,7 +648,7 @@ export class StorageLocationService {
private syncStorageStateToMap( private syncStorageStateToMap(
pointId: string, pointId: string,
locationName: string, locationName: string,
state: { occupied: boolean; locked: boolean } state: { occupied: boolean; locked: boolean },
): void { ): void {
if (!storageStateMap.has(pointId)) { if (!storageStateMap.has(pointId)) {
storageStateMap.set(pointId, new Map()); storageStateMap.set(pointId, new Map());
@ -653,7 +666,7 @@ export class StorageLocationService {
private updatePenStorageState( private updatePenStorageState(
penId: string, penId: string,
storageLocation: any, storageLocation: any,
state: { occupied?: boolean; locked?: boolean } state: { occupied?: boolean; locked?: boolean },
): void { ): void {
if (!this.editor) return; if (!this.editor) return;
// 计算新旧状态,用于比较与更新 // 计算新旧状态,用于比较与更新
@ -686,12 +699,12 @@ export class StorageLocationService {
*/ */
private batchSyncStorageStateToMap( private batchSyncStorageStateToMap(
pointId: string, pointId: string,
updates: Record<string, { occupied?: boolean; locked?: boolean }> updates: Record<string, { occupied?: boolean; locked?: boolean }>,
): void { ): void {
Object.entries(updates).forEach(([locationName, state]) => { Object.entries(updates).forEach(([locationName, state]) => {
this.syncStorageStateToMap(pointId, locationName, { this.syncStorageStateToMap(pointId, locationName, {
occupied: !!state.occupied, occupied: !!state.occupied,
locked: !!state.locked locked: !!state.locked,
}); });
}); });
} }
@ -704,15 +717,11 @@ export class StorageLocationService {
*/ */
private getStorageLocationPens(pointId: string, includeMore: boolean = true): MapPen[] { private getStorageLocationPens(pointId: string, includeMore: boolean = true): MapPen[] {
if (!this.editor) return []; if (!this.editor) return [];
const { penTypes, tags } = this.config; const { penTypes, tags } = this.config;
const searchTypes = includeMore const searchTypes = includeMore ? `${penTypes.storageLocation},${penTypes.storageMore}` : penTypes.storageLocation;
? `${penTypes.storageLocation},${penTypes.storageMore}`
: penTypes.storageLocation; return this.editor.find(searchTypes).filter((pen) => pen.tags?.includes(`${tags.pointPrefix}${pointId}`));
return this.editor.find(searchTypes).filter(
(pen) => pen.tags?.includes(`${tags.pointPrefix}${pointId}`)
);
} }
/** /**
@ -723,7 +732,7 @@ export class StorageLocationService {
*/ */
private findStorageLocationPen(pointId: string, locationName: string): MapPen | undefined { private findStorageLocationPen(pointId: string, locationName: string): MapPen | undefined {
return this.getStorageLocationPens(pointId, false).find( return this.getStorageLocationPens(pointId, false).find(
(pen) => pen.storageLocation?.locationName === locationName (pen) => pen.storageLocation?.locationName === locationName,
); );
} }
@ -734,17 +743,16 @@ export class StorageLocationService {
public createAll(): void { public createAll(): void {
if (!this.editor) return; if (!this.editor) return;
this.editor.find(this.config.penTypes.point) this.editor
.filter(pen => pen.point?.type === MapPointType. && pen.point?.associatedStorageLocations?.length) .find(this.config.penTypes.point)
.forEach(pen => { .filter((pen) => pen.point?.type === MapPointType. && pen.point?.associatedStorageLocations?.length)
.forEach((pen) => {
if (pen.id && pen.point?.associatedStorageLocations) { if (pen.id && pen.point?.associatedStorageLocations) {
this.create(pen.id, pen.point.associatedStorageLocations); this.create(pen.id, pen.point.associatedStorageLocations);
} }
}); });
} }
/** /**
* *
*/ */
@ -761,17 +769,17 @@ export class StorageLocationService {
* *
*/ */
export interface StorageLocationState { export interface StorageLocationState {
occupied: boolean occupied: boolean;
locked: boolean locked: boolean;
} }
/** /**
* *
*/ */
export interface StorageLocationUpdate { export interface StorageLocationUpdate {
pointId: string pointId: string;
locationName: string locationName: string;
state: Partial<StorageLocationState> state: Partial<StorageLocationState>;
} }
/** /**
@ -806,7 +814,7 @@ export class StorageLocationUpdater {
update( update(
pointId: string, pointId: string,
updates: string | Record<string, Partial<StorageLocationState>>, updates: string | Record<string, Partial<StorageLocationState>>,
state?: Partial<StorageLocationState> state?: Partial<StorageLocationState>,
): this { ): this {
this.service.update(pointId, updates, state); this.service.update(pointId, updates, state);
return this; return this;
@ -836,12 +844,12 @@ export function createStorageLocationUpdater(service: StorageLocationService): S
/** /**
* *
* *
* @example * @example
* ```typescript * ```typescript
* // 使用默认配置 * // 使用默认配置
* const service = new StorageLocationService(editor, sceneId); * const service = new StorageLocationService(editor, sceneId);
* *
* // 使用自定义配置 * // 使用自定义配置
* const customService = new StorageLocationService(editor, sceneId, { * const customService = new StorageLocationService(editor, sceneId, {
* colors: { * colors: {
@ -857,7 +865,7 @@ export function createStorageLocationUpdater(service: StorageLocationService): S
* defaultInterval: 5 // 自定义监控间隔 * defaultInterval: 5 // 自定义监控间隔
* } * }
* }); * });
* *
* // 运行时更新配置 * // 运行时更新配置
* service.updateConfig({ * service.updateConfig({
* colors: { occupied: '#ff4444' } * colors: { occupied: '#ff4444' }