@@ -3,6 +3,7 @@ import { PageContainer } from '@ant-design/pro-layout';
33import ProTable , { ActionType , ProColumns } from '@ant-design/pro-table' ;
44import { Button , message , Modal , Space , Tag } from 'antd' ;
55import { ModalForm , ProFormSelect , ProFormText } from '@ant-design/pro-form' ;
6+ import type { CustomTagProps } from 'rc-select/lib/BaseSelect' ;
67import React , { useEffect , useMemo , useRef , useState } from 'react' ;
78import { useIntl } from 'umi' ;
89import type { RoleFormValues , RoleItem } from './data' ;
@@ -11,6 +12,34 @@ import { RequireFunction } from '@/utils/permission';
1112
1213const { 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+
1443const 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