deploy-ease-platform/frontend/src/config/icons.tsx
2024-12-02 23:37:30 +08:00

43 lines
1.4 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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]
}));
};