fix: read permission
This commit is contained in:
parent
8e8726cd9d
commit
b9aa36ed1e
@ -9,16 +9,15 @@
|
|||||||
/>
|
/>
|
||||||
<el-table-column prop="permission" :label="$t('views.model.modelForm.permissionType.label')">
|
<el-table-column prop="permission" :label="$t('views.model.modelForm.permissionType.label')">
|
||||||
<template #default="{ row }">
|
<template #default="{ row }">
|
||||||
<el-checkbox-group v-model="row.perChecked" @change="handleCellChange($event, row)">
|
<el-checkbox
|
||||||
<el-checkbox
|
v-for="item in row.permission"
|
||||||
v-for="item in row.permission"
|
:key="item.id"
|
||||||
:key="item.id"
|
v-model="item.enable"
|
||||||
:value="item.id"
|
:disabled="disabled"
|
||||||
:disabled="disabled"
|
@change="(val: boolean) => handleCellChange(val, item, row)"
|
||||||
>
|
>
|
||||||
<div class="ellipsis" style="width: 96px">{{ item.name }}</div>
|
<div class="ellipsis" style="width: 96px">{{ item.name }}</div>
|
||||||
</el-checkbox>
|
</el-checkbox>
|
||||||
</el-checkbox-group>
|
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
<el-table-column :width="40">
|
<el-table-column :width="40">
|
||||||
@ -74,12 +73,12 @@ const needDisable = computed(() => {
|
|||||||
const isAdminOrExtendAdmin = hasPermission([RoleConst.ADMIN, RoleConst.EXTENDS_ADMIN], 'OR')
|
const isAdminOrExtendAdmin = hasPermission([RoleConst.ADMIN, RoleConst.EXTENDS_ADMIN], 'OR')
|
||||||
const isWorkspaceManage =
|
const isWorkspaceManage =
|
||||||
hasPermission(
|
hasPermission(
|
||||||
[
|
[
|
||||||
RoleConst.WORKSPACE_MANAGE.getWorkspaceRole,
|
RoleConst.WORKSPACE_MANAGE.getWorkspaceRole,
|
||||||
RoleConst.EXTENDS_WORKSPACE_MANAGE.getWorkspaceRole,
|
RoleConst.EXTENDS_WORKSPACE_MANAGE.getWorkspaceRole,
|
||||||
],
|
],
|
||||||
'OR'
|
'OR'
|
||||||
)
|
)
|
||||||
|
|
||||||
if (!isEeOrPe) {
|
if (!isEeOrPe) {
|
||||||
return false
|
return false
|
||||||
@ -123,23 +122,35 @@ async function getRolePermission() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleCellChange(checkedValues: string[], row: RoleTableDataItem) {
|
function handleCellChange(
|
||||||
row.enable = checkedValues.length === row.permission.length
|
value: boolean,
|
||||||
row.indeterminate = checkedValues.length > 0 && checkedValues.length < row.permission.length
|
item: ChildrenPermissionItem,
|
||||||
|
row: RoleTableDataItem,
|
||||||
|
) {
|
||||||
|
item.enable = value
|
||||||
|
const readItem = row.permission.find((p) => /:READ$/.test(p.id))
|
||||||
|
// 如果勾选的不是 READ,则强制把 READ 也勾上
|
||||||
|
if (value && item.id !== readItem?.id && readItem && !readItem.enable) {
|
||||||
|
readItem.enable = true
|
||||||
|
} else if (!value && item.id === readItem?.id) {
|
||||||
|
// 取消 READ 整行其他权限全部取消
|
||||||
|
row.permission.forEach((p) => (p.enable = false))
|
||||||
|
}
|
||||||
|
|
||||||
row.permission.forEach((p) => {
|
const checkedIds = row.permission.filter((p) => p.enable).map((p) => p.id)
|
||||||
p.enable = checkedValues.includes(p.id)
|
row.perChecked = checkedIds
|
||||||
})
|
row.enable = checkedIds.length === row.permission.length
|
||||||
|
row.indeterminate =
|
||||||
|
checkedIds.length > 0 && checkedIds.length < row.permission.length
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleRowChange(checked: boolean, row: RoleTableDataItem) {
|
function handleRowChange(checked: boolean, row: RoleTableDataItem) {
|
||||||
if (checked) {
|
if (checked) {
|
||||||
row.perChecked = row.permission.map((p) => p.id)
|
|
||||||
row.permission.forEach((p) => (p.enable = true))
|
row.permission.forEach((p) => (p.enable = true))
|
||||||
} else {
|
} else {
|
||||||
row.perChecked = []
|
|
||||||
row.permission.forEach((p) => (p.enable = false))
|
row.permission.forEach((p) => (p.enable = false))
|
||||||
}
|
}
|
||||||
|
row.perChecked = checked ? row.permission.map((p) => p.id) : []
|
||||||
row.indeterminate = false
|
row.indeterminate = false
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -182,15 +193,9 @@ watch(() => props.currentRole?.id, getRolePermission, {immediate: true})
|
|||||||
|
|
||||||
async function handleSave() {
|
async function handleSave() {
|
||||||
try {
|
try {
|
||||||
const permissions: { id: string; enable: boolean }[] = []
|
const permissions = tableData.value.flatMap((row) =>
|
||||||
tableData.value.forEach((e) => {
|
row.permission.map((p) => ({ id: p.id, enable: p.enable })),
|
||||||
e.permission?.forEach((ele: ChildrenPermissionItem) => {
|
)
|
||||||
permissions.push({
|
|
||||||
id: ele.id,
|
|
||||||
enable: ele.enable,
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
await loadPermissionApi('role').saveRolePermission(props.currentRole?.id as string, permissions, loading)
|
await loadPermissionApi('role').saveRolePermission(props.currentRole?.id as string, permissions, loading)
|
||||||
MsgSuccess(t('common.saveSuccess'))
|
MsgSuccess(t('common.saveSuccess'))
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user