"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

{(Object.keys(config.flags) as (keyof typeof config.flags)[]).map((k) => ( ))}

文案 / VIP

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