feat(web): 患者详情 AI 标签页添加趋势分析+体检方案触发按钮
Some checks failed
CI / rust-check (push) Has been cancelled
CI / rust-test (push) Has been cancelled
CI / frontend-build (push) Has been cancelled
CI / security-audit (push) Has been cancelled

This commit is contained in:
iven
2026-05-01 18:23:10 +08:00
parent 8a972f8f4d
commit 7764f7f8a6

View File

@@ -1,5 +1,6 @@
import { useEffect, useState, useCallback } from 'react';
import { useParams, useNavigate } from 'react-router-dom';
import { startAnalysis, type AnalysisType } from '../../api/ai/analysisSse';
import {
Card,
Descriptions,
@@ -44,6 +45,19 @@ export default function PatientDetail() {
const navigate = useNavigate();
const [patient, setPatient] = useState<PatientDetailType | null>(null);
const [loading, setLoading] = useState(false);
const [analysisResult, setAnalysisResult] = useState('');
const [analyzing, setAnalyzing] = useState(false);
const triggerAnalysis = async (type: AnalysisType) => {
if (!id) return;
setAnalyzing(true);
setAnalysisResult('');
await startAnalysis(type, { patient_id: id }, {
onChunk: (content) => setAnalysisResult(prev => prev + content),
onError: (msg) => { message.error(msg); setAnalyzing(false); },
onDone: () => { message.success('分析完成'); setAnalyzing(false); },
});
};
const [editModalOpen, setEditModalOpen] = useState(false);
const [form] = Form.useForm();
const isDark = useThemeMode();
@@ -313,7 +327,26 @@ export default function PatientDetail() {
{
key: 'ai',
label: 'AI 建议',
children: id ? <AiSuggestionTab patientId={id} /> : null,
children: id ? (
<Space direction="vertical" style={{ width: '100%' }}>
<Space>
<AuthButton code="ai.analysis.manage">
<Button size="small" loading={analyzing} onClick={() => triggerAnalysis('trends')}>
</Button>
<Button size="small" loading={analyzing} onClick={() => triggerAnalysis('checkup-plan')}>
</Button>
</AuthButton>
</Space>
<AiSuggestionTab patientId={id} />
{analysisResult && (
<Card title="分析结果" size="small" style={{ marginTop: 8 }}>
<div style={{ whiteSpace: 'pre-wrap' }}>{analysisResult}</div>
</Card>
)}
</Space>
) : null,
},
]}
/>