feat: enhance agent system with hot/quick questions, dynamic chat UI, and new enterprise agents
- Add hotQuestions and quickQuestions fields to agent model - Update admin form with textarea inputs for hot/quick questions - Make chat page display dynamic agent data (name, icon, questions) - Widen center chat area to 60% for better readability - Add enterprise service category and 3 new agents (jiaotou, promotion, group-policy) - Update Prisma schema formatting and seed data
This commit is contained in:
@@ -16,6 +16,8 @@ export default function AgentForm({
|
||||
icon?: string
|
||||
categoryId?: number
|
||||
features?: string
|
||||
hotQuestions?: string
|
||||
quickQuestions?: string
|
||||
status?: string
|
||||
}
|
||||
}) {
|
||||
@@ -27,6 +29,8 @@ export default function AgentForm({
|
||||
icon: agent?.icon || "",
|
||||
categoryId: agent?.categoryId || "",
|
||||
features: agent?.features || "",
|
||||
hotQuestions: agent?.hotQuestions ? JSON.parse(agent.hotQuestions).join('\n') : '',
|
||||
quickQuestions: agent?.quickQuestions ? JSON.parse(agent.quickQuestions).join('\n') : '',
|
||||
status: agent?.status || "active",
|
||||
})
|
||||
const [loading, setLoading] = useState(false)
|
||||
@@ -44,10 +48,16 @@ export default function AgentForm({
|
||||
|
||||
const method = agent?.id ? "PUT" : "POST"
|
||||
|
||||
const body = {
|
||||
...formData,
|
||||
hotQuestions: JSON.stringify(formData.hotQuestions.split('\n').filter(q => q.trim())),
|
||||
quickQuestions: JSON.stringify(formData.quickQuestions.split('\n').filter(q => q.trim())),
|
||||
}
|
||||
|
||||
const res = await fetch(url, {
|
||||
method,
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(formData),
|
||||
body: JSON.stringify(body),
|
||||
})
|
||||
|
||||
if (res.ok) {
|
||||
@@ -175,6 +185,33 @@ export default function AgentForm({
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-6">
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-700 mb-2">
|
||||
热点问题(每行一个)
|
||||
</label>
|
||||
<textarea
|
||||
rows={5}
|
||||
value={formData.hotQuestions}
|
||||
onChange={(e) => setFormData({ ...formData, hotQuestions: e.target.value })}
|
||||
className="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500"
|
||||
placeholder="养老政策有哪些最新变化? 如何申请养老服务补贴? 老年人健康管理需要注意什么? 养老机构如何选择?"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-700 mb-2">
|
||||
快捷提问(每行一个)
|
||||
</label>
|
||||
<textarea
|
||||
rows={5}
|
||||
value={formData.quickQuestions}
|
||||
onChange={(e) => setFormData({ ...formData, quickQuestions: e.target.value })}
|
||||
className="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500"
|
||||
placeholder="养老政策咨询 养老机构推荐 养老服务申请"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex gap-4">
|
||||
<button
|
||||
type="submit"
|
||||
|
||||
@@ -49,6 +49,8 @@ export default async function EditAgentPage({
|
||||
icon: agent.icon || "",
|
||||
categoryId: agent.categoryId || undefined,
|
||||
features: agent.features,
|
||||
hotQuestions: agent.hotQuestions,
|
||||
quickQuestions: agent.quickQuestions,
|
||||
status: agent.status,
|
||||
}}
|
||||
/>
|
||||
|
||||
@@ -93,7 +93,7 @@ export default function LoginPage() {
|
||||
</form>
|
||||
|
||||
<div className="text-center text-sm text-gray-500">
|
||||
默认账号: admin / admin123
|
||||
{/* 默认账号: admin / admin123 */}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -28,6 +28,8 @@ interface Agent {
|
||||
category: {
|
||||
name: string
|
||||
} | null
|
||||
hotQuestions: string
|
||||
quickQuestions: string
|
||||
}
|
||||
|
||||
export default function AgentChatPage() {
|
||||
@@ -288,12 +290,8 @@ export default function AgentChatPage() {
|
||||
setInput(question)
|
||||
}
|
||||
|
||||
const suggestedQuestions = [
|
||||
'养老政策有哪些最新变化?',
|
||||
'如何申请养老服务补贴?',
|
||||
'老年人健康管理需要注意什么?',
|
||||
'养老机构如何选择?',
|
||||
]
|
||||
const hotQuestions = agent ? JSON.parse(agent.hotQuestions || '[]') : []
|
||||
const quickQuestions = agent ? JSON.parse(agent.quickQuestions || '[]') : []
|
||||
|
||||
if (loading) {
|
||||
return (
|
||||
@@ -389,22 +387,21 @@ export default function AgentChatPage() {
|
||||
</div>
|
||||
|
||||
{/* 中间聊天区域 */}
|
||||
<div className="w-1/2 flex flex-col">
|
||||
<div className="w-[60%] flex flex-col">
|
||||
<div className="flex flex-col h-full bg-white rounded-2xl shadow-lg overflow-hidden">
|
||||
{/* 聊天头部 */}
|
||||
<div className="bg-gradient-to-r from-blue-600 to-blue-700 text-white p-4 flex items-center justify-between">
|
||||
<div className="flex items-center gap-3">
|
||||
<div className="w-10 h-10 rounded-full bg-white/20 flex items-center justify-center">
|
||||
<i className="fas fa-heartbeat text-white text-xl"></i>
|
||||
<span className="text-white text-xl">{agent.icon || '🤖'}</span>
|
||||
</div>
|
||||
<div>
|
||||
<h3 className="font-semibold">智慧养老服务助手</h3>
|
||||
<h3 className="font-semibold">{agent.name}</h3>
|
||||
<p className="text-xs text-blue-100">
|
||||
{sending ? '正在回复...' : '24小时为您服务'}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<span className="bg-white/20 px-3 py-1 rounded text-xs">智能小养正在为您服务</span>
|
||||
</div>
|
||||
|
||||
{/* 消息区域 */}
|
||||
@@ -508,7 +505,7 @@ export default function AgentChatPage() {
|
||||
</div>
|
||||
|
||||
{/* 右侧服务区域 */}
|
||||
<div className="w-1/3 bg-white rounded-2xl border border-gray-200 p-4 overflow-y-auto">
|
||||
<div className="w-[23%] bg-white rounded-2xl border border-gray-200 p-4 overflow-y-auto">
|
||||
{/* 自助服务 */}
|
||||
<div className="bg-gray-50 rounded-lg p-4 mb-4">
|
||||
<h3 className="font-medium text-gray-900 mb-3 flex items-center gap-2">
|
||||
@@ -549,7 +546,7 @@ export default function AgentChatPage() {
|
||||
</a>
|
||||
</div>
|
||||
<ul className="space-y-2">
|
||||
{suggestedQuestions.map((question, index) => (
|
||||
{hotQuestions.map((question: string, index: number) => (
|
||||
<li key={index}>
|
||||
<button
|
||||
onClick={() => handleQuickQuestion(question)}
|
||||
@@ -562,38 +559,25 @@ export default function AgentChatPage() {
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
{/* 快捷提问 */}
|
||||
<div className="bg-gray-50 rounded-lg p-4">
|
||||
<h3 className="font-medium text-gray-900 mb-3 flex items-center gap-2">
|
||||
<i className="fas fa-question-circle text-blue-600"></i>
|
||||
快捷提问
|
||||
</h3>
|
||||
<div className="border-b border-gray-200 mb-3">
|
||||
<div className="flex gap-4 text-sm">
|
||||
<button className="pb-2 border-b-2 border-blue-600 text-blue-600 font-medium">
|
||||
养老服务
|
||||
</button>
|
||||
<button className="pb-2 border-b-2 border-transparent text-gray-500 hover:text-gray-700 transition">
|
||||
健康管理
|
||||
</button>
|
||||
<button className="pb-2 border-b-2 border-transparent text-gray-500 hover:text-gray-700 transition">
|
||||
生活服务
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<ul className="space-y-1">
|
||||
{['养老政策咨询', '养老机构推荐', '养老服务申请'].map((question, index) => (
|
||||
<li key={index}>
|
||||
<button
|
||||
onClick={() => handleQuickQuestion(question)}
|
||||
className="block py-2 px-3 text-sm text-gray-700 hover:bg-blue-50 rounded transition w-full text-left"
|
||||
>
|
||||
{question}
|
||||
</button>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</div>
|
||||
{/* 快捷提问 */}
|
||||
<div className="bg-gray-50 rounded-lg p-4">
|
||||
<h3 className="font-medium text-gray-900 mb-3 flex items-center gap-2">
|
||||
<i className="fas fa-question-circle text-blue-600"></i>
|
||||
快捷提问
|
||||
</h3>
|
||||
<ul className="space-y-2">
|
||||
{quickQuestions.map((question: string, index: number) => (
|
||||
<li key={index}>
|
||||
<button
|
||||
onClick={() => handleQuickQuestion(question)}
|
||||
className="text-sm text-gray-700 hover:text-blue-600 transition block py-1 text-left"
|
||||
>
|
||||
• {question}
|
||||
</button>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
@@ -18,11 +18,14 @@ export async function PUT(
|
||||
icon: data.icon || null,
|
||||
categoryId: data.categoryId ? parseInt(data.categoryId) : null,
|
||||
features: data.features || "",
|
||||
hotQuestions: data.hotQuestions || "[]",
|
||||
quickQuestions: data.quickQuestions || "[]",
|
||||
status: data.status || "active",
|
||||
},
|
||||
})
|
||||
return NextResponse.json(agent)
|
||||
} catch (error) {
|
||||
console.error('PUT /api/admin/agents error:', error)
|
||||
return NextResponse.json({ error: "更新失败" }, { status: 500 })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,8 @@ export async function POST(request: NextRequest) {
|
||||
icon: data.icon || null,
|
||||
categoryId: data.categoryId ? parseInt(data.categoryId) : null,
|
||||
features: data.features || "",
|
||||
hotQuestions: data.hotQuestions || "[]",
|
||||
quickQuestions: data.quickQuestions || "[]",
|
||||
status: data.status || "active",
|
||||
},
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user