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 }) => ( +
+ +