nomadro/app/admin/page.tsx
eric 9f8fec1723 Ship portal PC/H5 acceptance, VIP ScrollReader, admin analytics and ops anchors.
Adds /api/health, ntfy notify on config save, /admin/analytics charts, and deploy smoke for miniprogram config/API.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-28 23:52:00 -05:00

166 lines
5.5 KiB
TypeScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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 Link from "next/link";
import { useEffect, useState } from "react";
import styles from "./admin.module.css";
type Overview = {
sdk?: string;
payHint?: { provider: string; env: string };
pb?: { publicUrl: string };
health?: Record<string, { ok: boolean; status?: number; latencyMs?: number }>;
remoteConfig?: {
version?: number;
updatedAt?: string;
flags?: { payEnabled?: boolean; socialFollow?: boolean; offlineBadge?: boolean };
copy?: { vipPriceFen?: number; vipCta?: string; homeBrand?: string };
modules?: Record<string, { enabled: boolean; title: string }>;
};
verticals?: {
id: string;
name: string;
href: string;
admin?: string;
mini: string[];
}[];
};
export default function AdminOverviewPage() {
const [data, setData] = useState<Overview | null>(null);
const [err, setErr] = useState("");
useEffect(() => {
fetch("/api/admin/overview", { 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)));
}, []);
return (
<>
<h1 className={styles.pageTitle}>📡 统一编排总览</h1>
<p className={styles.pageLead}>
整合四垂直 · PC/H5 主端 + 微信/抖音/小红书 Taro 子项目 · SDK{" "}
{data?.sdk || "…"} · 支付提示{" "}
{data?.payHint ? `${data.payHint.provider}/${data.payHint.env}` : "…"}
</p>
{err ? <p className={styles.error}>{err}</p> : null}
{data?.remoteConfig ? (
<div className={styles.panel} style={{ marginBottom: 16 }}>
<h3>远程配置摘要</h3>
<p className={styles.muted}>
v{data.remoteConfig.version} · {data.remoteConfig.updatedAt || "—"} · VIP ¥
{((data.remoteConfig.copy?.vipPriceFen || 0) / 100).toFixed(0)} · CTA「
{data.remoteConfig.copy?.vipCta || "—"}」· pay=
{data.remoteConfig.flags?.payEnabled === false ? "关" : "开"}
</p>
<p style={{ marginTop: 8 }}>
{Object.entries(data.remoteConfig.modules || {}).map(([k, m]) => (
<span
key={k}
className={styles.chip}
style={{
opacity: m.enabled ? 1 : 0.45,
marginRight: 6,
marginBottom: 6,
display: "inline-block",
}}
>
{m.enabled ? "●" : "○"} {m.title || k}
</span>
))}
</p>
<p style={{ marginTop: 8 }}>
<Link href="/admin/config" className={styles.chip}>
编辑完整配置 →
</Link>
</p>
</div>
) : null}
<div className={styles.panel} style={{ marginBottom: 16 }}>
<h3>整合架构</h3>
<ul className={styles.listPlain}>
<li>
<strong>PC/H5</strong>:Next 同进程挂载{" "}
<code>/nav /book /community /vip</code>(源码在{" "}
<code>apps/*</code>)
</li>
<li>
<strong>小程序</strong>:统一仓 <code>apps/miniprogram</code>
(对照各垂直 wemini/dymini/redmini/weapp)
</li>
<li>
<strong>后台</strong>:本面板 +{" "}
<Link href="/admin/config">远程配置</Link> 动态开关页面/文案
</li>
<li>
<strong>离线</strong>:网络失败 → localCatalog / offlineBook / xhs
包内数据
</li>
</ul>
<p style={{ marginTop: 12 }}>
<Link href="/admin/config" className={styles.chip}>
⚙️ 远程配置
</Link>{" "}
<Link href="/admin/miniprogram" className={styles.chip}>
📱 小程序矩阵
</Link>{" "}
<Link href="/admin/verticals" className={styles.chip}>
🧩 垂直业务
</Link>
</p>
</div>
<div className={styles.grid2}>
{Object.entries(data?.health || {}).map(([key, h]) => (
<div key={key} className={styles.panel}>
<h3>{key}</h3>
<span className={h.ok ? styles.badgeOk : styles.badgeBad}>
{h.ok ? "OK" : "DOWN"}
</span>
<p className={styles.muted}>
{h.status ?? "—"} · {h.latencyMs ?? "—"}ms
</p>
</div>
))}
</div>
<h2
className={styles.pageTitle}
style={{ marginTop: "1.5rem", fontSize: "1.15rem" }}
>
四垂直 × PC/H5 × 小程序
</h2>
<div className={styles.grid2}>
{(data?.verticals || []).map((v) => (
<div key={v.id} className={styles.panel}>
<h3>{v.name}</h3>
<p className={styles.muted}>
PC/H5:{v.href} · 小程序:{v.mini.join(" / ")}
</p>
<p style={{ marginTop: 8 }}>
<Link href={v.href} className={styles.chip}>
打开 {v.href}
</Link>{" "}
{v.admin ? (
<Link href={v.admin} className={styles.chip}>
垂直后台
</Link>
) : null}
</p>
</div>
))}
</div>
<p className={styles.muted} style={{ marginTop: "1.25rem" }}>
PocketBase:{data?.pb?.publicUrl || "…"}
</p>
</>
);
}