ybt | 02e716d | 2025-04-15 17:19:32 +0800 | [diff] [blame^] | 1 | import React from 'react'; |
2 | |||||
3 | // 基于角色的UI控制组件 | ||||
4 | const RoleBasedControl = ({ allowedRoles, children }) => { | ||||
5 | const user = JSON.parse(localStorage.getItem('user') || '{}'); | ||||
6 | const userRole = user.role || 'guest'; | ||||
7 | |||||
8 | if (allowedRoles.includes(userRole)) { | ||||
9 | return <>{children}</>; | ||||
10 | } | ||||
11 | |||||
12 | return null; | ||||
13 | }; | ||||
14 | |||||
15 | export default RoleBasedControl; |