| | |
| | | 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' |
| | | |
| | | |
| | |
| | | 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') || '') || {}, |
| | |
| | | export const layout: RunTimeLayoutConfig = ({ initialState, setInitialState }) => { |
| | | |
| | | return { |
| | | siderWidth: '210', |
| | | token: { |
| | | |
| | | }, |
| | | logo: false, |
| | | avatarProps: { |
| | | title: <AvatarName />, |
| | | render: (_, avatarChildren) => { |
| | |
| | | }, |
| | | waterMarkProps: { |
| | | content: false, |
| | | }, |
| | | onPageChange: () => { |
| | | const { location: { pathname } } = history; |
| | | // 如果没有登录,重定向到 login |
| | | if (!initialState?.currentUser && location.pathname !== loginPath) { |
| | | // history.push(loginPath); |
| | | return |
| | | } |
| | | }, |
| | | // 自定义 403 页面 |
| | | unAccessible: <div></div>, |
| | |
| | | ); |
| | | }, |
| | | ...initialState?.settings, |
| | | logo |
| | | }; |
| | | }; |
| | | |