import { AvatarDropdown, AvatarName, Footer, SelectLang } from '@/components'; import type { Settings as LayoutSettings } from '@ant-design/pro-components'; import { SettingDrawer } from '@ant-design/pro-components'; import type { RunTimeLayoutConfig } from '@umijs/max'; import { history } from '@umijs/max'; import defaultSettings from '../config/defaultSettings'; import { errorConfig } from './requestErrorConfig'; import { clearSessionToken, getAccessToken, getRefreshToken, getTokenExpireTime } from './access'; import { exchangeThirdPartyCredential, isThirdPartyTransitionPage, } from './utils/thirdPartyLogin'; import { saveGetInfoCache } from './utils/jobPortalAuth'; import { getRemoteMenu, getRoutersInfo, getUserInfo, patchRouteWithRemoteMenus, setRemoteMenu, } from './services/session'; import { PageEnum } from './enums/pagesEnums'; import { stringify } from 'querystring'; import { message } from 'antd'; const isDev = process.env.NODE_ENV === 'development'; const loginOut = async () => { clearSessionToken(); setRemoteMenu(null); const { search, pathname } = window.location; const urlParams = new URL(window.location.href).searchParams; /** 此方法会跳转到 redirect 参数所在的位置 */ const redirect = urlParams.get('redirect'); // Note: There may be security issues, please note console.log('redirect', window.location.pathname, redirect); if (window.location.pathname !== '/shihezi/user/login' && !redirect) { history.replace({ pathname: '/user/login', search: stringify({ redirect: pathname.replace('/shihezi', '') + search, }), }); } }; /** * @see https://umijs.org/zh-CN/plugins/plugin-initial-state * */ export async function getInitialState(): Promise<{ settings?: Partial; currentUser?: API.CurrentUser; loading?: boolean; fetchUserInfo?: () => Promise; }> { const fetchUserInfo = async () => { try { const response = await getUserInfo({ skipErrorHandler: true, }); if (response.user.avatar === '') { response.user.avatar = 'https://gw.alipayobjects.com/zos/rmsportal/BiazfanxmamNRoxxVxka.png'; } saveGetInfoCache(response as unknown as Record); return { ...response.user, permissions: response.permissions, roles: response.roles, userType: response.roles?.[0], } as API.CurrentUser; } catch (error) { console.log(error); history.push(PageEnum.LOGIN); } return undefined; }; // 如果不是登录页面,执行 const { location } = history; // 排除登录页面、过渡页面和求职者页面(考虑基础路径 /shihezi/) const isTransitionPage = location.pathname === '/' || location.pathname === '/login-tow' || location.pathname === '/shihezi/' || location.pathname === '/shihezi/login-tow'; // 排除求职者相关页面 const isJobPortalPage = location.pathname.startsWith('/job-portal') || location.pathname.startsWith('/shihezi/job-portal'); if (location.pathname !== PageEnum.LOGIN && !isTransitionPage && !isJobPortalPage) { const currentUser = await fetchUserInfo(); return { fetchUserInfo, currentUser, settings: defaultSettings as Partial, }; } return { fetchUserInfo, settings: defaultSettings as Partial, }; } // ProLayout 支持的api https://procomponents.ant.design/components/layout export const layout: RunTimeLayoutConfig = ({ initialState, setInitialState }) => { return { // actionsRender: () => [, ], actionsRender: () => [], avatarProps: { src: initialState?.currentUser?.avatar, title: , render: (_, avatarChildren) => { return {avatarChildren}; }, }, waterMarkProps: { // content: initialState?.currentUser?.nickName, }, // actionRef: layoutActionRef, menu: { locale: false, // // 每当 initialState?.currentUser?.userid 发生修改时重新执行 request params: { userId: initialState?.currentUser?.userId, }, request: async () => { if (!initialState?.currentUser?.userId) { return []; } return getRemoteMenu(); }, }, footerRender: () =>