Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation
This project
Loading...
Sign in
李宁
/
Activity
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit dd3fce0a
authored
Nov 21, 2025
by
李宁
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
1
1 parent
640f1611
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
100 additions
and
28 deletions
channelBusiManage/src/assets/js/api/interface/role/index.js
channelBusiManage/src/components/PermissionTreeNode.vue
channelBusiManage/src/components/RoleManagement.vue
channelBusiManage/src/assets/js/api/interface/role/index.js
View file @
dd3fce0
...
@@ -26,3 +26,14 @@ export function createOrUpdateRole(data) {
...
@@ -26,3 +26,14 @@ export function createOrUpdateRole(data) {
data
,
data
,
})
})
}
}
/**
* 根据角色ID获取角色权限
*/
export
function
queryRolePermission
(
data
)
{
return
request
({
url
:
'/crm/getRoleFunction'
,
data
,
})
}
channelBusiManage/src/components/PermissionTreeNode.vue
View file @
dd3fce0
...
@@ -102,9 +102,29 @@ const isSelected = computed(() =>
...
@@ -102,9 +102,29 @@ const isSelected = computed(() =>
const
isIndeterminate
=
computed
(()
=>
{
const
isIndeterminate
=
computed
(()
=>
{
if
(
isSelected
.
value
||
!
hasChildren
.
value
)
return
false
if
(
isSelected
.
value
||
!
hasChildren
.
value
)
return
false
return
props
.
permission
.
children
!
.
some
(
c
=>
props
.
selectedPermissions
.
includes
(
c
.
id
)
// 获取所有子权限ID
)
const
getAllChildIds
=
(
children
:
Permission
[]):
string
[]
=>
{
const
ids
:
string
[]
=
[]
for
(
const
child
of
children
)
{
ids
.
push
(
child
.
id
)
if
(
child
.
children
)
{
ids
.
push
(...
getAllChildIds
(
child
.
children
))
}
}
return
ids
}
const
allChildIds
=
getAllChildIds
(
props
.
permission
.
children
!
)
if
(
allChildIds
.
length
===
0
)
return
false
// 检查是否所有子权限都被选中
const
allSelected
=
allChildIds
.
every
(
id
=>
props
.
selectedPermissions
.
includes
(
id
))
if
(
allSelected
)
return
false
// 检查是否有部分子权限被选中
const
someSelected
=
allChildIds
.
some
(
id
=>
props
.
selectedPermissions
.
includes
(
id
))
return
someSelected
})
})
</
script
>
</
script
>
...
...
channelBusiManage/src/components/RoleManagement.vue
View file @
dd3fce0
...
@@ -212,18 +212,16 @@ export interface Permission {
...
@@ -212,18 +212,16 @@ export interface Permission {
}
}
export
interface
Role
{
export
interface
Role
{
id
:
string
id
:
Number
n
ame
:
string
roleN
ame
:
string
description
?:
string
status
:
RoleStatus
level
:
RoleLevel
remark
?:
string
permissionIds
?:
string
[]
permissionIds
?:
string
[]
permissions
?:
string
[]
permissions
?:
string
[]
status
:
RoleStatus
createTime
?:
string
createTime
?:
string
}
}
export
type
RoleLevel
=
'地市级'
|
'区县级'
|
'一线人员'
export
type
RoleStatus
=
1
|
0
export
type
RoleStatus
=
'启用'
|
'禁用'
// Props
// Props
interface
Props
{
interface
Props
{
...
@@ -255,7 +253,7 @@ const roleStatusEnabled = ref(true)
...
@@ -255,7 +253,7 @@ const roleStatusEnabled = ref(true)
const
expandedPermissions
=
ref
<
Set
<
string
>>
(
new
Set
())
const
expandedPermissions
=
ref
<
Set
<
string
>>
(
new
Set
())
// 计算属性
// 计算属性
const
roleStatus
=
computed
(():
RoleStatus
=>
roleStatusEnabled
.
value
?
'
启用'
:
'禁用
'
)
const
roleStatus
=
computed
(():
RoleStatus
=>
roleStatusEnabled
.
value
?
'
1'
:
'0
'
)
const
topLevelPermissions
=
computed
(()
=>
const
topLevelPermissions
=
computed
(()
=>
props
.
permissions
.
filter
(
p
=>
!
p
.
parentId
)
props
.
permissions
.
filter
(
p
=>
!
p
.
parentId
)
...
@@ -264,11 +262,13 @@ const topLevelPermissions = computed(() =>
...
@@ -264,11 +262,13 @@ const topLevelPermissions = computed(() =>
const
filteredRoles
=
ref
([])
const
filteredRoles
=
ref
([])
// 获取角色的权限ID列表,兼容不同的字段名
// 获取角色的权限ID列表,兼容不同的字段名
const
getRolePermissionIds
=
(
role
:
Role
):
string
[]
=>
{
const
getRolePermissionIds
=
async
(
role
:
Role
)
=>
{
return
role
.
permissionIds
||
role
.
permissions
||
[]
const
response
=
await
$api
.
queryRolePermission
({
}
id
:
role
.
id
})
return
[
'1'
,
'2'
,
'3'
,
'4'
]
}
// 打开新增对话框
// 打开新增对话框
const
handleOpenAddDialog
=
()
=>
{
const
handleOpenAddDialog
=
()
=>
{
...
@@ -283,19 +283,23 @@ const handleOpenAddDialog = () => {
...
@@ -283,19 +283,23 @@ const handleOpenAddDialog = () => {
}
}
// 打开编辑对话框
// 打开编辑对话框
const
handleOpenEditDialog
=
(
role
:
Role
)
=>
{
const
handleOpenEditDialog
=
async
(
role
:
Role
)
=>
{
editingRole
.
value
=
role
editingRole
.
value
=
role
roleName
.
value
=
role
.
name
roleName
.
value
=
role
.
roleName
roleDescription
.
value
=
role
.
description
||
''
roleDescription
.
value
=
role
.
remark
||
''
roleStatusEnabled
.
value
=
role
.
status
===
1
selectedPermissions
.
value
=
[...
getRolePermissionIds
(
role
)]
selectedPermissions
.
value
=
await
getRolePermissionIds
(
role
)
roleStatusEnabled
.
value
=
role
.
status
===
'启用'
expandedPermissions
.
value
=
new
Set
(
props
.
permissions
.
filter
(
p
=>
!
p
.
parentId
).
map
(
p
=>
p
.
id
))
expandedPermissions
.
value
=
new
Set
(
props
.
permissions
.
filter
(
p
=>
!
p
.
parentId
).
map
(
p
=>
p
.
id
))
console
.
log
(
selectedPermissions
)
console
.
log
(
expandedPermissions
)
isDialogOpen
.
value
=
true
isDialogOpen
.
value
=
true
}
}
// 保存角色
// 保存角色
const
handleSave
=
()
=>
{
const
handleSave
=
async
()
=>
{
if
(
!
roleName
.
value
.
trim
())
{
if
(
!
roleName
.
value
.
trim
())
{
ElMessage
.
error
(
'请输入角色名称'
)
ElMessage
.
error
(
'请输入角色名称'
)
return
return
...
@@ -309,22 +313,47 @@ const handleSave = () => {
...
@@ -309,22 +313,47 @@ const handleSave = () => {
const
roleData
=
{
const
roleData
=
{
name
:
roleName
.
value
.
trim
(),
name
:
roleName
.
value
.
trim
(),
description
:
roleDescription
.
value
.
trim
(),
description
:
roleDescription
.
value
.
trim
(),
level
:
roleLevel
.
value
,
permissionIds
:
selectedPermissions
.
value
,
permissionIds
:
selectedPermissions
.
value
,
status
:
roleStatus
.
value
status
:
roleStatus
.
value
}
}
if
(
editingRole
.
value
)
{
console
.
log
(
roleData
)
emit
(
'updateRole'
,
editingRole
.
value
.
id
,
roleData
)
ElMessage
.
success
(
'角色更新成功'
)
const
response
=
await
$api
.
createOrUpdateRole
({
roleId
:
''
,
roleName
:
roleName
.
value
.
trim
(),
remark
:
roleDescription
.
value
.
trim
(),
status
:
roleStatus
.
value
,
functionIds
:
selectedPermissions
.
value
})
if
(
response
.
c
===
0
)
{
handleFilter
()
ElMessage
.
success
(
'创建成功'
);
}
else
{
}
else
{
emit
(
'addRole'
,
roleData
)
ElMessage
.
error
(
response
.
m
);
ElMessage
.
success
(
'角色创建成功'
)
}
}
isDialogOpen
.
value
=
false
isDialogOpen
.
value
=
false
}
}
// 获取所有子权限ID
const
getAllChildPermissionIds
=
(
permissionId
:
string
):
string
[]
=>
{
const
permission
=
findPermissionById
(
permissionId
)
if
(
!
permission
||
!
permission
.
children
)
return
[]
const
childIds
:
string
[]
=
[]
const
collectChildIds
=
(
perms
:
Permission
[])
=>
{
for
(
const
p
of
perms
)
{
childIds
.
push
(
p
.
id
)
if
(
p
.
children
)
{
collectChildIds
(
p
.
children
)
}
}
}
collectChildIds
(
permission
.
children
)
return
childIds
}
// 切换权限选择
// 切换权限选择
const
handleTogglePermission
=
(
permissionId
:
string
)
=>
{
const
handleTogglePermission
=
(
permissionId
:
string
)
=>
{
const
permission
=
findPermissionById
(
permissionId
)
const
permission
=
findPermissionById
(
permissionId
)
...
@@ -340,8 +369,18 @@ const handleTogglePermission = (permissionId: string) => {
...
@@ -340,8 +369,18 @@ const handleTogglePermission = (permissionId: string) => {
})
})
newSelected
=
newSelected
.
filter
(
id
=>
id
!==
permissionId
)
newSelected
=
newSelected
.
filter
(
id
=>
id
!==
permissionId
)
}
else
{
}
else
{
// 选择:自动选择所有父权限
// 选择:自动选择所有父权限
和所有子权限
newSelected
.
push
(
permissionId
)
newSelected
.
push
(
permissionId
)
// 自动选择所有子权限
const
childIds
=
getAllChildPermissionIds
(
permissionId
)
childIds
.
forEach
(
id
=>
{
if
(
!
newSelected
.
includes
(
id
))
{
newSelected
.
push
(
id
)
}
})
// 自动选择所有父权限
let
current
=
permission
let
current
=
permission
while
(
current
.
parentId
)
{
while
(
current
.
parentId
)
{
if
(
!
newSelected
.
includes
(
current
.
parentId
))
{
if
(
!
newSelected
.
includes
(
current
.
parentId
))
{
...
@@ -352,6 +391,8 @@ const handleTogglePermission = (permissionId: string) => {
...
@@ -352,6 +391,8 @@ const handleTogglePermission = (permissionId: string) => {
}
}
selectedPermissions
.
value
=
newSelected
selectedPermissions
.
value
=
newSelected
console
.
log
(
newSelected
)
}
}
// 查找权限
// 查找权限
...
...
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