diff --git a/app/admin/agents/AgentForm.tsx b/app/admin/agents/AgentForm.tsx index e9e4222..753d784 100644 --- a/app/admin/agents/AgentForm.tsx +++ b/app/admin/agents/AgentForm.tsx @@ -18,7 +18,11 @@ export default function AgentForm({ features?: string hotQuestions?: string quickQuestions?: string + difyApiUrl?: string + difyApiKey?: string status?: string + isFeatured?: boolean + featuredOrder?: number } }) { const router = useRouter() @@ -31,10 +35,15 @@ export default function AgentForm({ features: agent?.features || "", hotQuestions: agent?.hotQuestions ? JSON.parse(agent.hotQuestions).join('\n') : '', quickQuestions: agent?.quickQuestions ? JSON.parse(agent.quickQuestions).join('\n') : '', + difyApiUrl: agent?.difyApiUrl || "", + difyApiKey: agent?.difyApiKey || "", status: agent?.status || "active", + isFeatured: agent?.isFeatured ?? false, + featuredOrder: agent?.featuredOrder ?? 0, }) const [loading, setLoading] = useState(false) const [error, setError] = useState("") + const [success, setSuccess] = useState(false) const handleSubmit = async (e: React.FormEvent) => { e.preventDefault() @@ -50,6 +59,8 @@ export default function AgentForm({ const body = { ...formData, + isFeatured: formData.isFeatured, + featuredOrder: formData.featuredOrder, hotQuestions: JSON.stringify(formData.hotQuestions.split('\n').filter(q => q.trim())), quickQuestions: JSON.stringify(formData.quickQuestions.split('\n').filter(q => q.trim())), } @@ -61,9 +72,12 @@ export default function AgentForm({ }) if (res.ok) { + setSuccess(true) + await new Promise(r => setTimeout(r, 1000)) router.push("/admin/agents") } else { - setError("保存失败") + const data = await res.json().catch(() => ({})) + setError(data.error || "保存失败") } } catch (err) { setError("保存失败,请稍后重试") @@ -185,6 +199,34 @@ export default function AgentForm({ /> +
+

热门智能体配置

+
+ +
+ + setFormData({ ...formData, featuredOrder: parseInt(e.target.value) || 0 })} + className="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500" + placeholder="0" + /> +
+
+
+
+
+
+ + setFormData({ ...formData, difyApiUrl: e.target.value })} + className="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500" + placeholder="https://api.dify.ai/v1" + /> +
+
+ + setFormData({ ...formData, difyApiKey: e.target.value })} + className="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500" + placeholder="app-xxxxxxxxxxxx" + /> +
+
+ + {success && ( +
+ 保存成功 +
+ )} + + {error && ( +
+ {error} +
+ )} +
diff --git a/app/admin/agents/page.tsx b/app/admin/agents/page.tsx index be4ffd7..503d119 100644 --- a/app/admin/agents/page.tsx +++ b/app/admin/agents/page.tsx @@ -39,6 +39,7 @@ export default async function AdminAgentsPage() { 名称 分类 + 热门 状态 使用次数 操作 @@ -59,6 +60,15 @@ export default async function AdminAgentsPage() { {agent.category?.name || "-"} + + {agent.isFeatured ? ( + + 热门 + + ) : ( + - + )} + { e.preventDefault() @@ -41,9 +42,12 @@ export default function CategoryForm({ }) if (res.ok) { + setSuccess(true) + await new Promise(r => setTimeout(r, 1000)) router.push("/admin/categories") } else { - setError("保存失败") + const data = await res.json().catch(() => ({})) + setError(data.error || "保存失败") } } catch (err) { setError("保存失败,请稍后重试") @@ -100,10 +104,22 @@ export default function CategoryForm({ /> + {success && ( +
+ 保存成功 +
+ )} + + {error && ( +
+ {error} +
+ )} +
+ {success && ( +
+ 保存成功 +
+ )} + + {error && ( +
+ {error} +
+ )} +