"use client"; import { useCallback, useEffect, useState } from "react"; import type { NomadroRemoteConfig } from "~/lib/remote-config"; import styles from "../admin.module.css"; export default function AdminConfigPage() { const [config, setConfig] = useState(null); const [error, setError] = useState(""); const [saved, setSaved] = useState(""); const [busy, setBusy] = useState(false); const load = useCallback(async () => { setError(""); const res = await fetch("/api/admin/config", { cache: "no-store" }); const data = await res.json().catch(() => ({})); if (!res.ok) { setError(data.error || "加载失败"); return; } setConfig(data.config); }, []); useEffect(() => { void load(); }, [load]); async function save() { if (!config) return; setBusy(true); setSaved(""); setError(""); try { const res = await fetch("/api/admin/config", { method: "PUT", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ config }), }); const data = await res.json().catch(() => ({})); if (!res.ok) { setError(data.error || "保存失败"); return; } setConfig(data.config); setSaved(`已保存 · ${data.config.updatedAt}`); } finally { setBusy(false); } } if (!config) { return ( <>

⚙️ 远程配置

{error || "加载中…"}

); } const moduleKeys = Object.keys(config.modules) as (keyof typeof config.modules)[]; return ( <>

⚙️ 远程配置

前端模块开关 / 文案 / VIP 价格由后端下发;客户端无网用包内默认配置兜底。 持久化:data/remote-config.json

{error ?

{error}

: null} {saved ?

{saved}

: null}

模块开关

{moduleKeys.map((key) => { const m = config.modules[key]; return ( ); })}

功能 Flag

{( [ { key: "payEnabled" as const, label: "支付总开关", hint: "关闭后前端隐藏/拒绝支付入口(不影响已有订单数据)", }, { key: "socialFollow" as const, label: "关注引导总开关", hint: "关闭后不自动弹出「关注公众号 / X」弹窗(含稍后再说)", }, { key: "socialFollowAuto" as const, label: "自动弹出关注公众号(稍后再说)", hint: "开启后首页延迟约 4.5s 弹出;需同时打开「关注引导总开关」。默认关闭。", }, { key: "offlineBadge" as const, label: "离线模式角标", hint: "网络失败走本地兜底时是否显示离线提示", }, ] as const ).map(({ key, label, hint }) => ( ))}

文案 / VIP

{( [ ["homeBrand", "品牌"], ["homeTagline", "副标题"], ["homeLead", "导语"], ["vipProductId", "VIP productId"], ["vipCta", "VIP 按钮"], ] as const ).map(([key, label]) => ( ))}
); }