mirror of
https://github.com/babalae/bettergi-scripts-list.git
synced 2026-04-04 06:46:19 +08:00
refactor(FullyAutoAndSemiAutoTools): 优化键值生成逻辑
- 修改 generatedKey 函数支持 useParent 参数控制键值生成方式 - 优先处理 rootName->parentName->name 格式的键值生成 - 添加 useParent 模式下的父级键值生成逻辑 - 在 groupByParentAndName 函数中同时生成普通键值和父级键值 - 为每个项目创建两套分组键值以支持不同层级的分组需求
This commit is contained in:
@@ -699,25 +699,32 @@ async function initRun(config_run) {
|
||||
|
||||
// const {label} = multiCheckboxMap.get(settingsName);
|
||||
// const as_name = getBracketContent(label)//父名称 如:晶蝶
|
||||
function generatedKey(item) {
|
||||
function generatedKey(item, useParent = false) {
|
||||
const separator = "->";
|
||||
if (item.parentName) {
|
||||
if (item.rootName && item.parentName !== item.rootName) {
|
||||
return `${item.rootName}${separator}${item.parentName}${separator}${item.name}`;
|
||||
}
|
||||
// 优先处理 rootName->parentName->name 格式的情况
|
||||
if (!useParent && item.rootName && item.parentName && item.parentName !== item.rootName && item.rootName !== "") {
|
||||
return `${item.rootName}${separator}${item.parentName}${separator}${item.name}`;
|
||||
}
|
||||
// 然后处理 useParent 或 parentName 存在的情况
|
||||
if (useParent || item.parentName) {
|
||||
return `${item.parentName}${separator}${item.name}`;
|
||||
}
|
||||
// 默认返回 name
|
||||
return item.name;
|
||||
}
|
||||
|
||||
|
||||
function groupByParentAndName(list) {
|
||||
const map = new Map();
|
||||
|
||||
list.forEach(item => {
|
||||
// const key = `${item.parentName}->${item.name}`;
|
||||
const key = generatedKey(item);
|
||||
const key_parent = generatedKey(item, true);
|
||||
if (!map.has(key)) map.set(key, []);
|
||||
map.get(key).push(item);
|
||||
if (!map.has(key_parent)) map.set(key_parent, []);
|
||||
map.get(key_parent).push(item);
|
||||
});
|
||||
|
||||
return Array.from(map.values()); // 转成二维数组 [[], []]
|
||||
|
||||
Reference in New Issue
Block a user