mirror of
https://github.com/didi/KnowStreaming.git
synced 2026-01-03 19:38:20 +08:00
fix: 创建/编辑角色优化
This commit is contained in:
@@ -73,12 +73,12 @@ const CheckboxGroupContainer = (props: CheckboxGroupType) => {
|
|||||||
</Checkbox>
|
</Checkbox>
|
||||||
</div>
|
</div>
|
||||||
<Checkbox.Group disabled={disabled} style={{ width: '100%' }} value={checkedList} onChange={onCheckedChange}>
|
<Checkbox.Group disabled={disabled} style={{ width: '100%' }} value={checkedList} onChange={onCheckedChange}>
|
||||||
<Row gutter={[34, 10]}>
|
<Row gutter={[10, 10]}>
|
||||||
{options.map((option) => {
|
{options.map((option) => {
|
||||||
return (
|
return (
|
||||||
<Col span={8} key={option.value}>
|
<Col span={8} key={option.value}>
|
||||||
<Checkbox value={option.value} className="checkbox-content-ellipsis">
|
<Checkbox value={option.value} className="checkbox-content-ellipsis">
|
||||||
{option.label}
|
{option.label.replace('Cluster-Load', '')}
|
||||||
</Checkbox>
|
</Checkbox>
|
||||||
</Col>
|
</Col>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ import {
|
|||||||
IconFont,
|
IconFont,
|
||||||
} from 'knowdesign';
|
} from 'knowdesign';
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
import { CloseOutlined, LoadingOutlined, PlusOutlined } from '@ant-design/icons';
|
import { LoadingOutlined, PlusOutlined } from '@ant-design/icons';
|
||||||
import { defaultPagination } from 'constants/common';
|
import { defaultPagination } from 'constants/common';
|
||||||
import { RoleProps, PermissionNode, AssignUser, RoleOperate, FormItemPermission } from './config';
|
import { RoleProps, PermissionNode, AssignUser, RoleOperate, FormItemPermission } from './config';
|
||||||
import api from 'api';
|
import api from 'api';
|
||||||
@@ -50,11 +50,21 @@ const RoleDetailAndUpdate = forwardRef((props, ref): JSX.Element => {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const globalPermissions = global.permissions;
|
const globalPermissions = global.permissions;
|
||||||
if (globalPermissions && globalPermissions.length) {
|
if (globalPermissions && globalPermissions.length) {
|
||||||
const sysPermissions = globalPermissions.map((sys: PermissionNode) => ({
|
const sysPermissions = globalPermissions.map((sys: PermissionNode) => {
|
||||||
|
const result = {
|
||||||
id: sys.id,
|
id: sys.id,
|
||||||
name: sys.permissionName,
|
name: sys.permissionName,
|
||||||
options: sys.childList.map((node) => ({ label: node.permissionName, value: node.id })),
|
essentialPermission: undefined,
|
||||||
}));
|
options: [],
|
||||||
|
};
|
||||||
|
result.options = sys.childList.map((node) => {
|
||||||
|
if (node.permissionName === '多集群管理查看' || node.permissionName === '系统管理查看') {
|
||||||
|
result.essentialPermission = { label: node.permissionName, value: node.id };
|
||||||
|
}
|
||||||
|
return { label: node.permissionName, value: node.id };
|
||||||
|
});
|
||||||
|
return result;
|
||||||
|
});
|
||||||
setPermissions(sysPermissions);
|
setPermissions(sysPermissions);
|
||||||
}
|
}
|
||||||
}, [global]);
|
}, [global]);
|
||||||
@@ -77,10 +87,12 @@ const RoleDetailAndUpdate = forwardRef((props, ref): JSX.Element => {
|
|||||||
|
|
||||||
const onSubmit = () => {
|
const onSubmit = () => {
|
||||||
form.validateFields().then((formData) => {
|
form.validateFields().then((formData) => {
|
||||||
formData.permissionIdList = formData.permissionIdList.filter((l) => l);
|
|
||||||
formData.permissionIdList.forEach((arr, i) => {
|
formData.permissionIdList.forEach((arr, i) => {
|
||||||
// 如果分配的系统下的子权限,自动赋予该系统的权限
|
// 如果分配的系统下的子权限,自动赋予该系统的权限
|
||||||
if (arr !== null && arr.length) {
|
if (!Array.isArray(arr)) {
|
||||||
|
arr = [];
|
||||||
|
}
|
||||||
|
if (arr?.length) {
|
||||||
arr.push(permissions[i].id);
|
arr.push(permissions[i].id);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -210,10 +222,20 @@ const RoleDetailAndUpdate = forwardRef((props, ref): JSX.Element => {
|
|||||||
<Form.Item
|
<Form.Item
|
||||||
label="分配权限"
|
label="分配权限"
|
||||||
name="permissionIdList"
|
name="permissionIdList"
|
||||||
|
required
|
||||||
rules={[
|
rules={[
|
||||||
() => ({
|
() => ({
|
||||||
validator(_, value) {
|
validator(_, value) {
|
||||||
if (Array.isArray(value) && value.some((item) => !!item?.length)) {
|
if (Array.isArray(value) && value.some((item) => !!item?.length)) {
|
||||||
|
const errs = [];
|
||||||
|
value.forEach((arr, i) => {
|
||||||
|
if (arr?.length && !arr.includes(permissions[i].essentialPermission.value)) {
|
||||||
|
errs.push(`[${permissions[i].essentialPermission.label}]`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (errs.length) {
|
||||||
|
return Promise.reject(`您必须分配 ${errs.join(' 和 ')} 权限`);
|
||||||
|
}
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
return Promise.reject(new Error('请为角色至少分配一项权限'));
|
return Promise.reject(new Error('请为角色至少分配一项权限'));
|
||||||
|
|||||||
@@ -59,5 +59,6 @@ export enum RoleOperate {
|
|||||||
export interface FormItemPermission {
|
export interface FormItemPermission {
|
||||||
id: number;
|
id: number;
|
||||||
name: string;
|
name: string;
|
||||||
|
essentialPermission: { label: string; value: number };
|
||||||
options: { label: string; value: number }[];
|
options: { label: string; value: number }[];
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user