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 98694301
authored
Oct 29, 2021
by
胡悦
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
权限树组件提交
1 parent
4e7b7e95
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
253 additions
and
66 deletions
src/views/home/components/selectProduct.vue
src/views/home/components/selectProduct.vue
View file @
9869430
...
...
@@ -2,117 +2,292 @@
<div
class=
"account-body scrm-box-f"
>
<div
class=
"account-title"
>
功能权限
</div>
<el-tabs
v-model=
"tabName"
type=
"card"
>
<el-tab-pane
:label=
"item.accounttypeName"
:name=
"item.accounttypeId"
v-for=
"(item, index) in tabMenu"
:key=
"index"
></el-tab-pane>
<el-tab-pane
:label=
"item.accounttypeName"
:name=
"item.accounttypeId"
v-for=
"(item, index) in tabMenu"
:key=
"index"
></el-tab-pane>
</el-tabs>
<div
class=
"account-select-pro"
v-for=
"(item, index) in tabMenu"
:key=
"index"
v-show=
"tabName == item.accounttypeId"
>
<div
class=
"account-select-pro"
v-for=
"(item, index) in tabMenu"
:key=
"index"
v-show=
"tabName == item.accounttypeId"
>
<label>
选择产品
</label>
<el-checkbox-group
v-model=
"item.productsArr"
@
change=
"selectPro(index)"
>
<el-checkbox
v-for=
"(itm, idx) in item.products"
:label=
"itm.productName"
:key=
"idx"
></el-checkbox>
<el-checkbox-group
v-model=
"item.productsArr"
@
change=
"selectPro"
>
<el-checkbox
v-for=
"(itm, idx) in item.products"
:label=
"itm"
:key=
"idx"
>
{{
itm
.
productName
}}
</el-checkbox>
</el-checkbox-group>
</div>
<div
class=
"account-select-menu"
>
请选择产品权限
</div>
<div
class=
"menu-box"
>
<div
:key=
"index"
v-for=
"(item, index) in tabMenu"
>
<div
class=
"menu-box-tab"
v-show=
"tabName == item.accounttypeId"
>
<div
class=
"tab-item text-hide"
v-for=
"(itm, idx) in item.productsArr"
:key=
"idx"
>
{{
itm
}}
<div
class=
"menu-box-panel"
>
<div
:key=
"index"
v-for=
"(item, index) in tabMenu"
>
<div
class=
"menu-box-tab"
v-show=
"tabName == item.accounttypeId"
>
<div
v-show=
"item.productsArr.indexOf(itm) != -1"
class=
"tab-item text-hide"
:class=
"
{ 'select-checked': productTab == itm.productId }" @click="productClick(itm.productId)" v-for="(itm, idx) in item.products" :key="idx">
{{
itm
.
productName
}}
</div>
</div>
<div
v-show=
"tabName == item.accounttypeId"
class=
"menu-box-tree"
v-if=
"item.products"
:style=
"
{ 'min-height': treeHeight + 'px' }">
<div
v-for=
"(itm, idx) in item.products"
:key=
"idx"
>
<el-tree
v-show=
"productTab == itm.productId"
:data=
"itm.merchantProTreeResponses"
show-checkbox
check-strictly
check-on-click-node
:expand-on-click-node=
"false"
default-expand-all
node-key=
"id"
:class=
"'tree_' + item.accounttypeId + '_' + itm.productId"
:ref=
"`tree_$
{item.accounttypeId}_${itm.productId}`" highlight-current :render-content="renderContent" :props="defaultProps" @check="clickDeal">
</el-tree>
</div>
</div>
</div>
</div>
<div
v-if=
"item.products[0]"
class=
"menu-box-tree"
v-show=
"tabName == item.accounttypeId && item.productsArr.indexOf(item.accounttypeName) != -1"
>
<el-tree
:data=
"item.products[0].merchantProTreeResponses"
show-checkbox
default-expand-all
node-key=
"id"
ref=
"brandTree"
highlight-current
:props=
"defaultProps"
>
</el-tree>
</div>
</div>
</div>
<button
@
click=
"getSelectInfo"
>
tijiao
</button>
</div>
</
template
>
<
script
>
export
default
{
name
:
"product"
,
name
:
'product'
,
props
:
{
parentId
:
{
type
:
Number
,
type
:
Number
},
pId
:
{
type
:
Number
,
type
:
Number
},
accountlevel
:
{
type
:
Number
,
}
,
type
:
Number
}
},
data
()
{
return
{
treeHeight
:
300
,
tabMenu
:
[],
selectIndex
:
0
,
productId
:
0
,
products
:
[],
productsArr
:
[],
tabName
:
""
,
defaultProps
:
{
children
:
"children"
,
label
:
"label"
,
tabName
:
''
,
productTab
:
''
,
defaultProps
:
{
children
:
'children'
,
label
:
'label'
},
};
accountTypes
:
[]
}
},
methods
:
{
selectPro
()
{},
findPermissionsByMerId
()
{
selectPro
(
data
)
{
this
.
productTab
=
data
.
length
!=
0
?
data
[
data
.
length
-
1
].
productId
:
''
const
{
tabName
,
tabMenu
,
productTab
}
=
this
console
.
log
(
tabName
,
data
)
// 设置全选
var
arr
=
tabMenu
.
find
(
i
=>
i
.
accounttypeId
==
tabName
).
products
.
find
(
j
=>
j
.
productId
==
productTab
).
merchantProTreeResponses
this
.
$refs
[
`tree_
${
tabName
}
_
${
productTab
}
`
][
0
].
setCheckedKeys
(
this
.
getAllId
(
arr
))
console
.
log
(
tabMenu
)
},
productClick
(
productId
)
{
this
.
productTab
=
productId
},
// 获取当前的所有权限
findMenuFunTreeByMerId
()
{
let
params
=
{
accountlevel
:
2
,
parentId
:
41513
,
id
:
41555
,
};
this
.
$apis
.
store
.
findMenuFunTreeByMerId
(
params
).
then
((
res
)
=>
{
this
.
tabMenu
=
res
.
map
((
item
)
=>
{
accountlevel
:
4
,
parentId
:
41380
,
id
:
41588
}
this
.
$apis
.
store
.
findMenuFunTreeByMerId
(
params
).
then
(
res
=>
{
this
.
tabMenu
=
res
.
map
(
item
=>
{
console
.
log
(
item
)
return
{
productsArr
:
[],
products
:
item
.
products
,
accounttypeName
:
item
.
accounttypeName
,
accounttypeId
:
item
.
accounttypeId
,
};
});
this
.
tabName
=
this
.
tabMenu
[
0
].
accounttypeId
;
});
// merchantProTreeResponses: item.merchantProTreeResponses,
// productId: ''
}
})
this
.
$nextTick
(()
=>
{
this
.
addStyle
()
})
console
.
log
(
this
.
tabMenu
)
this
.
accountTypes
=
res
.
map
(
item
=>
{
return
{
products
:
null
,
accounttypeId
:
item
.
accounttypeId
}
})
this
.
tabName
=
this
.
tabMenu
[
0
].
accounttypeId
})
},
// 获取已选择的权限
findPermissionsByMerId
()
{
const
params
=
{
id
:
41588
}
this
.
$apis
.
store
.
findPermissionsByMerId
(
params
).
then
(
res
=>
{
console
.
log
(
res
)
res
.
map
(
i
=>
{
console
.
log
(
i
,
this
.
tabMenu
.
find
(
j
=>
j
.
accounttypeId
==
i
.
accounttypeId
))
// i.productsArr = this.tabMenu.find(j => j.accounttypeId == i.accounttypeId).products
})
})
},
// 渲染树结构
renderContent
(
h
,
v
)
{
if
(
v
.
data
.
logo
==
'functionValue'
)
{
return
(
<
div
class
=
"custom-tree-node fun-tree-node"
>
<
span
>
{
v
.
node
.
label
}
<
/span
>
<
/div
>
)
}
else
{
return
(
<
div
class
=
"custom-tree-node"
>
<
span
>
{
v
.
node
.
label
}
<
/span
>
<
/div
>
)
}
},
addStyle
()
{
const
nodes
=
document
.
getElementsByClassName
(
'fun-tree-node'
)
for
(
let
i
=
0
;
i
<
nodes
.
length
;
i
++
)
{
const
parentNode
=
nodes
[
i
].
parentNode
parentNode
.
style
.
float
=
'left'
}
},
clickDeal
(
currentObj
,
treeStatus
)
{
// 用于:父子节点严格互不关联时,父节点勾选变化时通知子节点同步变化,实现单向关联。
let
selected
=
treeStatus
.
checkedKeys
.
indexOf
(
currentObj
.
id
)
// -1未选中
// 选中
if
(
selected
!==
-
1
)
{
// 子节点只要被选中父节点就被选中
this
.
selectedParent
(
currentObj
)
// 统一处理子节点为相同的勾选状态
this
.
uniteChildSame
(
currentObj
,
true
)
}
else
{
// 未选中 处理子节点全部未选中
console
.
log
(
currentObj
)
if
(
currentObj
.
children
!==
null
)
{
if
(
currentObj
.
children
.
length
!==
0
)
{
this
.
uniteChildSame
(
currentObj
,
false
)
}
//放开时为当子节点全为未选中时父节点也变为未选中状态 注释后就是父节点不和子节点强制绑定
// this.uniteParentSame(currentObj.id,treeStatus)//当子节点全为未选中时父节点也变为未选中状态
}
// else {
// this.uniteParentSame(currentObj.id,treeStatus)
// }
}
},
uniteParentSame
(
id
,
treeStatus
)
{
//当子节点全为未选中时父节点也变为未选中状态
const
tree_ref
=
`tree_
${
this
.
tabName
}
_
${
this
.
productTab
}
`
let
node
=
this
.
$refs
[
tree_ref
][
0
].
getNode
(
id
)
//获取当前节点的节点树
if
(
node
.
parent
!==
null
&&
node
.
parent
!==
undefined
)
{
let
parentNode
=
node
.
parent
.
data
//获取当前节点的父节点树
if
(
parentNode
!=
undefined
)
{
//判断父节点是否存在
for
(
let
i
=
0
;
i
<
parentNode
.
children
.
length
;
i
++
)
{
let
checkedKeys
=
this
.
$refs
[
tree_ref
][
0
].
getCheckedKeys
()
let
hafCheckedKeys
=
this
.
$refs
[
tree_ref
][
0
].
getHalfCheckedKeys
()
let
selectNodes
=
checkedKeys
.
concat
(
hafCheckedKeys
)
//获取已选择树节点
let
selected
=
selectNodes
.
indexOf
(
parentNode
.
children
[
i
].
id
)
// -1当前节点的同级节点是否全部未选中
if
(
selected
!==
-
1
)
{
return
}
}
}
else
{
return
}
this
.
$refs
[
tree_ref
][
0
].
setChecked
(
parentNode
.
id
,
false
)
//修改节点为未选择
if
(
node
.
level
>
2
)
{
//判断是否是最上级节点
this
.
uniteParentSame
(
parentNode
.
id
,
treeStatus
)
}
}
else
{
return
}
},
// 统一处理子节点为相同的勾选状态
uniteChildSame
(
treeList
,
isSelected
)
{
const
tree_ref
=
`tree_
${
this
.
tabName
}
_
${
this
.
productTab
}
`
this
.
$refs
[
tree_ref
][
0
].
setChecked
(
treeList
.
id
,
isSelected
)
console
.
log
(
treeList
)
if
(
treeList
.
children
!==
null
)
{
for
(
let
i
=
0
;
i
<
treeList
.
children
.
length
;
i
++
)
{
this
.
uniteChildSame
(
treeList
.
children
[
i
],
isSelected
)
}
}
},
// 统一处理父节点为选中
selectedParent
(
currentObj
)
{
const
tree_ref
=
`tree_
${
this
.
tabName
}
_
${
this
.
productTab
}
`
let
currentNode
=
this
.
$refs
[
tree_ref
][
0
].
getNode
(
currentObj
)
if
(
currentNode
.
parent
.
key
!==
undefined
)
{
this
.
$refs
[
tree_ref
][
0
].
setChecked
(
currentNode
.
parent
,
true
)
this
.
selectedParent
(
currentNode
.
parent
)
}
},
// 获取所有节点的id
getAllId
(
data
,
arr
=
[])
{
if
(
data
)
{
data
.
forEach
(
item
=>
{
arr
.
push
(
item
.
id
)
if
(
item
.
children
&&
item
.
children
.
length
!=
0
)
{
item
.
children
.
forEach
(
i
=>
{
arr
.
push
(
i
.
id
)
this
.
getAllId
(
i
.
children
,
arr
)
})
}
})
}
return
arr
},
getSelectInfo
()
{
this
.
accountTypes
=
this
.
tabMenu
.
map
(
item
=>
{
let
products
=
[]
item
.
productsArr
.
forEach
(
itm
=>
{
const
checkedNodes
=
this
.
$refs
[
`tree_
${
item
.
accounttypeId
}
_
${
itm
.
productId
}
`
]
?
this
.
$refs
[
`tree_
${
item
.
accounttypeId
}
_
${
itm
.
productId
}
`
][
0
].
getCheckedNodes
()
:
[]
console
.
log
(
checkedNodes
)
const
menuIdList
=
checkedNodes
.
filter
(
item
=>
item
.
logo
===
'menu'
).
map
(
i
=>
i
.
id
)
// 全选菜单idlist
// const partSelectList = halfCheckedNodes.filter(item => item.logo === 'menu').map(i => i.id) // 半选菜单idlist
const
functionIdList
=
checkedNodes
.
filter
(
item
=>
item
.
logo
===
'function'
)
const
functionValueIdLists
=
checkedNodes
.
filter
(
item
=>
item
.
logo
===
'functionValue'
)
var
list
=
[]
/** { menuId, id, functionValue} */
if
(
functionValueIdLists
.
length
!==
0
)
{
functionValueIdLists
.
forEach
((
j
,
index
)
=>
{
if
(
list
.
map
(
item
=>
item
.
id
).
includes
(
j
.
parentId
))
{
const
obj
=
list
.
find
(
k
=>
k
.
id
===
j
.
parentId
)
obj
.
functionValue
+=
';'
+
j
.
id
+
':'
+
j
.
label
}
else
{
list
.
push
({
id
:
j
.
parentId
,
menuId
:
j
.
superParentId
,
functionValue
:
j
.
id
+
':'
+
j
.
label
})
}
})
}
console
.
log
(
menuIdList
,
functionIdList
,
functionValueIdLists
,
list
)
products
.
push
({
productId
:
itm
.
productId
,
functionIds
:
functionIdList
,
functionValue
:
list
,
menuIds
:
menuIdList
})
})
return
{
accounttypeId
:
item
.
accounttypeId
,
products
}
})
console
.
log
(
this
.
accountTypes
)
}
},
mounted
()
{
this
.
findPermissionsByMerId
();
},
};
</
script
>
this
.
findMenuFunTreeByMerId
()
this
.
findPermissionsByMerId
()
}
}
</
script
>
<
style
scoped
lang=
"scss"
>
.account-body
{
padding
:
20px
;
margin-bottom
:
50px
;
.account-title
{
font-size
:
20px
;
font-weight
:
600
;
...
...
@@ -153,10 +328,22 @@ export default {
font-size
:
14px
;
line-height
:
14px
;
font-weight
:
400
;
color
:
#3
22ad9
;
color
:
#3
7383a
;
text-align
:
center
;
padding
:
12px
0px
;
cursor
:
pointer
;
&.select-checked
{
color
:
#322ad9
;
font-weight
:
700
;
border-bottom
:
none
;
}
}
.menu-box-tab
{
display
:
flex
;
}
.menu-box-tree
{
background
:
#ffffff
;
}
}
}
</
style
>
\ No newline at end of file
</
style
>
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