"use client"; import Link from "next/link"; import { usePathname, useRouter } from "next/navigation"; import { useCallback, useEffect, useState, type ReactNode } from "react"; import { ThemeToggle } from "~/components/theme-toggle"; import styles from "./admin.module.css"; const NAV = [ { href: "/admin", label: "总览", emoji: "📡" }, { href: "/admin/config", label: "远程配置", emoji: "⚙️" }, { href: "/admin/tt", label: "抖音小程序", emoji: "🎵" }, { href: "/admin/users", label: "用户", emoji: "👥" }, { href: "/admin/orders", label: "订单/支付", emoji: "💳" }, { href: "/admin/verticals", label: "垂直业务", emoji: "🧩" }, { href: "/admin/miniprogram", label: "小程序", emoji: "📱" }, { href: "/admin/analytics", label: "统计", emoji: "📈" }, { href: "/admin/ops", label: "运维", emoji: "🛠️" }, ] as const; export function AdminShell({ children }: { children: ReactNode }) { const pathname = usePathname(); const router = useRouter(); const [ready, setReady] = useState(false); const [authed, setAuthed] = useState(false); const [configured, setConfigured] = useState(true); const [password, setPassword] = useState(""); const [error, setError] = useState(""); const [busy, setBusy] = useState(false); const check = useCallback(async () => { const res = await fetch("/api/admin/session", { cache: "no-store" }); const data = await res.json().catch(() => ({})); setConfigured(Boolean(data.configured)); setAuthed(Boolean(data.ok)); setReady(true); }, []); useEffect(() => { void check(); }, [check]); async function onLogin(e: React.FormEvent) { e.preventDefault(); setBusy(true); setError(""); try { const res = await fetch("/api/admin/login", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ password }), }); const data = await res.json().catch(() => ({})); if (!res.ok || !data.ok) { setError(data.error || "登录失败"); return; } setAuthed(true); setPassword(""); router.refresh(); } finally { setBusy(false); } } async function onLogout() { await fetch("/api/admin/logout", { method: "POST" }); setAuthed(false); } if (!ready) { return (
加载会话…
🔐 Nomadro Admin
{configured ? "输入管理员密码进入编排面板" : "请先在 .env.local 配置 NOMADRO_ADMIN_PASSWORD"}
← 返回门户