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
1bad1714
Commit
1bad1714
authored
Dec 17, 2023
by
tyn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
三级联动下拉 传递父级 递归处理
parent
3f5debd4
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
74 additions
and
46 deletions
+74
-46
index.js
dsk-operate-ui/src/utils/index.js
+71
-42
detailsOfCooperation.vue
...components/EnterpriseList/detail/detailsOfCooperation.vue
+3
-4
No files found.
dsk-operate-ui/src/utils/index.js
View file @
1bad1714
...
...
@@ -629,33 +629,70 @@ export function queryConditionFiltering(params) {
* @param {Array<object>} selectList
* @returns
*/
export
function
getTreeSelectAreaList
(
node
,
tree
)
{
export
function
getTreeSelectAreaList
(
nodeList
=
[],
tree
,
idkey
=
"id"
)
{
try
{
if
(
Object
.
prototype
.
toString
.
call
(
node
)
!=
"[object Object]"
)
throw
new
Error
(
"传入参数不是一个对象
"
);
if
(
Object
.
prototype
.
toString
.
call
(
node
List
)
!=
"[object Array]"
)
throw
new
Error
(
"传入参数不是一个节点数组
"
);
const
_result
=
[];
// 克隆源数据
const
_tempTree
=
JSON
.
parse
(
JSON
.
stringify
(
tree
));
// 根据所选节点生成tree
const
newTree
=
generateDirectSubtreeAndRemove
(
nodeList
,
_tempTree
,
idkey
);
if
(
newTree
)
{
// 循环找到每个节点的父节点 的选中状态
return
findParentStatus
(
nodeList
,
newTree
,
idkey
);
}
// 多树形结构
if
(
Object
.
prototype
.
toString
.
call
(
_tempTree
)
==
"[object Array]"
)
{
if
(
_tempTree
.
length
)
{
for
(
const
iterator
of
_tempTree
)
{
const
nodeAncestors
=
findNodeAndAncestors
(
iterator
,
node
.
value
,
"value"
);
// 查找到
if
(
nodeAncestors
)
{
console
.
log
(
nodeAncestors
);
// 找父节点 拿到父节点的child 数量 跟 length 没有父节点 就是顶级节点
const
parent
=
findParentNode
(
nodeAncestors
,
node
.
value
,
"value"
);
console
.
log
(
parent
);
}
catch
(
error
)
{
console
.
log
(
error
);
}
}
/**
*
*/
export
function
findParentStatus
(
nodeList
,
tree
,
idkey
)
{
const
_temp
=
nodeList
.
map
(
item
=>
{
// 找节点parent
const
parent
=
findParentNode
(
tree
,
item
,
idkey
);
// 有parent
if
(
parent
)
{
const
count
=
parent
.
childrenLength
;
const
len
=
parent
.
children
?.
length
;
// 比较 count 跟 length 看子节点是否全选中
const
flag
=
count
==
len
&&
parent
.
children
?.
every
(
childItem
=>
nodeList
.
includes
(
childItem
[
idkey
]))
?
true
:
false
;
// flag为true 当前节点下的子节点全选中返回父节点id 没有则是根节点 根节点返回所有child id
if
(
flag
)
{
return
parent
[
idkey
]
?
parent
[
idkey
]
:
parent
.
children
?.
map
(
childItem
=>
childItem
[
idkey
]);
}
else
{
console
.
log
(
"没有全选中"
);
// 没有全选中 看当前子节点是否有选中状态
const
itemNode
=
findNodeFromTree
(
tree
,
item
,
[],
idkey
);
console
.
log
(
itemNode
);
// 当前节点有子节点
if
(
itemNode
?.
children
?.
length
)
{
// 当前节点的子节点选中结果 子节点是全选状态 传递自身 否则传递子节点
const
childResult
=
itemNode
?.
children
?.
every
(
childItem
=>
nodeList
.
includes
(
childItem
[
idkey
]))
&&
itemNode
?.
children
?.
length
==
itemNode
?.
childrenLength
;
if
(
childResult
)
{
return
item
;
}
const
childNodes
=
itemNode
?.
children
?.
filter
(
childItem
=>
nodeList
.
includes
(
childItem
[
idkey
]));
return
childNodes
?
childNodes
.
map
(
childItem
=>
childItem
[
idkey
])
:
[];
}
// 当前节点没有子节点 看父节点是否全选 父节点全选 返回父节点
const
childResult
=
parent
.
children
?.
every
(
childItem
=>
nodeList
.
includes
(
childItem
[
idkey
]))
&&
parent
.
children
?.
length
==
parent
?.
childrenLength
;
if
(
childResult
)
{
return
item
;
}
const
childNodes
=
parent
.
children
?.
filter
(
childItem
=>
nodeList
.
includes
(
childItem
[
idkey
]));
return
childNodes
?
childNodes
.
map
(
childItem
=>
childItem
[
idkey
])
:
[];
}
}
});
// 单树形结构
}
catch
(
error
)
{
console
.
log
(
error
);
}
return
Array
.
from
(
new
Set
(
_temp
.
flat
()));
}
...
...
@@ -726,17 +763,17 @@ export function findNodeAndAncestors(tree, targetId, idKey = "id", directAncesto
* 根据节点唯一标识查找节点信息
* @param {*} tree
* @param {*} targetId
* @param {*} idKe
s
* @param {*} idKe
y
*/
export
function
findNodeFromTree
(
tree
,
targetId
,
idKes
=
"id"
)
{
if
(
tree
[
idKe
s
]
==
targetId
)
{
return
tree
;
export
function
findNodeFromTree
(
tree
,
targetId
,
ancestors
=
[],
idKey
=
"id"
)
{
if
(
tree
[
idKe
y
]
==
targetId
)
{
return
{
...
tree
,
ancestors
}
;
}
if
(
tree
?.
children
?.
length
)
{
for
(
const
child
of
tree
.
children
)
{
// 递归到孙子集查找
const
result
=
findNodeFromTree
(
child
,
targetId
);
const
result
=
findNodeFromTree
(
child
,
targetId
,
[...
ancestors
,
tree
],
idKey
);
if
(
result
)
{
// 如果找到目标节点,返回目标节点
return
result
;
...
...
@@ -761,32 +798,24 @@ export function removeAncestors(node, removeKey = "ancestors") {
/**
* 根据id 数组 生成直系关系树形结构 并排除不需要的属性
* @param tree
* @param targetIds
* @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
;
};
export
function
generateDirectSubtreeAndRemove
(
targetIds
,
tree
,
idKey
=
"id"
)
{
const
result
=
{
...
tree
,
children
:
[]
};
for
(
const
targetId
of
targetIds
)
{
const
targetNode
=
findNodeById
(
tree
,
targetId
);
const
targetNode
=
findNodeFromTree
(
tree
,
targetId
,
[],
idKey
);
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
);
const
existingNode
=
currentNode
.
children
.
find
((
child
)
=>
child
[
idKey
]
===
ancestor
[
idKey
]
);
if
(
existingNode
)
{
currentNode
=
existingNode
;
}
else
{
...
...
@@ -796,15 +825,15 @@ export function generateDirectSubtreeAndRemove(tree, targetIds) {
}
}
//
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
return
result
?
JSON
.
parse
(
JSON
.
stringify
({
...
result
,
children
:
result
.
children
[
0
]?.
children
||
[]
}))
:
null
;
}
// 甲方详情左侧菜单映射
...
...
dsk-operate-ui/src/views/consultingOrgManagement/components/EnterpriseList/detail/detailsOfCooperation.vue
View file @
1bad1714
...
...
@@ -260,10 +260,9 @@ export default {
handleChange
(
params
)
{
const
selectNode
=
this
.
$refs
?.
areaTree
?.
getCheckedNodes
();
if
(
selectNode
?.
length
)
{
const
result
=
selectNode
.
map
(
item
=>
{
return
getTreeSelectAreaList
(
item
,
this
.
areaDataList
);
});
console
.
log
(
result
);
const
nodeValueList
=
selectNode
.
map
(
item
=>
item
.
value
);
console
.
log
(
nodeValueList
);
console
.
log
(
getTreeSelectAreaList
(
nodeValueList
,
{
childrenLength
:
this
.
areaDataList
.
length
,
children
:
this
.
areaDataList
},
"value"
));
}
}
},
...
...
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