|
|
@ -1732,17 +1732,18 @@ function getTree1() { |
|
|
orgAndManTree.value = data |
|
|
orgAndManTree.value = data |
|
|
|
|
|
|
|
|
}).finally(()=>{ |
|
|
}).finally(()=>{ |
|
|
console.log(rangedUsers) |
|
|
//console.log(rangedUsers) |
|
|
|
|
|
|
|
|
// 使用示例 |
|
|
// 使用示例 |
|
|
const configArray = rangedUsers; |
|
|
const configArray = rangedUsers; |
|
|
const groupedNames = groupExpandUserConfigs(configArray); |
|
|
const groupedNames = groupExpandUserConfigs(configArray); |
|
|
console.log(groupedNames); |
|
|
//console.log(groupedNames); |
|
|
groupedNames.forEach((element:any) => { |
|
|
groupedNames.forEach((element:any) => { |
|
|
let keys = element.keys |
|
|
let keys = element.keys |
|
|
let arr = [] |
|
|
let arr = [] |
|
|
arr.push(modifyTreeData(orgAndManTree.value,keys)) |
|
|
arr.push(modifyTreeData(orgAndManTree.value,keys)) |
|
|
element.tree = arr |
|
|
element.tree = arr |
|
|
|
|
|
console.log(arr) |
|
|
|
|
|
|
|
|
rangedUsers.forEach((item:any) => { |
|
|
rangedUsers.forEach((item:any) => { |
|
|
let i = 0 |
|
|
let i = 0 |
|
|
@ -1759,17 +1760,26 @@ function getTree1() { |
|
|
rangedUserTrees1.value = rangedUsers |
|
|
rangedUserTrees1.value = rangedUsers |
|
|
}) |
|
|
}) |
|
|
} |
|
|
} |
|
|
|
|
|
function modifyTreeData(treeData, idList) { |
|
|
|
|
|
//console.log("modifyTreeDataMinimal 执行了"); |
|
|
|
|
|
let gkFlag = true |
|
|
|
|
|
const idArray = Array.isArray(idList) ? idList : [idList]; |
|
|
|
|
|
|
|
|
|
|
|
// 当 gkFlag 为 true 且 idList 为空时,查找特定节点作为新的 treeData |
|
|
|
|
|
if (gkFlag && idArray.length === 0) { |
|
|
|
|
|
const targetNode = findTargetNode(treeData); |
|
|
|
|
|
if (targetNode) { |
|
|
|
|
|
// 使用找到的节点作为新的 treeData |
|
|
|
|
|
treeData = targetNode; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 当 idList 为空时,使用相同的处理逻辑,但保持所有节点 |
|
|
|
|
|
if (idArray.length === 0) { |
|
|
|
|
|
return processTreeWithAllNodes(treeData); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!treeData) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function modifyTreeData(treeData, idList) { |
|
|
|
|
|
console.log("modifyTreeDataMinimal 执行了"); |
|
|
|
|
|
|
|
|
|
|
|
const idArray = Array.isArray(idList) ? idList : [idList]; |
|
|
|
|
|
if (idArray.length === 0 || !treeData) { |
|
|
|
|
|
return Array.isArray(treeData) ? [] : null; |
|
|
return Array.isArray(treeData) ? [] : null; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -1786,13 +1796,16 @@ function modifyTreeData(treeData, idList) { |
|
|
const node = stack.pop(); |
|
|
const node = stack.pop(); |
|
|
if (!node?.id) continue; |
|
|
if (!node?.id) continue; |
|
|
|
|
|
|
|
|
nodeMap.set(node.id, node); |
|
|
// 如果节点ID已存在,跳过重复节点 |
|
|
|
|
|
if (!nodeMap.has(node.id)) { |
|
|
|
|
|
nodeMap.set(node.id, node); |
|
|
|
|
|
|
|
|
if (node.children) { |
|
|
if (node.children) { |
|
|
for (const child of node.children) { |
|
|
for (const child of node.children) { |
|
|
if (child?.id) { |
|
|
if (child?.id) { |
|
|
parentMap.set(child.id, node.id); |
|
|
parentMap.set(child.id, node.id); |
|
|
stack.push(child); |
|
|
stack.push(child); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
@ -1831,6 +1844,29 @@ function modifyTreeData(treeData, idList) { |
|
|
return Array.isArray(treeData) ? result : result[0] || null; |
|
|
return Array.isArray(treeData) ? result : result[0] || null; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 辅助函数:查找特定条件的节点 |
|
|
|
|
|
function findTargetNode(treeData) { |
|
|
|
|
|
if (!treeData) return null; |
|
|
|
|
|
|
|
|
|
|
|
const stack = Array.isArray(treeData) ? [...treeData] : [treeData]; |
|
|
|
|
|
|
|
|
|
|
|
while (stack.length > 0) { |
|
|
|
|
|
const node = stack.pop(); |
|
|
|
|
|
|
|
|
|
|
|
// 检查节点是否符合条件 |
|
|
|
|
|
if (node.id === "309" && node.label === "山东恒信高科能源有限公司") { |
|
|
|
|
|
return node; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 继续遍历子节点 |
|
|
|
|
|
if (node.children && node.children.length > 0) { |
|
|
|
|
|
stack.push(...node.children); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return null; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// 辅助函数:递归构建节点树 |
|
|
// 辅助函数:递归构建节点树 |
|
|
function buildNodeTree(node, keepIds, idArray, processedIds) { |
|
|
function buildNodeTree(node, keepIds, idArray, processedIds) { |
|
|
const newNode = { |
|
|
const newNode = { |
|
|
@ -1848,9 +1884,11 @@ function buildNodeTree(node, keepIds, idArray, processedIds) { |
|
|
// 处理子节点 |
|
|
// 处理子节点 |
|
|
if (node.children && node.children.length > 0) { |
|
|
if (node.children && node.children.length > 0) { |
|
|
const children = []; |
|
|
const children = []; |
|
|
|
|
|
const childProcessedIds = new Set(); // 用于子节点的去重 |
|
|
|
|
|
|
|
|
for (const child of node.children) { |
|
|
for (const child of node.children) { |
|
|
if (child?.id && keepIds.has(child.id) && !processedIds.has(child.id)) { |
|
|
if (child?.id && keepIds.has(child.id) && !childProcessedIds.has(child.id)) { |
|
|
processedIds.add(child.id); |
|
|
childProcessedIds.add(child.id); |
|
|
children.push(buildNodeTree(child, keepIds, idArray, processedIds)); |
|
|
children.push(buildNodeTree(child, keepIds, idArray, processedIds)); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
@ -1862,8 +1900,84 @@ function buildNodeTree(node, keepIds, idArray, processedIds) { |
|
|
return newNode; |
|
|
return newNode; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 当 idList 为空时处理树数据,使用与不为空时相同的格式化逻辑 |
|
|
|
|
|
function processTreeWithAllNodes(treeData) { |
|
|
|
|
|
if (!treeData) { |
|
|
|
|
|
return Array.isArray(treeData) ? [] : null; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const roots = Array.isArray(treeData) ? treeData : [treeData]; |
|
|
|
|
|
|
|
|
|
|
|
// 构建结果树 - 使用与不为空时相同的逻辑,但应用到所有节点 |
|
|
|
|
|
const result = []; |
|
|
|
|
|
const processedIds = new Set(); |
|
|
|
|
|
|
|
|
|
|
|
// 处理所有根节点 |
|
|
|
|
|
for (const root of roots) { |
|
|
|
|
|
if (!root?.id || processedIds.has(root.id)) { |
|
|
|
|
|
continue; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
processedIds.add(root.id); |
|
|
|
|
|
// 使用相同的格式化逻辑,但应用到所有节点,并过滤没有用户的组织节点 |
|
|
|
|
|
const formattedNode = formatAllNodes(root, processedIds); |
|
|
|
|
|
if (formattedNode) { |
|
|
|
|
|
result.push(formattedNode); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 清理临时数据 |
|
|
|
|
|
processedIds.clear(); |
|
|
|
|
|
|
|
|
|
|
|
return Array.isArray(treeData) ? result : result[0] || null; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 递归格式化所有节点,保持与非空时相同的格式,并过滤没有用户的组织节点 |
|
|
|
|
|
function formatAllNodes(node, processedIds) { |
|
|
|
|
|
// 判断是否为组织节点(ID长度小于5) |
|
|
|
|
|
const isOrganization = node.id && node.id.length < 5; |
|
|
|
|
|
|
|
|
|
|
|
// 处理子节点 |
|
|
|
|
|
let children = []; |
|
|
|
|
|
const childProcessedIds = new Set(); |
|
|
|
|
|
|
|
|
|
|
|
if (node.children && node.children.length > 0) { |
|
|
|
|
|
for (const child of node.children) { |
|
|
|
|
|
if (child?.id && !childProcessedIds.has(child.id)) { |
|
|
|
|
|
childProcessedIds.add(child.id); |
|
|
|
|
|
const formattedChild = formatAllNodes(child, processedIds); |
|
|
|
|
|
if (formattedChild) { |
|
|
|
|
|
children.push(formattedChild); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 如果是组织节点且没有用户子节点,则过滤掉 |
|
|
|
|
|
if (isOrganization && children.length === 0) { |
|
|
|
|
|
return null; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 对所有节点应用相同的格式化逻辑 |
|
|
|
|
|
const newNode = { |
|
|
|
|
|
id: node.id, |
|
|
|
|
|
label: node.label, |
|
|
|
|
|
value: node.value |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
// 对所有节点应用相同的标签格式化 |
|
|
|
|
|
if (node.value !== null && node.value !== undefined) { |
|
|
|
|
|
newNode.label = `${node.label}(${node.value})`; |
|
|
|
|
|
newNode.number = newNode.label; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 如果有子节点,添加子节点 |
|
|
|
|
|
if (children.length > 0) { |
|
|
|
|
|
newNode.children = children; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return newNode; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
function groupExpandUserConfigs(configs) { |
|
|
function groupExpandUserConfigs(configs) { |
|
|
// 用于存储分组结果的Map |
|
|
// 用于存储分组结果的Map |
|
|
@ -2023,7 +2137,7 @@ const resetFields = () => { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function checkAndGetTree(){ |
|
|
function checkAndGetTree(){ |
|
|
console.log("checkAndGetTree") |
|
|
//console.log("checkAndGetTree") |
|
|
if(rangedUsers.length>0){ |
|
|
if(rangedUsers.length>0){ |
|
|
getTree1(); |
|
|
getTree1(); |
|
|
}else{ |
|
|
}else{ |
|
|
|