diff --git a/src/components/card/point-edit-card.vue b/src/components/card/point-edit-card.vue index 1e10c72..d3c868f 100644 --- a/src/components/card/point-edit-card.vue +++ b/src/components/card/point-edit-card.vue @@ -66,10 +66,42 @@ const actions = computed( const coArea1 = computed(() => editor.value.getBoundAreas(props.id, 'point', MapAreaType.库区)); const coArea2 = computed(() => editor.value.getBoundAreas(props.id, 'point', MapAreaType.互斥区)); +// 生成默认库位名称 function onAddLocation() { const p = point.value!; if (!p.associatedStorageLocations) p.associatedStorageLocations = []; - p.associatedStorageLocations.push(''); + + // 获取动作点名称(去掉前缀,如 "AP1" -> "AP1") + const pointName = pen.value?.label || ''; + + // 生成默认库位名称 + const generateDefaultLocationName = (): string => { + const existingLocations = p.associatedStorageLocations || []; + const prefix = `${pointName}_`; + + // 找出已存在的符合格式的库位编号 + const existingNumbers = new Set(); + existingLocations.forEach((location) => { + if (location.startsWith(prefix)) { + const suffix = location.substring(prefix.length); + const num = parseInt(suffix, 10); + if (!isNaN(num) && suffix === num.toString().padStart(2, '0')) { + existingNumbers.add(num); + } + } + }); + + // 找到第一个未使用的编号 + let nextNumber = 1; + while (existingNumbers.has(nextNumber)) { + nextNumber++; + } + + return `${prefix}${nextNumber.toString().padStart(2, '0')}`; + }; + + const defaultName = generateDefaultLocationName(); + p.associatedStorageLocations.push(defaultName); editor.value.updatePen(props.id!, { point: { ...p } }, false); } function onRemoveLocation(i: number) {