fix(health): 修复患者端咨询权限+聊天页UI+SVG模板警告

- consultation_handler: create_message/mark_session_read 从 .manage 降为 .list,
  患者端只有 list 权限,导致发送消息和标记已读 403
- consultation.ts: 同步后端 DTO doctor_name/patient_name 等缺失字段
- messages/index.tsx: 咨询卡片显示医生姓名替代 consultation_type
- consultation/index.tsx: 同步显示 doctor_name
- pkg-consultation/detail: 按原型重写聊天页(医生头像+在线状态+非对称气泡+药丸输入栏)
- ProgressRing: SVG 替换为 conic-gradient 纯 CSS,消除 tmpl_0_svg 模板警告
- usePageData: stopPullDownRefresh 加 try-catch 防止 DevTools fd race
This commit is contained in:
iven
2026-05-16 22:38:21 +08:00
parent 95e219ad5a
commit 4be28de3ce
10 changed files with 278 additions and 208 deletions

View File

@@ -4,9 +4,30 @@
position: relative; position: relative;
flex-shrink: 0; flex-shrink: 0;
&__center { &--sm {
position: absolute; width: 64px;
inset: 0; height: 64px;
}
&--lg {
width: 80px;
height: 80px;
}
&__track {
width: 100%;
height: 100%;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
}
&__inner {
width: calc(100% - 8px);
height: calc(100% - 8px);
border-radius: 50%;
background: $card;
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: center; justify-content: center;

View File

@@ -15,39 +15,24 @@ const ProgressRing: React.FC<ProgressRingProps> = ({
label, label,
className = '', className = '',
}) => { }) => {
const px = size === 'sm' ? 64 : 80; const pct = Math.round(Math.min(progress, 1) * 100);
const r = (px / 2) - 4; const deg = (pct / 100) * 360;
const circumference = 2 * Math.PI * r;
const offset = circumference * (1 - Math.min(progress, 1));
const cls = ['progress-ring', `progress-ring--${size}`, className].filter(Boolean).join(' '); const cls = ['progress-ring', `progress-ring--${size}`, className].filter(Boolean).join(' ');
return ( return (
<View className={cls} style={{ width: px, height: px }}> <View className={cls}>
<svg width={px} height={px} viewBox={`0 0 ${px} ${px}`}> <View
<circle className='progress-ring__track'
cx={px / 2} cy={px / 2} r={r} style={{ background: `conic-gradient(var(--tk-pri) ${deg}deg, var(--tk-pri-l, #E8E2DC) ${deg}deg)` }}
fill='none' >
stroke='var(--tk-pri-l, #E8E2DC)' <View className='progress-ring__inner'>
strokeWidth={4} {label ? (
/> <Text className='progress-ring__label'>{label}</Text>
<circle ) : (
cx={px / 2} cy={px / 2} r={r} <Text className='progress-ring__pct'>{pct}%</Text>
fill='none' )}
stroke='var(--tk-pri)' </View>
strokeWidth={4}
strokeDasharray={circumference}
strokeDashoffset={offset}
strokeLinecap='round'
transform={`rotate(-90 ${px / 2} ${px / 2})`}
/>
</svg>
<View className='progress-ring__center'>
{label ? (
<Text className='progress-ring__label'>{label}</Text>
) : (
<Text className='progress-ring__pct'>{Math.round(progress * 100)}%</Text>
)}
</View> </View>
</View> </View>
); );

View File

@@ -67,7 +67,7 @@ export function usePageData(
try { try {
await refresh(); await refresh();
} finally { } finally {
Taro.stopPullDownRefresh(); try { Taro.stopPullDownRefresh(); } catch { /* DevTools fd race */ }
} }
}); });

View File

@@ -161,7 +161,7 @@ export default function Consultation() {
<View className='session-body'> <View className='session-body'>
<View className='session-top'> <View className='session-top'>
<Text className='session-subject'> <Text className='session-subject'>
{session.subject || '在线咨询'} {session.doctor_name || session.subject || '在线咨询'}
</Text> </Text>
<Text className='session-time'> <Text className='session-time'>
{session.last_message_at {session.last_message_at

View File

@@ -143,6 +143,13 @@
color: $tx; color: $tx;
} }
.consult-type-tag {
font-size: var(--tk-font-micro);
font-weight: 400;
color: $tx3;
margin-left: 6px;
}
.consult-time { .consult-time {
font-size: var(--tk-font-micro); font-size: var(--tk-font-micro);
color: var(--tk-text-secondary); color: var(--tk-text-secondary);

View File

@@ -159,7 +159,8 @@ export default function Messages() {
) : ( ) : (
<View className='msg-list'> <View className='msg-list'>
{sessions.map((session) => { {sessions.map((session) => {
const doctorName = session.last_message?.slice(0, 1) || ''; const displayName = session.doctor_name || '在线咨询';
const avatarChar = session.doctor_name?.charAt(0) || '咨';
const hasUnread = session.unread_count_patient > 0; const hasUnread = session.unread_count_patient > 0;
return ( return (
<ContentCard <ContentCard
@@ -169,12 +170,17 @@ export default function Messages() {
className={`consult-card ${hasUnread ? '' : 'consult-card-muted'}`} className={`consult-card ${hasUnread ? '' : 'consult-card-muted'}`}
> >
<View className={`consult-avatar ${hasUnread ? 'consult-avatar-active' : ''}`}> <View className={`consult-avatar ${hasUnread ? 'consult-avatar-active' : ''}`}>
<Text className='consult-avatar-char'>{doctorName}</Text> <Text className='consult-avatar-char'>{avatarChar}</Text>
</View> </View>
<View className='consult-body'> <View className='consult-body'>
<View className='consult-row'> <View className='consult-row'>
<Text className='consult-doctor'> <Text className='consult-doctor'>
{session.consultation_type === 'online' ? '在线咨询' : '门诊咨询'} {displayName}
{session.consultation_type && (
<Text className='consult-type-tag'>
{session.consultation_type === 'online' ? '在线' : '门诊'}
</Text>
)}
</Text> </Text>
<Text className='consult-time'>{formatTime(session.last_message_at)}</Text> <Text className='consult-time'>{formatTime(session.last_message_at)}</Text>
</View> </View>

View File

@@ -9,223 +9,263 @@
} }
/* ─── 导航栏 ─── */ /* ─── 导航栏 ─── */
.chat-header { .chat-nav {
display: flex; display: flex;
align-items: center; align-items: center;
padding: var(--tk-gap-sm) var(--tk-gap-md); justify-content: space-between;
padding: 16px 20px 12px;
background: $card; background: $card;
border-bottom: 1px solid $bd-l; border-bottom: 1px solid $bd-l;
flex-shrink: 0; flex-shrink: 0;
position: relative;
} }
.chat-header__back { .chat-nav__back {
position: absolute; width: 32px;
left: 16px; height: 32px;
z-index: 1; display: flex;
align-items: center;
justify-content: center;
&:active { &:active {
opacity: var(--tk-touch-feedback-opacity); opacity: var(--tk-touch-feedback-opacity);
} }
} }
.chat-header__back-text { .chat-nav__back-icon {
font-size: var(--tk-font-body-sm); font-size: 24px;
color: var(--tk-pri); font-weight: 300;
color: $tx;
line-height: 1;
} }
.chat-header__center { .chat-nav__center {
flex: 1;
display: flex; display: flex;
flex-direction: column; flex-direction: column;
align-items: center; align-items: center;
} }
.chat-header__title { .chat-nav__title {
font-size: var(--tk-font-body-sm); font-family: Georgia, 'Times New Roman', serif;
font-weight: 600; font-size: 17px;
font-weight: 700;
color: $tx; color: $tx;
} }
.chat-header__status { .chat-nav__online {
font-size: var(--tk-font-micro); display: flex;
color: $acc; align-items: center;
gap: 4px;
margin-top: 2px; margin-top: 2px;
}
&--closed { .chat-nav__dot {
color: $tx3; width: 6px;
height: 6px;
border-radius: 3px;
background: $acc;
}
.chat-nav__online-text {
font-size: 11px;
color: $acc;
}
.chat-nav__offline-text {
font-size: 11px;
color: $tx3;
margin-top: 2px;
}
.chat-nav__more {
width: 32px;
height: 32px;
display: flex;
align-items: center;
justify-content: center;
&:active {
opacity: var(--tk-touch-feedback-opacity);
} }
} }
/* ─── 消息区 ─── */ .chat-nav__more-icon {
.chat-messages { font-size: 18px;
flex: 1; font-weight: 700;
padding: var(--tk-gap-md) var(--tk-gap-md) 0; color: $tx3;
overflow-y: auto; letter-spacing: 1px;
} }
.msg-row { /* ─── 消息区域 ─── */
.chat-body {
flex: 1;
padding: 16px 20px;
}
/* ─── 日期分隔 ─── */
.chat-date-pill {
display: flex; display: flex;
margin-bottom: var(--tk-gap-md); justify-content: center;
gap: var(--tk-gap-xs); margin: 8px 0 12px;
&__text {
font-size: 11px;
color: $tx3;
background: $surface-alt;
padding: 3px 12px;
border-radius: 10px;
}
}
/* ─── 消息行 ─── */
.chat-msg {
display: flex;
align-items: flex-start;
margin-bottom: 8px;
&--self { &--self {
justify-content: flex-end; justify-content: flex-end;
} }
&--doctor {
gap: 10px;
}
} }
/* ─── 医生头像 ─── */ /* ─── 医生头像 ─── */
.msg-avatar { .chat-msg__avatar {
width: 32px; width: 36px;
height: 32px; height: 36px;
border-radius: $r; border-radius: 18px;
background: var(--tk-pri-l); background: $pri;
@include flex-center; display: flex;
align-items: center;
justify-content: center;
flex-shrink: 0; flex-shrink: 0;
} }
.msg-avatar-char { .chat-msg__avatar-char {
@include serif-number; color: $white;
font-size: var(--tk-font-cap); font-size: 15px;
font-weight: 700; font-weight: 600;
color: var(--tk-pri);
} }
/* ─── 消息气泡 ─── */ /* ─── 消息气泡 ─── */
.msg-bubble { .chat-msg__bubble {
max-width: 70%; max-width: 72%;
padding: var(--tk-gap-sm) var(--tk-gap-md); padding: 10px 14px;
box-shadow: $shadow-sm;
&--other { &--doctor {
background: $card; background: $card;
border-radius: $r $r $r $r-xs; border-radius: 4px 16px 16px 16px;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
} }
&--self { &--self {
background: var(--tk-pri); background: $pri-l;
border-radius: $r $r $r-xs $r; border-radius: 16px 4px 16px 16px;
} }
} }
.msg-text { .chat-msg__text {
font-size: var(--tk-font-cap); font-size: 15px;
color: $tx; color: $tx;
display: block;
line-height: 1.6; line-height: 1.6;
word-break: break-all; word-break: break-all;
.msg-bubble--self & {
color: $white;
}
} }
.msg-date-divider { .chat-msg__image {
display: flex;
justify-content: center;
padding: var(--tk-gap-sm) 0;
&__text {
font-size: var(--tk-font-micro);
color: var(--tk-text-secondary);
background: $surface-alt;
padding: 2px 12px;
border-radius: $r-pill;
}
}
.msg-truncated-hint {
display: flex;
justify-content: center;
padding: var(--tk-gap-sm) 0;
&__text {
font-size: var(--tk-font-micro);
color: var(--tk-text-secondary);
background: $surface-alt;
padding: 2px 12px;
border-radius: $r-pill;
}
}
.msg-image {
width: 200px; width: 200px;
border-radius: $r-sm; border-radius: 12px;
margin-top: var(--tk-gap-2xs);
}
.msg-time {
font-size: var(--tk-font-micro);
color: var(--tk-text-secondary);
display: block;
margin-top: var(--tk-gap-2xs);
.msg-bubble--self & {
color: rgba(255, 255, 255, 0.7);
text-align: right;
}
} }
/* ─── 空状态 ─── */
.chat-empty { .chat-empty {
text-align: center; text-align: center;
padding: 80px var(--tk-page-padding); padding: 80px 20px;
&__text { &__text {
font-size: var(--tk-font-cap); font-size: 14px;
color: var(--tk-text-secondary); color: $tx3;
} }
} }
/* ─── 输入栏 ─── */ /* ─── 底部输入栏 ─── */
.chat-input-bar { .chat-bar {
display: flex; display: flex;
align-items: center; align-items: center;
gap: 10px; gap: 10px;
padding: 10px 16px 38px; padding: 10px 16px;
padding-bottom: calc(10px + env(safe-area-inset-bottom));
background: $card; background: $card;
border-top: 1px solid $bd-l; border-top: 1px solid $bd-l;
flex-shrink: 0; flex-shrink: 0;
&--closed {
justify-content: center;
}
} }
.chat-input { .chat-bar__add {
width: 36px;
height: 36px;
display: flex;
align-items: center;
justify-content: center;
flex-shrink: 0;
&:active {
opacity: var(--tk-touch-feedback-opacity);
}
}
.chat-bar__add-icon {
font-size: 22px;
color: $tx3;
font-weight: 300;
}
.chat-bar__input {
flex: 1; flex: 1;
height: 48px; height: 40px;
background: $bg; background: $surface-alt;
border: 1.5px solid $bd; border: none;
border-radius: $r-lg; border-radius: 20px;
padding: 0 14px; padding: 0 14px;
font-size: var(--tk-font-cap); font-size: 14px;
color: $tx; color: $tx;
} }
.chat-send-btn { .chat-bar__placeholder {
width: 48px; color: $tx3;
height: 48px; font-size: 14px;
border-radius: $r-lg; }
background: var(--tk-pri);
@include flex-center; .chat-bar__send {
width: 40px;
height: 40px;
border-radius: 20px;
background: $pri;
display: flex;
align-items: center;
justify-content: center;
flex-shrink: 0; flex-shrink: 0;
box-shadow: 0 2px 6px rgba($pri, 0.3);
&--disabled { &--disabled {
opacity: 0.5; opacity: 0.5;
} }
}
.chat-send-btn__icon { &:active:not(&--disabled) {
font-size: var(--tk-font-cap); opacity: var(--tk-touch-feedback-opacity);
color: $white;
font-weight: 600;
}
.chat-closed-bar {
padding: var(--tk-gap-md);
text-align: center;
background: $card;
border-top: 1px solid $bd-l;
&__text {
font-size: var(--tk-font-cap);
color: var(--tk-text-secondary);
} }
} }
.chat-bar__send-icon {
color: $white;
font-size: 20px;
font-weight: 700;
}
.chat-bar__closed-text {
font-size: 14px;
color: $tx3;
}

View File

@@ -105,11 +105,6 @@ export default function ConsultationDetail() {
} }
}; };
const formatTime = (dateStr: string) => {
const d = new Date(dateStr);
return d.toLocaleTimeString('zh-CN', { hour: '2-digit', minute: '2-digit' });
};
const getDateLabel = (dateStr: string): string => { const getDateLabel = (dateStr: string): string => {
const d = new Date(dateStr); const d = new Date(dateStr);
const today = new Date(); const today = new Date();
@@ -128,42 +123,49 @@ export default function ConsultationDetail() {
const isImageUrl = (url: string) => /\.(jpg|jpeg|png|gif|webp)(\?.*)?$/i.test(url); const isImageUrl = (url: string) => /\.(jpg|jpeg|png|gif|webp)(\?.*)?$/i.test(url);
// 渲染层面的消息数量上限,防止长对话 DOM 节点过多
const hiddenCount = Math.max(0, messages.length - MAX_RENDER_MESSAGES); const hiddenCount = Math.max(0, messages.length - MAX_RENDER_MESSAGES);
const renderMessages = hiddenCount > 0 ? messages.slice(-MAX_RENDER_MESSAGES) : messages; const renderMessages = hiddenCount > 0 ? messages.slice(-MAX_RENDER_MESSAGES) : messages;
if (loading) return <Loading />; if (loading) return <Loading />;
const isOpen = session?.status !== 'closed'; const isOpen = session?.status !== 'closed';
const doctorInitial = (session?.subject || '医').charAt(0); const doctorName = session?.doctor_name || '医生';
const statusLabel = session?.status === 'active' ? '进行中' const avatarChar = doctorName.charAt(0);
: session?.status === 'pending' ? '等待接诊' const isOnline = session?.status === 'active';
: '已结束';
return ( return (
<View className={`chat-page ${modeClass}`}> <View className={`chat-page ${modeClass}`}>
{/* 导航栏 — 对齐设计稿:返回 + 标题 + 副标题 */} {/* 导航栏 */}
<View className='chat-header'> <View className='chat-nav'>
<View className='chat-header__back' onClick={() => Taro.navigateBack()}> <View className='chat-nav__back' onClick={() => Taro.navigateBack()}>
<Text className='chat-header__back-text'> </Text> <Text className='chat-nav__back-icon'></Text>
</View> </View>
<View className='chat-header__center'> <View className='chat-nav__center'>
<Text className='chat-header__title'>{session?.subject || '在线咨询'}</Text> <Text className='chat-nav__title'>{doctorName}</Text>
<Text className={`chat-header__status ${isOpen ? '' : 'chat-header__status--closed'}`}> {isOnline ? (
{statusLabel} <View className='chat-nav__online'>
</Text> <View className='chat-nav__dot' />
<Text className='chat-nav__online-text'>线</Text>
</View>
) : (
<Text className='chat-nav__offline-text'>线</Text>
)}
</View>
<View className='chat-nav__more'>
<Text className='chat-nav__more-icon'>···</Text>
</View> </View>
</View> </View>
{/* 消息区域 */}
<ScrollView <ScrollView
scrollY scrollY
className='chat-messages' className='chat-body'
scrollIntoView={scrollViewRef.current} scrollIntoView={scrollViewRef.current}
scrollWithAnimation scrollWithAnimation
> >
{hiddenCount > 0 && ( {hiddenCount > 0 && (
<View className='msg-truncated-hint'> <View className='chat-date-pill'>
<Text className='msg-truncated-hint__text'> {hiddenCount} </Text> <Text className='chat-date-pill__text'> {hiddenCount} </Text>
</View> </View>
)} )}
{renderMessages.map((msg, idx) => { {renderMessages.map((msg, idx) => {
@@ -172,28 +174,27 @@ export default function ConsultationDetail() {
return ( return (
<View key={msg.id}> <View key={msg.id}>
{showDateDivider && ( {showDateDivider && (
<View className='msg-date-divider'> <View className='chat-date-pill'>
<Text className='msg-date-divider__text'>{getDateLabel(msg.created_at)}</Text> <Text className='chat-date-pill__text'>{getDateLabel(msg.created_at)}</Text>
</View> </View>
)} )}
<View id={`msg-${hiddenCount + idx + 1}`} className={`msg-row ${isSelf ? 'msg-row--self' : ''}`}> <View id={`msg-${hiddenCount + idx + 1}`} className={`chat-msg ${isSelf ? 'chat-msg--self' : 'chat-msg--doctor'}`}>
{!isSelf && ( {!isSelf && (
<View className='msg-avatar'> <View className='chat-msg__avatar'>
<Text className='msg-avatar-char'>{doctorInitial}</Text> <Text className='chat-msg__avatar-char'>{avatarChar}</Text>
</View> </View>
)} )}
<View className={`msg-bubble ${isSelf ? 'msg-bubble--self' : 'msg-bubble--other'}`}> <View className={`chat-msg__bubble ${isSelf ? 'chat-msg__bubble--self' : 'chat-msg__bubble--doctor'}`}>
{isImageUrl(msg.content) ? ( {isImageUrl(msg.content) ? (
<Image <Image
className='msg-image' className='chat-msg__image'
src={msg.content} src={msg.content}
mode='widthFix' mode='widthFix'
onClick={() => Taro.previewImage({ urls: [msg.content], current: msg.content })} onClick={() => Taro.previewImage({ urls: [msg.content], current: msg.content })}
/> />
) : ( ) : (
<Text className='msg-text'>{msg.content}</Text> <Text className='chat-msg__text'>{msg.content}</Text>
)} )}
<Text className='msg-time'>{formatTime(msg.created_at)}</Text>
</View> </View>
</View> </View>
</View> </View>
@@ -206,11 +207,16 @@ export default function ConsultationDetail() {
)} )}
</ScrollView> </ScrollView>
{/* 底部输入栏 */}
{isOpen ? ( {isOpen ? (
<View className='chat-input-bar'> <View className='chat-bar'>
<View className='chat-bar__add'>
<Text className='chat-bar__add-icon'>+</Text>
</View>
<Input <Input
className='chat-input' className='chat-bar__input'
placeholder='输入消息...' placeholder='输入消息...'
placeholderClass='chat-bar__placeholder'
value={inputText} value={inputText}
onInput={(e) => setInputText(e.detail.value)} onInput={(e) => setInputText(e.detail.value)}
confirmType='send' confirmType='send'
@@ -218,15 +224,15 @@ export default function ConsultationDetail() {
disabled={sending} disabled={sending}
/> />
<View <View
className={`chat-send-btn ${(!inputText.trim() || sending) ? 'chat-send-btn--disabled' : ''}`} className={`chat-bar__send ${(!inputText.trim() || sending) ? 'chat-bar__send--disabled' : ''}`}
onClick={handleSend} onClick={handleSend}
> >
<Text className='chat-send-btn__icon'></Text> <Text className='chat-bar__send-icon'></Text>
</View> </View>
</View> </View>
) : ( ) : (
<View className='chat-closed-bar'> <View className='chat-bar chat-bar--closed'>
<Text className='chat-closed-bar__text'></Text> <Text className='chat-bar__closed-text'></Text>
</View> </View>
)} )}
</View> </View>

View File

@@ -4,13 +4,18 @@ export interface ConsultationSession {
id: string; id: string;
patient_id: string; patient_id: string;
doctor_id: string | null; doctor_id: string | null;
patient_name?: string | null;
doctor_name?: string | null;
consultation_type: string; consultation_type: string;
status: string; status: string;
subject?: string | null; subject?: string | null;
last_message?: string | null; last_message?: string | null;
last_message_at: string | null; last_message_at: string | null;
unread_count_patient: number; unread_count_patient: number;
unread_count_doctor?: number;
created_at: string; created_at: string;
updated_at?: string;
version?: number;
} }
export interface ConsultationMessage { export interface ConsultationMessage {

View File

@@ -191,7 +191,7 @@ where
HealthState: FromRef<S>, HealthState: FromRef<S>,
S: Clone + Send + Sync + 'static, S: Clone + Send + Sync + 'static,
{ {
require_permission(&ctx, "health.consultation.manage")?; require_permission(&ctx, "health.consultation.list")?;
// 从 JWT 身份推导 sender_role不信任客户端输入 // 从 JWT 身份推导 sender_role不信任客户端输入
let is_doctor = crate::entity::doctor_profile::Entity::find() let is_doctor = crate::entity::doctor_profile::Entity::find()
.filter(crate::entity::doctor_profile::Column::UserId.eq(ctx.user_id)) .filter(crate::entity::doctor_profile::Column::UserId.eq(ctx.user_id))
@@ -262,7 +262,7 @@ where
HealthState: FromRef<S>, HealthState: FromRef<S>,
S: Clone + Send + Sync + 'static, S: Clone + Send + Sync + 'static,
{ {
require_permission(&ctx, "health.consultation.manage")?; require_permission(&ctx, "health.consultation.list")?;
let is_doctor = crate::entity::doctor_profile::Entity::find() let is_doctor = crate::entity::doctor_profile::Entity::find()
.filter(crate::entity::doctor_profile::Column::UserId.eq(ctx.user_id)) .filter(crate::entity::doctor_profile::Column::UserId.eq(ctx.user_id))
.filter(crate::entity::doctor_profile::Column::TenantId.eq(ctx.tenant_id)) .filter(crate::entity::doctor_profile::Column::TenantId.eq(ctx.tenant_id))