feat(web): Phase 2A-1 AI 侧边栏骨架 — 浮动按钮 + 聊天 Drawer
新增 Web 管理后台 AI 侧边栏: - 右下角渐变色浮动按钮(RobotOutlined),hover 放大效果 - AiSidebar Drawer 组件:聊天消息列表 + 输入框 + 发送按钮 - 自动检测当前页面患者 ID,携带 patient_id 上下文到 /ai/chat - 权限检查:无 ai.chat.send 权限时禁用输入并提示 - 气泡样式对话:用户消息蓝色右对齐,助手消息灰色左对齐 - 清空对话、加载态(思考中 Spin)、Enter 发送 + Shift+Enter 换行 新增文件: - apps/web/src/api/ai/chat.ts — AI 聊天 API 模块 - apps/web/src/components/ai/AiSidebar.tsx — 侧边栏组件 修改文件: - apps/web/src/layouts/MainLayout.tsx — 集成浮动按钮 + AiSidebar
This commit is contained in:
27
apps/web/src/api/ai/chat.ts
Normal file
27
apps/web/src/api/ai/chat.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import client from '../client';
|
||||
|
||||
export interface ChatHistoryItem {
|
||||
role: 'user' | 'assistant';
|
||||
content: string;
|
||||
}
|
||||
|
||||
export interface ChatResponse {
|
||||
reply: string;
|
||||
message_id: string;
|
||||
iterations: number;
|
||||
}
|
||||
|
||||
export const aiChatApi = {
|
||||
sendMessage: async (
|
||||
message: string,
|
||||
history: ChatHistoryItem[],
|
||||
patientId?: string
|
||||
): Promise<ChatResponse> => {
|
||||
const resp = await client.post('/ai/chat', {
|
||||
message,
|
||||
history,
|
||||
...(patientId ? { patient_id: patientId } : {}),
|
||||
});
|
||||
return resp.data.data as ChatResponse;
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user