43 lines
1.4 KiB
TypeScript
43 lines
1.4 KiB
TypeScript
import React from 'react';
|
||
import * as AntdIcons from '@ant-design/icons';
|
||
import type { ReactNode } from 'react';
|
||
|
||
// 图标名称映射配置
|
||
export const iconMap: Record<string, string> = {
|
||
'setting': 'SettingOutlined',
|
||
'user': 'UserOutlined',
|
||
'tree-table': 'TableOutlined',
|
||
'tree': 'ApartmentOutlined',
|
||
'api': 'ApiOutlined',
|
||
'menu': 'MenuOutlined',
|
||
'department': 'TeamOutlined',
|
||
'role': 'UserSwitchOutlined',
|
||
'external': 'ApiOutlined',
|
||
'system': 'SettingOutlined'
|
||
};
|
||
|
||
// 获取图标组件的通用函数
|
||
export const getIconComponent = (iconName: string | undefined): ReactNode => {
|
||
if (!iconName) return null;
|
||
|
||
// 如果在映射中存在,使用映射的名称
|
||
const mappedName = iconMap[iconName] || iconName;
|
||
|
||
// 确保首字母大写并添加Outlined后缀(如果需要)
|
||
const iconKey = mappedName.endsWith('Outlined')
|
||
? mappedName.charAt(0).toUpperCase() + mappedName.slice(1)
|
||
: `${mappedName.charAt(0).toUpperCase() + mappedName.slice(1)}Outlined`;
|
||
|
||
const Icon = (AntdIcons as any)[iconKey];
|
||
return Icon ? <Icon /> : null;
|
||
};
|
||
|
||
// 获取所有可用的图标列表
|
||
export const getAvailableIcons = () => {
|
||
return Object.keys(AntdIcons)
|
||
.filter(key => key.endsWith('Outlined'))
|
||
.map(key => ({
|
||
name: key,
|
||
component: (AntdIcons as any)[key]
|
||
}));
|
||
};
|