Skip to content

Commit b9aa36e

Browse files
committed
fix: read permission
1 parent 8e8726c commit b9aa36e

File tree

1 file changed

+37
-32
lines changed

1 file changed

+37
-32
lines changed

ui/src/views/system/role/component/PermissionConfiguration.vue

Lines changed: 37 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,15 @@
99
/>
1010
<el-table-column prop="permission" :label="$t('views.model.modelForm.permissionType.label')">
1111
<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>
2221
</template>
2322
</el-table-column>
2423
<el-table-column :width="40">
@@ -74,12 +73,12 @@ const needDisable = computed(() => {
7473
const isAdminOrExtendAdmin = hasPermission([RoleConst.ADMIN, RoleConst.EXTENDS_ADMIN], 'OR')
7574
const isWorkspaceManage =
7675
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+
],
8180
'OR'
82-
)
81+
)
8382
8483
if (!isEeOrPe) {
8584
return false
@@ -123,23 +122,35 @@ async function getRolePermission() {
123122
}
124123
}
125124
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+
}
129139
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
133145
}
134146
135147
function handleRowChange(checked: boolean, row: RoleTableDataItem) {
136148
if (checked) {
137-
row.perChecked = row.permission.map((p) => p.id)
138149
row.permission.forEach((p) => (p.enable = true))
139150
} else {
140-
row.perChecked = []
141151
row.permission.forEach((p) => (p.enable = false))
142152
}
153+
row.perChecked = checked ? row.permission.map((p) => p.id) : []
143154
row.indeterminate = false
144155
}
145156
@@ -182,15 +193,9 @@ watch(() => props.currentRole?.id, getRolePermission, {immediate: true})
182193
183194
async function handleSave() {
184195
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+
)
194199
await loadPermissionApi('role').saveRolePermission(props.currentRole?.id as string, permissions, loading)
195200
MsgSuccess(t('common.saveSuccess'))
196201
} catch (error) {

0 commit comments

Comments
 (0)