Skip to content

Commit 58f1350

Browse files
author
agile.zhou
committed
set permission group color
1 parent 87bd820 commit 58f1350

File tree

2 files changed

+40
-4
lines changed

2 files changed

+40
-4
lines changed

src/AgileConfig.Server.UI/react-ui-antd/src/locales/zh-CN/pages.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ export default {
278278
'pages.user.reset_password_default': '的密码为默认密码【123456】?',
279279
'pages.role.table.cols.name': '名称',
280280
'pages.role.table.cols.description': '描述',
281-
'pages.role.table.cols.system': '系统角色',
281+
'pages.role.table.cols.system': '系统',
282282
'pages.role.system.yes': '是',
283283
'pages.role.system.no': '否',
284284
'pages.role.table.cols.functions': '权限',

src/AgileConfig.Server.UI/react-ui-antd/src/pages/Role/index.tsx

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { PageContainer } from '@ant-design/pro-layout';
33
import ProTable, { ActionType, ProColumns } from '@ant-design/pro-table';
44
import { Button, message, Modal, Space, Tag } from 'antd';
55
import { ModalForm, ProFormSelect, ProFormText } from '@ant-design/pro-form';
6+
import type { CustomTagProps } from 'rc-select/lib/BaseSelect';
67
import React, { useEffect, useMemo, useRef, useState } from 'react';
78
import { useIntl } from 'umi';
89
import type { RoleFormValues, RoleItem } from './data';
@@ -11,6 +12,34 @@ import { RequireFunction } from '@/utils/permission';
1112

1213
const { confirm } = Modal;
1314

15+
const PERMISSION_GROUP_COLORS: Record<string, string> = {
16+
APP: 'blue',
17+
CONFIG: 'geekblue',
18+
NODE: 'purple',
19+
CLIENT: 'green',
20+
USER: 'gold',
21+
ROLE: 'volcano',
22+
SERVICE: 'cyan',
23+
LOG: 'magenta',
24+
OTHER: 'default',
25+
};
26+
27+
const getPermissionTagColor = (permission: string) => {
28+
const prefix = permission.split('_')[0];
29+
return PERMISSION_GROUP_COLORS[prefix] || PERMISSION_GROUP_COLORS.OTHER;
30+
};
31+
32+
const renderPermissionTag = (props: CustomTagProps) => {
33+
const { label, value, closable, onClose } = props;
34+
return (
35+
<Tag
36+
key={String(value)}
37+
>
38+
123
39+
</Tag>
40+
);
41+
};
42+
1443
const RolePage: React.FC = () => {
1544
const actionRef = useRef<ActionType>();
1645
const intl = useIntl();
@@ -163,16 +192,21 @@ const RolePage: React.FC = () => {
163192
}
164193
return (
165194
<Space size={[0, 4]} wrap>
166-
{fns.map((fn) => (
167-
<Tag key={`${record.id}-${fn}`}>{intl.formatMessage({ id: `pages.role.permissions.${fn}`, defaultMessage: fn })}</Tag>
168-
))}
195+
{fns.map((fn) => {
196+
return (
197+
<Tag color={getPermissionTagColor(fn)} key={`${record.id}-${fn}`}>
198+
{intl.formatMessage({ id: `pages.role.permissions.${fn}`, defaultMessage: fn })}
199+
</Tag>
200+
);
201+
})}
169202
</Space>
170203
);
171204
},
172205
},
173206
{
174207
title: intl.formatMessage({ id: 'pages.role.table.cols.action', defaultMessage: 'Action' }),
175208
valueType: 'option',
209+
width: 160,
176210
render: (_, record) => [
177211
<RequireFunction fn="ROLE_EDIT" key="edit" fallback={null}>
178212
<a
@@ -256,6 +290,7 @@ const RolePage: React.FC = () => {
256290
label={intl.formatMessage({ id: 'pages.role.form.functions', defaultMessage: 'Permissions' })}
257291
mode="multiple"
258292
options={groupedPermissionOptions}
293+
tagRender={renderPermissionTag}
259294
/>
260295
</ModalForm>
261296

@@ -297,6 +332,7 @@ const RolePage: React.FC = () => {
297332
label={intl.formatMessage({ id: 'pages.role.form.functions', defaultMessage: 'Permissions' })}
298333
mode="multiple"
299334
options={groupedPermissionOptions}
335+
tagRender={renderPermissionTag}
300336
/>
301337
</ModalForm>
302338
)}

0 commit comments

Comments
 (0)