feat(frontend): add frontend-v2 modular architecture (Task 17)
- React 19 + TypeScript + Vite - Module registration mechanism with dynamic loading - Permission management system (basic/advanced/premium) - Route guards for access control - Error boundaries for module isolation - 6 business module placeholders (AIA/ASL/PKB/DC/SSA/ST) - Top navigation layout - Tailwind CSS 3 + Ant Design 5
This commit is contained in:
125
frontend-v2/src/framework/modules/moduleRegistry.ts
Normal file
125
frontend-v2/src/framework/modules/moduleRegistry.ts
Normal file
@@ -0,0 +1,125 @@
|
||||
import { lazy } from 'react'
|
||||
import { ModuleDefinition } from './types'
|
||||
import {
|
||||
MessageOutlined,
|
||||
FileSearchOutlined,
|
||||
FolderOpenOutlined,
|
||||
ClearOutlined,
|
||||
BarChartOutlined,
|
||||
LineChartOutlined
|
||||
} from '@ant-design/icons'
|
||||
|
||||
/**
|
||||
* 模块注册中心
|
||||
* 按照平台架构文档顺序注册所有业务模块
|
||||
* 参考:docs/01-平台基础层/06-前端架构/01-前端总体架构设计.md
|
||||
*/
|
||||
export const MODULES: ModuleDefinition[] = [
|
||||
{
|
||||
id: 'ai-qa',
|
||||
name: 'AI问答',
|
||||
path: '/ai-qa',
|
||||
icon: MessageOutlined,
|
||||
component: lazy(() => import('@/modules/aia')),
|
||||
placeholder: true, // 后续重写
|
||||
requiredVersion: 'basic',
|
||||
description: '基于LLM的智能问答系统',
|
||||
},
|
||||
{
|
||||
id: 'literature-platform',
|
||||
name: 'AI智能文献',
|
||||
path: '/literature',
|
||||
icon: FileSearchOutlined,
|
||||
component: lazy(() => import('@/modules/asl')),
|
||||
placeholder: false, // Week 3 开发
|
||||
requiredVersion: 'advanced',
|
||||
description: 'AI驱动的文献筛选和分析系统',
|
||||
standalone: true, // 支持独立运行
|
||||
},
|
||||
{
|
||||
id: 'knowledge-base',
|
||||
name: '知识库',
|
||||
path: '/knowledge-base',
|
||||
icon: FolderOpenOutlined,
|
||||
component: lazy(() => import('@/modules/pkb')),
|
||||
placeholder: true, // 后续重写
|
||||
requiredVersion: 'basic',
|
||||
description: '个人知识库管理系统',
|
||||
},
|
||||
{
|
||||
id: 'data-cleaning',
|
||||
name: '智能数据清洗',
|
||||
path: '/data-cleaning',
|
||||
icon: ClearOutlined,
|
||||
component: lazy(() => import('@/modules/dc')),
|
||||
placeholder: true, // 占位
|
||||
requiredVersion: 'advanced',
|
||||
description: '智能数据清洗整理工具',
|
||||
},
|
||||
{
|
||||
id: 'statistical-analysis',
|
||||
name: '智能统计分析',
|
||||
path: '/intelligent-analysis',
|
||||
icon: BarChartOutlined,
|
||||
component: lazy(() => import('@/modules/ssa')),
|
||||
placeholder: true, // Java团队开发,前端集成
|
||||
requiredVersion: 'premium',
|
||||
description: '智能统计分析系统(Java团队开发)',
|
||||
isExternal: true, // 外部模块
|
||||
},
|
||||
{
|
||||
id: 'statistical-tools',
|
||||
name: '统计分析工具',
|
||||
path: '/statistical-tools',
|
||||
icon: LineChartOutlined,
|
||||
component: lazy(() => import('@/modules/st')),
|
||||
placeholder: true, // Java团队开发,前端集成
|
||||
requiredVersion: 'premium',
|
||||
description: '统计分析工具集(Java团队开发)',
|
||||
isExternal: true, // 外部模块
|
||||
},
|
||||
]
|
||||
|
||||
/**
|
||||
* 根据ID获取模块
|
||||
*/
|
||||
export const getModuleById = (id: string): ModuleDefinition | undefined => {
|
||||
return MODULES.find(module => module.id === id)
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据路径获取模块
|
||||
*/
|
||||
export const getModuleByPath = (path: string): ModuleDefinition | undefined => {
|
||||
return MODULES.find(module => path.startsWith(module.path))
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有可用模块(根据权限过滤)
|
||||
*
|
||||
* @param userVersion 用户版本(权限等级)
|
||||
* @returns 用户有权访问的模块列表
|
||||
*
|
||||
* @version Week 2 Day 7 - 任务17:实现权限过滤逻辑
|
||||
*/
|
||||
export const getAvailableModules = (userVersion: string = 'premium'): ModuleDefinition[] => {
|
||||
// 权限等级映射
|
||||
const versionLevel: Record<string, number> = {
|
||||
basic: 1,
|
||||
advanced: 2,
|
||||
premium: 3,
|
||||
}
|
||||
|
||||
const currentLevel = versionLevel[userVersion] || 0
|
||||
|
||||
// 过滤出用户有权限访问的模块
|
||||
return MODULES.filter(module => {
|
||||
// 如果模块没有权限要求,所有人都可以访问
|
||||
if (!module.requiredVersion) return true
|
||||
|
||||
// 检查用户权限等级是否满足模块要求
|
||||
const requiredLevel = versionLevel[module.requiredVersion] || 0
|
||||
return currentLevel >= requiredLevel
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user