Files
Edu/apps/admin-portal/src/app/admin-app.tsx
SpecialX b3511910d1 feat(admin-portal): 完整实现 admin-portal 管理端微前端
包含 src 全部实现、Dockerfile、配置文件等
2026-07-10 19:09:12 +08:00

52 lines
1.6 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"use client";
import { type ReactNode } from "react";
import { GraphQLProvider } from "@/providers/graphql-provider";
import { AuthProvider } from "@/providers/auth-provider";
import { ToastProvider } from "@/providers/toast-provider";
import { AdminShell } from "@/components/admin-shell";
import { MswInitializer } from "@/components/msw-initializer";
import { useState, useEffect } from "react";
/**
* MF Remote 入口组件
*
* 仲裁 ARB-002 §2.2Shell 动态 import admin/AdminApp 加载管理端
* - MF 模式Shell 提供 GraphQLProvider/AuthProvider/AppShellAdminApp 仅渲染页面
* - Standalone 模式AdminApp 自建 providers + AdminShell
*
* 暴露next.config.js exposes: { './AdminApp': './src/app/admin-app.tsx' }
*/
export default function AdminApp({ children }: { children: ReactNode }) {
const [mswReady, setMswReady] = useState(false);
// MF 模式下复用 Shell providers通过 dynamic import
// Standalone 模式下自建 providers
const isStandalone = process.env.NEXT_PUBLIC_MF_ENABLED !== "true";
useEffect(() => {
if (!isStandalone) {
setMswReady(true);
}
}, [isStandalone]);
if (!isStandalone) {
// MF 模式Shell 已提供 providers + AppShell
return <>{children}</>;
}
// Standalone 模式:自建 providers
return (
<GraphQLProvider>
<MswInitializer onReady={() => setMswReady(true)} />
{mswReady && (
<AuthProvider>
<ToastProvider>
<AdminShell>{children}</AdminShell>
</ToastProvider>
</AuthProvider>
)}
</GraphQLProvider>
);
}