feat(medications): 添加AI用药分析功能

- 集成流式AI分析接口,支持实时展示分析结果
- 添加VIP权限校验和会员弹窗引导
- 使用Markdown渲染AI分析内容
- 优化底部按钮布局,AI分析按钮占2/3宽度
- 支持请求取消和错误处理
- 自动滚动到分析结果区域
- InfoCard组件优化,图标、标签和箭头排列在同一行
This commit is contained in:
richarjiang
2025-11-12 17:07:42 +08:00
parent 0bea454dca
commit 7c8538f5c6
4 changed files with 405 additions and 45 deletions

View File

@@ -10,7 +10,7 @@ import type {
MedicationStatus,
RepeatPattern,
} from '@/types/medication';
import { api } from './api';
import { api, postTextStream, type TextStreamCallbacks } from './api';
// ==================== DTO 类型定义 ====================
@@ -308,4 +308,24 @@ export const getOverallStats = async (): Promise<{
streak: number;
}> => {
return api.get(`/medication-stats/overall`);
};
};
// ==================== AI 分析相关 ====================
/**
* 流式获取药品 AI 分析
* @param medicationId 药品 ID
* @param callbacks 流式回调
* @returns 包含 abort 方法的对象,用于取消请求
*/
export async function analyzeMedicationStream(
medicationId: string,
callbacks: TextStreamCallbacks
) {
return postTextStream(
`/api/medications/${medicationId}/ai-analysis`,
{},
callbacks,
{ timeoutMs: 120000 }
);
}