"use client"; import { FileTextOutlined, HomeOutlined, LogoutOutlined, PictureOutlined, SettingOutlined } from "@ant-design/icons"; import { Button, Flex, Layout, Menu, Typography, theme } from "antd"; import { LogOut } from "lucide-react"; import Link from "next/link"; import { usePathname, useRouter } from "next/navigation"; import type { ReactNode } from "react"; import { useEffect } from "react"; import { UserStatusActions } from "@/components/user-status-actions"; import { adminLayoutStyle } from "@/lib/app-theme"; import { useThemeStore } from "@/stores/use-theme-store"; import { useUserStore } from "@/stores/use-user-store"; export default function AdminLayout({ children }: { children: ReactNode }) { const { token: antToken } = theme.useToken(); const router = useRouter(); const pathname = usePathname(); const token = useUserStore((state) => state.token); const user = useUserStore((state) => state.user); const isReady = useUserStore((state) => state.isReady); const logout = useUserStore((state) => state.clearSession); const colorTheme = useThemeStore((state) => state.theme); const setTheme = useThemeStore((state) => state.setTheme); const activeKey = pathname.startsWith("/admin/settings") ? "/admin/settings" : pathname.startsWith("/admin/assets") ? "/admin/assets" : pathname.startsWith("/admin/prompts") ? "/admin/prompts" : ""; const pageTitle = pathname.startsWith("/admin/settings") ? "系统设置" : pathname.startsWith("/admin/assets") ? "素材库管理" : "提示词管理"; const appVersion = process.env.NEXT_PUBLIC_APP_VERSION || "dev"; useEffect(() => { if (!isReady) return; if (!token) { router.replace("/login?redirect=/admin"); return; } if (user?.role !== "admin") { router.replace("/"); } }, [isReady, router, token, user?.role]); if (!isReady || !token || user?.role !== "admin") { return (