import { AvatarDropdown, AvatarName, Footer, Question, SelectLang, } from "@/components"; import { type Admin, services } from "@/services"; 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 } from "@umijs/max"; import defaultSettings from "../config/defaultSettings"; import { errorConfig } from "./requestErrorConfig"; 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?: Admin; loading?: boolean; fetchUserInfo?: () => Promise; }> { const fetchUserInfo = async () => { try { return await services.admin.Current({}); } catch { // Redirecting on 401 is handled globally in requestErrorConfig. 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?.avatar, title: , render: (_, avatarChildren) => ( {avatarChildren} ), }, waterMarkProps: { content: initialState?.currentUser?.name, }, footerRender: () =>