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:
44
frontend-v2/src/framework/permission/usePermission.ts
Normal file
44
frontend-v2/src/framework/permission/usePermission.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
import { useContext } from 'react'
|
||||
import { PermissionContext } from './PermissionContext'
|
||||
import { PermissionContextType } from './types'
|
||||
|
||||
/**
|
||||
* 权限Hook
|
||||
*
|
||||
* @description 提供便捷的权限检查功能
|
||||
* @version Week 2 Day 7 - 任务17
|
||||
*
|
||||
* @example
|
||||
* ```tsx
|
||||
* const MyComponent = () => {
|
||||
* const { user, checkModulePermission } = usePermission()
|
||||
*
|
||||
* if (!checkModulePermission('advanced')) {
|
||||
* return <UpgradePrompt />
|
||||
* }
|
||||
*
|
||||
* return <div>欢迎 {user?.name}</div>
|
||||
* }
|
||||
* ```
|
||||
*/
|
||||
export const usePermission = (): PermissionContextType => {
|
||||
const context = useContext(PermissionContext)
|
||||
|
||||
if (context === undefined) {
|
||||
throw new Error(
|
||||
'usePermission must be used within a PermissionProvider. ' +
|
||||
'Please wrap your app with <PermissionProvider>.'
|
||||
)
|
||||
}
|
||||
|
||||
return context
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出权限相关类型(方便使用)
|
||||
*/
|
||||
export type { UserInfo, UserVersion, PermissionContextType } from './types'
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user