feat(ai): 对话页接入实时语音、图片识别与失败重试

- 聊天 WebSocket 提到 app 级,语音分片与对话共用连接,补齐心跳、重连与连接单飞
- 语音输入走 asr_start/asr_chunk/asr_stop,中间结果实时回填,链路异常退回整段转写
- 图片选完先上屏再 OCR,识别原文以 format 消息并入对话
- 失败状态挂在原提问上可点击重试,401 静默重登后原样重发
- 消息区改为暖白纸面与头像+时间布局,常见问题与清空收进更多菜单
This commit is contained in:
lik
2026-11-18 22:34:17 +08:00
parent 8e508d6934
commit 6da802cff9
9 changed files with 1931 additions and 717 deletions
+125 -375
View File
@@ -1,6 +1,25 @@
/* 与就诊人端 AI 页同源:暖白纸面、清晰左基线、克制的暖橙强调。
页面不滚动,唯一滚动容器是消息区;颜色令牌取自本项目 TDesign 主题色阶。 */
page {
background-color: #FAF6F1;
color: #2A211B;
--brand-strong: #C26A2E;
--brand-soft: #FCF3E9;
--brand-line: #EFCAA6;
--brand-ink: #A8551F;
--ink: #2A211B;
--ink-2: #4A4038;
--muted: #6F655C;
--line: #EAE1D6;
--paper: #FAF6F1;
--white: #FFFFFF;
--fs-24: 24rpx;
--fs-26: 26rpx;
--fs-28: 28rpx;
--fs-30: 30rpx;
--shadow-card: 0 2rpx 10rpx rgba(63, 43, 25, 0.07);
background-color: var(--paper);
color: var(--ink);
font-size: var(--fs-28);
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}
@@ -8,389 +27,120 @@ page {
display: flex;
flex-direction: column;
height: 100vh;
background-color: #FAF6F1;
}
.chat-header {
display: flex;
align-items: center;
justify-content: space-between;
height: 88rpx;
padding: 0 24rpx;
background-color: #ffffff;
border-bottom: 1rpx solid #EAE1D6;
flex-shrink: 0;
}
.chat-header-title {
font-size: 30rpx;
font-weight: 600;
color: #2A211B;
}
.message-list {
flex: 1;
padding: 20rpx;
padding-bottom: 200rpx;
box-sizing: border-box;
overflow: hidden;
background: var(--paper);
}
.quick-questions {
display: flex;
flex-direction: column;
align-items: center;
padding: 40rpx 20rpx;
}
.message-list { flex: 1; height: 0; min-height: 0; box-sizing: border-box; }
.welcome-area { padding: 32rpx 32rpx 24rpx; }
.welcome-title { display: block; color: var(--ink); font-size: 44rpx; font-weight: 600; line-height: 1.45; }
.question-heading { display: flex; justify-content: space-between; align-items: baseline; gap: 12rpx; margin: 32rpx 0 16rpx; color: var(--ink); font-size: var(--fs-28); font-weight: 500; }
.question-heading-sub { color: var(--muted); font-size: var(--fs-24); font-weight: 400; }
.question-list { display: flex; flex-direction: column; gap: 12rpx; width: 100%; box-sizing: border-box; }
.quick-item { display: flex; align-items: center; justify-content: space-between; gap: 16rpx; min-height: 96rpx; box-sizing: border-box; padding: 20rpx; border: 2rpx solid var(--line); border-radius: 20rpx; background: var(--white); color: var(--ink-2); font-size: var(--fs-28); line-height: 1.6; }
.quick-item > text { flex: 1; min-width: 0; word-break: break-all; }
.question-mark { display: flex; align-items: center; justify-content: center; flex-shrink: 0; width: 40rpx; height: 40rpx; border-radius: 12rpx; background: var(--paper); color: var(--brand-ink); font-size: var(--fs-26); }
.quick-item.question-hover, .quick-item:active { background: var(--brand-soft); border-color: var(--brand-line); }
.welcome-note { display: block; margin-top: 20rpx; color: var(--muted); font-size: var(--fs-24); line-height: 1.7; }
.welcome-text {
font-size: 32rpx;
color: #2A211B;
margin-bottom: 40rpx;
text-align: center;
font-weight: 500;
}
.quick-list {
display: flex;
flex-direction: column;
width: 100%;
gap: 20rpx;
}
.quick-item {
background-color: #ffffff;
border-radius: 24rpx;
padding: 24rpx 32rpx;
font-size: 28rpx;
color: #C26A2E;
box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.04);
text-align: center;
border: 1rpx solid #EAE1D6;
transition: all 0.2s ease;
}
.quick-item:active {
transform: scale(0.98);
background-color: rgba(194, 106, 46, 0.05);
}
.message-item {
display: flex;
flex-direction: column;
margin-bottom: 32rpx;
}
.message-item.ai {
align-items: flex-start;
}
.message-item.user {
align-items: flex-end;
}
.message-time {
font-size: 24rpx;
color: #A3988B;
margin-top: 8rpx;
padding: 0 4rpx;
}
.message-item.ai .message-time {
text-align: left;
align-self: flex-start;
}
.message-item.user .message-time {
text-align: right;
align-self: flex-end;
}
.avatar {
width: 64rpx;
height: 64rpx;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
flex-shrink: 0;
margin-bottom: 12rpx;
}
.user-avatar {
background: #C26A2E;
box-shadow: 0 4rpx 12rpx rgba(180, 85, 42, 0.25);
}
.ai-avatar {
background: #B4552A;
box-shadow: 0 4rpx 12rpx rgba(217, 134, 52, 0.25);
}
.avatar-text {
color: #fff;
font-size: 28rpx;
font-weight: 500;
}
.message-content {
display: flex;
flex-direction: column;
max-width: 95%;
}
.message-item.user .message-content {
align-items: flex-end;
}
.message-item.ai .message-content {
align-items: flex-start;
}
.message-bubble {
padding: 20rpx 24rpx;
border-radius: 16rpx;
font-size: 28rpx;
line-height: 1.6;
word-break: break-word;
max-width: 100%;
}
.user-bubble {
background: #C26A2E;
color: #fff;
border-bottom-right-radius: 4rpx;
box-shadow: 0 4rpx 12rpx rgba(180, 85, 42, 0.2);
margin-right: 4rpx;
}
.ai-bubble {
background-color: #ffffff;
color: #2A211B;
border-bottom-left-radius: 4rpx;
box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.04);
border: 1rpx solid #EAE1D6;
margin-left: 4rpx;
}
/* Markdown 渲染区域 */
/* 对话正文占据主要宽度,避免头像左右分栏挤压长回答和报告表格 */
.message-item { display: flex; flex-direction: column; padding: 20rpx 32rpx; }
.message-item.user { align-items: flex-end; }
.message-head { display: flex; align-items: center; gap: 10rpx; margin-bottom: 12rpx; }
.message-item.user .message-head { flex-direction: row-reverse; }
.avatar { display: flex; align-items: center; justify-content: center; flex-shrink: 0; width: 44rpx; height: 44rpx; border-radius: 14rpx; background: var(--white); border: 2rpx solid var(--line); }
.avatar-img { width: 30rpx; height: 30rpx; }
.message-item.user .avatar { background: transparent; border-color: transparent; }
.message-author { color: var(--ink-2); font-size: var(--fs-24); font-weight: 500; }
.message-time { color: var(--muted); font-size: var(--fs-24); margin: 0 6rpx; }
.message-content { display: flex; flex-direction: column; align-items: flex-start; min-width: 0; max-width: 100%; }
.message-item.ai .message-content { width: 100%; }
.message-item.user .message-content { align-items: flex-end; max-width: 90%; }
.message-bubble { box-sizing: border-box; min-width: 0; max-width: 100%; padding: 24rpx; border-radius: 24rpx; word-wrap: break-word; word-break: break-word; }
.message-item.ai .message-bubble { width: 100%; border: 2rpx solid var(--line); border-top-left-radius: 8rpx; background: var(--white); }
.message-item.user .message-bubble { border: 2rpx solid var(--brand-line); border-top-right-radius: 8rpx; background: var(--brand-soft); }
.message-text { font-size: var(--fs-30); line-height: 1.75; white-space: pre-wrap; color: var(--ink-2); word-break: break-word; }
.message-item.user .message-text { color: var(--brand-ink); }
.message-image { display: block; width: 400rpx; max-width: 100%; border-radius: 16rpx; }
.message-image-placeholder { font-size: var(--fs-28); color: var(--muted); line-height: 1.6; }
.message-note { margin-top: 10rpx; color: var(--muted); font-size: var(--fs-24); line-height: 1.6; }
.message-retry { display: flex; align-items: center; min-height: 88rpx; color: var(--brand-ink); font-size: var(--fs-26); }
.message-item.system { align-items: center; }
.system-message { max-width: 100%; padding: 8rpx 16rpx; color: var(--muted); font-size: var(--fs-26); line-height: 1.7; text-align: center; }
.message-markdown {
display: block;
width: 100%;
font-size: 28rpx;
color: #2A211B;
line-height: 1.6;
min-width: 0;
font-size: var(--fs-30);
line-height: 1.75;
color: var(--ink-2);
/* 组件内的色彩通过实际消费的 TDesign 变量传入,不依赖跨组件选择器 */
--td-text-color-primary: var(--ink-2);
--td-bg-color-component: var(--brand-soft);
--td-bg-color-page: var(--paper);
--td-bg-color-secondarycontainer: var(--paper);
--td-component-border: var(--line);
}
/* 表格样式覆盖(防止过宽) */
.message-markdown .t-chat-markdown-table {
width: 100%;
max-width: 100%;
overflow-x: auto;
-webkit-overflow-scrolling: touch;
border: 1rpx solid #EAE1D6;
border-radius: 8rpx;
}
.message-markdown .t-chat-markdown-table__container {
display: table;
min-width: 100%;
max-width: max-content;
border-collapse: collapse;
white-space: normal;
table-layout: fixed;
word-break: break-word;
}
.message-markdown .t-chat-markdown-table { max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; border: 2rpx solid var(--line); border-radius: 12rpx; }
.message-markdown .t-chat-markdown-table__container { display: table; min-width: 100%; border-collapse: collapse; }
.message-markdown .t-chat-markdown-table__container-th,
.message-markdown .t-chat-markdown-table__container-td { padding: 12rpx; font-size: var(--fs-26); line-height: 1.6; word-break: break-word; }
.message-markdown .t-chat-markdown-table__container-th { background: var(--brand-soft); color: var(--ink); }
.message-markdown .t-chat-markdown-table__container-tr:nth-child(2n) { background: var(--paper); }
/* 兼容表格子组件的另一套类名 */
.message-markdown .t-chat-markdown-table__th,
.message-markdown .t-chat-markdown-table__td {
padding: 8rpx 12rpx;
font-size: 26rpx;
line-height: 1.4;
white-space: normal;
word-break: break-word;
word-wrap: break-word;
overflow-wrap: break-word;
max-width: 320rpx;
}
.message-markdown .t-chat-markdown-table__td { padding: 12rpx; font-size: var(--fs-26); line-height: 1.6; white-space: normal; word-break: break-word; }
.message-markdown .t-chat-markdown-table__th { background: var(--brand-soft); color: var(--ink); }
.message-markdown .t-chat-markdown-table__tr:nth-child(2n) { background: var(--paper); }
.message-markdown .t-chat-markdown-code, .message-markdown .t-chat-markdown-codespan { font-size: var(--fs-26); word-break: break-all; }
.message-item.ai .typing-bubble { display: flex; align-items: center; width: auto; min-height: 88rpx; }
.typing-lines { display: flex; flex-direction: column; gap: 2rpx; }
.typing-text { font-size: var(--fs-26); color: var(--muted); line-height: 1.6; }
.typing-progress { font-size: 22rpx; color: var(--muted); line-height: 1.5; opacity: 0.85; }
.message-markdown .t-chat-markdown-table__th {
background-color: #FAF6F1;
font-weight: 600;
color: #2A211B;
}
/* 统一白色输入面板:文字在上,更多与发送在下,所有操作横向展开。
position: relative 供「更多」菜单定位(菜单从按钮上方展开) */
.composer { position: relative; flex-shrink: 0; margin: 12rpx 24rpx 8rpx; padding: 20rpx 20rpx 12rpx; border: 2rpx solid var(--line); border-radius: 28rpx; background: var(--white); box-shadow: var(--shadow-card); }
.input-area { padding: 0 4rpx; }
.message-input { display: block; box-sizing: border-box; width: 100%; min-height: 76rpx; max-height: 180rpx; padding: 4rpx 0 12rpx; color: var(--ink); font-size: var(--fs-30); line-height: 1.6; background: transparent; }
.message-input.is-readonly { color: var(--muted); }
.input-placeholder { color: var(--muted); font-size: var(--fs-28); }
.composer-actions { display: flex; align-items: center; justify-content: space-between; gap: 16rpx; }
.input-tools { display: flex; align-items: center; gap: 8rpx; }
.input-tool { display: flex; align-items: center; justify-content: center; gap: 8rpx; box-sizing: border-box; min-width: 104rpx; min-height: 88rpx; padding: 12rpx; border-radius: 16rpx; color: var(--muted); font-size: var(--fs-24); }
.input-tool.is-open { color: var(--brand-ink); background: var(--brand-soft); }
.input-tool.is-recording { color: var(--brand-ink); background: var(--brand-soft); }
.input-tool:active { background: var(--paper); }
/* 三个点用 CSS 画,不依赖图标名;与文字同一条基线 */
.more-dots { display: flex; align-items: center; justify-content: center; gap: 5rpx; width: 34rpx; height: 34rpx; }
.more-dot { width: 8rpx; height: 8rpx; border-radius: 50%; background: var(--muted); }
.input-tool.is-open .more-dot { background: var(--brand-ink); }
.send-btn { display: flex; align-items: center; justify-content: center; flex-shrink: 0; gap: 10rpx; box-sizing: border-box; min-width: 136rpx; min-height: 88rpx; padding: 16rpx 20rpx; border-radius: 20rpx; background: var(--paper); color: var(--muted); font-size: var(--fs-28); font-weight: 500; }
.send-btn.active { background: var(--brand-strong); color: var(--white); }
.send-btn.active:active { background: var(--brand-ink); }
.message-markdown .t-chat-markdown-table__tr:nth-child(2n) {
background-color: #FCFAF7;
}
/* ===== 「更多」菜单 =====
透明遮罩负责点外部关闭;菜单锚在输入面板上方左侧,向上展开 */
.more-mask { position: fixed; top: 0; right: 0; bottom: 0; left: 0; z-index: 120; background: transparent; }
.more-menu { position: absolute; left: 20rpx; bottom: calc(100% + 8rpx); z-index: 121; box-sizing: border-box; min-width: 320rpx; padding: 8rpx 0; border: 2rpx solid var(--line); border-radius: 20rpx; background: var(--white); box-shadow: var(--shadow-card); animation: more-menu-in 0.16s ease-out; }
@keyframes more-menu-in { from { opacity: 0; transform: translateY(8rpx); } to { opacity: 1; transform: translateY(0); } }
.more-item { display: flex; align-items: center; gap: 14rpx; box-sizing: border-box; min-height: 88rpx; padding: 0 24rpx; color: var(--ink-2); font-size: var(--fs-28); line-height: 1.4; }
.more-item:active { background: var(--brand-soft); }
.more-item-muted { color: var(--muted); }
.more-divider { height: 2rpx; margin: 0 20rpx; background: var(--line); }
/* 代码块样式覆盖 */
.message-markdown .t-chat-markdown-codespan,
.message-markdown .t-chat-markdown-code {
font-size: 26rpx;
word-break: break-all;
}
/* subagent 引用卡片(默认折叠) */
.subagent-header {
display: flex;
align-items: center;
justify-content: space-between;
padding: 4rpx 0;
}
.subagent-label {
font-size: 26rpx;
color: #6F655C;
}
.subagent-arrow {
font-size: 26rpx;
color: #A3988B;
transition: transform 0.2s ease;
}
.subagent-arrow.expanded {
transform: rotate(90deg);
}
.subagent-body {
margin-top: 12rpx;
padding-top: 12rpx;
border-top: 1rpx solid #EAE1D6;
}
.typing-indicator {
display: flex;
flex-direction: column;
align-items: flex-start;
margin-bottom: 32rpx;
}
.typing-bubble {
display: flex;
align-items: center;
gap: 12rpx;
background-color: #ffffff;
padding: 24rpx 32rpx;
border-radius: 16rpx;
border-bottom-left-radius: 4rpx;
box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.04);
border: 1rpx solid #EAE1D6;
}
.dot {
width: 16rpx;
height: 16rpx;
background-color: #A3988B;
border-radius: 50%;
animation: bounce 1.4s infinite ease-in-out both;
}
.dot:nth-child(1) {
animation-delay: -0.32s;
}
.dot:nth-child(2) {
animation-delay: -0.16s;
}
@keyframes bounce {
0%, 80%, 100% {
transform: scale(0.6);
}
40% {
transform: scale(1);
}
}
.input-area {
display: flex;
align-items: center;
padding: 20rpx 24rpx;
background-color: #ffffff;
gap: 16rpx;
box-sizing: border-box;
}
.chat-footer {
position: fixed;
left: 0;
right: 0;
bottom: 0;
z-index: 10;
background-color: #ffffff;
}
.chat-toolbar {
display: flex;
align-items: right;
justify-content: right;
padding: 12rpx 24rpx;
background-color: #FAF6F1;
border-top: 1rpx solid #EAE1D6;
border-bottom: 1rpx solid #EAE1D6;
}
.chat-toolbar-action {
display: flex;
align-items: right;
justify-content: right;
padding: 6rpx 24rpx;
border-radius: 24rpx;
background-color: #ffffff;
border: 1rpx solid #EAE1D6;
transition: all 0.2s ease;
}
.chat-toolbar-action:active {
transform: scale(0.96);
background-color: rgba(194, 106, 46, 0.08);
border-color: #C26A2E;
}
.chat-toolbar-action text {
font-size: 26rpx;
color: #6F655C;
}
.chat-input {
flex: 1;
height: 72rpx;
background-color: #FAF6F1;
border-radius: 36rpx;
padding: 0 28rpx;
font-size: 28rpx;
color: #2A211B;
border: 1rpx solid #EAE1D6;
}
.chat-input::placeholder {
color: #A3988B;
}
.send-btn {
width: 120rpx;
height: 72rpx;
background-color: #EAE1D6;
border-radius: 36rpx;
display: flex;
align-items: center;
justify-content: center;
transition: all 0.2s ease;
}
.send-btn.active {
background: #C26A2E;
box-shadow: 0 4rpx 12rpx rgba(180, 85, 42, 0.25);
}
.send-text {
color: #A3988B;
font-size: 28rpx;
font-weight: 500;
transition: color 0.2s ease;
}
.send-btn.active .send-text {
color: #FFFFFF;
/* 语音状态条:只在录音阶段显示,紧贴输入区上方 */
.voice-status { display: flex; align-items: center; flex-shrink: 0; gap: 16rpx; margin: 8rpx 24rpx 0; padding: 8rpx 16rpx; border: 2rpx solid var(--brand-line); border-radius: 20rpx; background: var(--brand-soft); }
.voice-dot { flex-shrink: 0; width: 12rpx; height: 12rpx; border-radius: 50%; background: var(--brand-strong); }
.voice-dot.recording { animation: record-pulse 1.2s infinite ease-in-out; }
.voice-status-main { display: flex; flex: 1; flex-direction: column; gap: 4rpx; min-width: 0; }
.voice-status-text { font-size: var(--fs-26); font-weight: 500; color: var(--ink-2); line-height: 1.5; }
.voice-status-sub { font-size: var(--fs-24); color: var(--muted); line-height: 1.5; }
.voice-cancel { display: flex; align-items: center; justify-content: center; flex-shrink: 0; gap: 8rpx; min-width: 88rpx; min-height: 88rpx; padding: 0 8rpx; color: var(--brand-ink); font-size: var(--fs-26); }
@keyframes record-pulse { 0%, 100% { opacity: 0.4; } 50% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .voice-dot.recording, .more-menu { animation: none; transition: none; } }
@media (max-width: 340px) {
.input-tool { min-width: 88rpx; padding: 8rpx; }
.composer-actions { gap: 8rpx; }
}