完善角色权限与数据隔离

This commit is contained in:
yml2213
2026-07-26 14:00:50 +08:00
parent b483cbc26d
commit 16d9ab0e5e
38 changed files with 2847 additions and 292 deletions
+13
View File
@@ -1,4 +1,5 @@
import { Navigate, Outlet } from 'react-router-dom'
import { Result, Spin } from 'antd'
import { useAuth } from '@/stores/auth'
const RequireAuth = () => {
@@ -35,4 +36,16 @@ export const RequireTenantAdmin = () => {
return <Outlet />
}
export const RequirePermission = ({ anyOf }: { anyOf: string[] }) => {
const { user, permissions, permissionsLoaded } = useAuth()
if (!user) return <Navigate to="/login" replace />
if (!permissionsLoaded) {
return <div className="h-full flex items-center justify-center"><Spin /></div>
}
if (!anyOf.some(code => permissions.has(code))) {
return <Result status="403" title="403" subTitle="无权访问此页面" />
}
return <Outlet />
}
export default RequireAuth