feat(role): 添加角色管理相关常量并优化角色状态切换
refactor(role): 使用常量替换硬编码的角色ID和key fix(role): 修正角色排序默认值为1 feat(component): 导出ApiSwitch全局组件
This commit is contained in:
parent
07fa5626fd
commit
448856e547
@ -12,3 +12,5 @@ export function setupGlobalComponent(app: App) {
|
||||
// 表格操作列专用按钮
|
||||
app.component('GhostButton', GhostButton);
|
||||
}
|
||||
|
||||
export { default as ApiSwitch } from './api-switch.vue';
|
||||
|
||||
@ -131,7 +131,7 @@ export const drawerSchema: FormSchemaGetter = () => [
|
||||
fieldName: 'roleSort',
|
||||
label: '角色排序',
|
||||
rules: 'required',
|
||||
defaultValue: 0,
|
||||
defaultValue: 1,
|
||||
},
|
||||
{
|
||||
component: 'Select',
|
||||
|
||||
@ -9,6 +9,12 @@ import { useRouter } from 'vue-router';
|
||||
|
||||
import { useAccess } from '@vben/access';
|
||||
import { Page, useVbenDrawer, useVbenModal } from '@vben/common-ui';
|
||||
import {
|
||||
ADMIN_ROLE_KEY,
|
||||
EnableStatus,
|
||||
SUPERADMIN_ROLE_ID,
|
||||
SUPERADMIN_ROLE_KEY,
|
||||
} from '@vben/constants';
|
||||
import { getVxePopupContainer } from '@vben/utils';
|
||||
|
||||
import { Modal, Popconfirm, Space } from 'antdv-next';
|
||||
@ -20,7 +26,7 @@ import {
|
||||
roleList,
|
||||
roleRemove,
|
||||
} from '#/api/system/role';
|
||||
import { TableSwitch } from '#/components/table';
|
||||
import { ApiSwitch } from '#/components/global';
|
||||
import { commonDownloadExcel } from '#/utils/file/download';
|
||||
|
||||
import { columns, querySchema } from './data';
|
||||
@ -122,7 +128,7 @@ function handleDownloadExcel() {
|
||||
|
||||
const { hasAccessByCodes, hasAccessByRoles } = useAccess();
|
||||
|
||||
const isSuperAdmin = computed(() => hasAccessByRoles(['superadmin']));
|
||||
const isSuperAdmin = computed(() => hasAccessByRoles([SUPERADMIN_ROLE_KEY]));
|
||||
|
||||
const [RoleAuthModal, authModalApi] = useVbenModal({
|
||||
connectedComponent: roleAuthModal,
|
||||
@ -137,6 +143,13 @@ const router = useRouter();
|
||||
function handleAssignRole(record: Role) {
|
||||
router.push(`/system/role-auth/user/${record.roleId}`);
|
||||
}
|
||||
|
||||
async function handleChangeStatus(checked: boolean, row: Role) {
|
||||
await roleChangeStatus({
|
||||
roleId: row.roleId,
|
||||
status: checked ? EnableStatus.Enable : EnableStatus.Disable,
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@ -169,12 +182,12 @@ function handleAssignRole(record: Role) {
|
||||
</Space>
|
||||
</template>
|
||||
<template #status="{ row }">
|
||||
<TableSwitch
|
||||
v-model:value="row.status"
|
||||
:api="() => roleChangeStatus(row)"
|
||||
<ApiSwitch
|
||||
:value="row.status === EnableStatus.Enable"
|
||||
:api="(checked) => handleChangeStatus(checked, row)"
|
||||
:disabled="
|
||||
row.roleId === 1 ||
|
||||
row.roleKey === 'admin' ||
|
||||
row.roleId === SUPERADMIN_ROLE_ID ||
|
||||
row.roleKey === ADMIN_ROLE_KEY ||
|
||||
!hasAccessByCodes(['system:role:edit'])
|
||||
"
|
||||
@reload="tableApi.query()"
|
||||
@ -184,7 +197,9 @@ function handleAssignRole(record: Role) {
|
||||
<!-- 租户管理员不可修改admin角色 防止误操作 -->
|
||||
<!-- 超级管理员可通过租户切换来操作租户管理员角色 -->
|
||||
<template
|
||||
v-if="!row.superAdmin && (row.roleKey !== 'admin' || isSuperAdmin)"
|
||||
v-if="
|
||||
!row.superAdmin && (row.roleKey !== ADMIN_ROLE_KEY || isSuperAdmin)
|
||||
"
|
||||
>
|
||||
<Space>
|
||||
<ghost-button
|
||||
|
||||
@ -41,6 +41,16 @@ export const UNAUTHORIZED_CODE = 401;
|
||||
* 超管用户ID
|
||||
*/
|
||||
export const SUPERADMIN_USER_ID = 1;
|
||||
export const SUPERADMIN_ROLE_ID = 1;
|
||||
|
||||
/**
|
||||
* 超管角色key
|
||||
*/
|
||||
export const SUPERADMIN_ROLE_KEY = 'superadmin';
|
||||
/**
|
||||
* 管理员(非超管) 角色key
|
||||
*/
|
||||
export const ADMIN_ROLE_KEY = 'admin';
|
||||
|
||||
/**
|
||||
* 对应 字典-S系统开关的状态
|
||||
|
||||
Loading…
Reference in New Issue
Block a user