"use client"; import { useEffect, useState } from "react"; import { RefreshCcw, Save } from "lucide-react"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { Button } from "@/components/ui/button"; type EditableConfig = { key: string; value: string; description: string; }; export function ConfigPageClient() { const [configs, setConfigs] = useState([]); const [editing, setEditing] = useState>({}); const [saving, setSaving] = useState(false); const [result, setResult] = useState(""); const load = async () => { try { const res = await fetch("/api/ops/config"); if (res.ok) { const data = (await res.json()) as { configs?: EditableConfig[] }; setConfigs(data.configs ?? []); } } catch { /* backend not ready yet */ } }; const handleSave = async (key: string) => { const newVal = editing[key]; if (newVal == null) return; setSaving(true); setResult(""); try { const res = await fetch("/api/ops/config", { method: "PUT", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ key, value: newVal }), }); if (res.ok) { setResult(`${key} 已更新`); setConfigs((prev) => prev.map((c) => (c.key === key ? { ...c, value: newVal } : c))); setEditing((prev) => { const n = { ...prev }; delete n[key]; return n; }); } else { setResult(`保存失败: ${await res.text().catch(() => "")}`); } } catch { setResult("保存失败"); } setSaving(false); }; useEffect(() => { void load(); }, []); return (

系统配置

可编辑配置 {configs.length === 0 ? (

配置 API 尚未就绪(需要后端支持)

) : (
{configs.map((cfg) => (
{cfg.key}
{cfg.description}
setEditing((prev) => ({ ...prev, [cfg.key]: e.target.value }))} className="w-24 rounded-lg border border-white/10 bg-black/30 px-3 py-1.5 text-sm text-white font-mono text-center outline-none focus:border-cyan-400/50" />
))}
)} {result && (

{result}

)}

仅显示非敏感配置项。API Key 等密钥不在此处暴露。修改后立即生效,建议重启服务以确保持久化。

); }