refactor: 前端登录/权限/界面状态迁移至 zustand
This commit is contained in:
@@ -3,6 +3,7 @@ import { Result, Button, Spin } from 'antd';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { findRoleAwareLandingPath } from '../auth/menu-policy';
|
||||
import { usePermission } from '../hooks/usePermission';
|
||||
import { useUserStore } from '../store/user/userStore';
|
||||
|
||||
interface PermissionRouteProps {
|
||||
permission: string;
|
||||
@@ -11,17 +12,12 @@ interface PermissionRouteProps {
|
||||
|
||||
const PermissionRoute: React.FC<PermissionRouteProps> = ({ permission, children }) => {
|
||||
const { permissions, permissionsReady, hasPermission } = usePermission();
|
||||
const roles = useUserStore((state) => state.user?.roles ?? []);
|
||||
const navigate = useNavigate();
|
||||
if (!permissionsReady) {
|
||||
return <Spin size="large" style={{ display: 'block', margin: '80px auto' }} />;
|
||||
}
|
||||
if (!hasPermission(permission)) {
|
||||
let roles: string[] = [];
|
||||
try {
|
||||
roles = JSON.parse(localStorage.getItem('user') || '{}').roles || [];
|
||||
} catch {
|
||||
roles = [];
|
||||
}
|
||||
const firstPath = findRoleAwareLandingPath(roles, permissions);
|
||||
return (
|
||||
<Result
|
||||
|
||||
Reference in New Issue
Block a user