@@ -6,6 +6,8 @@ import { MsgSuccess } from '@/utils/message'
66
77interface PermissionTableRow {
88 id: string
9+ categoryId: string
10+ category: string
911 moduleId: string
1012 module: string
1113 name: string
@@ -30,15 +32,35 @@ function loadPermissions() {
3032}
3133
3234function transformPermissions(modules : RolePermissionModule []) {
33- return modules .flatMap ((module ) =>
34- module .children .map ((feature ) => ({ id: ` ${module .id }:${feature .id } ` , moduleId: module .id , module: module .name , name: feature .name , permissions: feature .permission })),
35+ // 后端返回 分类(category) → 分组(group) → 叶子(feature) → 权限 的结构,
36+ // 分类 → “分类”列,分组 → “模块名称”列,叶子 → “操作对象”列,向下展平为表格行
37+ return modules .flatMap ((category ) =>
38+ category .children .flatMap ((group ) =>
39+ group .children .map ((feature ) => ({
40+ id: ` ${category .id }:${group .id }:${feature .id } ` ,
41+ categoryId: category .id ,
42+ category: category .name ,
43+ moduleId: ` ${category .id }:${group .id } ` ,
44+ module: group .name ,
45+ name: feature .name ,
46+ permissions: feature .permission ,
47+ })),
48+ ),
3549 )
3650}
3751
3852function permissionTableSpan({ row , rowIndex , columnIndex }: { row: PermissionTableRow ; rowIndex: number ; columnIndex: number }) {
39- if (columnIndex !== 0 ) return [1 , 1 ]
40- const firstRowIndex = permissionData .value .findIndex (({ moduleId }) => moduleId === row .moduleId )
41- return rowIndex === firstRowIndex ? [permissionData .value .filter (({ moduleId }) => moduleId === row .moduleId ).length , 1 ] : [0 , 0 ]
53+ if (columnIndex === 0 ) {
54+ // “分类”列按分类纵向合并
55+ const firstRowIndex = permissionData .value .findIndex (({ categoryId }) => categoryId === row .categoryId )
56+ return rowIndex === firstRowIndex ? [permissionData .value .filter (({ categoryId }) => categoryId === row .categoryId ).length , 1 ] : [0 , 0 ]
57+ }
58+ if (columnIndex === 1 ) {
59+ // “模块名称”列按分组纵向合并
60+ const firstRowIndex = permissionData .value .findIndex (({ moduleId }) => moduleId === row .moduleId )
61+ return rowIndex === firstRowIndex ? [permissionData .value .filter (({ moduleId }) => moduleId === row .moduleId ).length , 1 ] : [0 , 0 ]
62+ }
63+ return [1 , 1 ]
4264}
4365
4466/* 单项权限与查看权限联动 */
@@ -96,6 +118,7 @@ watch(() => props.currentRole.id, loadPermissions, { immediate: true })
96118 :data =" permissionData "
97119 v-loading =" loading "
98120 >
121+ <el-table-column prop =" category" label =" 分类" width =" 120" />
99122 <el-table-column prop =" module" label =" 模块名称" width =" 150" />
100123 <el-table-column prop =" name" label =" 操作对象" width =" 150" />
101124 <el-table-column label =" 权限" >
0 commit comments