Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
杨明
/
scrm-micro-config
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 5976cb3d
authored
Nov 25, 2021
by
杨北旺
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
角色查看处理树的横向
1 parent
fe1adbde
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
40 additions
and
36 deletions
src/views/role/look.vue
src/views/role/look.vue
View file @
5976cb3
...
...
@@ -123,71 +123,75 @@ export default {
history
.
go
(
-
1
)
},
// 递归:处理某个值
traverse
(
arr
=
[],
count
=
0
)
{
traverse
(
arr
=
[],
count
=
0
)
{
count
++
arr
.
map
(
item
=>
{
if
(
item
.
children
&&
item
.
children
instanceof
Array
)
{
item
.
perms
=
false
this
.
traverse
(
item
.
children
,
count
)
}
else
if
(
!
item
.
children
&&
count
>
2
){
this
.
traverse
(
item
.
children
,
count
)
}
else
if
(
!
item
.
children
&&
count
>
2
)
{
item
.
perms
=
true
}
item
.
count
=
count
return
item
})
return
arr
},
// 继续处理已经处理完的树
toContiuneTree
(
arr
=
[],
count
=
0
,
maxLevel
=
0
)
{
count
++
arr
.
map
(
item
=>
{
if
(
item
.
children
&&
item
.
children
instanceof
Array
)
{
item
.
perms
=
false
this
.
toContiuneTree
(
item
.
children
,
count
,
maxLevel
)
}
else
if
(
!
item
.
children
&&
count
>
maxLevel
-
1
)
{
item
.
perms
=
true
}
item
.
count
=
count
return
item
})
return
arr
},
// 调用此方法去重构树节点
handlerTreeDom
()
{
this
.
newTreeList
=
this
.
traverse
(
this
.
newTreeList
)
// if (this.newTreeList.length) {
// this.newTreeList.map(item => {
// if (item.children) {
// item.children.map(el => {
// if (el.children) {
// el.children.map(ele => {
// if (ele.children) {
// ele.perms = false
// ele.children.map(elel => {
// elel.perms = true
// return elel
// })
// } else {
// ele.perms = true
// }
// return ele
// })
// }
// el.perms = false
// return el
// })
// }
// item.perms = false
// return item
// })
// }
console
.
log
(
this
.
newTreeList
,
'*******'
)
let
temp
=
this
.
flattenDeep
(
this
.
newTreeList
)
let
maxval
=
Math
.
max
.
apply
(
Math
,
temp
.
map
(
item
=>
{
return
item
.
count
})
)
this
.
newTreeList
=
this
.
toContiuneTree
(
this
.
newTreeList
,
0
,
maxval
)
console
.
log
(
this
.
newTreeList
);
this
.
maxval
=
maxval
-
1
this
.
$nextTick
(()
=>
{
this
.
changeTreeClass
()
this
.
changeTreeClass
(
maxval
)
})
},
// 处理树横向
renderContent
(
h
,
{
node
,
data
})
{
let
className
=
''
if
(
data
.
perms
)
{
if
(
data
.
perms
&&
data
.
count
>
this
.
maxval
)
{
className
=
'especially'
}
return
<
div
class
=
{
className
}
>
{
data
.
label
}
<
/div
>
},
// 改变tree节点样式
changeTreeClass
()
{
changeTreeClass
(
maxval
)
{
let
piefix
=
(
maxval
-
1
)
*
20
var
classDomList
=
document
.
getElementsByClassName
(
'especially'
)
for
(
var
i
=
0
;
i
<
classDomList
.
length
;
i
++
)
{
classDomList
[
i
].
parentNode
.
style
.
cssText
=
'float:left'
classDomList
[
i
].
parentNode
.
className
=
'el-tree-node__content option-wrapper'
classDomList
[
i
].
parentNode
.
parentNode
.
parentNode
.
style
.
marginLeft
=
'20px'
//
classDomList[i].parentNode.className = 'el-tree-node__content option-wrapper'
classDomList
[
i
].
parentNode
.
parentNode
.
parentNode
.
style
.
marginLeft
=
`
${
piefix
}
px`
}
},
flattenDeep
(
arr
=
[],
childs
=
'children'
,
pid
=
0
)
{
return
arr
.
reduce
((
flat
,
item
)
=>
{
item
.
pid
=
pid
return
flat
.
concat
(
item
,
item
[
childs
]
?
this
.
flattenDeep
(
item
[
childs
],
childs
,
item
.
id
)
:
[])
},
[])
}
}
}
...
...
Write
Preview
Markdown
is supported
Attach a file
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 post a comment