pyt
2025-02-24 b31c7c629a2efddc53c89b8f0df0de0e2a33e8d9
management/src/app.tsx
@@ -6,7 +6,6 @@
import { AvatarDropdown, AvatarName } from './components/RightContent/AvatarDropdown';
import { errorConfig } from './requestErrorConfig';
const loginPath = '/login';
import logo from '../public/logo/logo.png'
import '../public/font.css'
@@ -19,7 +18,18 @@
  permission?: Array<Permissions>;
  loading?: boolean;
}> {
  // 如果不是登录页面,执行
  const { location } = history;
  if (location.pathname !== loginPath && !localStorage.getItem('userInfo')) {
    history.replace(loginPath)
    return {
      permission: JSON.parse(localStorage.getItem('access') || '') || [],
      currentUser: JSON.parse(localStorage.getItem('userInfo') || '') || {},
      settings: { ...defaultSettings, fixedHeader: true } as Partial<LayoutSettings>,
    };
  }
  return {
    permission: JSON.parse(localStorage.getItem('access') || '') || [],
    currentUser: JSON.parse(localStorage.getItem('userInfo') || '') || {},
@@ -31,10 +41,7 @@
export const layout: RunTimeLayoutConfig = ({ initialState, setInitialState }) => {
  return {
    siderWidth: '210',
    token: {
    },
    logo: false,
    avatarProps: {
      title: <AvatarName />,
      render: (_, avatarChildren) => {
@@ -43,14 +50,6 @@
    },
    waterMarkProps: {
      content: false,
    },
    onPageChange: () => {
      const { location: { pathname } } = history;
      // 如果没有登录,重定向到 login
      if (!initialState?.currentUser && location.pathname !== loginPath) {
        // history.push(loginPath);
        return
      }
    },
    // 自定义 403 页面
    unAccessible: <div></div>,
@@ -76,7 +75,6 @@
      );
    },
    ...initialState?.settings,
    logo
  };
};