feat: 添加生成默认库位名称功能,优化存储位置管理逻辑
This commit is contained in:
parent
d17ce3a8f6
commit
0ce15e11d2
@ -66,10 +66,42 @@ const actions = computed<MapPen[]>(
|
|||||||
const coArea1 = computed<MapPen[]>(() => editor.value.getBoundAreas(props.id, 'point', MapAreaType.库区));
|
const coArea1 = computed<MapPen[]>(() => editor.value.getBoundAreas(props.id, 'point', MapAreaType.库区));
|
||||||
const coArea2 = computed<MapPen[]>(() => editor.value.getBoundAreas(props.id, 'point', MapAreaType.互斥区));
|
const coArea2 = computed<MapPen[]>(() => editor.value.getBoundAreas(props.id, 'point', MapAreaType.互斥区));
|
||||||
|
|
||||||
|
// 生成默认库位名称
|
||||||
function onAddLocation() {
|
function onAddLocation() {
|
||||||
const p = point.value!;
|
const p = point.value!;
|
||||||
if (!p.associatedStorageLocations) p.associatedStorageLocations = [];
|
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);
|
editor.value.updatePen(props.id!, { point: { ...p } }, false);
|
||||||
}
|
}
|
||||||
function onRemoveLocation(i: number) {
|
function onRemoveLocation(i: number) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user