From 93e67bb8dc7a3d5ffb1187d49c23f5df3e5f1dd0 Mon Sep 17 00:00:00 2001 From: sion123 <450702724@qq.com> Date: Thu, 7 May 2026 02:29:31 +0800 Subject: [PATCH] feat(web): add settings config form --- .../src/components/config/ConfigForm.tsx | 55 ++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/web/client/src/components/config/ConfigForm.tsx b/web/client/src/components/config/ConfigForm.tsx index 57b39cb..f60be8e 100644 --- a/web/client/src/components/config/ConfigForm.tsx +++ b/web/client/src/components/config/ConfigForm.tsx @@ -1,3 +1,56 @@ +import { useState, useEffect } from 'react'; +import { Button } from '@/components/ui/button'; +import { api } from '@/lib/api'; + export function ConfigForm() { - return
设置
; + const [configs, setConfigs] = useState>({}); + const [saving, setSaving] = useState(false); + + useEffect(() => { + api.getConfigs().then((list) => { + const map: Record = {}; + list.forEach((c) => { map[c.key] = JSON.stringify(c.value, null, 2); }); + setConfigs(map); + }); + }, []); + + const handleSave = async (key: string, raw: string) => { + setSaving(true); + try { + await api.saveConfig(key, JSON.parse(raw)); + } catch { alert('Invalid JSON'); } + setSaving(false); + }; + + const configKeys = [ + { key: 'api_keys', label: 'API 密钥' }, + { key: 'defaults', label: '默认参数' }, + { key: 'endpoints', label: '服务端点' }, + ]; + + return ( +
+

设置

+ {configKeys.map(({ key, label }) => ( +
+ +