import { LinkOutlined } from "@ant-design/icons"; import type { Settings as LayoutSettings } from "@ant-design/pro-components"; import { SettingDrawer } from "@ant-design/pro-components"; import type { RequestConfig, RunTimeLayoutConfig } from "@umijs/max"; import { history, Link } from "@umijs/max"; import React from "react"; import { AvatarDropdown, AvatarName, Footer, Question, SelectLang, } from "@/components"; import { getInfo } from "@/services/login"; import type { UserVO, TokenType } from "@/services/login/types"; import defaultSettings from "../config/defaultSettings"; import { errorConfig } from "./requestErrorConfig"; import "@ant-design/v5-patch-for-react-19"; import { getAccessToken, getRefreshToken, getTenantId } from "./utils/auth"; const isDev = process.env.NODE_ENV === "development"; const isDevOrTest = isDev || process.env.CI; const loginPath = "/user/login"; /** * @see https://umijs.org/docs/api/runtime-config#getinitialstate * */ export async function getInitialState(): Promise<{ settings?: Partial; currentUser?: { user: UserVO }; loading?: boolean; fetchUserInfo?: () => Promise<{ user: UserVO } | undefined>; }> { const fetchUserInfo = async () => { // history.push(loginPath); try { const token = getAccessToken(); if (!token) { throw new Error("No token found"); } const msg = await getInfo(); return msg.data; } catch (_error) { history.push(loginPath); } return undefined; }; // 如果不是登录页面,执行 const { location } = history; if ( ![loginPath, "/user/register", "/user/register-result"].includes( location.pathname ) ) { 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: () => [ , , ], avatarProps: { src: initialState?.currentUser?.user.avatar, title: , render: (_, avatarChildren) => ( {avatarChildren} ), }, waterMarkProps: { content: initialState?.currentUser?.user.nickname, }, footerRender: () =>