feat: 医生端Web后台 + SignalR实时问诊

- 新增 doctor_web/ React前端 (dashboard/患者/问诊/报告/随访)
- 后端新增 doctor_endpoints (14个医生API) + ConsultationHub (SignalR)
- Flutter端 SignalR 替换轮询实现实时聊天
This commit is contained in:
MingNian
2026-06-05 17:46:07 +08:00
parent 20a5ce1199
commit d0d7d8428d
41 changed files with 5892 additions and 18 deletions

7
doctor_web/src/App.tsx Normal file
View File

@@ -0,0 +1,7 @@
import { RouterProvider } from 'react-router-dom';
import { router } from './router';
import './index.css';
export default function App() {
return <RouterProvider router={router} />;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

View File

@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="35.93" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 228"><path fill="#00D8FF" d="M210.483 73.824a171.49 171.49 0 0 0-8.24-2.597c.465-1.9.893-3.777 1.273-5.621c6.238-30.281 2.16-54.676-11.769-62.708c-13.355-7.7-35.196.329-57.254 19.526a171.23 171.23 0 0 0-6.375 5.848a155.866 155.866 0 0 0-4.241-3.917C100.759 3.829 77.587-4.822 63.673 3.233C50.33 10.957 46.379 33.89 51.995 62.588a170.974 170.974 0 0 0 1.892 8.48c-3.28.932-6.445 1.924-9.474 2.98C17.309 83.498 0 98.307 0 113.668c0 15.865 18.582 31.778 46.812 41.427a145.52 145.52 0 0 0 6.921 2.165a167.467 167.467 0 0 0-2.01 9.138c-5.354 28.2-1.173 50.591 12.134 58.266c13.744 7.926 36.812-.22 59.273-19.855a145.567 145.567 0 0 0 5.342-4.923a168.064 168.064 0 0 0 6.92 6.314c21.758 18.722 43.246 26.282 56.54 18.586c13.731-7.949 18.194-32.003 12.4-61.268a145.016 145.016 0 0 0-1.535-6.842c1.62-.48 3.21-.974 4.76-1.488c29.348-9.723 48.443-25.443 48.443-41.52c0-15.417-17.868-30.326-45.517-39.844Zm-6.365 70.984c-1.4.463-2.836.91-4.3 1.345c-3.24-10.257-7.612-21.163-12.963-32.432c5.106-11 9.31-21.767 12.459-31.957c2.619.758 5.16 1.557 7.61 2.4c23.69 8.156 38.14 20.213 38.14 29.504c0 9.896-15.606 22.743-40.946 31.14Zm-10.514 20.834c2.562 12.94 2.927 24.64 1.23 33.787c-1.524 8.219-4.59 13.698-8.382 15.893c-8.067 4.67-25.32-1.4-43.927-17.412a156.726 156.726 0 0 1-6.437-5.87c7.214-7.889 14.423-17.06 21.459-27.246c12.376-1.098 24.068-2.894 34.671-5.345a134.17 134.17 0 0 1 1.386 6.193ZM87.276 214.515c-7.882 2.783-14.16 2.863-17.955.675c-8.075-4.657-11.432-22.636-6.853-46.752a156.923 156.923 0 0 1 1.869-8.499c10.486 2.32 22.093 3.988 34.498 4.994c7.084 9.967 14.501 19.128 21.976 27.15a134.668 134.668 0 0 1-4.877 4.492c-9.933 8.682-19.886 14.842-28.658 17.94ZM50.35 144.747c-12.483-4.267-22.792-9.812-29.858-15.863c-6.35-5.437-9.555-10.836-9.555-15.216c0-9.322 13.897-21.212 37.076-29.293c2.813-.98 5.757-1.905 8.812-2.773c3.204 10.42 7.406 21.315 12.477 32.332c-5.137 11.18-9.399 22.249-12.634 32.792a134.718 134.718 0 0 1-6.318-1.979Zm12.378-84.26c-4.811-24.587-1.616-43.134 6.425-47.789c8.564-4.958 27.502 2.111 47.463 19.835a144.318 144.318 0 0 1 3.841 3.545c-7.438 7.987-14.787 17.08-21.808 26.988c-12.04 1.116-23.565 2.908-34.161 5.309a160.342 160.342 0 0 1-1.76-7.887Zm110.427 27.268a347.8 347.8 0 0 0-7.785-12.803c8.168 1.033 15.994 2.404 23.343 4.08c-2.206 7.072-4.956 14.465-8.193 22.045a381.151 381.151 0 0 0-7.365-13.322Zm-45.032-43.861c5.044 5.465 10.096 11.566 15.065 18.186a322.04 322.04 0 0 0-30.257-.006c4.974-6.559 10.069-12.652 15.192-18.18ZM82.802 87.83a323.167 323.167 0 0 0-7.227 13.238c-3.184-7.553-5.909-14.98-8.134-22.152c7.304-1.634 15.093-2.97 23.209-3.984a321.524 321.524 0 0 0-7.848 12.897Zm8.081 65.352c-8.385-.936-16.291-2.203-23.593-3.793c2.26-7.3 5.045-14.885 8.298-22.6a321.187 321.187 0 0 0 7.257 13.246c2.594 4.48 5.28 8.868 8.038 13.147Zm37.542 31.03c-5.184-5.592-10.354-11.779-15.403-18.433c4.902.192 9.899.29 14.978.29c5.218 0 10.376-.117 15.453-.343c-4.985 6.774-10.018 12.97-15.028 18.486Zm52.198-57.817c3.422 7.8 6.306 15.345 8.596 22.52c-7.422 1.694-15.436 3.058-23.88 4.071a382.417 382.417 0 0 0 7.859-13.026a347.403 347.403 0 0 0 7.425-13.565Zm-16.898 8.101a358.557 358.557 0 0 1-12.281 19.815a329.4 329.4 0 0 1-23.444.823c-7.967 0-15.716-.248-23.178-.732a310.202 310.202 0 0 1-12.513-19.846h.001a307.41 307.41 0 0 1-10.923-20.627a310.278 310.278 0 0 1 10.89-20.637l-.001.001a307.318 307.318 0 0 1 12.413-19.761c7.613-.576 15.42-.876 23.31-.876H128c7.926 0 15.743.303 23.354.883a329.357 329.357 0 0 1 12.335 19.695a358.489 358.489 0 0 1 11.036 20.54a329.472 329.472 0 0 1-11 20.722Zm22.56-122.124c8.572 4.944 11.906 24.881 6.52 51.026c-.344 1.668-.73 3.367-1.15 5.09c-10.622-2.452-22.155-4.275-34.23-5.408c-7.034-10.017-14.323-19.124-21.64-27.008a160.789 160.789 0 0 1 5.888-5.4c18.9-16.447 36.564-22.941 44.612-18.3ZM128 90.808c12.625 0 22.86 10.235 22.86 22.86s-10.235 22.86-22.86 22.86s-22.86-10.235-22.86-22.86s10.235-22.86 22.86-22.86Z"></path></svg>

After

Width:  |  Height:  |  Size: 4.0 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 8.5 KiB

View File

@@ -0,0 +1,124 @@
.layout {
display: flex;
min-height: 100vh;
}
/* ---- 侧边栏 ---- */
.sidebar {
width: 224px;
background: #FFF;
border-right: 1px solid #EDF0F7;
display: flex;
flex-direction: column;
flex-shrink: 0;
}
.brand {
padding: 24px 20px 20px;
border-bottom: 1px solid #EDF0F7;
}
.brandTitle {
font-size: 18px;
font-weight: 700;
color: #1A1D28;
display: flex;
align-items: center;
gap: 8px;
}
.brandSub {
font-size: 12px;
color: #9BA0B4;
margin-top: 2px;
}
.nav {
flex: 1;
padding: 12px 12px;
display: flex;
flex-direction: column;
gap: 2px;
}
.navItem {
display: flex;
align-items: center;
gap: 12px;
padding: 10px 12px;
border-radius: 10px;
text-decoration: none;
color: #5A6072;
font-size: 14px;
font-weight: 500;
transition: all 0.15s;
}
.navItem:hover {
background: #F5F6FA;
color: #1A1D28;
}
.navItem.active {
background: #EDF0FD;
color: #4F6EF7;
font-weight: 600;
}
.navIcon {
width: 20px;
height: 20px;
display: flex;
align-items: center;
justify-content: center;
font-size: 16px;
}
.footer {
padding: 16px 20px;
border-top: 1px solid #EDF0F7;
background: #FAFBFD;
}
.doctorInfo {
display: flex;
align-items: center;
gap: 12px;
}
.avatar {
width: 40px;
height: 40px;
border-radius: 10px;
background: linear-gradient(135deg, #4F6EF7, #6C8AFF);
display: flex;
align-items: center;
justify-content: center;
color: #FFF;
font-size: 16px;
font-weight: 600;
}
.doctorName {
font-size: 14px;
font-weight: 600;
color: #1A1D28;
}
.doctorMeta {
font-size: 12px;
color: #9BA0B4;
}
/* ---- 内容区 ---- */
.content {
flex: 1;
background: #F2F5FA;
min-width: 0;
animation: fadeIn 0.25s ease;
}
@keyframes fadeIn {
from { opacity: 0; transform: translateY(6px); }
to { opacity: 1; transform: translateY(0); }
}

View File

@@ -0,0 +1,70 @@
import { NavLink, Outlet, useLocation } from 'react-router-dom';
import { useEffect, useState } from 'react';
import { api } from '../../services/api-client';
import type { DashboardStats } from '../../types';
import styles from './DoctorLayout.module.css';
const NAV_ITEMS = [
{ to: '/dashboard', label: '工作台', icon: '📊' },
{ to: '/patients', label: '患者管理', icon: '👥' },
{ to: '/consultations', label: '在线问诊', icon: '💬' },
{ to: '/reports', label: '报告审核', icon: '📋' },
{ to: '/follow-ups', label: '复查随访', icon: '📅' },
];
export default function DoctorLayout() {
const location = useLocation();
const [doctor, setDoctor] = useState<DashboardStats | null>(null);
useEffect(() => {
api.get<DashboardStats>('/api/doctor/dashboard').then(setDoctor).catch(() => {});
}, []);
return (
<div className={styles.layout}>
{/* 侧边栏 */}
<aside className={styles.sidebar}>
<div className={styles.brand}>
<div className={styles.brandTitle}>
<span></span>
</div>
<div className={styles.brandSub}></div>
</div>
<nav className={styles.nav}>
{NAV_ITEMS.map(item => (
<NavLink
key={item.to}
to={item.to}
className={({ isActive }) =>
`${styles.navItem} ${isActive ? styles.active : ''}`
}
>
<span className={styles.navIcon}>{item.icon}</span>
{item.label}
</NavLink>
))}
</nav>
<div className={styles.footer}>
<div className={styles.doctorInfo}>
<div className={styles.avatar}>
{doctor?.doctorName?.[0] ?? '王'}
</div>
<div>
<div className={styles.doctorName}>{doctor?.doctorName ?? '王建国'}</div>
<div className={styles.doctorMeta}>
{doctor?.doctorTitle ?? '主任医师'} · {doctor?.doctorDepartment ?? '心血管内科'}
</div>
</div>
</div>
</div>
</aside>
{/* 内容区 */}
<main className={styles.content} key={location.pathname}>
<Outlet />
</main>
</div>
);
}

5
doctor_web/src/index.css Normal file
View File

@@ -0,0 +1,5 @@
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif; color: #1A1D28; background: #F2F5FA; -webkit-font-smoothing: antialiased; }
a { text-decoration: none; color: inherit; }
button { cursor: pointer; font-family: inherit; }
input, textarea, select { font-family: inherit; }

9
doctor_web/src/main.tsx Normal file
View File

@@ -0,0 +1,9 @@
import { StrictMode } from 'react';
import { createRoot } from 'react-dom/client';
import App from './App';
createRoot(document.getElementById('root')!).render(
<StrictMode>
<App />
</StrictMode>,
);

View File

@@ -0,0 +1,167 @@
import { useEffect, useRef, useState } from 'react';
import { useParams } from 'react-router-dom';
import { api } from '../../services/api-client';
import { getConnection, startConnection } from '../../services/signalr';
import type { ConsultationMessage } from '../../types';
export default function ChatPage() {
const { id } = useParams<{ id: string }>();
const [messages, setMessages] = useState<ConsultationMessage[]>([]);
const [status, setStatus] = useState('');
const [text, setText] = useState('');
const [connected, setConnected] = useState(false);
const bottomRef = useRef<HTMLDivElement>(null);
// 加载历史消息
useEffect(() => {
if (!id) return;
api.get<{ status: string; messages: ConsultationMessage[] }>(`/api/doctor/consultations/${id}/messages`)
.then(data => {
setMessages(data.messages);
setStatus(data.status);
})
.catch(() => {});
}, [id]);
// 建立 SignalR 连接
useEffect(() => {
if (!id) return;
let disposed = false;
(async () => {
try {
const conn = getConnection();
await startConnection();
if (disposed) return;
// 加入问诊房间
await conn.invoke('JoinConsultation', id);
setConnected(true);
// 注册消息接收
const handler = (msg: ConsultationMessage & { consultationId: string }) => {
if (msg.consultationId !== id) return;
setMessages(prev => {
if (prev.some(m => m.id === msg.id)) return prev; // 去重
return [...prev, msg];
});
};
conn.on('ReceiveMessage', handler);
// 重连时重新加入房间
conn.onreconnected(() => {
conn.invoke('JoinConsultation', id);
});
} catch { /* ignore */ }
})();
return () => {
disposed = true;
const conn = getConnection();
if (conn.state === 'Connected') {
conn.invoke('LeaveConsultation', id).catch(() => {});
conn.off('ReceiveMessage');
}
};
}, [id]);
// 自动滚到底部
useEffect(() => {
bottomRef.current?.scrollIntoView({ behavior: 'smooth' });
}, [messages]);
async function sendMessage() {
if (!text.trim() || !id) return;
const content = text.trim();
setText('');
// 通过 HTTP 发送(后端会通过 SignalR 广播)
try {
await api.post(`/api/doctor/consultations/${id}/messages`, { content });
} catch {
// fallback: 直接通过 SignalR 发送
try {
await getConnection().invoke('SendMessage', id, 'Doctor', '医生 · 王建国', content);
} catch { /* ignore */ }
}
}
return (
<div style={{ display: 'flex', flexDirection: 'column', height: '100vh' }}>
{/* 顶栏 */}
<div style={{ background: '#FFF', padding: '16px 24px', borderBottom: '1px solid #EDF0F7', display: 'flex', alignItems: 'center', justifyContent: 'space-between' }}>
<div>
<div style={{ fontSize: 16, fontWeight: 600 }}></div>
<div style={{ fontSize: 12, color: '#9BA0B4', marginTop: 2 }}>
{status === 'AiTalking' ? 'AI 分身对话中' : status === 'WaitingDoctor' ? '等待医生回复' : status === 'DoctorReplied' ? '医生已回复' : status === 'Closed' ? '已结束' : status}
</div>
</div>
<div style={{ display: 'flex', alignItems: 'center', gap: 6 }}>
<div style={{ width: 8, height: 8, borderRadius: 4, background: connected ? '#20C997' : '#EF4444' }} />
<span style={{ fontSize: 12, color: '#9BA0B4' }}>{connected ? '已连接' : '未连接'}</span>
</div>
</div>
{/* 消息列表 */}
<div style={{ flex: 1, overflow: 'auto', padding: '20px 24px' }}>
{messages.map((msg, i) => {
const isDoctor = msg.senderType === 'Doctor';
const isAi = msg.senderType === 'Ai';
return (
<div key={msg.id || i} style={{ display: 'flex', flexDirection: 'column', alignItems: isDoctor ? 'flex-end' : 'flex-start', marginBottom: 16 }}>
{/* 发送者名称 */}
{!isDoctor && msg.senderName && (
<div style={{ fontSize: 11, color: '#9BA0B4', marginBottom: 4, marginLeft: 8 }}>{msg.senderName}</div>
)}
{/* 气泡 */}
<div style={{
maxWidth: '70%',
padding: '12px 18px',
borderRadius: isDoctor ? '18px 4px 18px 18px' : '4px 18px 18px 18px',
background: isDoctor ? '#4F6EF7' : isAi ? '#F5F5F5' : '#FFF',
color: isDoctor ? '#FFF' : '#1A1D28',
border: isDoctor ? 'none' : '1px solid #EDF0F7',
fontSize: 15,
lineHeight: 1.6,
whiteSpace: 'pre-wrap',
wordBreak: 'break-word',
}}>
{msg.content}
</div>
{/* AI 标记 */}
{isAi && (
<div style={{ fontSize: 10, color: '#F9A825', marginTop: 4, marginLeft: 8, background: '#FFF8E1', padding: '2px 8px', borderRadius: 6 }}>
AI
</div>
)}
{/* 时间 */}
<div style={{ fontSize: 11, color: '#CCC', marginTop: 4, marginLeft: 8, marginRight: 8 }}>
{new Date(msg.createdAt).toLocaleTimeString('zh-CN', { hour: '2-digit', minute: '2-digit' })}
</div>
</div>
);
})}
<div ref={bottomRef} />
</div>
{/* 输入栏 */}
<div style={{ background: '#FFF', padding: '14px 24px', borderTop: '1px solid #EDF0F7' }}>
<div style={{ display: 'flex', gap: 12 }}>
<input
value={text}
onChange={e => setText(e.target.value)}
onKeyDown={e => e.key === 'Enter' && sendMessage()}
placeholder="输入回复..."
style={{ flex: 1, padding: '12px 18px', border: '1px solid #E1E5ED', borderRadius: 12, fontSize: 15, outline: 'none' }}
/>
<button
onClick={sendMessage}
disabled={!text.trim()}
style={{ padding: '12px 24px', background: text.trim() ? '#4F6EF7' : '#E1E5ED', color: text.trim() ? '#FFF' : '#9BA0B4', border: 'none', borderRadius: 12, fontSize: 15, fontWeight: 600 }}>
</button>
</div>
</div>
</div>
);
}

View File

@@ -0,0 +1,57 @@
import { useEffect, useState } from 'react';
import { Link } from 'react-router-dom';
import { api } from '../../services/api-client';
import type { Consultation } from '../../types';
const STATUS_MAP: Record<string, { label: string; color: string }> = {
AiTalking: { label: 'AI 对话中', color: '#9BA0B4' },
WaitingDoctor: { label: '等待医生', color: '#F59E0B' },
DoctorReplied: { label: '医生已回复', color: '#20C997' },
Closed: { label: '已结束', color: '#CCC' },
};
export default function ConsultationListPage() {
const [list, setList] = useState<Consultation[]>([]);
useEffect(() => {
api.get<Consultation[]>('/api/doctor/consultations').then(setList).catch(() => {});
}, []);
return (
<div style={{ padding: 32, maxWidth: 1200 }}>
<h1 style={{ fontSize: 24, fontWeight: 700, marginBottom: 24 }}>线</h1>
{list.length === 0 ? (
<div style={{ color: '#9BA0B4', padding: 40, textAlign: 'center' }}></div>
) : (
<div style={{ display: 'flex', flexDirection: 'column', gap: 12 }}>
{list.map(c => {
const st = STATUS_MAP[c.status] ?? { label: c.status, color: '#9BA0B4' };
return (
<Link key={c.id} to={`/consultations/${c.id}`}
style={{ background: '#FFF', borderRadius: 14, padding: '18px 20px', boxShadow: '0 1px 8px rgba(0,0,0,0.04)', display: 'flex', alignItems: 'center', gap: 16 }}>
<div style={{ width: 44, height: 44, borderRadius: 12, background: '#EDF0FD', display: 'flex', alignItems: 'center', justifyContent: 'center', fontSize: 18, fontWeight: 700, color: '#4F6EF7', flexShrink: 0 }}>
{(c.patientName || '患')[0]}
</div>
<div style={{ flex: 1 }}>
<div style={{ fontWeight: 600, fontSize: 15 }}>{c.patientName || c.patientPhone}</div>
<div style={{ fontSize: 13, color: '#9BA0B4', marginTop: 2 }}>
{c.lastMessage?.content?.slice(0, 40) || '暂无消息'}
</div>
</div>
<div style={{ textAlign: 'right' }}>
<span style={{ padding: '3px 12px', borderRadius: 10, fontSize: 12, fontWeight: 500, background: `${st.color}18`, color: st.color }}>
{st.label}
</span>
<div style={{ fontSize: 11, color: '#CCC', marginTop: 4 }}>
{new Date(c.createdAt).toLocaleDateString('zh-CN')}
</div>
</div>
</Link>
);
})}
</div>
)}
</div>
);
}

View File

@@ -0,0 +1,72 @@
import { useEffect, useState } from 'react';
import { Link } from 'react-router-dom';
import { api } from '../../services/api-client';
import type { DashboardStats } from '../../types';
const CARD_CONFIG = [
{ key: 'totalPatients', label: '患者总数', color: '#4F6EF7', bg: '#EDF0FD' },
{ key: 'activeConsultations', label: '进行中问诊', color: '#20C997', bg: '#E6F9F2' },
{ key: 'pendingReports', label: '待审核报告', color: '#F59E0B', bg: '#FFF8E6' },
{ key: 'todayFollowUps', label: '今日随访', color: '#845EF7', bg: '#F3E8FF' },
];
const QUICK_LINKS = [
{ to: '/patients', label: '患者列表', color: '#4F6EF7' },
{ to: '/consultations', label: '在线问诊', color: '#20C997' },
{ to: '/reports', label: '报告审核', color: '#F59E0B' },
{ to: '/follow-ups', label: '随访管理', color: '#845EF7' },
];
export default function DashboardPage() {
const [stats, setStats] = useState<DashboardStats | null>(null);
useEffect(() => {
api.get<DashboardStats>('/api/doctor/dashboard').then(setStats).catch(() => {});
}, []);
if (!stats) return <div style={{ padding: 40, color: '#9BA0B4' }}>...</div>;
return (
<div style={{ padding: 32, maxWidth: 1200 }}>
{/* 欢迎 */}
<div style={{ marginBottom: 32 }}>
<h1 style={{ fontSize: 24, fontWeight: 700 }}>{stats.doctorName}</h1>
<p style={{ color: '#9BA0B4', marginTop: 4 }}>{stats.doctorTitle} · {stats.doctorDepartment}</p>
</div>
{/* 统计卡片 */}
<div style={{ display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(220px, 1fr))', gap: 20, marginBottom: 32 }}>
{CARD_CONFIG.map(c => (
<div key={c.key} style={{ background: '#FFF', borderRadius: 16, padding: '24px 20px', position: 'relative', overflow: 'hidden', boxShadow: '0 2px 12px rgba(0,0,0,0.04)' }}>
<div style={{ position: 'absolute', top: 0, left: 0, width: 4, height: '100%', background: c.color }} />
<div style={{ fontSize: 30, fontWeight: 800, color: c.color }}>{(stats as any)[c.key]}</div>
<div style={{ fontSize: 13, color: '#5A6072', marginTop: 4 }}>{c.label}</div>
</div>
))}
</div>
{/* 快捷操作 */}
<div style={{ display: 'grid', gridTemplateColumns: '2fr 1fr', gap: 20 }}>
<div style={{ background: '#FFF', borderRadius: 16, padding: 24, boxShadow: '0 2px 12px rgba(0,0,0,0.04)' }}>
<h2 style={{ fontSize: 16, fontWeight: 600, marginBottom: 16 }}></h2>
<div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 12 }}>
{QUICK_LINKS.map(l => (
<Link key={l.to} to={l.to} style={{ padding: '14px 16px', borderRadius: 12, border: `1px solid ${l.color}20`, color: l.color, fontWeight: 500, textAlign: 'center', transition: 'all 0.15s', fontSize: 14 }}>
{l.label}
</Link>
))}
</div>
</div>
<div style={{ background: '#FFF', borderRadius: 16, padding: 24, boxShadow: '0 2px 12px rgba(0,0,0,0.04)' }}>
<h2 style={{ fontSize: 16, fontWeight: 600, marginBottom: 16 }}></h2>
<div style={{ display: 'flex', flexDirection: 'column', gap: 12 }}>
<div style={{ fontSize: 14, color: '#5A6072' }}>📋 <b style={{ color: '#F59E0B' }}>{stats.pendingReports}</b> </div>
<div style={{ fontSize: 14, color: '#5A6072' }}>💬 <b style={{ color: '#20C997' }}>{stats.activeConsultations}</b> </div>
<div style={{ fontSize: 14, color: '#5A6072' }}>📅 访 <b style={{ color: '#845EF7' }}>{stats.todayFollowUps}</b> </div>
</div>
</div>
</div>
</div>
);
}

View File

@@ -0,0 +1,105 @@
import { useEffect, useState } from 'react';
import { useParams, useNavigate } from 'react-router-dom';
import { api } from '../../services/api-client';
interface PatientSimple { id: string; name: string; phone: string; }
export default function FollowUpEditPage() {
const { id } = useParams<{ id: string }>();
const nav = useNavigate();
const isEdit = !!id;
const [patients, setPatients] = useState<PatientSimple[]>([]);
const [userId, setUserId] = useState('');
const [title, setTitle] = useState('');
const [scheduledAt, setScheduledAt] = useState('');
const [notes, setNotes] = useState('');
const [saving, setSaving] = useState(false);
useEffect(() => {
// 加载患者列表
api.get<PatientSimple[]>('/api/doctor/patients-simple').then(setPatients).catch(() => {});
// 编辑模式:加载现有随访
if (id) {
api.get<any[]>(`/api/doctor/follow-ups`).then(list => {
const item = list.find(f => f.id === id);
if (item) {
setUserId(item.userId);
setTitle(item.title);
// datetime-local 格式
const d = new Date(item.scheduledAt);
setScheduledAt(d.toISOString().slice(0, 16));
setNotes(item.notes || '');
}
}).catch(() => {});
}
}, [id]);
async function save() {
if (!userId || !title || !scheduledAt) return alert('请填写完整信息');
setSaving(true);
try {
const body = { userId, title, scheduledAt: new Date(scheduledAt).toISOString(), notes };
if (isEdit) {
await api.put(`/api/doctor/follow-ups/${id}`, body);
} else {
await api.post('/api/doctor/follow-ups', body);
}
nav('/follow-ups');
} catch { alert('保存失败'); }
setSaving(false);
}
return (
<div style={{ padding: 32, maxWidth: 600 }}>
<div style={{ display: 'flex', alignItems: 'center', gap: 12, marginBottom: 24 }}>
<button onClick={() => nav(-1)} style={{ color: '#4F6EF7', fontSize: 14, border: 'none', background: 'none' }}> </button>
<h1 style={{ fontSize: 24, fontWeight: 700 }}>{isEdit ? '编辑随访' : '新建随访'}</h1>
</div>
<div style={{ background: '#FFF', borderRadius: 16, padding: 24, boxShadow: '0 2px 12px rgba(0,0,0,0.04)' }}>
{/* 患者选择 */}
<div style={{ marginBottom: 20 }}>
<label style={{ display: 'block', fontSize: 14, fontWeight: 500, marginBottom: 6, color: '#5A6072' }}></label>
<select value={userId} onChange={e => setUserId(e.target.value)}
style={{ width: '100%', padding: '10px 14px', border: '1px solid #E1E5ED', borderRadius: 10, fontSize: 14, outline: 'none' }}>
<option value=""></option>
{patients.map(p => (
<option key={p.id} value={p.id}>{p.name || '未设置'} ({p.phone})</option>
))}
</select>
</div>
{/* 标题 */}
<div style={{ marginBottom: 20 }}>
<label style={{ display: 'block', fontSize: 14, fontWeight: 500, marginBottom: 6, color: '#5A6072' }}>访</label>
<input value={title} onChange={e => setTitle(e.target.value)} placeholder="如PCI术后1个月随访"
style={{ width: '100%', padding: '10px 14px', border: '1px solid #E1E5ED', borderRadius: 10, fontSize: 14, outline: 'none' }} />
</div>
{/* 时间 */}
<div style={{ marginBottom: 20 }}>
<label style={{ display: 'block', fontSize: 14, fontWeight: 500, marginBottom: 6, color: '#5A6072' }}></label>
<input type="datetime-local" value={scheduledAt} onChange={e => setScheduledAt(e.target.value)}
style={{ width: '100%', padding: '10px 14px', border: '1px solid #E1E5ED', borderRadius: 10, fontSize: 14, outline: 'none' }} />
</div>
{/* 备注 */}
<div style={{ marginBottom: 24 }}>
<label style={{ display: 'block', fontSize: 14, fontWeight: 500, marginBottom: 6, color: '#5A6072' }}></label>
<textarea value={notes} onChange={e => setNotes(e.target.value)} placeholder="备注信息..."
rows={3}
style={{ width: '100%', padding: '10px 14px', border: '1px solid #E1E5ED', borderRadius: 10, fontSize: 14, outline: 'none', resize: 'vertical' }} />
</div>
<button onClick={save} disabled={saving}
style={{
width: '100%', padding: '14px', background: saving ? '#E1E5ED' : 'linear-gradient(135deg, #4F6EF7, #6C8AFF)',
color: saving ? '#9BA0B4' : '#FFF', border: 'none', borderRadius: 12, fontSize: 16, fontWeight: 600,
}}>
{saving ? '保存中...' : '保存'}
</button>
</div>
</div>
);
}

View File

@@ -0,0 +1,94 @@
import { useEffect, useState } from 'react';
import { Link, useNavigate } from 'react-router-dom';
import { api } from '../../services/api-client';
import type { FollowUp } from '../../types';
const STATUS_MAP: Record<string, { label: string; color: string }> = {
Upcoming: { label: '即将到来', color: '#4F6EF7' },
Completed: { label: '已完成', color: '#20C997' },
Cancelled: { label: '已取消', color: '#EF4444' },
};
export default function FollowUpListPage() {
const [list, setList] = useState<FollowUp[]>([]);
const [filter, setFilter] = useState('');
const nav = useNavigate();
useEffect(() => { loadList(); }, [filter]);
async function loadList() {
const q = filter ? `?status=${filter}` : '';
try { setList(await api.get<FollowUp[]>(`/api/doctor/follow-ups${q}`)); } catch { setList([]); }
}
async function deleteItem(id: string) {
if (!confirm('确定删除?')) return;
try {
await api.del(`/api/doctor/follow-ups/${id}`);
setList(prev => prev.filter(f => f.id !== id));
} catch { alert('删除失败'); }
}
async function markComplete(id: string) {
try {
await api.put(`/api/doctor/follow-ups/${id}`, { status: 'Completed' });
loadList();
} catch { alert('操作失败'); }
}
return (
<div style={{ padding: 32, maxWidth: 1200 }}>
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: 24 }}>
<h1 style={{ fontSize: 24, fontWeight: 700 }}>访</h1>
<button onClick={() => nav('/follow-ups/new')}
style={{ padding: '10px 24px', background: 'linear-gradient(135deg, #4F6EF7, #6C8AFF)', color: '#FFF', border: 'none', borderRadius: 12, fontSize: 14, fontWeight: 600 }}>
+ 访
</button>
</div>
{/* 筛选 */}
<div style={{ display: 'flex', gap: 8, marginBottom: 20 }}>
{[{ k: '', l: '全部' }, { k: 'Upcoming', l: '即将到来' }, { k: 'Completed', l: '已完成' }, { k: 'Cancelled', l: '已取消' }].map(t => (
<button key={t.k} onClick={() => setFilter(t.k)}
style={{ padding: '6px 18px', borderRadius: 10, border: 'none', fontSize: 13, fontWeight: 500,
background: filter === t.k ? '#4F6EF7' : '#F2F3F7', color: filter === t.k ? '#FFF' : '#5A6072' }}>
{t.l}
</button>
))}
</div>
{list.length === 0 ? (
<div style={{ color: '#9BA0B4', padding: 40, textAlign: 'center' }}>访</div>
) : (
<div style={{ display: 'flex', flexDirection: 'column', gap: 12 }}>
{list.map(f => {
const st = STATUS_MAP[f.status] ?? { label: f.status, color: '#9BA0B4' };
return (
<div key={f.id} style={{ background: '#FFF', borderRadius: 14, padding: '18px 20px', boxShadow: '0 1px 8px rgba(0,0,0,0.04)', display: 'flex', alignItems: 'center', gap: 16 }}>
<span style={{ fontSize: 24 }}>📅</span>
<div style={{ flex: 1 }}>
<div style={{ fontWeight: 600, fontSize: 15 }}>{f.title}</div>
<div style={{ fontSize: 13, color: '#5A6072', marginTop: 2 }}>
{f.patientName || '-'} · {new Date(f.scheduledAt).toLocaleString('zh-CN')}
</div>
{f.notes && <div style={{ fontSize: 12, color: '#9BA0B4', marginTop: 2 }}>{f.notes}</div>}
</div>
<span style={{ padding: '3px 12px', borderRadius: 10, fontSize: 12, fontWeight: 500, background: `${st.color}18`, color: st.color }}>
{st.label}
</span>
{/* 操作按钮 */}
<div style={{ display: 'flex', gap: 6 }}>
{f.status === 'Upcoming' && (
<button onClick={() => markComplete(f.id)} style={{ padding: '4px 12px', borderRadius: 8, border: '1px solid #20C997', background: '#E6F9F2', color: '#20C997', fontSize: 12 }}></button>
)}
<Link to={`/follow-ups/${f.id}/edit`} style={{ padding: '4px 12px', borderRadius: 8, border: '1px solid #E1E5ED', color: '#5A6072', fontSize: 12 }}></Link>
<button onClick={() => deleteItem(f.id)} style={{ padding: '4px 12px', borderRadius: 8, border: '1px solid #FEE2E2', background: '#FFF5F5', color: '#EF4444', fontSize: 12 }}></button>
</div>
</div>
);
})}
</div>
)}
</div>
);
}

View File

@@ -0,0 +1,273 @@
import { useEffect, useState } from 'react';
import { useParams, Link } from 'react-router-dom';
import { api } from '../../services/api-client';
import type { PatientDetail, TrendRecord } from '../../types';
import { LineChart, Line, XAxis, YAxis, CartesianGrid, Tooltip, ResponsiveContainer, Legend } from 'recharts';
const METRIC_LABELS: Record<string, string> = {
BloodPressure: '血压', HeartRate: '心率', Glucose: '血糖', SpO2: '血氧', Weight: '体重',
};
const METRIC_COLORS: Record<string, string> = {
BloodPressure: '#EF4444', HeartRate: '#F59E0B', Glucose: '#4F6EF7', SpO2: '#20C997', Weight: '#845EF7',
};
const DAY_LABELS = ['日', '一', '二', '三', '四', '五', '六'];
export default function PatientDetailPage() {
const { id } = useParams<{ id: string }>();
const [data, setData] = useState<PatientDetail | null>(null);
const [chartMetric, setChartMetric] = useState<string>('BloodPressure');
useEffect(() => {
if (id) api.get<PatientDetail>(`/api/doctor/patients/${id}`).then(setData).catch(() => {});
}, [id]);
if (!data) return <div style={{ padding: 40, color: '#9BA0B4' }}>...</div>;
const p = data.profile;
const a = data.archive;
// 趋势图数据(用 any 兼容不同指标的数据结构)
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const chartData: any[] = buildChartData(data.trendRecords, chartMetric);
return (
<div style={{ padding: 32, maxWidth: 1200 }}>
{/* 标题 */}
<div style={{ display: 'flex', alignItems: 'center', gap: 12, marginBottom: 24 }}>
<Link to="/patients" style={{ color: '#4F6EF7', fontSize: 14 }}> </Link>
<h1 style={{ fontSize: 24, fontWeight: 700 }}>{p.name || '未设置'} </h1>
</div>
{/* 基本信息卡片 */}
<InfoCard p={p} a={a} />
{/* 健康指标 */}
<Section title="最新健康指标">
<div style={{ display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(180px, 1fr))', gap: 16 }}>
{data.latestRecords.map(r => (
<div key={r.id} style={{ background: '#FFF', borderRadius: 14, padding: 20, position: 'relative', overflow: 'hidden', boxShadow: '0 1px 8px rgba(0,0,0,0.04)' }}>
<div style={{ position: 'absolute', top: 0, left: 0, width: 3, height: '100%', background: METRIC_COLORS[r.metricType] || '#9BA0B4' }} />
<div style={{ fontSize: 12, color: '#9BA0B4', marginBottom: 4 }}>{METRIC_LABELS[r.metricType] || r.metricType}</div>
<div style={{ fontSize: 26, fontWeight: 700, color: r.isAbnormal ? '#EF4444' : '#1A1D28' }}>
{r.metricType === 'BloodPressure' ? `${r.systolic}/${r.diastolic}` : r.value}
<span style={{ fontSize: 14, fontWeight: 400, color: '#9BA0B4', marginLeft: 4 }}>{r.unit}</span>
</div>
<div style={{ fontSize: 11, color: '#9BA0B4', marginTop: 4 }}>
{new Date(r.recordedAt).toLocaleDateString('zh-CN')}
</div>
</div>
))}
{data.latestRecords.length === 0 && <Empty text="暂无健康数据" />}
</div>
</Section>
{/* 趋势图 */}
<Section title="健康趋势30天">
<div style={{ display: 'flex', gap: 8, marginBottom: 16 }}>
{Object.keys(METRIC_LABELS).map(m => (
<button key={m} onClick={() => setChartMetric(m)}
style={{
padding: '6px 14px', borderRadius: 8, border: 'none', fontSize: 13, fontWeight: 500,
background: chartMetric === m ? METRIC_COLORS[m] : '#F2F3F7',
color: chartMetric === m ? '#FFF' : '#5A6072',
}}>
{METRIC_LABELS[m]}
</button>
))}
</div>
{chartData.length > 0 ? (
<div style={{ background: '#FFF', borderRadius: 14, padding: 24, boxShadow: '0 1px 8px rgba(0,0,0,0.04)' }}>
<ResponsiveContainer width="100%" height={300}>
<LineChart data={chartData}>
<CartesianGrid strokeDasharray="3 3" stroke="#F0F0F0" />
<XAxis dataKey="date" tick={{ fontSize: 12 }} />
<YAxis tick={{ fontSize: 12 }} />
<Tooltip />
<Legend />
{chartMetric === 'BloodPressure' ? (
<>
<Line type="monotone" dataKey="systolic" stroke="#EF4444" name="收缩压" strokeWidth={2} dot={{ r: 3 }} />
<Line type="monotone" dataKey="diastolic" stroke="#F59E0B" name="舒张压" strokeWidth={2} dot={{ r: 3 }} />
</>
) : (
<Line type="monotone" dataKey="value" stroke={METRIC_COLORS[chartMetric]} name={METRIC_LABELS[chartMetric]} strokeWidth={2} dot={{ r: 4 }} />
)}
</LineChart>
</ResponsiveContainer>
</div>
) : <Empty text="暂无趋势数据" />}
</Section>
{/* 用药 */}
<Section title="当前用药">
{data.medications.length > 0 ? (
<div style={{ display: 'flex', flexDirection: 'column', gap: 8 }}>
{data.medications.map(m => (
<div key={m.id} style={{ background: '#FFF', borderRadius: 12, padding: '14px 18px', boxShadow: '0 1px 8px rgba(0,0,0,0.04)', display: 'flex', alignItems: 'center', gap: 12 }}>
<span style={{ fontSize: 20 }}>💊</span>
<div style={{ flex: 1 }}>
<div style={{ fontWeight: 600 }}>{m.name} <span style={{ fontWeight: 400, color: '#5A6072', fontSize: 14 }}>{m.dosage}</span></div>
<div style={{ fontSize: 12, color: '#9BA0B4' }}>{m.frequency} · {m.timeOfDay?.join(', ')}</div>
</div>
</div>
))}
</div>
) : <Empty text="暂无用药" />}
</Section>
{/* 饮食 + 运动 双列 */}
<div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 24, marginBottom: 24 }}>
<div>
<div style={{ fontSize: 16, fontWeight: 600, marginBottom: 12 }}>🍽 </div>
{data.dietRecords.length > 0 ? (
<div style={{ display: 'flex', flexDirection: 'column', gap: 8 }}>
{data.dietRecords.map(d => (
<div key={d.id} style={{ background: '#FFF', borderRadius: 12, padding: '12px 16px', boxShadow: '0 1px 8px rgba(0,0,0,0.04)' }}>
<div style={{ fontSize: 13, fontWeight: 500 }}>{d.foods.map(f => f.name).join('、')}</div>
<div style={{ fontSize: 12, color: '#9BA0B4', marginTop: 4 }}>
{d.mealType === 'Breakfast' ? '早餐' : d.mealType === 'Lunch' ? '午餐' : d.mealType === 'Dinner' ? '晚餐' : '加餐'}
{' · '}{d.totalCalories}kcal · {d.healthScore}/5
</div>
</div>
))}
</div>
) : <Empty text="暂无饮食记录" />}
</div>
<div>
<div style={{ fontSize: 16, fontWeight: 600, marginBottom: 12 }}>🏃 </div>
{data.exercisePlan ? (
<div style={{ display: 'flex', flexDirection: 'column', gap: 6 }}>
{data.exercisePlan.items.map((item, i) => (
<div key={i} style={{ background: '#FFF', borderRadius: 12, padding: '10px 16px', boxShadow: '0 1px 8px rgba(0,0,0,0.04)', display: 'flex', alignItems: 'center', gap: 10, opacity: item.isRestDay ? 0.5 : 1 }}>
<span style={{ fontSize: 12, color: '#9BA0B4', minWidth: 36 }}>{DAY_LABELS[item.dayOfWeek]}</span>
<span style={{ flex: 1, fontSize: 13 }}>
{item.isRestDay ? '休息' : `${item.exerciseType} ${item.durationMinutes}分钟`}
</span>
{item.isCompleted && <span style={{ color: '#20C997', fontSize: 12, fontWeight: 500 }}> </span>}
</div>
))}
</div>
) : <Empty text="暂无运动计划" />}
</div>
</div>
{/* 报告 */}
<Section title="📋 检查报告">
{data.reports.length > 0 ? (
<div style={{ display: 'flex', flexDirection: 'column', gap: 8 }}>
{data.reports.map(r => (
<Link key={r.id} to={`/reports/${r.id}`} style={{ background: '#FFF', borderRadius: 12, padding: '14px 18px', boxShadow: '0 1px 8px rgba(0,0,0,0.04)', display: 'flex', alignItems: 'center', gap: 12 }}>
<span style={{ fontSize: 20 }}>📄</span>
<div style={{ flex: 1 }}>
<div style={{ fontWeight: 500, fontSize: 14 }}>{r.category} </div>
<div style={{ fontSize: 12, color: '#9BA0B4' }}>{new Date(r.createdAt).toLocaleDateString('zh-CN')}</div>
</div>
<StatusBadge status={r.status} map={{ PendingDoctor: ['待审核', '#F59E0B'], DoctorReviewed: ['已审核', '#20C997'] }} />
</Link>
))}
</div>
) : <Empty text="暂无报告" />}
</Section>
{/* 随访 */}
<Section title="📅 复查随访">
{data.followUps.length > 0 ? (
<div style={{ display: 'flex', flexDirection: 'column', gap: 8 }}>
{data.followUps.map(f => (
<div key={f.id} style={{ background: '#FFF', borderRadius: 12, padding: '14px 18px', boxShadow: '0 1px 8px rgba(0,0,0,0.04)', display: 'flex', alignItems: 'center', gap: 12 }}>
<span style={{ fontSize: 20 }}>📅</span>
<div style={{ flex: 1 }}>
<div style={{ fontWeight: 500, fontSize: 14 }}>{f.title}</div>
<div style={{ fontSize: 12, color: '#9BA0B4' }}>
{new Date(f.scheduledAt).toLocaleString('zh-CN')}
{f.doctorName ? ` · ${f.doctorName}` : ''}
{f.notes ? ` · ${f.notes}` : ''}
</div>
</div>
<StatusBadge status={f.status} map={{ Upcoming: ['即将到来', '#4F6EF7'], Completed: ['已完成', '#20C997'], Cancelled: ['已取消', '#EF4444'] }} />
</div>
))}
</div>
) : <Empty text="暂无随访安排" />}
</Section>
</div>
);
}
// ===== 子组件 =====
function InfoCard({ p, a }: { p: PatientDetail['profile']; a: PatientDetail['archive'] }) {
return (
<div style={{ background: '#FFF', borderRadius: 16, padding: 24, marginBottom: 24, boxShadow: '0 2px 12px rgba(0,0,0,0.04)' }}>
<div style={{ display: 'flex', gap: 24 }}>
<div style={{ width: 64, height: 64, borderRadius: 16, background: 'linear-gradient(135deg, #4F6EF7, #6C8AFF)', display: 'flex', alignItems: 'center', justifyContent: 'center', color: '#FFF', fontSize: 28, fontWeight: 700, flexShrink: 0 }}>
{p.name?.[0] ?? '?'}
</div>
<div style={{ flex: 1 }}>
<div style={{ fontSize: 20, fontWeight: 700 }}>{p.name || '未设置'}</div>
<div style={{ fontSize: 13, color: '#9BA0B4', marginTop: 2 }}>{p.phone} · {p.gender || '未知'} · {p.birthDate || '未知'}</div>
{a && (
<div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: '4px 24px', marginTop: 12, fontSize: 13 }}>
<Row label="诊断" value={a.diagnosis} />
<Row label="手术类型" value={a.surgeryType} />
<Row label="手术日期" value={a.surgeryDate} />
<Row label="过敏史" value={a.allergies?.join('、')} />
<Row label="饮食限制" value={a.dietRestrictions?.join('、')} />
<Row label="慢病史" value={a.chronicDiseases?.join('、')} />
<Row label="家族病史" value={a.familyHistory} />
</div>
)}
</div>
</div>
</div>
);
}
function Row({ label, value }: { label: string; value?: string | null }) {
return (
<div>
<span style={{ color: '#9BA0B4' }}>{label}</span>
<span style={{ color: value ? '#1A1D28' : '#CCC' }}>{value || '未填写'}</span>
</div>
);
}
function Section({ title, children }: { title: string; children: React.ReactNode }) {
return (
<div style={{ marginBottom: 24 }}>
<div style={{ fontSize: 16, fontWeight: 600, marginBottom: 12 }}>{title}</div>
{children}
</div>
);
}
function Empty({ text }: { text: string }) {
return <div style={{ color: '#CCC', fontSize: 13, padding: 16, textAlign: 'center' }}>{text}</div>;
}
function StatusBadge({ status, map }: { status: string; map: Record<string, [string, string]> }) {
const [label, color] = map[status] ?? [status, '#9BA0B4'];
return (
<span style={{ padding: '3px 12px', borderRadius: 10, fontSize: 12, fontWeight: 500, background: `${color}18`, color }}>
{label}
</span>
);
}
// 构建趋势图数据
function buildChartData(records: TrendRecord[], metric: string) {
const filtered = records.filter(r => r.metricType === metric);
if (metric === 'BloodPressure') {
return filtered.map(r => ({
date: new Date(r.recordedAt).toLocaleDateString('zh-CN', { month: 'short', day: 'numeric' }),
systolic: r.systolic,
diastolic: r.diastolic,
}));
}
return filtered.map(r => ({
date: new Date(r.recordedAt).toLocaleDateString('zh-CN', { month: 'short', day: 'numeric' }),
value: r.value,
}));
}

View File

@@ -0,0 +1,80 @@
import { useEffect, useState } from 'react';
import { Link } from 'react-router-dom';
import { api } from '../../services/api-client';
import type { Patient } from '../../types';
export default function PatientListPage() {
const [patients, setPatients] = useState<Patient[]>([]);
const [search, setSearch] = useState('');
const [loading, setLoading] = useState(true);
useEffect(() => { loadPatients(); }, []);
async function loadPatients(s?: string) {
setLoading(true);
try {
const q = s !== undefined ? s : search;
const data = await api.get<Patient[]>(`/api/doctor/patients${q ? `?search=${encodeURIComponent(q)}` : ''}`);
setPatients(data);
} catch { setPatients([]); }
setLoading(false);
}
return (
<div style={{ padding: 32, maxWidth: 1200 }}>
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: 24 }}>
<h1 style={{ fontSize: 24, fontWeight: 700 }}></h1>
<div style={{ display: 'flex', gap: 8 }}>
<input
value={search}
onChange={e => setSearch(e.target.value)}
onKeyDown={e => e.key === 'Enter' && loadPatients()}
placeholder="搜索姓名或手机号..."
style={{ padding: '8px 16px', border: '1px solid #E1E5ED', borderRadius: 10, fontSize: 14, outline: 'none', width: 240 }}
/>
<button onClick={() => loadPatients()} style={{ padding: '8px 20px', background: '#4F6EF7', color: '#FFF', border: 'none', borderRadius: 10, fontSize: 14, fontWeight: 500 }}>
</button>
</div>
</div>
{loading ? (
<div style={{ color: '#9BA0B4', padding: 40 }}>...</div>
) : patients.length === 0 ? (
<div style={{ color: '#9BA0B4', padding: 40, textAlign: 'center' }}></div>
) : (
<div style={{ background: '#FFF', borderRadius: 16, overflow: 'hidden', boxShadow: '0 2px 12px rgba(0,0,0,0.04)' }}>
<table style={{ width: '100%', borderCollapse: 'collapse', fontSize: 14 }}>
<thead>
<tr style={{ background: '#FAFBFD', borderBottom: '1px solid #EDF0F7' }}>
{['姓名', '手机号', '性别', '出生日期', '健康档案', '操作'].map(h => (
<th key={h} style={{ padding: '14px 16px', textAlign: 'left', fontWeight: 600, color: '#5A6072', fontSize: 13 }}>{h}</th>
))}
</tr>
</thead>
<tbody>
{patients.map(p => (
<tr key={p.id} style={{ borderBottom: '1px solid #F2F3F7' }}>
<td style={{ padding: '12px 16px', fontWeight: 500 }}>{p.name || '未设置'}</td>
<td style={{ padding: '12px 16px', color: '#5A6072' }}>{p.phone}</td>
<td style={{ padding: '12px 16px', color: '#5A6072' }}>{p.gender || '-'}</td>
<td style={{ padding: '12px 16px', color: '#5A6072' }}>{p.birthDate || '-'}</td>
<td style={{ padding: '12px 16px' }}>
<span style={{ padding: '2px 10px', borderRadius: 10, fontSize: 12, background: p.hasArchive ? '#E6F9F2' : '#FFF3E0', color: p.hasArchive ? '#20C997' : '#F59E0B' }}>
{p.hasArchive ? '已建立' : '未建立'}
</span>
</td>
<td style={{ padding: '12px 16px' }}>
<Link to={`/patients/${p.id}`} style={{ color: '#4F6EF7', fontWeight: 500, fontSize: 13 }}>
</Link>
</td>
</tr>
))}
</tbody>
</table>
</div>
)}
</div>
);
}

View File

@@ -0,0 +1,133 @@
import { useEffect, useState } from 'react';
import { useParams, useNavigate } from 'react-router-dom';
import { api } from '../../services/api-client';
import type { Report } from '../../types';
export default function ReportDetailPage() {
const { id } = useParams<{ id: string }>();
const nav = useNavigate();
const [report, setReport] = useState<Report | null>(null);
const [comment, setComment] = useState('');
const [submitting, setSubmitting] = useState(false);
const [success, setSuccess] = useState(false);
useEffect(() => {
if (id) api.get<Report>(`/api/doctor/reports/${id}`).then(r => { setReport(r); setComment(r.doctorComment || ''); }).catch(() => {});
}, [id]);
async function submitReview() {
if (!id) return;
setSubmitting(true);
try {
await api.post(`/api/doctor/reports/${id}/review`, { comment });
setSuccess(true);
} catch { alert('提交失败'); }
setSubmitting(false);
}
if (!report) return <div style={{ padding: 40, color: '#9BA0B4' }}>...</div>;
// 解析 AI 指标
let indicators: any[] = [];
try { indicators = JSON.parse(report.aiIndicators || '[]'); } catch {}
return (
<div style={{ padding: 32, maxWidth: 900 }}>
<div style={{ display: 'flex', alignItems: 'center', gap: 12, marginBottom: 24 }}>
<button onClick={() => nav(-1)} style={{ color: '#4F6EF7', fontSize: 14, border: 'none', background: 'none', cursor: 'pointer' }}> </button>
<h1 style={{ fontSize: 24, fontWeight: 700 }}></h1>
</div>
{/* 基本信息 */}
<div style={{ background: '#FFF', borderRadius: 16, padding: 24, marginBottom: 20, boxShadow: '0 2px 12px rgba(0,0,0,0.04)' }}>
<div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: '8px 24px', fontSize: 14 }}>
<div><span style={{ color: '#9BA0B4' }}></span>{report.patientName || '-'}</div>
<div><span style={{ color: '#9BA0B4' }}></span>{report.category}</div>
<div><span style={{ color: '#9BA0B4' }}></span>{new Date(report.createdAt).toLocaleString('zh-CN')}</div>
<div>
<span style={{ color: '#9BA0B4' }}></span>
<span style={{ padding: '2px 10px', borderRadius: 10, fontSize: 12, background: report.status === 'PendingDoctor' ? '#FFF8E6' : '#E6F9F2', color: report.status === 'PendingDoctor' ? '#F59E0B' : '#20C997' }}>
{report.status === 'PendingDoctor' ? '待审核' : '已审核'}
</span>
</div>
</div>
{report.fileUrl && (
<div style={{ marginTop: 16 }}>
<a href={`http://localhost:5000${report.fileUrl}`} target="_blank" rel="noopener noreferrer"
style={{ color: '#4F6EF7', fontSize: 13, textDecoration: 'underline' }}>
📎
</a>
</div>
)}
</div>
{/* AI 预解读 */}
<div style={{ background: '#FFF', borderRadius: 16, padding: 24, marginBottom: 20, boxShadow: '0 2px 12px rgba(0,0,0,0.04)' }}>
<h2 style={{ fontSize: 16, fontWeight: 600, marginBottom: 16 }}>🤖 AI </h2>
{report.aiSummary && (
<div style={{ fontSize: 14, lineHeight: 1.7, color: '#5A6072', marginBottom: 16, padding: '12px 16px', background: '#FAFBFD', borderRadius: 10 }}>
{report.aiSummary}
</div>
)}
{indicators.length > 0 && (
<table style={{ width: '100%', borderCollapse: 'collapse', fontSize: 13 }}>
<thead>
<tr style={{ borderBottom: '2px solid #EDF0F7' }}>
{['指标', '结果', '单位', '参考范围', '状态'].map(h => (
<th key={h} style={{ padding: '8px 12px', textAlign: 'left', color: '#9BA0B4', fontWeight: 500 }}>{h}</th>
))}
</tr>
</thead>
<tbody>
{indicators.map((ind: any, i: number) => {
const abnormal = ind.status === 'high' || ind.status === 'abnormal';
const low = ind.status === 'low';
return (
<tr key={i} style={{ borderBottom: '1px solid #F2F3F7' }}>
<td style={{ padding: '8px 12px' }}>{ind.name}</td>
<td style={{ padding: '8px 12px', fontWeight: 500, color: abnormal ? '#EF4444' : low ? '#F59E0B' : '#20C997' }}>{ind.value}</td>
<td style={{ padding: '8px 12px', color: '#5A6072' }}>{ind.unit || '-'}</td>
<td style={{ padding: '8px 12px', color: '#5A6072' }}>{ind.range || '-'}</td>
<td style={{ padding: '8px 12px' }}>
<span style={{ padding: '2px 8px', borderRadius: 8, fontSize: 11, background: abnormal ? '#FEE2E2' : low ? '#FFF8E6' : '#E6F9F2', color: abnormal ? '#EF4444' : low ? '#F59E0B' : '#20C997' }}>
{abnormal ? '偏高' : low ? '偏低' : '正常'}
</span>
</td>
</tr>
);
})}
</tbody>
</table>
)}
</div>
{/* 医生审核 */}
<div style={{ background: '#FFF', borderRadius: 16, padding: 24, boxShadow: '0 2px 12px rgba(0,0,0,0.04)' }}>
<h2 style={{ fontSize: 16, fontWeight: 600, marginBottom: 16 }}>👨 </h2>
{success && (
<div style={{ marginBottom: 16, padding: '12px 18px', background: '#E6F9F2', borderRadius: 10, color: '#20C997', fontWeight: 500, fontSize: 14 }}>
</div>
)}
<textarea
value={comment}
onChange={e => setComment(e.target.value)}
placeholder="请输入您的专业解读意见..."
rows={5}
style={{ width: '100%', padding: 14, border: '1px solid #E1E5ED', borderRadius: 12, fontSize: 14, outline: 'none', resize: 'vertical' }}
/>
<div style={{ marginTop: 16, display: 'flex', justifyContent: 'flex-end' }}>
<button onClick={submitReview} disabled={submitting || !comment.trim()}
style={{
padding: '12px 32px',
background: submitting || !comment.trim() ? '#E1E5ED' : 'linear-gradient(135deg, #4F6EF7, #6C8AFF)',
color: submitting || !comment.trim() ? '#9BA0B4' : '#FFF',
border: 'none', borderRadius: 12, fontSize: 15, fontWeight: 600,
}}>
{submitting ? '提交中...' : '提交审核意见'}
</button>
</div>
</div>
</div>
);
}

View File

@@ -0,0 +1,75 @@
import { useEffect, useState } from 'react';
import { Link } from 'react-router-dom';
import { api } from '../../services/api-client';
import type { Report } from '../../types';
const STATUS_MAP: Record<string, { label: string; color: string }> = {
PendingDoctor: { label: '待审核', color: '#F59E0B' },
DoctorReviewed: { label: '已审核', color: '#20C997' },
};
export default function ReportListPage() {
const [reports, setReports] = useState<Report[]>([]);
const [filter, setFilter] = useState('');
useEffect(() => {
const q = filter ? `?status=${filter}` : '';
api.get<Report[]>(`/api/doctor/reports${q}`).then(setReports).catch(() => {});
}, [filter]);
return (
<div style={{ padding: 32, maxWidth: 1200 }}>
<h1 style={{ fontSize: 24, fontWeight: 700, marginBottom: 24 }}></h1>
{/* 筛选标签 */}
<div style={{ display: 'flex', gap: 8, marginBottom: 20 }}>
{[{ k: '', l: '全部' }, { k: 'PendingDoctor', l: '待审核' }, { k: 'DoctorReviewed', l: '已审核' }].map(t => (
<button key={t.k} onClick={() => setFilter(t.k)}
style={{ padding: '6px 18px', borderRadius: 10, border: 'none', fontSize: 13, fontWeight: 500,
background: filter === t.k ? '#4F6EF7' : '#F2F3F7', color: filter === t.k ? '#FFF' : '#5A6072' }}>
{t.l}
</button>
))}
</div>
{reports.length === 0 ? (
<div style={{ color: '#9BA0B4', padding: 40, textAlign: 'center' }}></div>
) : (
<div style={{ background: '#FFF', borderRadius: 16, overflow: 'hidden', boxShadow: '0 2px 12px rgba(0,0,0,0.04)' }}>
<table style={{ width: '100%', borderCollapse: 'collapse', fontSize: 14 }}>
<thead>
<tr style={{ background: '#FAFBFD', borderBottom: '1px solid #EDF0F7' }}>
{['患者', '类型', '状态', 'AI 摘要', '上传时间', '操作'].map(h => (
<th key={h} style={{ padding: '14px 16px', textAlign: 'left', fontWeight: 600, color: '#5A6072', fontSize: 13 }}>{h}</th>
))}
</tr>
</thead>
<tbody>
{reports.map(r => {
const st = STATUS_MAP[r.status] ?? { label: r.status, color: '#9BA0B4' };
return (
<tr key={r.id} style={{ borderBottom: '1px solid #F2F3F7' }}>
<td style={{ padding: '12px 16px', fontWeight: 500 }}>{r.patientName || '-'}</td>
<td style={{ padding: '12px 16px', color: '#5A6072' }}>{r.category}</td>
<td style={{ padding: '12px 16px' }}>
<span style={{ padding: '3px 12px', borderRadius: 10, fontSize: 12, fontWeight: 500, background: `${st.color}18`, color: st.color }}>{st.label}</span>
</td>
<td style={{ padding: '12px 16px', color: '#5A6072', maxWidth: 240, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>
{r.aiSummary?.slice(0, 40) || '-'}
</td>
<td style={{ padding: '12px 16px', color: '#9BA0B4', fontSize: 13 }}>{new Date(r.createdAt).toLocaleDateString('zh-CN')}</td>
<td style={{ padding: '12px 16px' }}>
<Link to={`/reports/${r.id}`} style={{ color: '#4F6EF7', fontWeight: 500, fontSize: 13 }}>
{r.status === 'PendingDoctor' ? '审核 →' : '查看 →'}
</Link>
</td>
</tr>
);
})}
</tbody>
</table>
</div>
)}
</div>
);
}

View File

@@ -0,0 +1,31 @@
import { createBrowserRouter, Navigate } from 'react-router-dom';
import DoctorLayout from '../components/layout/DoctorLayout';
import DashboardPage from '../pages/dashboard/DashboardPage';
import PatientListPage from '../pages/patients/PatientListPage';
import PatientDetailPage from '../pages/patients/PatientDetailPage';
import ConsultationListPage from '../pages/consultations/ConsultationListPage';
import ChatPage from '../pages/consultations/ChatPage';
import ReportListPage from '../pages/reports/ReportListPage';
import ReportDetailPage from '../pages/reports/ReportDetailPage';
import FollowUpListPage from '../pages/followups/FollowUpListPage';
import FollowUpEditPage from '../pages/followups/FollowUpEditPage';
export const router = createBrowserRouter([
{
path: '/',
element: <DoctorLayout />,
children: [
{ index: true, element: <Navigate to="/dashboard" replace /> },
{ path: 'dashboard', element: <DashboardPage /> },
{ path: 'patients', element: <PatientListPage /> },
{ path: 'patients/:id', element: <PatientDetailPage /> },
{ path: 'consultations', element: <ConsultationListPage /> },
{ path: 'consultations/:id', element: <ChatPage /> },
{ path: 'reports', element: <ReportListPage /> },
{ path: 'reports/:id', element: <ReportDetailPage /> },
{ path: 'follow-ups', element: <FollowUpListPage /> },
{ path: 'follow-ups/new', element: <FollowUpEditPage /> },
{ path: 'follow-ups/:id/edit', element: <FollowUpEditPage /> },
],
},
]);

View File

@@ -0,0 +1,29 @@
const BASE_URL = 'http://localhost:5000';
async function request<T>(method: string, path: string, body?: unknown): Promise<T> {
const headers: Record<string, string> = { 'Content-Type': 'application/json' };
const res = await fetch(`${BASE_URL}${path}`, {
method,
headers,
body: body ? JSON.stringify(body) : undefined,
});
if (!res.ok) {
const text = await res.text();
throw new Error(text || `HTTP ${res.status}`);
}
const json = await res.json();
if (json.code !== 0) {
throw new Error(json.message || `Error code ${json.code}`);
}
return json.data as T;
}
export const api = {
get: <T>(path: string) => request<T>('GET', path),
post: <T>(path: string, body?: unknown) => request<T>('POST', path, body),
put: <T>(path: string, body?: unknown) => request<T>('PUT', path, body),
del: <T>(path: string) => request<T>('DELETE', path),
};

View File

@@ -0,0 +1,30 @@
import { HubConnectionBuilder, HubConnection, LogLevel } from '@microsoft/signalr';
const HUB_URL = 'http://localhost:5000/hubs/consultation';
let connection: HubConnection | null = null;
export function getConnection(): HubConnection {
if (!connection) {
connection = new HubConnectionBuilder()
.withUrl(HUB_URL)
.withAutomaticReconnect()
.configureLogging(LogLevel.Information)
.build();
}
return connection;
}
export async function startConnection(): Promise<void> {
const conn = getConnection();
if (conn.state === 'Disconnected') {
await conn.start();
}
}
export async function stopConnection(): Promise<void> {
if (connection && connection.state !== 'Disconnected') {
await connection.stop();
connection = null;
}
}

View File

@@ -0,0 +1,158 @@
// 患者
export interface Patient {
id: string;
phone: string;
name: string | null;
gender: string | null;
birthDate: string | null;
hasArchive: boolean;
}
// 患者详情
export interface PatientDetail {
profile: {
id: string;
phone: string;
name: string | null;
gender: string | null;
birthDate: string | null;
avatarUrl: string | null;
};
archive: {
diagnosis: string | null;
surgeryType: string | null;
surgeryDate: string | null;
allergies: string[];
dietRestrictions: string[];
chronicDiseases: string[];
familyHistory: string | null;
} | null;
latestRecords: HealthRecord[];
trendRecords: TrendRecord[];
medications: Medication[];
dietRecords: DietRecord[];
exercisePlan: ExercisePlan | null;
reports: Report[];
followUps: FollowUp[];
}
// 健康记录
export interface HealthRecord {
id: string;
metricType: string;
systolic: number | null;
diastolic: number | null;
value: number | null;
unit: string;
recordedAt: string;
isAbnormal: boolean;
}
// 趋势数据
export interface TrendRecord {
id: string;
metricType: string;
systolic: number | null;
diastolic: number | null;
value: number | null;
unit: string;
recordedAt: string;
isAbnormal: boolean;
}
// 用药
export interface Medication {
id: string;
name: string;
dosage: string;
frequency: string;
timeOfDay: string[];
startDate: string;
endDate: string | null;
}
// 饮食记录
export interface DietRecord {
id: string;
mealType: string;
totalCalories: number;
healthScore: number;
recordedAt: string;
foods: { name: string; portion: string; calories: number; warning: string | null }[];
}
// 运动计划
export interface ExercisePlan {
weekStartDate: string;
items: {
dayOfWeek: number;
exerciseType: string | null;
durationMinutes: number;
isCompleted: boolean;
isRestDay: boolean;
completedAt: string | null;
}[];
}
// 报告
export interface Report {
id: string;
userId: string;
patientName?: string;
fileUrl: string;
fileType: string;
category: string;
status: string;
aiSummary: string | null;
aiIndicators: string | null;
doctorComment: string | null;
doctorName: string | null;
reviewedAt: string | null;
createdAt: string;
}
// 随访
export interface FollowUp {
id: string;
userId: string;
patientName?: string;
title: string;
doctorName: string | null;
department: string | null;
scheduledAt: string;
notes: string | null;
status: string;
createdAt: string;
}
// 问诊
export interface Consultation {
id: string;
userId: string;
patientName?: string;
patientPhone?: string;
status: string;
createdAt: string;
closedAt: string | null;
lastMessage: { content: string; senderType: string; createdAt: string } | null;
}
// 问诊消息
export interface ConsultationMessage {
id: string;
senderType: string;
senderName: string | null;
content: string;
createdAt: string;
}
// Dashboard
export interface DashboardStats {
doctorName: string;
doctorTitle: string;
doctorDepartment: string;
totalPatients: number;
activeConsultations: number;
pendingReports: number;
todayFollowUps: number;
}