Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
micro-customization-system
/
system
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 9641032f
authored
Jul 07, 2021
by
胡悦
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
角色管理添加指定数据权限
1 parent
2dfc20f7
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
288 additions
and
142 deletions
src/config/config.js
src/services/role.js
src/utils/constants.js
src/views/role/index.vue
src/config/config.js
View file @
9641032
...
...
@@ -30,7 +30,8 @@ const ROLE_API = {
ROLE_EDIT
:
'/usercenter/role/edit'
,
ROLE_DELETE
:
'/usercenter/role/delete'
,
MENU_TREE
:
'/usercenter/menu/checkedtree'
,
ROLE_VISIBILITY
:
'/usercenter/role/visibility'
ROLE_VISIBILITY
:
'/usercenter/role/visibility'
,
ROLE_PERMISSION
:
'/usercenter/tenant/rolepermission'
}
const
MENU_API
=
{
MENU_SEARCH
:
'/usercenter/menu/search'
,
...
...
src/services/role.js
View file @
9641032
...
...
@@ -48,4 +48,10 @@ function getVisibility (params) {
return
request
(
params
,
url
)
}
export
{
getRoleList
,
roleInfo
,
getTenantList
,
addRole
,
editRole
,
deleteRole
,
getMenuTree
,
getVisibility
}
// 数据权限租户列表接口
function
getPermission
(
params
)
{
const
url
=
ROLE_API
.
ROLE_PERMISSION
return
request
(
params
,
url
)
}
export
{
getRoleList
,
roleInfo
,
getTenantList
,
addRole
,
editRole
,
deleteRole
,
getMenuTree
,
getVisibility
,
getPermission
}
src/utils/constants.js
View file @
9641032
...
...
@@ -10,8 +10,35 @@ const Constants = {
'1'
:
'本人及下属'
,
'2'
:
'本人部门'
,
'3'
:
'本部门及下级部门'
,
'6'
:
'指定数据权限'
,
'4'
:
'全部'
},
ROLEAUTH_LIST
:
[
{
label
:
'本人'
,
value
:
0
},
{
label
:
'本人及下属'
,
value
:
1
},
{
label
:
'本人部门'
,
value
:
2
},
{
label
:
'本部门及下级部门'
,
value
:
3
},
{
label
:
'指定数据权限'
,
value
:
6
},
{
label
:
'全部'
,
value
:
4
}
],
// 租户可见度
ROLE_VISIBLE
:
{
0
:
'共享'
,
...
...
src/views/role/index.vue
View file @
9641032
...
...
@@ -6,32 +6,33 @@
:formModel=
"searchForm"
:formList=
"roleFormList"
>
<span
class=
"inline-b"
slot=
"form-slot"
>
<span
class=
"inline-b"
slot=
"form-slot"
>
<el-button
type=
"primary"
:size=
"btn_size"
icon=
"el-icon-search"
:id=
"tableParams.btnId"
>
搜索
</el-button>
>
搜索
</el-button
>
<el-button
type=
"primary"
:size=
"btn_size"
icon=
"el-icon-refresh"
@
click=
"refresh"
>
重置
</el-button>
>
重置
</el-button
>
</span>
</search-form>
<h3>
角色管理
<h3>
角色管理
<div
class=
"pull-right"
>
<el-button
type=
"primary"
:size=
"btn_size"
icon=
"el-icon-plus"
@
click=
"btnClick('create')"
>
新增
</el-button>
>
新增
</el-button
>
</div>
</h3>
<basic-table
...
...
@@ -41,27 +42,30 @@
:searchForm=
"searchForm"
:hasNum=
"false"
>
<span
slot=
"status"
slot-scope=
"scope"
>
<span
slot=
"status"
slot-scope=
"scope"
>
<span
class=
"dot"
:class=
"scope.scope.enableStatus ? USERSTATUS[scope.scope.enableStatus].split(',')[1] : ''"
:class=
"
scope.scope.enableStatus
? USERSTATUS[scope.scope.enableStatus].split(',')[1]
: ''
"
></span>
<span
class=
"statusText"
>
{{
scope
.
scope
.
enableStatus
?
USERSTATUS
[
scope
.
scope
.
enableStatus
].
split
(
','
)[
0
]
:
'--'
}}
</span>
<span
class=
"statusText"
>
{{
scope
.
scope
.
enableStatus
?
USERSTATUS
[
scope
.
scope
.
enableStatus
].
split
(
","
)[
0
]
:
"--"
}}
</span>
</span>
<span
slot=
"table-button"
slot-scope=
"scope"
>
<span
slot=
"table-button"
slot-scope=
"scope"
>
<el-button
v-for=
"(j, idx) in tableParams.tableOption.btnList"
:key=
"idx"
:type=
"j.type || 'text'"
:size=
"btn_size"
@
click=
"btnClick(j.pType, scope.scope)"
>
{{
j
.
name
}}
</el-button>
>
{{
j
.
name
}}
</el-button
>
</span>
</basic-table>
<basic-dialog
...
...
@@ -77,7 +81,7 @@
:rules=
"roleRules"
:ruleData=
"roleData"
:labelWidth=
"'120px'"
ref=
'roleForm'
ref=
"roleForm"
>
<div
slot=
"visible-type"
>
<el-radio-group
...
...
@@ -85,10 +89,11 @@
v-model=
"roleForm.roleVisibility"
>
<el-radio
v-for=
"(child,childIndex) in visibilityList"
v-for=
"(child,
childIndex) in visibilityList"
:key=
"childIndex"
:label=
"child.code"
>
{{
child
.
value
}}
</el-radio>
>
{{
child
.
value
}}
</el-radio
>
</el-radio-group>
<el-select
v-if=
"roleForm.roleVisibility == 2"
...
...
@@ -106,6 +111,34 @@
</el-option>
</el-select>
</div>
<div
slot=
"data-auth"
>
<el-radio-group
@
change=
"radioChange(roleForm.roleVisibility)"
v-model=
"roleForm.rolePermissionType"
>
<el-radio
v-for=
"(child, childIndex) in $Constants.ROLEAUTH_LIST"
:key=
"childIndex"
:label=
"child.value"
>
{{
child
.
label
}}
</el-radio
>
</el-radio-group>
<el-select
v-if=
"roleForm.rolePermissionType == 6"
v-model=
"roleForm.permTenants"
placeholder=
"请选择"
multiple
filterable
>
<el-option
v-for=
"i in permissionList"
:key=
"i.tenantId"
:label=
"i.tenantName"
:value=
"i.tenantId"
>
</el-option>
</el-select>
</div>
<el-tree
slot=
"menu-list"
:data=
"treedata"
...
...
@@ -113,7 +146,7 @@
default-expand-all
node-key=
"id"
ref=
"tree"
check-strictly=
"true"
:
check-strictly=
"true"
highlight-current
>
</el-tree>
...
...
@@ -125,244 +158,323 @@
</
template
>
<
script
>
import
{
getRoleList
,
roleInfo
,
getTenantList
,
addRole
,
editRole
,
deleteRole
,
getMenuTree
,
getVisibility
}
from
'services/role'
;
import
{
getRoleList
,
roleInfo
,
getTenantList
,
addRole
,
editRole
,
deleteRole
,
getMenuTree
,
getVisibility
,
getPermission
}
from
"services/role"
;
export
default
{
data
()
{
var
checkMenu
=
(
rule
,
value
,
callBack
)
=>
{
if
(
value
&&
value
.
length
==
0
)
{
return
callBack
(
new
Error
(
'请选择菜单列表'
))
return
callBack
(
new
Error
(
"请选择菜单列表"
));
}
else
{
return
callBack
()
return
callBack
()
;
}
}
};
var
checkRoleVisibility
=
(
rule
,
value
,
callBack
)
=>
{
if
(
value
&&
value
==
2
)
{
return
callBack
(
new
Error
(
"请选择指定租户"
));
}
else
{
return
callBack
();
}
};
var
checkRolePermissionType
=
(
rule
,
value
,
callBack
)
=>
{
if
(
value
&&
value
==
6
)
{
return
callBack
(
new
Error
(
"请选择指定数据权限"
));
}
else
{
return
callBack
();
}
};
return
{
USERSTATUS
:
this
.
$Constants
.
USER_STATUS
,
searchForm
:
{},
roleFormList
:
[
{
type
:
'input'
,
inputType
:
'text'
,
prop
:
'roleName'
,
placeholder
:
'请输入角色名称'
type
:
"input"
,
inputType
:
"text"
,
prop
:
"roleName"
,
placeholder
:
"请输入角色名称"
}
],
tableParams
:
{
// mutiSelectName: 'role',
// mutiSelectUniqueKey: 'id',
btnId
:
new
Date
().
getTime
()
+
parseInt
(
Math
.
random
()
*
1000
),
listName
:
'list'
,
listName
:
"list"
,
tableColumns
:
[
{
label
:
'角色名称'
,
prop
:
'roleName'
},
{
label
:
'备注'
,
prop
:
'remark'
},
{
label
:
'状态'
,
prop
:
'enableStatus'
,
addHtml
:
'status'
},
{
label
:
'创建时间'
,
prop
:
'createdDate'
label
:
"角色名称"
,
prop
:
"roleName"
},
{
label
:
"备注"
,
prop
:
"remark"
},
{
label
:
"状态"
,
prop
:
"enableStatus"
,
addHtml
:
"status"
},
{
label
:
"创建时间"
,
prop
:
"createdDate"
}
],
tableOption
:
{
width
:
300
,
btnList
:
[
{
name
:
'编辑'
,
pType
:
'edit'
name
:
"编辑"
,
pType
:
"edit"
},
{
name
:
'删除'
,
pType
:
'delete'
name
:
"删除"
,
pType
:
"delete"
}
]
}
},
getListApi
:
getRoleList
,
// 弹窗数据
roleDialogTitle
:
'新增角色'
,
roleDialogTitle
:
"新增角色"
,
roleVisible
:
false
,
roleForm
:
{
enableStatus
:
true
,
menuIdList
:
[]
},
roleData
:
[
{
label
:
'角色名称:'
,
prop
:
'roleName'
,
type
:
'input'
,
maxlength
:
50
},
{
label
:
'备注:'
,
prop
:
'remark'
,
type
:
'input'
,
inputText
:
'textarea'
,
maxlength
:
200
,
showWordLimit
:
true
},
{
label
:
'状态:'
,
prop
:
'enableStatus'
,
type
:
'switch'
},
{
label
:
'租户可见度:'
,
prop
:
'roleVisibility'
,
type
:
'customize'
,
slotName
:
'visible-type'
},
{
label
:
'数据权限:'
,
prop
:
'rolePermissionType'
,
type
:
'radio'
,
children
:
this
.
$Constants
.
ROLE_AUTH
},
{
label
:
'菜单权限:'
,
prop
:
'menuIdList'
,
type
:
'customize'
,
slotName
:
'menu-list'
}
{
label
:
"角色名称:"
,
prop
:
"roleName"
,
type
:
"input"
,
maxlength
:
50
},
{
label
:
"备注:"
,
prop
:
"remark"
,
type
:
"input"
,
inputText
:
"textarea"
,
maxlength
:
200
,
showWordLimit
:
true
},
{
label
:
"状态:"
,
prop
:
"enableStatus"
,
type
:
"switch"
},
{
label
:
"租户可见度:"
,
prop
:
"roleVisibility"
,
type
:
"customize"
,
slotName
:
"visible-type"
},
{
label
:
"数据权限:"
,
prop
:
"rolePermissionType"
,
type
:
"customize"
,
slotName
:
"data-auth"
// children: this.$Constants.ROLE_AUTH
},
{
label
:
"菜单权限:"
,
prop
:
"menuIdList"
,
type
:
"customize"
,
slotName
:
"menu-list"
}
],
roleRules
:
{
roleName
:
[{
required
:
true
,
message
:
'请输入角色名称'
,
trigger
:
'blur'
},
{
validator
:
this
.
$Common
.
checkName
,
trigger
:
'blur'
},
{
min
:
5
,
max
:
50
,
message
:
'长度在 5 到 50 个字符'
,
trigger
:
'blur'
}],
roleName
:
[
{
required
:
true
,
message
:
"请输入角色名称"
,
trigger
:
"blur"
},
{
validator
:
this
.
$Common
.
checkName
,
trigger
:
"blur"
},
{
min
:
5
,
max
:
50
,
message
:
"长度在 5 到 50 个字符"
,
trigger
:
"blur"
}
],
enableStatus
:
[{
required
:
true
}],
roleVisibility
:
[{
required
:
true
,
message
:
'请选择租户可见度'
}],
rolePermissionType
:
[{
required
:
true
,
message
:
'请选择数据权限'
}],
menuIdList
:
[{
required
:
true
,
validator
:
checkMenu
,
trigger
:
'blur'
}]
roleVisibility
:
[
{
required
:
true
,
message
:
"请选择租户可见度"
},
{
validator
:
checkRoleVisibility
,
trigger
:
"change"
}
],
rolePermissionType
:
[
{
required
:
true
,
message
:
"请选择数据权限"
},
{
validator
:
checkRolePermissionType
,
trigger
:
"change"
}
],
menuIdList
:
[{
required
:
true
,
validator
:
checkMenu
,
trigger
:
"blur"
}]
},
treedata
:
[],
tenantList
:
[],
visibilityList
:
[]
}
visibilityList
:
[],
permissionList
:
[]
};
},
mounted
()
{
this
.
getTenantList
()
this
.
getVisibility
()
this
.
getTenantList
();
this
.
getVisibility
();
this
.
getPermission
();
},
methods
:
{
// 重置搜索条件
refresh
()
{
this
.
searchForm
=
{}
this
.
$refs
.
roleTable
.
refreshTable
()
this
.
searchForm
=
{}
;
this
.
$refs
.
roleTable
.
refreshTable
()
;
},
// 确定
handleConfirm
()
{
this
.
getCheckedKeys
()
console
.
log
(
this
.
roleForm
)
this
.
$refs
.
roleForm
.
$children
[
0
].
validate
((
valid
)
=>
{
this
.
getCheckedKeys
();
this
.
$refs
.
roleForm
.
$children
[
0
].
validate
(
valid
=>
{
if
(
valid
)
{
let
api
=
addRole
let
api
=
addRole
;
let
params
=
{
remark
:
this
.
roleForm
.
remark
,
roleName
:
this
.
roleForm
.
roleName
,
menuIdList
:
this
.
roleForm
.
menuIdList
};
params
.
enableStatus
=
this
.
roleForm
.
enableStatus
?
1
:
2
;
params
.
roleVisibility
=
Number
(
this
.
roleForm
.
roleVisibility
);
params
.
rolePermissionType
=
Number
(
this
.
roleForm
.
rolePermissionType
);
if
(
params
.
roleVisibility
==
2
)
{
params
.
roleTenants
=
this
.
roleForm
.
roleTenants
.
toString
();
}
if
(
params
.
rolePermissionType
==
6
)
{
params
.
permTenants
=
this
.
roleForm
.
permTenants
.
toString
();
}
params
.
enableStatus
=
this
.
roleForm
.
enableStatus
?
1
:
2
params
.
roleVisibility
=
Number
(
this
.
roleForm
.
roleVisibility
)
params
.
rolePermissionType
=
Number
(
this
.
roleForm
.
rolePermissionType
)
if
(
params
.
roleVisibility
==
2
)
params
.
roleTenants
=
this
.
roleForm
.
roleTenants
.
toString
()
if
(
this
.
roleForm
.
id
)
{
api
=
editRole
params
.
roleId
=
this
.
roleForm
.
id
api
=
editRole
;
params
.
roleId
=
this
.
roleForm
.
id
;
}
api
(
params
).
then
(
res
=>
{
if
(
res
.
code
==
'200'
)
{
if
(
res
.
code
==
"200"
)
{
this
.
$message
({
type
:
'success'
,
message
:
'操作成功!'
})
this
.
handleClose
()
this
.
$refs
.
roleTable
.
refreshTable
()
type
:
"success"
,
message
:
"操作成功!"
})
;
this
.
handleClose
()
;
this
.
$refs
.
roleTable
.
refreshTable
()
;
}
else
{
this
.
$message
({
type
:
'error'
,
type
:
"error"
,
message
:
res
.
message
})
})
;
}
})
})
;
}
})
})
;
},
// 取消
handleClose
()
{
if
(
!
this
.
roleVisible
&&
this
.
$refs
.
roleForm
)
{
this
.
$refs
.
roleForm
.
$children
[
0
].
resetFields
()
this
.
$refs
.
roleForm
.
$children
[
0
].
resetFields
()
;
}
this
.
roleVisible
=
!
this
.
roleVisible
if
(
!
this
.
roleVisible
)
this
.
$refs
.
tree
.
setCheckedKeys
([])
this
.
roleVisible
=
!
this
.
roleVisible
;
if
(
!
this
.
roleVisible
)
this
.
$refs
.
tree
.
setCheckedKeys
([])
;
},
// 按钮事件
btnClick
(
pType
,
scope
)
{
console
.
log
(
pType
,
scope
)
console
.
log
(
pType
,
scope
)
;
switch
(
pType
)
{
case
'create'
:
this
.
roleDialogTitle
=
'新增角色'
case
"create"
:
this
.
roleDialogTitle
=
"新增角色"
;
this
.
roleForm
=
{
enableStatus
:
true
,
menuIdList
:
[]
}
this
.
getMenuTree
()
this
.
handleClose
()
break
case
'edit'
:
this
.
roleDialogTitle
=
'编辑角色'
this
.
editEvent
(
scope
)
break
case
'delete'
:
this
.
deleteEvent
(
scope
.
id
)
break
}
;
this
.
getMenuTree
()
;
this
.
handleClose
()
;
break
;
case
"edit"
:
this
.
roleDialogTitle
=
"编辑角色"
;
this
.
editEvent
(
scope
)
;
break
;
case
"delete"
:
this
.
deleteEvent
(
scope
.
id
)
;
break
;
}
},
// 编辑触发事件
editEvent
(
row
)
{
const
that
=
this
const
that
=
this
;
roleInfo
({
id
:
row
.
id
}).
then
(
res
=>
{
this
.
roleForm
=
JSON
.
parse
(
JSON
.
stringify
(
res
.
data
))
this
.
roleForm
.
enableStatus
=
res
.
data
.
enableStatus
==
1
?
true
:
false
this
.
roleForm
.
roleVisibility
=
res
.
data
.
roleVisibility
+
''
this
.
roleForm
.
rolePermissionType
=
res
.
data
.
rolePermissionType
+
''
if
(
res
.
data
.
roleTenants
)
this
.
roleForm
.
roleTenants
=
res
.
data
.
roleTenants
.
split
(
','
).
map
(
Number
)
this
.
getMenuTree
({
roleId
:
row
.
id
})
this
.
handleClose
(
res
.
data
)
})
this
.
roleForm
=
JSON
.
parse
(
JSON
.
stringify
(
res
.
data
));
this
.
roleForm
.
enableStatus
=
res
.
data
.
enableStatus
==
1
?
true
:
false
;
this
.
roleForm
.
roleVisibility
=
res
.
data
.
roleVisibility
;
this
.
roleForm
.
rolePermissionType
=
res
.
data
.
rolePermissionType
;
if
(
res
.
data
.
roleTenants
)
{
this
.
roleForm
.
roleTenants
=
res
.
data
.
roleTenants
.
split
(
","
)
.
map
(
Number
);
}
if
(
res
.
data
.
permTenants
)
{
this
.
roleForm
.
permTenants
=
res
.
data
.
permTenants
.
split
(
","
)
.
map
(
Number
);
}
this
.
getMenuTree
({
roleId
:
row
.
id
});
this
.
handleClose
(
res
.
data
);
});
},
// 删除触发事件
deleteEvent
(
id
)
{
const
that
=
this
const
that
=
this
;
const
tipData
=
{
that
:
that
,
tipText
:
'是否删除当前记录'
,
tipTitle
:
'提示'
,
type
:
'error'
,
tipText
:
"是否删除当前记录"
,
tipTitle
:
"提示"
,
type
:
"error"
,
callBack
:
()
=>
{
deleteRole
({
id
:
id
}).
then
(
res
=>
{
if
(
res
.
code
==
'200'
)
{
if
(
res
.
code
==
"200"
)
{
this
.
$message
({
type
:
'success'
,
message
:
'删除成功!'
})
this
.
$refs
.
roleTable
.
refreshTable
()
type
:
"success"
,
message
:
"删除成功!"
})
;
this
.
$refs
.
roleTable
.
refreshTable
()
;
}
else
{
this
.
$message
({
type
:
'error'
,
type
:
"error"
,
message
:
res
.
message
})
})
;
}
})
})
;
}
}
this
.
$Common
.
confirmDialog
(
tipData
)
}
;
this
.
$Common
.
confirmDialog
(
tipData
)
;
},
// 获取菜单权限列表
getMenuTree
(
params
)
{
getMenuTree
(
params
).
then
(
res
=>
{
this
.
treedata
=
res
.
data
.
menuTree
this
.
treedata
=
res
.
data
.
menuTree
;
setTimeout
(()
=>
{
this
.
$refs
.
tree
.
setCheckedKeys
(
res
.
data
.
checkedIds
)
},
1000
/
60
)
})
this
.
$refs
.
tree
.
setCheckedKeys
(
res
.
data
.
checkedIds
)
;
},
1000
/
60
)
;
})
;
},
// 获取选中菜单数组
getCheckedKeys
()
{
this
.
roleForm
.
menuIdList
=
this
.
$refs
.
tree
.
getCheckedKeys
()
this
.
roleForm
.
menuIdList
=
this
.
$refs
.
tree
.
getCheckedKeys
()
;
},
// 获取角色可见度可选项
getVisibility
()
{
getVisibility
().
then
(
res
=>
{
console
.
log
(
res
.
data
)
this
.
visibilityList
=
res
.
data
})
console
.
log
(
res
.
data
);
this
.
visibilityList
=
res
.
data
;
});
},
// 获取数据权限租户列表
getPermission
()
{
getPermission
().
then
(
res
=>
{
this
.
permissionList
=
res
.
data
;
});
},
// 获取租户列表
getTenantList
()
{
getTenantList
().
then
(
res
=>
{
this
.
tenantList
=
res
.
data
})
this
.
tenantList
=
res
.
data
;
})
;
},
radioChange
(
e
)
{
this
.
$set
(
this
.
roleForm
,
'roleVisibility'
,
e
)
this
.
$set
(
this
.
roleForm
,
"roleVisibility"
,
e
);
}
}
}
}
;
</
script
>
<
style
lang=
"scss"
>
.role
.el-tree
{
margin-top
:
7px
;
}
</
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