"use client" import { useState, useEffect } from "react" import { useRouter, usePathname } from "next/navigation" import Link from "next/link" import { Users, User, Radio, Building2, ShoppingBag, FileText, Wallet, MessageSquare, Settings, LogOut, Gamepad2, Hotel, CreditCard, Bell, Search, Activity, ChevronLeft, ChevronRight, LayoutDashboard, Trophy, Monitor, } from "lucide-react" import { Input } from "@/components/ui/input" import { Avatar, AvatarFallback } from "@/components/ui/avatar" import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card" import { Button } from "@/components/ui/button" import { cn } from "@/lib/utils" function AdminLoginForm({ onSuccess }: { onSuccess: () => void; theme?: "light" }) { const [username, setUsername] = useState("") const [password, setPassword] = useState("") const [loading, setLoading] = useState(false) const handleLogin = async () => { if (!username.trim() || !password) { alert("请输入用户名和密码") return } setLoading(true) try { const res = await fetch("/api/admin/auth/login", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ username: username.trim(), password }), }) const json = await res.json() if (json.success) { localStorage.setItem("admin_logged_in", "true") onSuccess() } else { alert(json.message || "用户名或密码错误") } } catch { alert("登录请求失败") } setLoading(false) } return ( <>
setUsername(e.target.value)} placeholder="请输入用户名" className="bg-gray-50 border-gray-200 text-gray-900 placeholder:text-gray-400" />
setPassword(e.target.value)} placeholder="请输入密码" className="bg-gray-50 border-gray-200 text-gray-900 placeholder:text-gray-400" onKeyDown={(e) => e.key === "Enter" && handleLogin()} />
) } const menuGroups: { title: string; items: { id: string; label: string; icon: typeof LayoutDashboard; path: string }[] }[] = [ { title: "概览", items: [ { id: "dashboard", label: "数据概览", icon: LayoutDashboard, path: "/admin" }, { id: "screen", label: "大屏", icon: Monitor, path: "/admin/screen" }, ], }, { title: "用户与创作者", items: [ { id: "users", label: "用户管理", icon: Users, path: "/admin/users" }, { id: "streamers", label: "主播管理", icon: Radio, path: "/admin/streamers" }, { id: "guilds", label: "公会管理", icon: Building2, path: "/admin/guilds" }, { id: "live", label: "直播管理", icon: Gamepad2, path: "/admin/live" }, { id: "party", label: "派对群管理", icon: MessageSquare, path: "/admin/party" }, { id: "content", label: "内容管理", icon: Trophy, path: "/admin/content" }, ], }, { title: "业务与订单", items: [ { id: "mall", label: "商城管理", icon: ShoppingBag, path: "/admin/mall" }, { id: "points", label: "游戏点卡", icon: CreditCard, path: "/admin/points" }, { id: "orders", label: "订单管理", icon: FileText, path: "/admin/orders" }, { id: "leveling", label: "代练管理", icon: Activity, path: "/admin/leveling" }, { id: "pawn", label: "典当管理", icon: Wallet, path: "/admin/pawn" }, { id: "accounts", label: "游戏账号", icon: User, path: "/admin/accounts" }, { id: "hotel", label: "酒店/网咖", icon: Hotel, path: "/admin/hotel" }, ], }, { title: "财务与系统", items: [ { id: "finance", label: "财务管理", icon: CreditCard, path: "/admin/finance" }, { id: "settings", label: "系统设置", icon: Settings, path: "/admin/settings" }, ], }, ] function getCurrentMenuId(pathname: string | null): string { if (!pathname) return "dashboard" if (pathname === "/admin" || pathname === "/admin/") return "dashboard" for (const group of menuGroups) { for (const item of group.items) { if (item.path !== "/admin" && pathname.startsWith(item.path)) return item.id if (pathname === item.path) return item.id } } return "dashboard" } export default function AdminLayout({ children }: { children: React.ReactNode }) { const router = useRouter() const pathname = usePathname() const [isLoggedIn, setIsLoggedIn] = useState(null) const [sidebarOpen, setSidebarOpen] = useState(true) useEffect(() => { const loggedIn = localStorage.getItem("admin_logged_in") === "true" setIsLoggedIn(loggedIn) if (!loggedIn && pathname !== "/admin" && !pathname?.endsWith("/admin")) { router.replace("/admin") } }, [pathname, router]) const handleLogout = () => { localStorage.removeItem("admin_logged_in") setIsLoggedIn(false) router.replace("/admin") } const currentMenuId = getCurrentMenuId(pathname) if (isLoggedIn === null) { return (
加载中...
) } if (!isLoggedIn) { return (
玩值电竞 · 管理后台

请使用管理员账号登录(玩值舱)

setIsLoggedIn(true)} />

默认账号: admin / k123456

) } return (
{/* 左侧导航:神射手风格、可折叠、悬浮、苹果毛玻璃 */}
{/* 主内容区:顶栏 + 内容区 */}
{typeof process !== "undefined" && process.env.NEXT_PUBLIC_BUILD_TIME && ( 部署:{process.env.NEXT_PUBLIC_BUILD_TIME} )} 管理员
{children}
) }