refactor: single doctor, direct chat, any phone login, UI polish, fix animations

This commit is contained in:
MingNian
2026-05-21 16:05:21 +08:00
parent bec65959a7
commit 0df75c35e9
8 changed files with 110 additions and 102 deletions

View File

@@ -26,9 +26,20 @@ public class AuthController(
{ {
var user = await authService.GetUserByPhoneAsync(request.Phone); var user = await authService.GetUserByPhoneAsync(request.Phone);
if (user == null) if (user == null)
return Unauthorized(new { message = "用户不存在" }); {
// Demo: auto-register new users
var db = HttpContext.RequestServices.GetRequiredService<Infrastructure.Data.AppDbContext>();
user = new User
{
Phone = request.Phone,
Name = "用户" + request.Phone[^4..],
Role = "patient",
PasswordHash = AuthService.HashPassword("demo123"),
};
db.Users.Add(user);
await db.SaveChangesAsync();
}
// Demo: accept any SMS code
var accessToken = jwtProvider.GenerateAccessToken(user.Id, user.Name, user.Role); var accessToken = jwtProvider.GenerateAccessToken(user.Id, user.Name, user.Role);
var refreshToken = jwtProvider.GenerateRefreshToken(); var refreshToken = jwtProvider.GenerateRefreshToken();
await authService.SaveRefreshTokenAsync(user.Id, refreshToken, DateTime.UtcNow.AddDays(7)); await authService.SaveRefreshTokenAsync(user.Id, refreshToken, DateTime.UtcNow.AddDays(7));

View File

@@ -1,10 +1,10 @@
:root { :root {
/* Primary - Medical Blue */ /* Primary - Rich Medical Blue */
--color-primary: #1E6BFF; --color-primary: #2563EB;
--color-primary-light: #4D8FFF; --color-primary-light: #3B82F6;
--color-primary-dark: #1055E0; --color-primary-dark: #1D4ED8;
--color-primary-bg: #EBF3FF; --color-primary-bg: #EFF6FF;
--color-primary-gradient: linear-gradient(135deg, #1E6BFF, #4D8FFF); --color-primary-gradient: linear-gradient(135deg, #2563EB, #4F8AF8);
/* Status */ /* Status */
--color-success: #10B981; --color-success: #10B981;
@@ -14,20 +14,15 @@
--color-danger: #EF4444; --color-danger: #EF4444;
--color-danger-bg: #FEF2F2; --color-danger-bg: #FEF2F2;
/* Risk */
--color-risk-normal: #10B981;
--color-risk-attention: #F59E0B;
--color-risk-abnormal: #EF4444;
/* Neutral */ /* Neutral */
--color-white: #FFFFFF; --color-white: #FFFFFF;
--color-bg: #F2F5FA; --color-bg: #F4F6FA;
--color-bg-secondary: #E8ECF2; --color-bg-secondary: #EBEEF3;
--color-border: #E2E8F0; --color-border: #E4E7EC;
--color-border-light: #F0F2F5; --color-border-light: #F0F1F4;
/* Text */ /* Text */
--color-text-primary: #1A1D28; --color-text-primary: #1A1E2B;
--color-text-secondary: #6B7280; --color-text-secondary: #6B7280;
--color-text-tertiary: #9CA3AF; --color-text-tertiary: #9CA3AF;
--color-text-inverse: #FFFFFF; --color-text-inverse: #FFFFFF;
@@ -46,16 +41,17 @@
--radius-md: 12px; --radius-md: 12px;
--radius-lg: 16px; --radius-lg: 16px;
--radius-xl: 20px; --radius-xl: 20px;
--radius-2xl: 24px;
--radius-full: 9999px; --radius-full: 9999px;
/* Shadows */ /* Shadows */
--shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.04); --shadow-xs: 0 1px 2px rgba(0,0,0,0.04);
--shadow-md: 0 2px 12px rgba(0, 0, 0, 0.06); --shadow-sm: 0 2px 8px rgba(0,0,0,0.05);
--shadow-lg: 0 4px 24px rgba(0, 0, 0, 0.08); --shadow-md: 0 4px 16px rgba(0,0,0,0.07);
--shadow-lg: 0 8px 32px rgba(0,0,0,0.09);
/* Font */ /* Font */
--font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
--font-size-xs: 11px; --font-size-xs: 11px;
--font-size-sm: 12px; --font-size-sm: 12px;
--font-size-base: 14px; --font-size-base: 14px;

View File

@@ -9,13 +9,12 @@ export function AppLayout() {
return ( return (
<div className={styles.layout}> <div className={styles.layout}>
<main className={styles.main}> <main className={styles.main}>
<AnimatePresence mode="wait"> <AnimatePresence>
<motion.div <motion.div
key={location.pathname} key={location.pathname}
initial={{ opacity: 0, y: 8 }} initial={{ opacity: 0 }}
animate={{ opacity: 1, y: 0 }} animate={{ opacity: 1 }}
exit={{ opacity: 0, y: -8 }} transition={{ duration: 0.12 }}
transition={{ duration: 0.15, ease: 'easeOut' }}
> >
<Outlet /> <Outlet />
</motion.div> </motion.div>

View File

@@ -5,13 +5,13 @@ export function StackLayout() {
const location = useLocation(); const location = useLocation();
return ( return (
<AnimatePresence mode="wait"> <AnimatePresence>
<motion.div <motion.div
key={location.pathname} key={location.pathname}
initial={{ opacity: 0, x: 40 }} initial={{ opacity: 0 }}
animate={{ opacity: 1, x: 0 }} animate={{ opacity: 1 }}
exit={{ opacity: 0, x: -40 }} exit={{ opacity: 0 }}
transition={{ duration: 0.2, ease: 'easeOut' }} transition={{ duration: 0.15 }}
> >
<Outlet /> <Outlet />
</motion.div> </motion.div>

View File

@@ -7,36 +7,42 @@
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: center; justify-content: center;
background: var(--color-white);
border-radius: 50%;
box-shadow: var(--shadow-xs);
} }
.overviewCard { .overviewCard {
margin-bottom: 16px; margin-bottom: 16px;
background: linear-gradient(135deg, #1E6BFF, #4D8FFF); background: linear-gradient(135deg, #2563EB 0%, #3B82F6 40%, #5B9AFF 100%);
color: #fff; color: #fff;
border-radius: var(--radius-xl);
padding: 20px;
overflow: hidden;
} }
.overviewHeader { .overviewHeader {
display: flex; display: flex;
justify-content: space-between; justify-content: space-between;
align-items: center; align-items: center;
margin-bottom: 16px; margin-bottom: 18px;
} }
.overviewTitle { .overviewTitle {
font-size: var(--font-size-md); font-size: var(--font-size-md);
font-weight: 600; font-weight: 600;
color: #fff; opacity: 0.9;
} }
.overviewTime { .overviewTime {
font-size: var(--font-size-xs); font-size: var(--font-size-xs);
color: var(--color-text-tertiary); opacity: 0.7;
} }
.overviewData { .overviewData {
display: flex; display: flex;
align-items: center; align-items: center;
gap: 16px; gap: 20px;
} }
.bpSection, .bpSection,
@@ -50,7 +56,7 @@
.dataLabel { .dataLabel {
font-size: var(--font-size-xs); font-size: var(--font-size-xs);
color: var(--color-text-tertiary); opacity: 0.7;
} }
.bpValues { .bpValues {
@@ -60,63 +66,58 @@
} }
.bpNum { .bpNum {
font-size: var(--font-size-3xl); font-size: 36px;
font-weight: 700; font-weight: 700;
line-height: 1.1; line-height: 1.1;
color: #fff;
} }
.risk_normal { color: var(--color-success); }
.risk_borderline { color: var(--color-warning); }
.risk_abnormal { color: var(--color-danger); }
.bpSep { .bpSep {
font-size: var(--font-size-xl); font-size: var(--font-size-xl);
color: var(--color-text-tertiary); opacity: 0.5;
} }
.hrNum { .hrNum {
font-size: var(--font-size-3xl); font-size: 36px;
font-weight: 700; font-weight: 700;
color: var(--color-text-primary);
line-height: 1.1; line-height: 1.1;
} }
.unit { .unit {
font-size: var(--font-size-xs); font-size: var(--font-size-xs);
color: var(--color-text-tertiary); opacity: 0.6;
} }
.divider { .divider {
width: 1px; width: 1px;
height: 60px; height: 60px;
background: var(--color-border); background: rgba(255,255,255,0.2);
} }
/* Quick Actions */ /* Quick Actions */
.quickActions { .quickActions {
display: grid; display: grid;
grid-template-columns: repeat(3, 1fr); grid-template-columns: repeat(3, 1fr);
gap: 8px; gap: 10px;
margin-bottom: 16px; margin-bottom: 16px;
background: var(--color-white);
border-radius: var(--radius-lg);
padding: 16px;
box-shadow: var(--shadow-sm);
} }
.quickAction { .quickAction {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
align-items: center; align-items: center;
gap: 6px; gap: 8px;
padding: 12px 8px; padding: 14px 8px;
border-radius: var(--radius-md); background: var(--color-white);
transition: background 0.15s; border-radius: var(--radius-lg);
box-shadow: var(--shadow-sm);
transition: all 0.15s;
-webkit-tap-highlight-color: transparent; -webkit-tap-highlight-color: transparent;
} }
.quickAction:active { .quickAction:active {
background: var(--color-bg); transform: scale(0.96);
box-shadow: var(--shadow-md);
} }
.quickIcon { .quickIcon {
@@ -133,6 +134,8 @@
/* Health Tip */ /* Health Tip */
.tipCard { .tipCard {
margin-bottom: 16px; margin-bottom: 16px;
background: linear-gradient(135deg, #FFFBEB, #FFF7ED);
border: 1px solid #FDE68A;
} }
.tipHeader { .tipHeader {
@@ -145,7 +148,7 @@
.tipTitle { .tipTitle {
font-size: var(--font-size-sm); font-size: var(--font-size-sm);
font-weight: 600; font-weight: 600;
color: var(--color-text-secondary); color: #92400E;
} }
.tipHint { .tipHint {
@@ -156,6 +159,6 @@
.tipContent { .tipContent {
font-size: var(--font-size-sm); font-size: var(--font-size-sm);
color: var(--color-text-secondary); color: #78350F;
line-height: 1.6; line-height: 1.6;
} }

View File

@@ -15,7 +15,7 @@ import styles from './HomePage.module.css';
const QUICK_ACTIONS = [ const QUICK_ACTIONS = [
{ label: '测血压', icon: '💓', path: '/health/records?type=blood_pressure' }, { label: '测血压', icon: '💓', path: '/health/records?type=blood_pressure' },
{ label: '记用药', icon: '💊', path: '/health/medications' }, { label: '记用药', icon: '💊', path: '/health/medications' },
{ label: '在线问诊', icon: '👨‍⚕️', path: '/services/consultation' }, { label: '在线问诊', icon: '💬', path: '/services/consultation' },
{ label: '报告解读', icon: '📋', path: '/services/reports' }, { label: '报告解读', icon: '📋', path: '/services/reports' },
{ label: '健康日历', icon: '📅', path: '/health/calendar' }, { label: '健康日历', icon: '📅', path: '/health/calendar' },
{ label: '运动饮食', icon: '🏃', path: '/health/exercise-diet' }, { label: '运动饮食', icon: '🏃', path: '/health/exercise-diet' },

View File

@@ -1,5 +1,4 @@
import { useEffect, useState, useRef } from 'react'; import { useEffect, useState, useRef } from 'react';
import { useParams } from 'react-router-dom';
import { PageHeader } from '@/components/layout/PageHeader'; import { PageHeader } from '@/components/layout/PageHeader';
import * as consultationService from '@/services/consultation.service'; import * as consultationService from '@/services/consultation.service';
import type { Consultation, ConsultationMessage, Doctor } from '@/types'; import type { Consultation, ConsultationMessage, Doctor } from '@/types';
@@ -7,7 +6,6 @@ import { formatRelative } from '@/utils/format';
import styles from './ChatPage.module.css'; import styles from './ChatPage.module.css';
export function ChatPage() { export function ChatPage() {
const { doctorId } = useParams<{ doctorId: string }>();
const [doctor, setDoctor] = useState<Doctor | null>(null); const [doctor, setDoctor] = useState<Doctor | null>(null);
const [consultation, setConsultation] = useState<Consultation | null>(null); const [consultation, setConsultation] = useState<Consultation | null>(null);
const [messages, setMessages] = useState<ConsultationMessage[]>([]); const [messages, setMessages] = useState<ConsultationMessage[]>([]);
@@ -16,36 +14,43 @@ export function ChatPage() {
const bottomRef = useRef<HTMLDivElement>(null); const bottomRef = useRef<HTMLDivElement>(null);
useEffect(() => { useEffect(() => {
if (doctorId) { // Get the first available doctor
consultationService.getDoctor(doctorId).then((d) => setDoctor(d || null)); consultationService.getDoctors().then((docs) => {
consultationService.getConsultation(doctorId).then(async (c) => { if (docs.length > 0) {
if (c) { const doc = docs[0];
setConsultation(c); setDoctor(doc);
} else { // Find or create consultation
const newC = await consultationService.startConsultation(doctorId); consultationService.getConsultation(doc.id).then(async (c) => {
setConsultation(newC); if (c) {
} setConsultation(c);
}); loadMessages(c.id);
} } else {
}, [doctorId]); const newC = await consultationService.startConsultation(doc.id, '在线咨询');
setConsultation(newC);
// Fetch messages when consultation is loaded }
useEffect(() => {
if (consultation?.id) {
consultationService.getDoctorReply(consultation.id).then(() => {
// The messages are fetched as a side effect; fetch them directly
import('@/services/api-client').then(({ api }) => {
api.get<ConsultationMessage[]>(`/api/consultations/${consultation.id}/messages`)
.then((res) => setMessages(res.data));
}); });
}); }
} });
}, [consultation?.id]); }, []);
const loadMessages = (cid: string) => {
import('@/services/api-client').then(({ api }) => {
api.get<ConsultationMessage[]>(`/api/consultations/${cid}/messages`)
.then((res) => setMessages(res.data));
});
};
useEffect(() => { useEffect(() => {
bottomRef.current?.scrollIntoView({ behavior: 'smooth' }); bottomRef.current?.scrollIntoView({ behavior: 'smooth' });
}, [messages]); }, [messages]);
useEffect(() => {
// Poll for new messages every 3 seconds
if (!consultation?.id) return;
const timer = setInterval(() => loadMessages(consultation.id), 3000);
return () => clearInterval(timer);
}, [consultation?.id]);
const handleSend = async () => { const handleSend = async () => {
if (!text.trim() || !consultation || sending) return; if (!text.trim() || !consultation || sending) return;
setSending(true); setSending(true);
@@ -54,22 +59,17 @@ export function ChatPage() {
const sent = await consultationService.sendMessage(consultation.id, msgText); const sent = await consultationService.sendMessage(consultation.id, msgText);
setMessages((prev) => [...prev, sent]); setMessages((prev) => [...prev, sent]);
setSending(false); setSending(false);
// Poll for doctor reply after delay
setTimeout(async () => {
const reply = await consultationService.getDoctorReply(consultation.id);
if (reply) {
setMessages((prev) => {
if (prev.find((m) => m.id === reply.id)) return prev;
return [...prev, reply];
});
}
}, 1500);
}; };
return ( return (
<div className={styles.page}> <div className={styles.page}>
<PageHeader title={doctor?.name || '咨询'} /> <PageHeader title={doctor?.name || '在线问诊'} />
<div className={styles.messages}> <div className={styles.messages}>
{messages.length === 0 && (
<div style={{ textAlign: 'center', color: '#9CA3AF', marginTop: 40, fontSize: 14 }}>
{doctor?.name || '医生'}
</div>
)}
{messages.map((msg) => ( {messages.map((msg) => (
<div <div
key={msg.id} key={msg.id}
@@ -90,7 +90,7 @@ export function ChatPage() {
onKeyDown={(e) => e.key === 'Enter' && handleSend()} onKeyDown={(e) => e.key === 'Enter' && handleSend()}
/> />
<button className={styles.sendBtn} onClick={handleSend} disabled={sending}> <button className={styles.sendBtn} onClick={handleSend} disabled={sending}>
{sending ? '...' : '发送'}
</button> </button>
</div> </div>
</div> </div>

View File

@@ -75,8 +75,7 @@ export const router = createBrowserRouter([
{ path: 'health/medications/add', element: <MedicationEditPage /> }, { path: 'health/medications/add', element: <MedicationEditPage /> },
{ path: 'health/medications/:id', element: <MedicationDetailPage /> }, { path: 'health/medications/:id', element: <MedicationDetailPage /> },
{ path: 'health/exercise-diet', element: <ExerciseDietPage /> }, { path: 'health/exercise-diet', element: <ExerciseDietPage /> },
{ path: 'services/consultation', element: <DoctorListPage /> }, { path: 'services/consultation', element: <ChatPage /> },
{ path: 'services/consultation/chat/:doctorId', element: <ChatPage /> },
{ path: 'services/reports', element: <ReportListPage /> }, { path: 'services/reports', element: <ReportListPage /> },
{ path: 'services/reports/upload', element: <ReportUploadPage /> }, { path: 'services/reports/upload', element: <ReportUploadPage /> },
{ path: 'services/reports/:id', element: <ReportDetailPage /> }, { path: 'services/reports/:id', element: <ReportDetailPage /> },