"use client"; import Link from "next/link"; import { useCallback, useEffect, useMemo, useState } from "react"; import styles from "../admin.module.css"; type Latency = { key: string; ok: boolean; latencyMs: number; status: number }; type AnalyticsPayload = { generatedAt?: string; charts?: { latencies: Latency[]; modules: { total: number; enabled: number; disabled: number; items: { id: string; title: string; enabled: boolean }[]; }; flags?: Record; copy?: { vipPriceFen?: number; homeBrand?: string }; }; anchors?: Record; ntfy?: { configured: boolean }; }; function LatencyBars({ rows }: { rows: Latency[] }) { const max = Math.max(1, ...rows.map((r) => r.latencyMs)); return (
{rows.map((r, i) => { const y = 12 + i * 36; const w = Math.max(4, (r.latencyMs / max) * 420); return ( {r.key} {r.latencyMs}ms · {r.ok ? "OK" : "DOWN"} ); })}
); } function ModuleDonut({ enabled, disabled }: { enabled: number; disabled: number }) { const total = Math.max(1, enabled + disabled); const r = 54; const c = 2 * Math.PI * r; const en = (enabled / total) * c; return (
{enabled}/{total} 模块开
  • ● 已开 {enabled}
  • ○ 已关 {disabled}
); } export default function AdminAnalyticsPage() { const [data, setData] = useState(null); const [err, setErr] = useState(""); const [ntfyMsg, setNtfyMsg] = useState("后台手动测试 · 请确认手机/桌面已订阅 topic"); const [ntfyBusy, setNtfyBusy] = useState(false); const [ntfyResult, setNtfyResult] = useState(""); const load = useCallback(() => { setErr(""); fetch("/api/admin/analytics", { cache: "no-store" }) .then(async (r) => { const j = await r.json(); if (!r.ok) throw new Error(j.error || r.statusText); setData(j); }) .catch((e) => setErr(e instanceof Error ? e.message : String(e))); }, []); useEffect(() => { load(); const t = window.setInterval(load, 60_000); return () => window.clearInterval(t); }, [load]); const latencies = data?.charts?.latencies || []; const modules = data?.charts?.modules; const okCount = useMemo(() => latencies.filter((l) => l.ok).length, [latencies]); async function sendNtfy() { setNtfyBusy(true); setNtfyResult(""); try { const res = await fetch("/api/admin/notify", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ title: "Nomadro 后台", message: ntfyMsg, tags: "chart_with_upwards_trend,nomadro", priority: "high", }), }); const j = await res.json().catch(() => ({})); setNtfyResult(j.ok ? "✅ 已推送 ntfy" : `❌ ${j.error || j.skipped || res.status}`); } finally { setNtfyBusy(false); } } return ( <>

📈 统计分析

探针延迟 · 模块开关 · Umami / Uptime-Kuma · 即时 ntfy。生成于{" "} {data?.generatedAt ? new Date(data.generatedAt).toLocaleString() : "…"} {" · "}

{err ?

{err}

: null}

探针健康

{okCount}/{latencies.length || "—"}

OK / 全部探测点

VIP 展示价

¥{(((data?.charts?.copy?.vipPriceFen || 0) as number) / 100).toFixed(0)}

{data?.charts?.copy?.homeBrand || "nomadro"}

服务延迟(ms)

{latencies.length ? :

加载中…

}

模块开关

{modules ? ( ) : (

…

)}
    {(modules?.items || []).map((m) => (
  • {m.enabled ? "●" : "○"} {m.title || m.id}
  • ))}

即时 ntfy

配置:{data?.ntfy?.configured ? "已就绪" : "缺 NTFY_* env(仍可试推公网 topic)"}