Initial commit: HealthManager full-stack health management platform

Backend: .NET 10 + PostgreSQL + EF Core + JWT + SignalR
Frontend patient: React 19 + TypeScript + Vite (mobile H5)
Frontend doctor: React 19 + TypeScript + Vite (desktop web)
This commit is contained in:
MingNian
2026-05-20 16:18:56 +08:00
commit 435af55c4a
215 changed files with 18595 additions and 0 deletions

184
frontend-doctor/src/App.css Normal file
View File

@@ -0,0 +1,184 @@
.counter {
font-size: 16px;
padding: 5px 10px;
border-radius: 5px;
color: var(--accent);
background: var(--accent-bg);
border: 2px solid transparent;
transition: border-color 0.3s;
margin-bottom: 24px;
&:hover {
border-color: var(--accent-border);
}
&:focus-visible {
outline: 2px solid var(--accent);
outline-offset: 2px;
}
}
.hero {
position: relative;
.base,
.framework,
.vite {
inset-inline: 0;
margin: 0 auto;
}
.base {
width: 170px;
position: relative;
z-index: 0;
}
.framework,
.vite {
position: absolute;
}
.framework {
z-index: 1;
top: 34px;
height: 28px;
transform: perspective(2000px) rotateZ(300deg) rotateX(44deg) rotateY(39deg)
scale(1.4);
}
.vite {
z-index: 0;
top: 107px;
height: 26px;
width: auto;
transform: perspective(2000px) rotateZ(300deg) rotateX(40deg) rotateY(39deg)
scale(0.8);
}
}
#center {
display: flex;
flex-direction: column;
gap: 25px;
place-content: center;
place-items: center;
flex-grow: 1;
@media (max-width: 1024px) {
padding: 32px 20px 24px;
gap: 18px;
}
}
#next-steps {
display: flex;
border-top: 1px solid var(--border);
text-align: left;
& > div {
flex: 1 1 0;
padding: 32px;
@media (max-width: 1024px) {
padding: 24px 20px;
}
}
.icon {
margin-bottom: 16px;
width: 22px;
height: 22px;
}
@media (max-width: 1024px) {
flex-direction: column;
text-align: center;
}
}
#docs {
border-right: 1px solid var(--border);
@media (max-width: 1024px) {
border-right: none;
border-bottom: 1px solid var(--border);
}
}
#next-steps ul {
list-style: none;
padding: 0;
display: flex;
gap: 8px;
margin: 32px 0 0;
.logo {
height: 18px;
}
a {
color: var(--text-h);
font-size: 16px;
border-radius: 6px;
background: var(--social-bg);
display: flex;
padding: 6px 12px;
align-items: center;
gap: 8px;
text-decoration: none;
transition: box-shadow 0.3s;
&:hover {
box-shadow: var(--shadow);
}
.button-icon {
height: 18px;
width: 18px;
}
}
@media (max-width: 1024px) {
margin-top: 20px;
flex-wrap: wrap;
justify-content: center;
li {
flex: 1 1 calc(50% - 8px);
}
a {
width: 100%;
justify-content: center;
box-sizing: border-box;
}
}
}
#spacer {
height: 88px;
border-top: 1px solid var(--border);
@media (max-width: 1024px) {
height: 48px;
}
}
.ticks {
position: relative;
width: 100%;
&::before,
&::after {
content: '';
position: absolute;
top: -4.5px;
border: 5px solid transparent;
}
&::before {
left: 0;
border-left-color: var(--border);
}
&::after {
right: 0;
border-right-color: var(--border);
}
}

View File

@@ -0,0 +1,6 @@
import { RouterProvider } from 'react-router-dom';
import { router } from './router';
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

View File

@@ -0,0 +1,4 @@
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; color: #333; }
a { color: inherit; }
button { cursor: pointer; }

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 8.5 KiB

View File

@@ -0,0 +1,83 @@
import { Outlet, NavLink, useNavigate } from 'react-router-dom';
import { useAuthStore } from '../../stores/auth.store';
const navItems = [
{ to: '/dashboard', label: '工作台', icon: '📊' },
{ to: '/patients', label: '患者管理', icon: '👥' },
{ to: '/consultations', label: '在线问诊', icon: '💬' },
{ to: '/reports', label: '报告审核', icon: '📋' },
{ to: '/follow-ups', label: '随访管理', icon: '📅' },
];
const sidebarBg = '#0F1D3D';
const accentColor = '#4D8FFF';
const textMuted = '#8E9DB5';
export function DoctorLayout() {
const { user, logout } = useAuthStore();
const navigate = useNavigate();
const handleLogout = () => {
logout();
navigate('/login');
};
return (
<div style={{ display: 'flex', minHeight: '100vh', fontFamily: '-apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif' }}>
{/* Sidebar */}
<aside style={{
width: 220, background: sidebarBg, color: '#fff',
display: 'flex', flexDirection: 'column', flexShrink: 0,
}}>
<div style={{ padding: '24px 20px 20px', borderBottom: '1px solid rgba(255,255,255,0.08)' }}>
<h1 style={{ fontSize: 17, margin: 0, fontWeight: 600, color: '#fff', letterSpacing: 1 }}>
<span style={{ color: accentColor }}></span>
</h1>
<p style={{ fontSize: 12, margin: '6px 0 0', color: textMuted }}></p>
</div>
<nav style={{ flex: 1, padding: '12px 0' }}>
{navItems.map((item) => (
<NavLink
key={item.to}
to={item.to}
style={({ isActive }) => ({
display: 'flex', alignItems: 'center', gap: 10,
padding: '11px 20px', margin: '2px 8px',
borderRadius: 8,
color: isActive ? '#fff' : textMuted,
background: isActive ? accentColor : 'transparent',
textDecoration: 'none', fontSize: 14,
fontWeight: isActive ? 500 : 400,
transition: 'all 0.15s',
})}
>
<span style={{ fontSize: 16 }}>{item.icon}</span>
<span>{item.label}</span>
</NavLink>
))}
</nav>
<div style={{ padding: '16px 20px', borderTop: '1px solid rgba(255,255,255,0.08)' }}>
<div style={{ fontSize: 13, color: '#fff', fontWeight: 500 }}>{user?.name}</div>
<div style={{ fontSize: 11, color: textMuted, marginTop: 2 }}>{user?.department} · {user?.title}</div>
<button onClick={handleLogout}
style={{
marginTop: 10, padding: '6px 14px', fontSize: 12,
background: 'transparent', color: textMuted, border: '1px solid rgba(255,255,255,0.15)',
borderRadius: 6, cursor: 'pointer', transition: 'all 0.15s',
}}
onMouseEnter={(e) => { e.currentTarget.style.color = '#fff'; e.currentTarget.style.borderColor = '#fff'; }}
onMouseLeave={(e) => { e.currentTarget.style.color = textMuted; e.currentTarget.style.borderColor = 'rgba(255,255,255,0.15)'; }}>
退
</button>
</div>
</aside>
{/* Main content */}
<main style={{ flex: 1, background: '#F2F5FA', overflow: 'auto' }}>
<Outlet />
</main>
</div>
);
}

View File

@@ -0,0 +1,111 @@
:root {
--text: #6b6375;
--text-h: #08060d;
--bg: #fff;
--border: #e5e4e7;
--code-bg: #f4f3ec;
--accent: #aa3bff;
--accent-bg: rgba(170, 59, 255, 0.1);
--accent-border: rgba(170, 59, 255, 0.5);
--social-bg: rgba(244, 243, 236, 0.5);
--shadow:
rgba(0, 0, 0, 0.1) 0 10px 15px -3px, rgba(0, 0, 0, 0.05) 0 4px 6px -2px;
--sans: system-ui, 'Segoe UI', Roboto, sans-serif;
--heading: system-ui, 'Segoe UI', Roboto, sans-serif;
--mono: ui-monospace, Consolas, monospace;
font: 18px/145% var(--sans);
letter-spacing: 0.18px;
color-scheme: light dark;
color: var(--text);
background: var(--bg);
font-synthesis: none;
text-rendering: optimizeLegibility;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
@media (max-width: 1024px) {
font-size: 16px;
}
}
@media (prefers-color-scheme: dark) {
:root {
--text: #9ca3af;
--text-h: #f3f4f6;
--bg: #16171d;
--border: #2e303a;
--code-bg: #1f2028;
--accent: #c084fc;
--accent-bg: rgba(192, 132, 252, 0.15);
--accent-border: rgba(192, 132, 252, 0.5);
--social-bg: rgba(47, 48, 58, 0.5);
--shadow:
rgba(0, 0, 0, 0.4) 0 10px 15px -3px, rgba(0, 0, 0, 0.25) 0 4px 6px -2px;
}
#social .button-icon {
filter: invert(1) brightness(2);
}
}
#root {
width: 1126px;
max-width: 100%;
margin: 0 auto;
text-align: center;
border-inline: 1px solid var(--border);
min-height: 100svh;
display: flex;
flex-direction: column;
box-sizing: border-box;
}
body {
margin: 0;
}
h1,
h2 {
font-family: var(--heading);
font-weight: 500;
color: var(--text-h);
}
h1 {
font-size: 56px;
letter-spacing: -1.68px;
margin: 32px 0;
@media (max-width: 1024px) {
font-size: 36px;
margin: 20px 0;
}
}
h2 {
font-size: 24px;
line-height: 118%;
letter-spacing: -0.24px;
margin: 0 0 8px;
@media (max-width: 1024px) {
font-size: 20px;
}
}
p {
margin: 0;
}
code,
.counter {
font-family: var(--mono);
display: inline-flex;
border-radius: 4px;
color: var(--text-h);
}
code {
font-size: 15px;
line-height: 135%;
padding: 4px 8px;
background: var(--code-bg);
}

View File

@@ -0,0 +1,11 @@
import { StrictMode } from 'react';
import { createRoot } from 'react-dom/client';
import { RouterProvider } from 'react-router-dom';
import { router } from './router';
import './assets/styles/global.css';
createRoot(document.getElementById('root')!).render(
<StrictMode>
<RouterProvider router={router} />
</StrictMode>,
);

View File

@@ -0,0 +1,66 @@
import { useState } from 'react';
import { useNavigate } from 'react-router-dom';
import { useAuthStore } from '../../stores/auth.store';
export function LoginPage() {
const [phone, setPhone] = useState('13700137000');
const [code, setCode] = useState('');
const [error, setError] = useState('');
const [loading, setLoading] = useState(false);
const login = useAuthStore((s) => s.login);
const navigate = useNavigate();
const handleLogin = async (e: React.FormEvent) => {
e.preventDefault();
setError('');
setLoading(true);
try {
await login(phone, code || '0000');
navigate('/dashboard');
} catch (err: unknown) {
setError(err instanceof Error ? err.message : '登录失败');
} finally {
setLoading(false);
}
};
return (
<div style={{
display: 'flex', justifyContent: 'center', alignItems: 'center',
minHeight: '100vh', background: '#f0f2f5',
}}>
<form onSubmit={handleLogin} style={{
width: 400, padding: 40, background: '#fff', borderRadius: 8,
boxShadow: '0 2px 12px rgba(0,0,0,0.1)',
}}>
<h2 style={{ textAlign: 'center', marginBottom: 24 }}></h2>
{error && <div style={{ color: '#f44336', marginBottom: 12, fontSize: 13 }}>{error}</div>}
<div style={{ marginBottom: 16 }}>
<label style={{ display: 'block', marginBottom: 4, fontSize: 13 }}></label>
<input value={phone} onChange={(e) => setPhone(e.target.value)}
style={{ width: '100%', padding: '10px 12px', border: '1px solid #ddd', borderRadius: 4, fontSize: 14 }} />
</div>
<div style={{ marginBottom: 20 }}>
<label style={{ display: 'block', marginBottom: 4, fontSize: 13 }}> ()</label>
<input value={code} onChange={(e) => setCode(e.target.value)}
placeholder="输入任意验证码"
style={{ width: '100%', padding: '10px 12px', border: '1px solid #ddd', borderRadius: 4, fontSize: 14 }} />
</div>
<button type="submit" disabled={loading} style={{
width: '100%', padding: '12px', background: '#1976d2', color: '#fff',
border: 'none', borderRadius: 4, fontSize: 15, opacity: loading ? 0.7 : 1,
}}>
{loading ? '登录中...' : '登录'}
</button>
<p style={{ marginTop: 16, fontSize: 12, color: '#999', textAlign: 'center' }}>
13700137000 ( )
</p>
</form>
</div>
);
}

View File

@@ -0,0 +1,81 @@
import { useEffect, useState, useRef } from 'react';
import { useParams } from 'react-router-dom';
import { api } from '../../services/api-client';
interface Message {
id: string; senderId: string; senderRole: string;
content: string; contentType: string; createdAt: string;
}
export function ChatPage() {
const { id } = useParams<{ id: string }>();
const [messages, setMessages] = useState<Message[]>([]);
const [input, setInput] = useState('');
const bottomRef = useRef<HTMLDivElement>(null);
useEffect(() => {
if (!id) return;
api.get<Message[]>(`/api/consultations/${id}/messages`)
.then((r) => setMessages(r.data))
.catch(() => {});
}, [id]);
useEffect(() => {
bottomRef.current?.scrollIntoView({ behavior: 'smooth' });
}, [messages]);
const handleSend = async () => {
if (!input.trim() || !id) return;
try {
const res = await api.post<Message>(`/api/consultations/${id}/messages`, { content: input });
setMessages((prev) => [...prev, res.data]);
setInput('');
} catch { /* ignore */ }
};
return (
<div style={{ display: 'flex', flexDirection: 'column', height: 'calc(100vh - 0px)' }}>
<div style={{ padding: '14px 20px', background: '#fff', borderBottom: '1px solid #eee', fontSize: 15, fontWeight: 500 }}>
线
</div>
<div style={{ flex: 1, overflow: 'auto', padding: 20, background: '#fafafa' }}>
{messages.map((msg) => (
<div key={msg.id} style={{
display: 'flex', justifyContent: msg.senderRole === 'doctor' ? 'flex-end' : 'flex-start',
marginBottom: 12,
}}>
<div style={{
maxWidth: '70%', padding: '10px 14px', borderRadius: 12, fontSize: 14,
background: msg.senderRole === 'doctor' ? '#1976d2' : '#fff',
color: msg.senderRole === 'doctor' ? '#fff' : '#333',
boxShadow: '0 1px 3px rgba(0,0,0,0.08)',
}}>
<div>{msg.content}</div>
<div style={{
fontSize: 10, marginTop: 4, textAlign: 'right',
opacity: 0.7,
}}>
{msg.createdAt?.split('T')[1]?.slice(0, 5)}
</div>
</div>
</div>
))}
<div ref={bottomRef} />
</div>
<div style={{ padding: '12px 20px', background: '#fff', borderTop: '1px solid #eee', display: 'flex', gap: 12 }}>
<input value={input} onChange={(e) => setInput(e.target.value)}
onKeyDown={(e) => e.key === 'Enter' && handleSend()}
placeholder="输入回复..."
style={{ flex: 1, padding: '10px 14px', border: '1px solid #ddd', borderRadius: 20, fontSize: 14 }} />
<button onClick={handleSend} style={{
padding: '10px 24px', background: '#1976d2', color: '#fff',
border: 'none', borderRadius: 20, fontSize: 14,
}}>
</button>
</div>
</div>
);
}

View File

@@ -0,0 +1,67 @@
import { useEffect, useState } from 'react';
import { Link } from 'react-router-dom';
import { api } from '../../services/api-client';
interface ConsultationItem {
id: string; patientId: string; patientName: string; subject: string;
status: string; startedAt: string;
}
interface RawConsultation {
id: string; patientId: string; patientName?: string; subject?: string;
status: string; startedAt: string;
}
export function ConsultationListPage() {
const [consultations, setConsultations] = useState<ConsultationItem[]>([]);
useEffect(() => {
api.get<RawConsultation[]>('/api/consultations').then((r) => {
const mapped = r.data.map((c) => ({
id: c.id,
patientId: c.patientId,
patientName: c.patientName || 'unknown',
subject: c.subject || 'online consult',
status: c.status,
startedAt: c.startedAt,
}));
setConsultations(mapped);
}).catch(() => {});
}, []);
return (
<div style={{ padding: 24 }}>
<h2 style={{ marginBottom: 16 }}>线</h2>
<div style={{ background: '#fff', borderRadius: 8, boxShadow: '0 1px 4px rgba(0,0,0,0.08)' }}>
{consultations.map((c) => (
<Link key={c.id} to={`/consultations/${c.id}`} style={{
display: 'flex', justifyContent: 'space-between', alignItems: 'center',
padding: '14px 20px', borderBottom: '1px solid #f5f5f5',
textDecoration: 'none', color: 'inherit',
}}>
<div>
<div style={{ fontSize: 14, fontWeight: 500 }}>{c.patientName}</div>
<div style={{ fontSize: 12, color: '#888', marginTop: 2 }}>{c.subject}</div>
</div>
<div style={{ textAlign: 'right' }}>
<span style={{
padding: '2px 8px', borderRadius: 10, fontSize: 11,
background: c.status === 'active' ? '#e8f5e9' : '#f5f5f5',
color: c.status === 'active' ? '#2e7d32' : '#999',
}}>
{c.status === 'active' ? '进行中' : '已结束'}
</span>
<div style={{ fontSize: 11, color: '#bbb', marginTop: 4 }}>
{c.startedAt?.split('T')[0]}
</div>
</div>
</Link>
))}
{consultations.length === 0 && (
<div style={{ padding: 40, textAlign: 'center', color: '#999' }}></div>
)}
</div>
</div>
);
}

View File

@@ -0,0 +1,102 @@
import { useEffect, useState } from 'react';
import { Link } from 'react-router-dom';
import { api } from '../../services/api-client';
import { useAuthStore } from '../../stores/auth.store';
import type { DashboardStats } from '../../types';
interface RawPatient { id: string; name: string; phone: string; }
interface RawConsultation { id: string; status: string; patientName: string; subject: string; }
interface RawFollowUp { id: string; scheduledAt: string; title: string; status: string; }
interface RawReport { id: string; title: string; status: string; }
export function DashboardPage() {
const user = useAuthStore((s) => s.user);
const [stats, setStats] = useState<DashboardStats>({
totalPatients: 0, activeConsultations: 0, pendingReports: 0,
todayFollowUps: 0, weeklyNewPatients: 0, weeklyConsultations: 0,
});
useEffect(() => {
async function loadStats() {
try {
const [patients, consultations, reports, followUps] = await Promise.all([
api.get<RawPatient[]>('/api/patients'),
api.get<RawConsultation[]>('/api/consultations'),
api.get<RawReport[]>('/api/reports?status=pending'),
api.get<RawFollowUp[]>('/api/follow-ups'),
]);
setStats({
totalPatients: patients.data.length,
activeConsultations: consultations.data.filter((c) => c.status === 'active').length,
pendingReports: reports.data.length,
todayFollowUps: followUps.data.filter((f) => {
const d = (f.scheduledAt as string)?.split('T')[0];
return d === new Date().toISOString().split('T')[0];
}).length,
weeklyNewPatients: 0,
weeklyConsultations: consultations.data.length,
});
} catch { /* ignore */ }
}
loadStats();
}, []);
return (
<div style={{ padding: 24 }}>
<h2 style={{ marginBottom: 20 }}>{user?.name}</h2>
<div style={{ display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(200px, 1fr))', gap: 16, marginBottom: 32 }}>
{[
{ label: '患者总数', value: stats.totalPatients, color: '#1976d2' },
{ label: '进行中问诊', value: stats.activeConsultations, color: '#388e3c' },
{ label: '待审核报告', value: stats.pendingReports, color: '#f57c00' },
{ label: '今日随访', value: stats.todayFollowUps, color: '#7b1fa2' },
].map((item) => (
<div key={item.label} style={{
background: '#fff', padding: 20, borderRadius: 8,
borderLeft: `4px solid ${item.color}`, boxShadow: '0 1px 4px rgba(0,0,0,0.08)',
}}>
<div style={{ fontSize: 28, fontWeight: 700, color: item.color }}>{item.value}</div>
<div style={{ fontSize: 13, color: '#888', marginTop: 4 }}>{item.label}</div>
</div>
))}
</div>
<div style={{ display: 'grid', gridTemplateColumns: '2fr 1fr', gap: 16 }}>
<div style={{ background: '#fff', padding: 20, borderRadius: 8, boxShadow: '0 1px 4px rgba(0,0,0,0.08)' }}>
<h3 style={{ marginBottom: 12, fontSize: 15 }}></h3>
<div style={{ display: 'flex', gap: 12, flexWrap: 'wrap' }}>
{[
{ label: '患者列表', href: '/patients' },
{ label: '在线问诊', href: '/consultations' },
{ label: '报告审核', href: '/reports' },
{ label: '随访管理', href: '/follow-ups' },
].map((action) => (
<Link key={action.label} to={action.href} style={{
padding: '8px 16px', background: '#f0f2f5', borderRadius: 4,
textDecoration: 'none', color: '#1976d2', fontSize: 13,
}}>
{action.label}
</Link>
))}
</div>
</div>
<div style={{ background: '#fff', padding: 20, borderRadius: 8, boxShadow: '0 1px 4px rgba(0,0,0,0.08)' }}>
<h3 style={{ marginBottom: 12, fontSize: 15 }}></h3>
<ul style={{ fontSize: 13, color: '#666', listStyle: 'none', padding: 0 }}>
<li style={{ padding: '6px 0', borderBottom: '1px solid #f0f0f0' }}>
📋 : {stats.pendingReports}
</li>
<li style={{ padding: '6px 0', borderBottom: '1px solid #f0f0f0' }}>
💬 : {stats.activeConsultations}
</li>
<li style={{ padding: '6px 0' }}>
📅 访: {stats.todayFollowUps}
</li>
</ul>
</div>
</div>
</div>
);
}

View File

@@ -0,0 +1,84 @@
import { useEffect, useState } from 'react';
import { useParams, useNavigate } from 'react-router-dom';
import { api } from '../../services/api-client';
export function FollowUpEditPage() {
const { id } = useParams<{ id: string }>();
const navigate = useNavigate();
const isNew = !id || id === 'new';
const [title, setTitle] = useState('');
const [patientId, setPatientId] = useState('');
const [scheduledAt, setScheduledAt] = useState('');
const [notes, setNotes] = useState('');
const [patients, setPatients] = useState<{ id: string; name: string }[]>([]);
useEffect(() => {
api.get<{ id: string; name: string }[]>('/api/patients').then((r) => setPatients(r.data));
if (!isNew) {
api.get<Record<string, unknown>>(`/api/follow-ups/${id}`).then((r) => {
setTitle(r.data.title as string);
setPatientId(r.data.patientId as string);
setScheduledAt((r.data.scheduledAt as string)?.slice(0, 16) || '');
setNotes((r.data.notes as string) || '');
}).catch(() => {});
}
}, [id, isNew]);
const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault();
const body = { title, patientId, scheduledAt, notes };
try {
if (isNew) {
await api.post('/api/follow-ups', body);
} else {
await api.put(`/api/follow-ups/${id}`, body);
}
navigate('/follow-ups');
} catch { alert('操作失败'); }
};
return (
<div style={{ padding: 24 }}>
<h2 style={{ marginBottom: 16 }}>{isNew ? '新建随访' : '编辑随访'}</h2>
<form onSubmit={handleSubmit} style={{ background: '#fff', padding: 24, borderRadius: 8, maxWidth: 500 }}>
<div style={{ marginBottom: 14 }}>
<label style={{ display: 'block', fontSize: 13, marginBottom: 4 }}></label>
<input value={title} onChange={(e) => setTitle(e.target.value)} required
style={{ width: '100%', padding: '8px 12px', border: '1px solid #ddd', borderRadius: 4 }} />
</div>
<div style={{ marginBottom: 14 }}>
<label style={{ display: 'block', fontSize: 13, marginBottom: 4 }}></label>
<select value={patientId} onChange={(e) => setPatientId(e.target.value)} required
style={{ width: '100%', padding: '8px 12px', border: '1px solid #ddd', borderRadius: 4 }}>
<option value=""></option>
{patients.map((p) => (
<option key={p.id} value={p.id}>{p.name}</option>
))}
</select>
</div>
<div style={{ marginBottom: 14 }}>
<label style={{ display: 'block', fontSize: 13, marginBottom: 4 }}></label>
<input type="datetime-local" value={scheduledAt} onChange={(e) => setScheduledAt(e.target.value)} required
style={{ width: '100%', padding: '8px 12px', border: '1px solid #ddd', borderRadius: 4 }} />
</div>
<div style={{ marginBottom: 18 }}>
<label style={{ display: 'block', fontSize: 13, marginBottom: 4 }}></label>
<textarea value={notes} onChange={(e) => setNotes(e.target.value)} rows={3}
style={{ width: '100%', padding: '8px 12px', border: '1px solid #ddd', borderRadius: 4, resize: 'vertical' }} />
</div>
<button type="submit" style={{
padding: '10px 24px', background: '#1976d2', color: '#fff',
border: 'none', borderRadius: 4, fontSize: 14,
}}>
{isNew ? '创建' : '保存'}
</button>
</form>
</div>
);
}

View File

@@ -0,0 +1,82 @@
import { useEffect, useState } from 'react';
import { Link } from 'react-router-dom';
import { api } from '../../services/api-client';
interface FollowUpItem {
id: string; patientId: string; patientName: string;
title: string; scheduledAt: string; status: string;
}
interface RawFollowUpItem {
id: string; patientId: string; patientName?: string;
title: string; scheduledAt: string; status: string;
}
export function FollowUpListPage() {
const [followUps, setFollowUps] = useState<FollowUpItem[]>([]);
useEffect(() => {
api.get<RawFollowUpItem[]>('/api/follow-ups').then((r) => {
const mapped = r.data.map((f) => ({
id: f.id,
patientId: f.patientId,
patientName: f.patientName || 'unknown',
title: f.title,
scheduledAt: f.scheduledAt,
status: f.status,
}));
setFollowUps(mapped);
}).catch(() => {});
}, []);
const statusLabel = (s: string) => {
switch (s) {
case 'pending': return { text: '待随访', color: '#f57c00', bg: '#fff3e0' };
case 'completed': return { text: '已完成', color: '#2e7d32', bg: '#e8f5e9' };
case 'missed': return { text: '已错过', color: '#c62828', bg: '#ffebee' };
default: return { text: s, color: '#666', bg: '#f5f5f5' };
}
};
return (
<div style={{ padding: 24 }}>
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: 16 }}>
<h2>访</h2>
<Link to="/follow-ups/new/edit" style={{
padding: '8px 16px', background: '#1976d2', color: '#fff',
borderRadius: 4, textDecoration: 'none', fontSize: 13,
}}>
+ 访
</Link>
</div>
<div style={{ background: '#fff', borderRadius: 8, boxShadow: '0 1px 4px rgba(0,0,0,0.08)' }}>
{followUps.map((f) => {
const s = statusLabel(f.status);
return (
<div key={f.id} style={{
display: 'flex', justifyContent: 'space-between', alignItems: 'center',
padding: '14px 20px', borderBottom: '1px solid #f5f5f5',
}}>
<div>
<div style={{ fontSize: 14, fontWeight: 500 }}>{f.title}</div>
<div style={{ fontSize: 12, color: '#888', marginTop: 2 }}>
{f.patientName} · {f.scheduledAt?.split('T')[0]}
</div>
</div>
<div style={{ display: 'flex', alignItems: 'center', gap: 12 }}>
<span style={{ padding: '2px 8px', borderRadius: 10, fontSize: 11, background: s.bg, color: s.color }}>
{s.text}
</span>
<Link to={`/follow-ups/${f.id}/edit`} style={{ color: '#1976d2', fontSize: 13 }}></Link>
</div>
</div>
);
})}
{followUps.length === 0 && (
<div style={{ padding: 40, textAlign: 'center', color: '#999' }}>访</div>
)}
</div>
</div>
);
}

View File

@@ -0,0 +1,81 @@
import { useEffect, useState } from 'react';
import { useParams, Link } from 'react-router-dom';
import { api } from '../../services/api-client';
interface PatientDetail {
id: string; name: string; phone: string; gender: string; birthday: string;
heightCm: number; weightKg: number; medicalHistory: string[];
stentDate: string; stentType: string;
}
interface HealthRecord {
id: string; type: string; value: string; unit: string; recordedAt: string;
}
export function PatientDetailPage() {
const { id } = useParams<{ id: string }>();
const [patient, setPatient] = useState<PatientDetail | null>(null);
const [records, setRecords] = useState<HealthRecord[]>([]);
useEffect(() => {
if (!id) return;
// Fetch patient detail directly by ID + health records
api.get<PatientDetail>(`/api/patients/${id}`).then((r) => {
if (r.data) setPatient(r.data);
}).catch(() => {});
api.get<HealthRecord[]>(`/api/health-records?patientId=${id}&days=30`).then((r) => setRecords(r.data));
}, [id]);
if (!patient) return <div style={{ padding: 24 }}>...</div>;
const latestByType: Record<string, HealthRecord> = {};
records.forEach((r) => {
if (!latestByType[r.type] || r.recordedAt > latestByType[r.type].recordedAt) {
latestByType[r.type] = r;
}
});
const parseValueDisplay = (r: HealthRecord) => {
try {
const v = JSON.parse(r.value);
if (typeof v === 'object') return `${v.systolic ?? v.value ?? '-'}/${v.diastolic ?? '-'}`;
return String(v.value ?? v);
} catch { return r.value; }
};
return (
<div style={{ padding: 24 }}>
<Link to="/patients" style={{ fontSize: 13, color: '#1976d2' }}> </Link>
<div style={{ background: '#fff', marginTop: 16, padding: 24, borderRadius: 8, boxShadow: '0 1px 4px rgba(0,0,0,0.08)' }}>
<h2>{patient.name}</h2>
<div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: '8px 24px', marginTop: 12, fontSize: 14 }}>
<div>{patient.phone}</div>
<div>{patient.gender || '-'}</div>
<div>{patient.birthday || '-'}</div>
<div>{patient.heightCm}cm / {patient.weightKg}kg</div>
<div>{(patient.medicalHistory || []).join('、') || '-'}</div>
<div>{patient.stentDate || '-'}</div>
<div>{patient.stentType || '-'}</div>
</div>
</div>
<h3 style={{ marginTop: 24, marginBottom: 12 }}></h3>
<div style={{ display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(180px, 1fr))', gap: 12 }}>
{Object.entries(latestByType).map(([type, record]) => (
<div key={type} style={{ background: '#fff', padding: 16, borderRadius: 8, boxShadow: '0 1px 4px rgba(0,0,0,0.08)' }}>
<div style={{ fontSize: 12, color: '#888' }}>
{type === 'blood_pressure' ? '血压' : type === 'heart_rate' ? '心率' : type}
</div>
<div style={{ fontSize: 20, fontWeight: 600, marginTop: 4 }}>
{parseValueDisplay(record)} {record.unit}
</div>
<div style={{ fontSize: 11, color: '#bbb', marginTop: 4 }}>
{record.recordedAt?.split('T')[0]}
</div>
</div>
))}
</div>
</div>
);
}

View File

@@ -0,0 +1,68 @@
import { useEffect, useState } from 'react';
import { Link } from 'react-router-dom';
import { api } from '../../services/api-client';
interface Patient {
id: string; name: string; phone: string; gender: string;
medicalHistory: string[]; stentDate: string;
}
export function PatientListPage() {
const [patients, setPatients] = useState<Patient[]>([]);
const [search, setSearch] = useState('');
const [loading, setLoading] = useState(true);
useEffect(() => {
api.get<Patient[]>('/api/patients')
.then((r) => setPatients(r.data))
.catch(() => {})
.finally(() => setLoading(false));
}, []);
const filtered = patients.filter((p) =>
!search || p.name.includes(search) || p.phone.includes(search)
);
return (
<div style={{ padding: 24 }}>
<h2 style={{ marginBottom: 16 }}></h2>
<input value={search} onChange={(e) => setSearch(e.target.value)} placeholder="搜索姓名或手机号..."
style={{ width: 300, padding: '8px 12px', border: '1px solid #ddd', borderRadius: 4, marginBottom: 16 }} />
{loading ? <div>...</div> : (
<div style={{ background: '#fff', borderRadius: 8, boxShadow: '0 1px 4px rgba(0,0,0,0.08)' }}>
<table style={{ width: '100%', borderCollapse: 'collapse', fontSize: 14 }}>
<thead>
<tr style={{ borderBottom: '2px solid #f0f0f0', textAlign: 'left' }}>
<th style={{ padding: '12px 16px' }}></th>
<th style={{ padding: '12px 16px' }}></th>
<th style={{ padding: '12px 16px' }}></th>
<th style={{ padding: '12px 16px' }}></th>
<th style={{ padding: '12px 16px' }}></th>
<th style={{ padding: '12px 16px' }}></th>
</tr>
</thead>
<tbody>
{filtered.map((p) => (
<tr key={p.id} style={{ borderBottom: '1px solid #f5f5f5' }}>
<td style={{ padding: '10px 16px' }}>{p.name}</td>
<td style={{ padding: '10px 16px', color: '#888' }}>{p.phone}</td>
<td style={{ padding: '10px 16px' }}>{p.gender || '-'}</td>
<td style={{ padding: '10px 16px' }}>{(p.medicalHistory || []).slice(0, 3).join('、') || '-'}</td>
<td style={{ padding: '10px 16px' }}>{p.stentDate || '-'}</td>
<td style={{ padding: '10px 16px' }}>
<Link to={`/patients/${p.id}`} style={{ color: '#1976d2', fontSize: 13 }}></Link>
</td>
</tr>
))}
{filtered.length === 0 && (
<tr><td colSpan={6} style={{ padding: 24, textAlign: 'center', color: '#999' }}></td></tr>
)}
</tbody>
</table>
</div>
)}
</div>
);
}

View File

@@ -0,0 +1,114 @@
import { useEffect, useState } from 'react';
import { useParams, Link } from 'react-router-dom';
import { api } from '../../services/api-client';
interface RawReport {
id: string; patientId: string; title: string; category: string;
imageUrls: string[]; status: string; riskLevel?: string;
summary?: string; suggestions?: string;
patientName?: string; doctorName?: string;
createdAt: string; completedAt?: string;
items?: { id: string; itemName: string; resultValue: string; unit?: string; referenceRange?: string; isAbnormal: boolean }[];
}
export function ReportDetailPage() {
const { id } = useParams<{ id: string }>();
const [report, setReport] = useState<RawReport | null>(null);
const [interpretation, setInterpretation] = useState('');
const [submitting, setSubmitting] = useState(false);
useEffect(() => {
if (!id) return;
api.get<RawReport>(`/api/reports/${id}`).then((r) => setReport(r.data)).catch(() => {});
}, [id]);
const handleInterpret = async () => {
if (!interpretation.trim() || !id) return;
setSubmitting(true);
try {
await api.post(`/api/reports/${id}/interpret`, {
summary: interpretation,
items: [],
riskLevel: 'normal',
suggestions: null,
});
// Refetch report to show updated status
const updated = await api.get<RawReport>(`/api/reports/${id}`);
setReport(updated.data);
setInterpretation('');
alert('interpretation submitted');
} catch { alert('submit failed'); }
finally { setSubmitting(false); }
};
if (!report) return <div style={{ padding: 24 }}>loading...</div>;
return (
<div style={{ padding: 24 }}>
<Link to="/reports" style={{ fontSize: 13, color: '#1976d2' }}>&larr; back to reports</Link>
<div style={{ background: '#fff', marginTop: 16, padding: 24, borderRadius: 8, boxShadow: '0 1px 4px rgba(0,0,0,0.08)' }}>
<h2>{report.title}</h2>
<div style={{ marginTop: 12, fontSize: 14, color: '#666' }}>
<div>Patient: {report.patientName || 'unknown'}</div>
<div>Category: {report.category}</div>
<div>Status: {report.status}</div>
<div>Submitted: {report.createdAt?.split('T')[0]}</div>
</div>
{report.imageUrls && report.imageUrls.length > 0 && (
<div style={{ marginTop: 16 }}>
<h4 style={{ fontSize: 14, marginBottom: 8 }}>Report Images</h4>
{report.imageUrls.map((url, i) => (
<div key={i} style={{ padding: '8px 12px', background: '#f5f5f5', borderRadius: 4, marginBottom: 4, fontSize: 12 }}>
{url}
</div>
))}
</div>
)}
{report.status === 'completed' && (
<div style={{ marginTop: 16, padding: 16, background: '#e8f5e9', borderRadius: 8 }}>
<h4 style={{ fontSize: 14, marginBottom: 4 }}>Interpretation Result</h4>
<p style={{ fontSize: 13, color: '#555' }}>{report.summary || 'No summary'}</p>
{report.riskLevel && <p style={{ fontSize: 12, color: '#888' }}>Risk: {report.riskLevel}</p>}
{report.suggestions && <p style={{ fontSize: 12, color: '#888' }}>Suggestions: {report.suggestions}</p>}
{report.items && report.items.length > 0 && (
<table style={{ width: '100%', marginTop: 8, borderCollapse: 'collapse', fontSize: 12 }}>
<thead><tr style={{ textAlign: 'left', borderBottom: '1px solid #ddd' }}>
<th style={{ padding: 4 }}>Item</th><th style={{ padding: 4 }}>Value</th><th style={{ padding: 4 }}>Range</th><th style={{ padding: 4 }}>Abnormal</th>
</tr></thead>
<tbody>
{report.items.map((item) => (
<tr key={item.id} style={{ borderBottom: '1px solid #f0f0f0' }}>
<td style={{ padding: 4 }}>{item.itemName}</td>
<td style={{ padding: 4 }}>{item.resultValue} {item.unit || ''}</td>
<td style={{ padding: 4 }}>{item.referenceRange || '-'}</td>
<td style={{ padding: 4, color: item.isAbnormal ? '#c62828' : '#2e7d32' }}>{item.isAbnormal ? 'Yes' : 'No'}</td>
</tr>
))}
</tbody>
</table>
)}
</div>
)}
{report.status !== 'completed' && (
<div style={{ marginTop: 20 }}>
<h4 style={{ fontSize: 14, marginBottom: 8 }}>Doctor Interpretation</h4>
<textarea value={interpretation} onChange={(e) => setInterpretation(e.target.value)}
placeholder="Enter your interpretation..."
rows={5}
style={{ width: '100%', padding: 12, border: '1px solid #ddd', borderRadius: 4, fontSize: 14, resize: 'vertical' }} />
<button onClick={handleInterpret} disabled={submitting} style={{
marginTop: 8, padding: '10px 24px', background: '#1976d2', color: '#fff',
border: 'none', borderRadius: 4, fontSize: 14, opacity: submitting ? 0.7 : 1,
}}>
{submitting ? 'Submitting...' : 'Submit Interpretation'}
</button>
</div>
)}
</div>
</div>
);
}

View File

@@ -0,0 +1,85 @@
import { useEffect, useState } from 'react';
import { Link } from 'react-router-dom';
import { api } from '../../services/api-client';
interface ReportItem {
id: string; patientId: string; patientName: string;
title: string; category: string; status: string; createdAt: string;
}
interface RawReportItem {
id: string; patientId: string; patientName?: string;
title: string; category: string; status: string; createdAt: string;
}
export function ReportListPage() {
const [reports, setReports] = useState<ReportItem[]>([]);
useEffect(() => {
api.get<RawReportItem[]>('/api/reports').then((r) => {
const mapped = r.data.map((rp) => ({
id: rp.id,
patientId: rp.patientId,
patientName: rp.patientName || 'unknown',
title: rp.title,
category: rp.category,
status: rp.status,
createdAt: rp.createdAt,
}));
setReports(mapped);
}).catch(() => {});
}, []);
const statusLabel = (s: string) => {
switch (s) {
case 'pending': return { text: '待审核', color: '#f57c00', bg: '#fff3e0' };
case 'completed': return { text: '已完成', color: '#2e7d32', bg: '#e8f5e9' };
default: return { text: s, color: '#666', bg: '#f5f5f5' };
}
};
return (
<div style={{ padding: 24 }}>
<h2 style={{ marginBottom: 16 }}></h2>
<div style={{ background: '#fff', borderRadius: 8, boxShadow: '0 1px 4px rgba(0,0,0,0.08)' }}>
<table style={{ width: '100%', borderCollapse: 'collapse', fontSize: 14 }}>
<thead>
<tr style={{ borderBottom: '2px solid #f0f0f0', textAlign: 'left' }}>
<th style={{ padding: '12px 16px' }}></th>
<th style={{ padding: '12px 16px' }}></th>
<th style={{ padding: '12px 16px' }}></th>
<th style={{ padding: '12px 16px' }}></th>
<th style={{ padding: '12px 16px' }}></th>
<th style={{ padding: '12px 16px' }}></th>
</tr>
</thead>
<tbody>
{reports.map((r) => {
const s = statusLabel(r.status);
return (
<tr key={r.id} style={{ borderBottom: '1px solid #f5f5f5' }}>
<td style={{ padding: '10px 16px' }}>{r.patientName}</td>
<td style={{ padding: '10px 16px' }}>{r.title}</td>
<td style={{ padding: '10px 16px', color: '#888' }}>{r.category}</td>
<td style={{ padding: '10px 16px' }}>
<span style={{ padding: '2px 8px', borderRadius: 10, fontSize: 11, background: s.bg, color: s.color }}>
{s.text}
</span>
</td>
<td style={{ padding: '10px 16px', color: '#888' }}>{r.createdAt?.split('T')[0]}</td>
<td style={{ padding: '10px 16px' }}>
<Link to={`/reports/${r.id}`} style={{ color: '#1976d2', fontSize: 13 }}></Link>
</td>
</tr>
);
})}
{reports.length === 0 && (
<tr><td colSpan={6} style={{ padding: 24, textAlign: 'center', color: '#999' }}></td></tr>
)}
</tbody>
</table>
</div>
</div>
);
}

View File

@@ -0,0 +1,83 @@
import { useEffect, useState } from 'react';
import { api } from '../../services/api-client';
import { useAuthStore } from '../../stores/auth.store';
export function ProfilePage() {
const user = useAuthStore((s) => s.user);
const updateProfile = useAuthStore((s) => s.updateProfile);
const [form, setForm] = useState({
name: '', department: '', title: '', introduction: '', phone: '',
});
useEffect(() => {
if (user) setForm({
name: user.name || '',
department: user.department || '',
title: user.title || '',
introduction: user.introduction || '',
phone: user.phone || '',
});
}, [user]);
const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault();
try {
await api.put('/api/auth/me', {
name: form.name,
department: form.department,
title: form.title,
introduction: form.introduction,
});
updateProfile(form);
alert('保存成功');
} catch { alert('保存失败'); }
};
if (!user) return null;
return (
<div style={{ padding: 24 }}>
<h2 style={{ marginBottom: 16 }}></h2>
<form onSubmit={handleSubmit} style={{ background: '#fff', padding: 24, borderRadius: 8, maxWidth: 500 }}>
<div style={{ marginBottom: 14 }}>
<label style={{ display: 'block', fontSize: 13, marginBottom: 4 }}></label>
<input value={form.name} onChange={(e) => setForm({ ...form, name: e.target.value })}
style={{ width: '100%', padding: '8px 12px', border: '1px solid #ddd', borderRadius: 4 }} />
</div>
<div style={{ marginBottom: 14 }}>
<label style={{ display: 'block', fontSize: 13, marginBottom: 4 }}></label>
<input value={form.phone} disabled
style={{ width: '100%', padding: '8px 12px', border: '1px solid #eee', borderRadius: 4, background: '#f9f9f9' }} />
</div>
<div style={{ marginBottom: 14 }}>
<label style={{ display: 'block', fontSize: 13, marginBottom: 4 }}></label>
<input value={form.department} onChange={(e) => setForm({ ...form, department: e.target.value })}
style={{ width: '100%', padding: '8px 12px', border: '1px solid #ddd', borderRadius: 4 }} />
</div>
<div style={{ marginBottom: 14 }}>
<label style={{ display: 'block', fontSize: 13, marginBottom: 4 }}></label>
<input value={form.title} onChange={(e) => setForm({ ...form, title: e.target.value })}
style={{ width: '100%', padding: '8px 12px', border: '1px solid #ddd', borderRadius: 4 }} />
</div>
<div style={{ marginBottom: 18 }}>
<label style={{ display: 'block', fontSize: 13, marginBottom: 4 }}></label>
<textarea value={form.introduction} onChange={(e) => setForm({ ...form, introduction: e.target.value })} rows={4}
style={{ width: '100%', padding: '8px 12px', border: '1px solid #ddd', borderRadius: 4, resize: 'vertical' }} />
</div>
<button type="submit" style={{
padding: '10px 24px', background: '#1976d2', color: '#fff',
border: 'none', borderRadius: 4, fontSize: 14,
}}>
</button>
</form>
</div>
);
}

View File

@@ -0,0 +1,8 @@
import { Navigate } from 'react-router-dom';
import { useAuthStore } from '../stores/auth.store';
export function AuthGuard({ children }: { children: React.ReactNode }) {
const isAuthenticated = useAuthStore((s) => s.isAuthenticated);
if (!isAuthenticated) return <Navigate to="/login" replace />;
return <>{children}</>;
}

View File

@@ -0,0 +1,41 @@
import { createBrowserRouter, Navigate } from 'react-router-dom';
import { DoctorLayout } from '../components/layout/DoctorLayout';
import { AuthGuard } from './AuthGuard';
import { LoginPage } from '../pages/auth/LoginPage';
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';
import { ProfilePage } from '../pages/settings/ProfilePage';
export const router = createBrowserRouter([
{
path: '/login',
element: <LoginPage />,
},
{
element: (
<AuthGuard>
<DoctorLayout />
</AuthGuard>
),
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/:id/edit', element: <FollowUpEditPage /> },
{ path: 'profile', element: <ProfilePage /> },
],
},
]);

View File

@@ -0,0 +1,74 @@
/** Doctor frontend API client — calls same backend as patient frontend */
interface ApiResponse<T> {
code: number;
data: T;
message: string;
}
const BASE_URL = 'http://localhost:5000';
// Endpoints that should NEVER include auth token
const PUBLIC_ENDPOINTS = ['/api/auth/login', '/api/auth/register', '/api/auth/send-sms', '/api/auth/refresh'];
function getToken(): string | null {
try {
const raw = localStorage.getItem('doc_auth');
if (!raw) return null;
const state = JSON.parse(raw);
return state?.state?.token ?? null;
} catch {
return null;
}
}
function clearAuth() {
localStorage.removeItem('doc_auth');
}
async function request<T>(method: string, path: string, body?: unknown): Promise<ApiResponse<T>> {
const headers: Record<string, string> = { 'Content-Type': 'application/json' };
// Only attach token for non-public endpoints
if (!PUBLIC_ENDPOINTS.includes(path)) {
const token = getToken();
if (token) headers['Authorization'] = `Bearer ${token}`;
}
const response = await fetch(`${BASE_URL}${path}`, {
method, headers,
body: body ? JSON.stringify(body) : undefined,
});
if (response.status === 401) {
clearAuth();
if (!window.location.pathname.includes('/login')) {
window.location.href = '/login';
}
throw new Error('登录已过期,请重新登录');
}
const text = await response.text();
let data: T;
try {
data = JSON.parse(text);
} catch {
data = text as unknown as T;
}
if (!response.ok) {
const msg = (data as Record<string, unknown>)?.message || response.statusText;
throw new Error(String(msg));
}
return { code: response.status, data, message: 'success' };
}
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),
};
export type { ApiResponse };

View File

@@ -0,0 +1,66 @@
import { create } from 'zustand';
import { persist } from 'zustand/middleware';
import { api } from '../services/api-client';
import type { User } from '../types';
interface AuthState {
user: User | null;
token: string | null;
isAuthenticated: boolean;
login: (phone: string, code: string) => Promise<void>;
logout: () => void;
updateProfile: (data: Partial<User>) => void;
}
export const useAuthStore = create<AuthState>()(
persist(
(set) => ({
user: null,
token: null,
isAuthenticated: false,
login: async (phone: string, code: string) => {
const res = await api.post<{
userId: string; name: string; role: string;
accessToken: string; refreshToken: string;
}>('/api/auth/login', { phone, smsCode: code });
// Verify role is doctor
if (res.data.role !== 'doctor') {
throw new Error('仅限医生账号登录');
}
set({
token: res.data.accessToken,
isAuthenticated: true,
user: { id: res.data.userId, name: res.data.name, role: res.data.role } as User,
});
// Fetch full profile
try {
const profile = await api.get<User>('/api/auth/me');
set({ user: profile.data });
} catch { /* ignore */ }
},
logout: () => {
localStorage.removeItem('doc_auth');
set({ user: null, token: null, isAuthenticated: false });
},
updateProfile: (data: Partial<User>) => {
set((state) => ({
user: state.user ? { ...state.user, ...data } : null,
}));
},
}),
{
name: 'doc_auth',
partialize: (state) => ({
user: state.user,
token: state.token,
isAuthenticated: state.isAuthenticated,
}),
},
),
);

View File

@@ -0,0 +1,101 @@
export interface User {
id: string;
phone: string;
name: string;
role: string;
gender: string;
department: string;
title: string;
specialty: string[];
introduction: string;
}
export interface Patient {
id: string;
name: string;
phone: string;
gender: string;
age: number;
medicalHistory: string[];
stentDate: string;
stentType: string;
lastRecordAt?: string;
}
export interface HealthRecord {
id: string;
type: string;
value: string;
unit: string;
recordedAt: string;
source: string;
notes?: string;
}
export interface Medication {
id: string;
drugName: string;
dosage: string;
frequency: string;
timeSlots: string[];
startDate: string;
endDate?: string;
notes?: string;
status: string;
}
export interface Consultation {
id: string;
patientId: string;
patientName: string;
doctorId: string;
subject?: string;
status: string;
startedAt: string;
lastMessage?: string;
lastMessageAt?: string;
unreadCount?: number;
}
export interface ConsultationMessage {
id: string;
senderId: string;
senderRole: string;
content: string;
contentType: string;
isRead: boolean;
createdAt: string;
}
export interface Report {
id: string;
patientId: string;
patientName: string;
title: string;
category: string;
imageUrls: string[];
status: string;
result?: string;
createdAt: string;
}
export interface FollowUp {
id: string;
patientId: string;
patientName: string;
doctorId: string;
title: string;
scheduledAt: string;
status: string;
notes?: string;
completedAt?: string;
}
export interface DashboardStats {
totalPatients: number;
activeConsultations: number;
pendingReports: number;
todayFollowUps: number;
weeklyNewPatients: number;
weeklyConsultations: number;
}