feat: 添加生成默认库位名称功能,优化存储位置管理逻辑

This commit is contained in:
xudan 2025-07-30 11:46:15 +08:00
parent d17ce3a8f6
commit 0ce15e11d2

View File

@ -66,10 +66,42 @@ const actions = computed<MapPen[]>(
const coArea1 = computed<MapPen[]>(() => editor.value.getBoundAreas(props.id, 'point', MapAreaType.库区));
const coArea2 = computed<MapPen[]>(() => 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<number>();
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) {