mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-05-05 13:39:24 +08:00
refactor: optimize the order and style of role switching
This commit is contained in:
parent
2a03343d5d
commit
bbdec2881b
@ -16,6 +16,7 @@ import {
|
|||||||
SelectWithTitle,
|
SelectWithTitle,
|
||||||
useCurrentRoleMode,
|
useCurrentRoleMode,
|
||||||
} from '@nocobase/client';
|
} from '@nocobase/client';
|
||||||
|
import { Divider } from 'antd';
|
||||||
|
|
||||||
export const SwitchRole = () => {
|
export const SwitchRole = () => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
@ -36,7 +37,22 @@ export const SwitchRole = () => {
|
|||||||
label: 'title',
|
label: 'title',
|
||||||
value: 'name',
|
value: 'name',
|
||||||
}}
|
}}
|
||||||
options={roles}
|
options={roles.reduce((acc, role) => {
|
||||||
|
acc.push(role);
|
||||||
|
if (role.name === '__union__') {
|
||||||
|
acc.push({
|
||||||
|
name: 'divider',
|
||||||
|
title: <Divider style={{ margin: '2px 1px' }} />,
|
||||||
|
disabled: true,
|
||||||
|
style: {
|
||||||
|
minHeight: 0,
|
||||||
|
height: 'auto',
|
||||||
|
padding: 0,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return acc;
|
||||||
|
}, [])}
|
||||||
defaultValue={currentRole || roles[0].name}
|
defaultValue={currentRole || roles[0].name}
|
||||||
onChange={async (roleName) => {
|
onChange={async (roleName) => {
|
||||||
api.auth.setRole(roleName);
|
api.auth.setRole(roleName);
|
||||||
|
@ -58,10 +58,11 @@ export async function setCurrentRole(ctx: Context, next) {
|
|||||||
ctx.state.currentRoles = userRoles.map((role) => role.name);
|
ctx.state.currentRoles = userRoles.map((role) => role.name);
|
||||||
return next();
|
return next();
|
||||||
} else if (roleMode === SystemRoleMode.allowUseUnion) {
|
} else if (roleMode === SystemRoleMode.allowUseUnion) {
|
||||||
ctx.state.currentUser.roles = userRoles.concat({
|
userRoles.unshift({
|
||||||
name: UNION_ROLE_KEY,
|
name: UNION_ROLE_KEY,
|
||||||
title: ctx.t('Full permissions', { ns: 'acl' }),
|
title: ctx.t('Full permissions', { ns: 'acl' }),
|
||||||
});
|
});
|
||||||
|
ctx.state.currentUser.roles = userRoles;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (currentRole === UNION_ROLE_KEY) {
|
if (currentRole === UNION_ROLE_KEY) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user