| | |
| | | .map(id => Number(id)) |
| | | .filter(id => !existingIds.has(id)); |
| | | |
| | | // 为新增的ID创建排序项(默认排序为已有最大排序值+1) |
| | | // 为新增的ID创建排序项(默认排序从库区的 sort 字段获取,如果没有则使用已有最大排序值+1) |
| | | const maxSort = existingAreas.length > 0 |
| | | ? Math.max(...existingAreas.map(item => item.sort || 1), 0) |
| | | : 0; |
| | | const newItems = newIds.map((id, index) => ({ |
| | | const newItems = newIds.map((id, index) => { |
| | | // 从 areas 数组中查找对应库区的 sort 字段 |
| | | const area = areas.find(a => a.id === id); |
| | | const defaultSort = area && area.sort !== undefined && area.sort !== null |
| | | ? area.sort |
| | | : (maxSort + index + 1); |
| | | return { |
| | | id: id, |
| | | sort: maxSort + index + 1, |
| | | })); |
| | | sort: defaultSort, |
| | | }; |
| | | }); |
| | | |
| | | // 合并已有项和新项 |
| | | const converted = [...existingAreas, ...newItems]; |