Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
D
dsk-operate-sys-cscec
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
fulixin
dsk-operate-sys-cscec
Commits
3f5debd4
Commit
3f5debd4
authored
Dec 15, 2023
by
tyn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
🎈
perf(根据 节点数组 重新生成直系关系树):
parent
b189c987
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
92 additions
and
1 deletion
+92
-1
index.js
dsk-operate-ui/src/utils/index.js
+92
-1
No files found.
dsk-operate-ui/src/utils/index.js
View file @
3f5debd4
...
...
@@ -644,6 +644,9 @@ export function getTreeSelectAreaList(node, tree) {
// 查找到
if
(
nodeAncestors
)
{
console
.
log
(
nodeAncestors
);
// 找父节点 拿到父节点的child 数量 跟 length 没有父节点 就是顶级节点
const
parent
=
findParentNode
(
nodeAncestors
,
node
.
value
,
"value"
);
console
.
log
(
parent
);
}
}
}
...
...
@@ -655,6 +658,34 @@ export function getTreeSelectAreaList(node, tree) {
}
}
/**
* 根据节点 id 获取父节点
* @param {*} tree
* @param {*} targetId
* @param {*} parentNode
* @returns
*/
export
function
findParentNode
(
tree
,
targetId
,
idKey
=
"id"
,
parentNode
=
null
)
{
if
(
tree
[
idKey
]
===
targetId
)
{
// 找到目标节点,返回其父节点
return
parentNode
;
}
if
(
tree
?.
children
?.
length
)
{
for
(
const
child
of
tree
.
children
)
{
const
result
=
findParentNode
(
child
,
targetId
,
idKey
,
tree
);
if
(
result
)
{
// 如果找到目标节点,返回其父节点
return
result
;
}
}
}
// 如果未找到目标节点,返回 null
return
null
;
}
/**
* 根据节点信息 找到当前节点到祖先辈组成的树形结构
* @param {*} tree
...
...
@@ -664,7 +695,7 @@ export function getTreeSelectAreaList(node, tree) {
export
function
findNodeAndAncestors
(
tree
,
targetId
,
idKey
=
"id"
,
directAncestorsOnly
=
true
)
{
if
(
tree
[
idKey
]
===
targetId
)
{
// 找到目标节点,directAncestorsOnly 只找直系节点的情况下 如果是根节点(没有parent父级),返回节点本身不带子节点,否则返回节点的树形结构
return
directAncestorsOnly
&&
!
tree
.
parent
?
{
...
tree
,
children
:
[]
}
:
tree
;
return
directAncestorsOnly
&&
!
tree
.
parent
?
{
...
tree
,
children
:
null
}
:
tree
;
}
if
(
tree
?.
children
?.
length
)
{
...
...
@@ -716,6 +747,66 @@ export function findNodeFromTree(tree, targetId, idKes = "id") {
return
null
;
}
/**
* 删除某个属性节点
* @param node
*/
export
function
removeAncestors
(
node
,
removeKey
=
"ancestors"
)
{
delete
node
[
removeKey
];
for
(
const
child
of
node
.
children
)
{
removeAncestors
(
child
,
removeKey
);
}
}
/**
* 根据id 数组 生成直系关系树形结构 并排除不需要的属性
* @param tree
* @param targetIds
* @returns
*/
export
function
generateDirectSubtreeAndRemove
(
tree
,
targetIds
)
{
const
findNodeById
=
(
node
,
id
,
ancestors
=
[])
=>
{
if
(
node
.
id
===
id
)
{
return
{
...
node
,
ancestors
};
}
for
(
const
child
of
node
.
children
)
{
const
foundNode
=
findNodeById
(
child
,
id
,
[...
ancestors
,
node
]);
if
(
foundNode
)
{
return
foundNode
;
}
}
return
null
;
};
const
result
=
{
...
tree
,
children
:
[]
};
for
(
const
targetId
of
targetIds
)
{
const
targetNode
=
findNodeById
(
tree
,
targetId
);
if
(
targetNode
)
{
// Include the target node and its ancestors in the result
let
currentNode
=
result
;
for
(
const
ancestor
of
targetNode
.
ancestors
)
{
const
existingNode
=
currentNode
.
children
.
find
((
child
)
=>
child
.
id
===
ancestor
.
id
);
if
(
existingNode
)
{
currentNode
=
existingNode
;
}
else
{
const
newNode
=
{
...
ancestor
,
children
:
[]
};
currentNode
.
children
.
push
(
newNode
);
currentNode
=
newNode
;
}
}
// Add the target node to the result
currentNode
.
children
.
push
({
...
targetNode
,
children
:
[]
});
}
}
// Remove the ancestors property from the result
removeAncestors
(
result
);
return
result
.
children
;
// Return only the direct children of the new root
}
// 甲方详情左侧菜单映射
export
const
detailSideBar
=
new
Map
([
// 企业速览
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment