|
9 | 9 | /> |
10 | 10 | <el-table-column prop="permission" :label="$t('views.model.modelForm.permissionType.label')"> |
11 | 11 | <template #default="{ row }"> |
12 | | - <el-checkbox-group v-model="row.perChecked" @change="handleCellChange($event, row)"> |
13 | | - <el-checkbox |
14 | | - v-for="item in row.permission" |
15 | | - :key="item.id" |
16 | | - :value="item.id" |
17 | | - :disabled="disabled" |
18 | | - > |
19 | | - <div class="ellipsis" style="width: 96px">{{ item.name }}</div> |
20 | | - </el-checkbox> |
21 | | - </el-checkbox-group> |
| 12 | + <el-checkbox |
| 13 | + v-for="item in row.permission" |
| 14 | + :key="item.id" |
| 15 | + v-model="item.enable" |
| 16 | + :disabled="disabled" |
| 17 | + @change="(val: boolean) => handleCellChange(val, item, row)" |
| 18 | + > |
| 19 | + <div class="ellipsis" style="width: 96px">{{ item.name }}</div> |
| 20 | + </el-checkbox> |
22 | 21 | </template> |
23 | 22 | </el-table-column> |
24 | 23 | <el-table-column :width="40"> |
@@ -74,12 +73,12 @@ const needDisable = computed(() => { |
74 | 73 | const isAdminOrExtendAdmin = hasPermission([RoleConst.ADMIN, RoleConst.EXTENDS_ADMIN], 'OR') |
75 | 74 | const isWorkspaceManage = |
76 | 75 | hasPermission( |
77 | | - [ |
78 | | - RoleConst.WORKSPACE_MANAGE.getWorkspaceRole, |
79 | | - RoleConst.EXTENDS_WORKSPACE_MANAGE.getWorkspaceRole, |
80 | | - ], |
| 76 | + [ |
| 77 | + RoleConst.WORKSPACE_MANAGE.getWorkspaceRole, |
| 78 | + RoleConst.EXTENDS_WORKSPACE_MANAGE.getWorkspaceRole, |
| 79 | + ], |
81 | 80 | 'OR' |
82 | | - ) |
| 81 | + ) |
83 | 82 |
|
84 | 83 | if (!isEeOrPe) { |
85 | 84 | return false |
@@ -123,23 +122,35 @@ async function getRolePermission() { |
123 | 122 | } |
124 | 123 | } |
125 | 124 |
|
126 | | -function handleCellChange(checkedValues: string[], row: RoleTableDataItem) { |
127 | | - row.enable = checkedValues.length === row.permission.length |
128 | | - row.indeterminate = checkedValues.length > 0 && checkedValues.length < row.permission.length |
| 125 | +function handleCellChange( |
| 126 | + value: boolean, |
| 127 | + item: ChildrenPermissionItem, |
| 128 | + row: RoleTableDataItem, |
| 129 | +) { |
| 130 | + item.enable = value |
| 131 | + const readItem = row.permission.find((p) => /:READ$/.test(p.id)) |
| 132 | + // 如果勾选的不是 READ,则强制把 READ 也勾上 |
| 133 | + if (value && item.id !== readItem?.id && readItem && !readItem.enable) { |
| 134 | + readItem.enable = true |
| 135 | + } else if (!value && item.id === readItem?.id) { |
| 136 | + // 取消 READ 整行其他权限全部取消 |
| 137 | + row.permission.forEach((p) => (p.enable = false)) |
| 138 | + } |
129 | 139 |
|
130 | | - row.permission.forEach((p) => { |
131 | | - p.enable = checkedValues.includes(p.id) |
132 | | - }) |
| 140 | + const checkedIds = row.permission.filter((p) => p.enable).map((p) => p.id) |
| 141 | + row.perChecked = checkedIds |
| 142 | + row.enable = checkedIds.length === row.permission.length |
| 143 | + row.indeterminate = |
| 144 | + checkedIds.length > 0 && checkedIds.length < row.permission.length |
133 | 145 | } |
134 | 146 |
|
135 | 147 | function handleRowChange(checked: boolean, row: RoleTableDataItem) { |
136 | 148 | if (checked) { |
137 | | - row.perChecked = row.permission.map((p) => p.id) |
138 | 149 | row.permission.forEach((p) => (p.enable = true)) |
139 | 150 | } else { |
140 | | - row.perChecked = [] |
141 | 151 | row.permission.forEach((p) => (p.enable = false)) |
142 | 152 | } |
| 153 | + row.perChecked = checked ? row.permission.map((p) => p.id) : [] |
143 | 154 | row.indeterminate = false |
144 | 155 | } |
145 | 156 |
|
@@ -182,15 +193,9 @@ watch(() => props.currentRole?.id, getRolePermission, {immediate: true}) |
182 | 193 |
|
183 | 194 | async function handleSave() { |
184 | 195 | try { |
185 | | - const permissions: { id: string; enable: boolean }[] = [] |
186 | | - tableData.value.forEach((e) => { |
187 | | - e.permission?.forEach((ele: ChildrenPermissionItem) => { |
188 | | - permissions.push({ |
189 | | - id: ele.id, |
190 | | - enable: ele.enable, |
191 | | - }) |
192 | | - }) |
193 | | - }) |
| 196 | + const permissions = tableData.value.flatMap((row) => |
| 197 | + row.permission.map((p) => ({ id: p.id, enable: p.enable })), |
| 198 | + ) |
194 | 199 | await loadPermissionApi('role').saveRolePermission(props.currentRole?.id as string, permissions, loading) |
195 | 200 | MsgSuccess(t('common.saveSuccess')) |
196 | 201 | } catch (error) { |
|
0 commit comments