refactor(web): 消除侧边栏硬编码 — iconMap 抽离 + routeTitleFallback 精简
- iconMap 抽离为 utils/iconRegistry.tsx(单一真相源),补齐 10 个后端 seed 使用但前端缺失的图标 - MainLayout import 从 28 个图标减少到 6 个(仅保留布局专用图标) - routeTitleFallback 从 26 条精简到 10 条(仅保留动态参数路由 + 无后端菜单的静态路由) - 后端菜单已覆盖的 16 条标题映射移除(由 getTitleFromMenus 从后端数据获取) - wiki 关键数字更新:迁移 146、权限码 132
This commit is contained in:
107
apps/web/src/utils/iconRegistry.tsx
Normal file
107
apps/web/src/utils/iconRegistry.tsx
Normal file
@@ -0,0 +1,107 @@
|
||||
/**
|
||||
* 图标注册表 — 菜单图标名称 → React 组件的单一真相源
|
||||
*
|
||||
* 后端 menus.icon 字段存储图标名称字符串(如 "HomeOutlined"),
|
||||
* 前端通过此注册表将其转换为对应的 Ant Design 图标组件。
|
||||
*
|
||||
* 新增后端 seed 图标时必须同步在此添加映射,否则侧边栏回退为 AppstoreOutlined。
|
||||
*/
|
||||
|
||||
import {
|
||||
HomeOutlined,
|
||||
UserOutlined,
|
||||
SafetyOutlined,
|
||||
ApartmentOutlined,
|
||||
SettingOutlined,
|
||||
PartitionOutlined,
|
||||
MessageOutlined,
|
||||
AppstoreOutlined,
|
||||
TeamOutlined,
|
||||
TableOutlined,
|
||||
TagsOutlined,
|
||||
HeartOutlined,
|
||||
CalendarOutlined,
|
||||
PhoneOutlined,
|
||||
CommentOutlined,
|
||||
MedicineBoxOutlined,
|
||||
TrophyOutlined,
|
||||
ShopOutlined,
|
||||
FileTextOutlined,
|
||||
DashboardOutlined,
|
||||
RobotOutlined,
|
||||
HistoryOutlined,
|
||||
BarChartOutlined,
|
||||
AlertOutlined,
|
||||
BellOutlined,
|
||||
ControlOutlined,
|
||||
InboxOutlined,
|
||||
ApiOutlined,
|
||||
ReadOutlined,
|
||||
ExperimentOutlined,
|
||||
// 以下为后端 seed 使用但原 iconMap 缺失的图标
|
||||
AuditOutlined,
|
||||
ClockCircleOutlined,
|
||||
FileSearchOutlined,
|
||||
FormOutlined,
|
||||
MonitorOutlined,
|
||||
PictureOutlined,
|
||||
SafetyCertificateOutlined,
|
||||
SolutionOutlined,
|
||||
SwapOutlined,
|
||||
WifiOutlined,
|
||||
} from '@ant-design/icons';
|
||||
import type { ReactNode } from 'react';
|
||||
|
||||
export const iconRegistry: Record<string, ReactNode> = {
|
||||
// 基础模块
|
||||
HomeOutlined: <HomeOutlined />,
|
||||
UserOutlined: <UserOutlined />,
|
||||
SafetyOutlined: <SafetyOutlined />,
|
||||
ApartmentOutlined: <ApartmentOutlined />,
|
||||
SettingOutlined: <SettingOutlined />,
|
||||
PartitionOutlined: <PartitionOutlined />,
|
||||
MessageOutlined: <MessageOutlined />,
|
||||
AppstoreOutlined: <AppstoreOutlined />,
|
||||
TeamOutlined: <TeamOutlined />,
|
||||
TableOutlined: <TableOutlined />,
|
||||
TagsOutlined: <TagsOutlined />,
|
||||
SearchOutlined: <AppstoreOutlined />, // 搜索无专属侧边栏图标
|
||||
|
||||
// 健康模块
|
||||
HeartOutlined: <HeartOutlined />,
|
||||
CalendarOutlined: <CalendarOutlined />,
|
||||
PhoneOutlined: <PhoneOutlined />,
|
||||
CommentOutlined: <CommentOutlined />,
|
||||
MedicineBoxOutlined: <MedicineBoxOutlined />,
|
||||
TrophyOutlined: <TrophyOutlined />,
|
||||
ShopOutlined: <ShopOutlined />,
|
||||
FileTextOutlined: <FileTextOutlined />,
|
||||
DashboardOutlined: <DashboardOutlined />,
|
||||
RobotOutlined: <RobotOutlined />,
|
||||
HistoryOutlined: <HistoryOutlined />,
|
||||
BarChartOutlined: <BarChartOutlined />,
|
||||
AlertOutlined: <AlertOutlined />,
|
||||
BellOutlined: <BellOutlined />,
|
||||
ControlOutlined: <ControlOutlined />,
|
||||
InboxOutlined: <InboxOutlined />,
|
||||
ApiOutlined: <ApiOutlined />,
|
||||
ReadOutlined: <ReadOutlined />,
|
||||
ExperimentOutlined: <ExperimentOutlined />,
|
||||
|
||||
// 健康模块(补充原缺失)
|
||||
AuditOutlined: <AuditOutlined />,
|
||||
ClockCircleOutlined: <ClockCircleOutlined />,
|
||||
FileSearchOutlined: <FileSearchOutlined />,
|
||||
FormOutlined: <FormOutlined />,
|
||||
MonitorOutlined: <MonitorOutlined />,
|
||||
PictureOutlined: <PictureOutlined />,
|
||||
SafetyCertificateOutlined: <SafetyCertificateOutlined />,
|
||||
SolutionOutlined: <SolutionOutlined />,
|
||||
SwapOutlined: <SwapOutlined />,
|
||||
WifiOutlined: <WifiOutlined />,
|
||||
};
|
||||
|
||||
export function getIcon(name?: string): ReactNode {
|
||||
if (!name) return <AppstoreOutlined />;
|
||||
return iconRegistry[name] || <AppstoreOutlined />;
|
||||
}
|
||||
Reference in New Issue
Block a user