feat: add permission selection for user roles and update related UI components

This commit is contained in:
wxg0103 2025-12-24 17:33:51 +08:00
parent e6f0b83023
commit 12c66ae135
4 changed files with 66 additions and 18 deletions

View File

@ -8885,8 +8885,5 @@ msgstr ""
msgid "Role IDs cannot be empty"
msgstr ""
msgid "Role IDs"
msgstr ""
msgid "Some roles do not exist"
msgstr ""

View File

@ -9011,8 +9011,5 @@ msgstr "导出知识工作流"
msgid "Role IDs cannot be empty"
msgstr "角色 ID 不能为空"
msgid "Role IDs"
msgstr "角色 ID"
msgid "Some roles do not exist"
msgstr "部分角色不存在"

View File

@ -9011,8 +9011,5 @@ msgstr "匯出知識工作流"
msgid "Role IDs cannot be empty"
msgstr "角色 ID 不能为空"
msgid "Role IDs"
msgstr "角色 ID"
msgid "Some roles do not exist"
msgstr "部分角色不存在"

View File

@ -111,16 +111,17 @@
]"
>
<el-row :gutter="16" style="margin-left: 10px">
<el-col :span="12">
<div style="display: flex; align-items: center; gap: 8px; min-width: 0">
<span style="font-size: 13px; white-space: nowrap">
<el-col :span="24">
<div class="flex">
<span style="font-size: 13px; white-space: nowrap;width: 50px"
class="text-right mr-8">
{{ $t('views.role.member.role') }}
</span>
<el-select
v-model="form.role_id"
:placeholder="`${$t('common.selectPlaceholder')}${$t('views.role.member.role')}`"
style="flex: 1; min-width: 180px"
@change="handleRoleChange"
class="w-240"
>
<el-option
v-for="role in roleOptions"
@ -131,15 +132,16 @@
</el-select>
</div>
</el-col>
<el-col :span="12" v-if="user.isEE() && showWorkspaceSelector">
<div style="display: flex; align-items: center; gap: 8px; min-width: 0">
<span style="font-size: 13px; white-space: nowrap">
<el-col :span="24" v-if="user.isEE() && showWorkspaceSelector" class="mt-16">
<div class="flex">
<span style="font-size: 13px; white-space: nowrap;width: 50px"
class="text-right mr-8">
{{ $t('views.role.member.workspace') }}
</span>
<el-select
v-model="form.workspace_id"
:placeholder="`${$t('common.selectPlaceholder')}${$t('views.role.member.workspace')}`"
style="flex: 1; min-width: 180px"
class="w-240"
>
<el-option
v-for="workspace in workspaceOptions"
@ -150,6 +152,27 @@
</el-select>
</div>
</el-col>
<el-col :span="24" v-if="(user.isEE() || user.isPE()) && showPermissionSelector"
class="mt-16">
<div class="flex">
<span style="font-size: 13px; white-space: nowrap;width: 50px"
class="text-right mr-8">
{{ $t('views.system.resourceAuthorization.title') }}
</span>
<el-select
v-model="form.permission"
:placeholder="`${$t('common.selectPlaceholder')}${$t('views.system.resourceAuthorization.title')}`"
class="w-240"
>
<el-option
v-for="permission in permissionOptions"
:key="permission.value"
:label="permission.label"
:value="permission.value"
/>
</el-select>
</div>
</el-col>
</el-row>
</el-form-item>
</el-form>
@ -174,13 +197,15 @@
<script setup lang="ts">
import {ref, onMounted, computed} from 'vue'
import {ComplexPermission} from '@/utils/permission/type'
import {PermissionConst, RoleConst} from '@/utils/permission/data'
import {EditionConst, PermissionConst, RoleConst} from '@/utils/permission/data'
import type {FormInstance} from 'element-plus'
import {t} from '@/locales'
import authApi from '@/api/system-settings/auth-setting.ts'
import {MsgSuccess} from '@/utils/message.ts'
import WorkspaceApi from '@/api/workspace/workspace.ts'
import useStore from '@/stores'
import {AuthorizationEnum} from "@/enums/system.ts";
import {hasPermission} from "@/utils/permission";
const loginMethods = ref<Array<{ label: string; value: string }>>([])
const loading = ref(false)
@ -194,6 +219,7 @@ const form = ref<any>({
lock_time: 10,
role_id: 'USER',
workspace_id: 'default',
permission: 'NOT_AUTH',
})
const normalizeInputValue = (val: number | null): number => {
@ -234,6 +260,7 @@ const submit = async () => {
lock_time: form.value.lock_time,
role_id: form.value.role_id,
workspace_id: form.value.workspace_id,
permission: form.value.permission,
}
await authApi.putLoginSetting(params)
MsgSuccess(t('common.saveSuccess'))
@ -250,7 +277,36 @@ const workspaceOptions = ref<Array<{ id: string; name: string }>>([])
const {user} = useStore()
const selectedRoleType = ref<string>('') // workspace
const showWorkspaceSelector = computed(() => selectedRoleType.value !== 'ADMIN')
const showPermissionSelector = computed(() => selectedRoleType.value === 'USER')
const permissionOptions = computed(() => {
const baseOptions = [
{
label: t('views.system.resourceAuthorization.setting.check'),
value: AuthorizationEnum.VIEW,
desc: t('views.system.resourceAuthorization.setting.checkDesc'),
},
{
label: t('views.system.resourceAuthorization.setting.management'),
value: AuthorizationEnum.MANAGE,
desc: t('views.system.resourceAuthorization.setting.managementDesc'),
},
{
label: t('views.system.resourceAuthorization.setting.notAuthorized'),
value: AuthorizationEnum.NOT_AUTH,
desc: '',
}
];
if (hasPermission([EditionConst.IS_EE, EditionConst.IS_PE], 'OR')) {
baseOptions.splice(2, 0, {
label: t('views.system.resourceAuthorization.setting.role'),
value: AuthorizationEnum.ROLE,
desc: t('views.system.resourceAuthorization.setting.roleDesc'),
});
}
return baseOptions;
});
// selectedRoleType
const handleRoleChange = (roleId: string) => {
const selectedRole = roleOptions.value.find((role) => role.id === roleId)
@ -304,6 +360,7 @@ onMounted(async () => {
lock_time: data.lock_time ?? form.value.lock_time ?? 10,
role_id: data.role_id ?? form.value.role_id ?? 'USER',
workspace_id: data.workspace_id ?? form.value.workspace_id ?? 'default',
permission: data.permission ?? form.value.permission ?? 'NOT_AUTH',
}
loginMethods.value = Array.isArray(data.auth_types) ? data.auth_types : []