Files
wxapp_escort/pages/ai/aichat.wxml
T
lik 2ec0c2f486 feat(ai): AI 助手增加「更多」菜单并重排底部操作区
常见问题与清空聊天收进「更多」菜单,底部不再常驻两行低频操作;
页面禁止整页滚动、消息区独立滚动,欢迎区与输入面板按新版纸面/白面重构。
2026-11-16 19:30:54 +08:00

234 lines
10 KiB
Plaintext

<view class="chat-container">
<!-- 未登录提示条:提前说明「能不能聊」,把登录入口放在这里,
用户不必等打完字被拦下来才知道要先登录 -->
<view class="login-notice" wx:if="{{authChecked && !isLoggedIn}}">
<text class="login-notice-text">尚未登录,暂时无法与陪诊助手对话</text>
<text class="login-notice-link" bindtap="goLogin" aria-role="link">去登录</text>
</view>
<!-- 消息列表区域 -->
<scroll-view
class="message-list"
scroll-y
scroll-into-view="{{scrollToMessage}}"
enhanced
show-scrollbar="{{false}}"
>
<!-- 欢迎区:空会话时的落点 -->
<view class="welcome-area" wx:if="{{messages.length === 0}}">
<text class="welcome-title">陪诊服务咨询</text>
<view class="question-heading"><text>您可以这样问</text><text class="question-heading-sub">点选即发送</text></view>
<view class="question-list">
<view
class="quick-item"
wx:for="{{quickQuestions}}"
wx:key="id"
bindtap="onQuickQuestionTap"
data-question="{{item.text}}"
hover-class="question-hover"
aria-role="button"
aria-label="{{item.text}}"
>
<view class="question-mark" aria-hidden="true">?</view>
<text>{{item.text}}</text>
<t-icon name="chevron-right" size="26rpx" color="#9B4508" />
</view>
</view>
<text class="welcome-note">AI 助手不替代医生诊断,紧急情况请及时就医。</text>
</view>
<!-- 消息:头像在上、气泡在下,时间紧跟头像右侧;用户消息整条靠右 -->
<view
class="message-item {{item.type}}"
wx:for="{{messages}}"
wx:key="id"
id="msg-{{item.id}}"
>
<!-- 连接或服务错误是系统状态,不使用用户/AI 头像,也不带 AI 内容声明。
未登录提示额外带一个登录入口,避免只给一句「请先登录」的死胡同 -->
<view wx:if="{{item.type === 'system'}}" class="system-message">
<text>{{item.content}}</text>
<text
wx:if="{{item.contentType === 'login'}}"
class="system-login-link"
bindtap="goLogin"
aria-role="link"
>去登录</text>
</view>
<block wx:else>
<view class="message-head">
<!-- AI:品牌标记(暖墨线稿);底色与用户侧同构,身份只由图形区分 -->
<view wx:if="{{item.type === 'ai'}}" class="avatar">
<image class="avatar-img" src="/images/home-ink.png" mode="aspectFit" />
</view>
<!-- 用户:人像图标(暖陶土) -->
<view wx:else class="avatar">
<t-icon name="user" size="30rpx" color="#6F655C" />
</view>
<text class="message-author">{{item.type === 'ai' ? '暖橙助手' : '我'}}</text>
<!-- 时间只在与上一条相隔 ≥5 分钟时出现(首条必出现),
每条都挂时间会把对话读成日志;显隐由 stampMessageTimes 统一计算 -->
<text class="message-time" wx:if="{{item.showTime}}">{{item.time}}</text>
</view>
<view class="message-content">
<view class="message-bubble" wx:if="{{item.contentType !== 'questions'}}">
<t-chat-markdown
wx:if="{{item.type === 'ai' && item.contentType === 'text'}}"
class="message-markdown"
content="{{item.content}}"
/>
<text wx:elif="{{item.contentType === 'text'}}" class="message-text" user-select>{{item.content}}</text>
<image
wx:if="{{item.contentType === 'image' && item.content}}"
class="message-image"
src="{{item.content}}"
mode="widthFix"
bindtap="previewImage"
data-src="{{item.content}}"
/>
<!-- 历史里的图片不存临时路径(重启即失效),退化成一行占位 -->
<text wx:elif="{{item.contentType === 'image'}}" class="message-image-placeholder">[图片]</text>
</view>
<!-- 常见问题:由「常见问题」按钮触发,把问题清单直接铺进会话流里。
复用欢迎区的白卡 + chevron 语言,点一下即发送该问题 -->
<view wx:else class="question-list">
<view
class="quick-item"
wx:for="{{item.content}}"
wx:for-item="question"
wx:key="id"
bindtap="onQuickQuestionTap"
data-question="{{question.text}}"
hover-class="question-hover"
aria-role="button"
aria-label="{{question.text}}"
>
<text>{{question.text}}</text>
<t-icon name="chevron-right" size="26rpx" color="#9B4508" />
</view>
</view>
<!-- AI 声明:本地问题清单和系统错误均不展示。 -->
<text
wx:if="{{item.type === 'ai' && item.contentType !== 'questions'}}"
class="message-note"
>AI 生成,仅供参考,不替代医生诊断</text>
<text
wx:if="{{item.type === 'user' && item.status === 'failed'}}"
class="message-retry"
bindtap="onRetryMessage"
data-id="{{item.id}}"
>发送失败,点击重试</text>
</view>
</block>
</view>
<!-- AI 正在输入:图片/语音识别期间也用它作为 AI 回复区的默认等待态 -->
<view class="message-item ai" wx:if="{{isTyping}}" id="msg-typing">
<view class="message-head">
<view class="avatar">
<image class="avatar-img" src="/images/home-ink.png" mode="aspectFit" />
</view>
<text class="message-author">暖橙助手</text>
</view>
<view class="message-content">
<view class="message-bubble typing-bubble">
<view class="typing-indicator">
<view class="dot"></view>
<view class="dot"></view>
<view class="dot"></view>
</view>
<text class="typing-text">{{isRecognizing ? '正在识别,请稍候' : '正在为您整理'}}</text>
</view>
</view>
</view>
<!-- 底部留白,确保最新消息可见 -->
<view style="height: 40rpx;"></view>
</scroll-view>
<!-- 语音状态:只在录音阶段显示,紧贴输入区上方。
左侧展示计时与发送提示,右侧可随时取消;取消不会发送或识别本次录音。
识别/定稿阶段统一由 AI 回复区的等待气泡承载,与图片识别保持同一种反馈 -->
<view class="voice-status" wx:if="{{recording}}">
<view class="voice-dot recording"></view>
<view class="voice-status-main">
<text class="voice-status-text">正在录音 {{recordTime}}</text>
<text class="voice-status-sub">{{voiceRealtimeOff ? '结束后整段转写' : '点麦克风或发送键发出'}}</text>
</view>
<view
class="voice-cancel"
bindtap="onCancelVoiceTap"
aria-role="button"
aria-label="取消语音输入"
>
<t-icon name="close" size="24rpx" color="#9B4508" />
<text>取消</text>
</view>
</view>
<!-- 一个完整输入面板:上方文字,下方输入方式与发送;保留原录音发送逻辑。 -->
<view class="composer">
<view class="input-area">
<textarea
class="message-input {{recording || isRecognizing ? 'is-readonly' : ''}}"
value="{{inputValue}}"
placeholder="说说您的问题或需要…"
placeholder-class="input-placeholder"
auto-height
maxlength="-1"
cursor-spacing="24"
confirm-type="send"
disabled="{{recording || isRecognizing}}"
bindinput="onInputChange"
bindconfirm="sendMessage"
focus="{{inputFocus}}"
/>
</view>
<view class="composer-actions">
<view class="input-tools">
<view class="input-tool {{recording ? 'is-recording' : ''}}" bindtap="onMicTap" aria-role="button" aria-label="{{recording ? '结束并发送语音' : '语音输入'}}">
<t-icon name="microphone" size="34rpx" color="{{recording ? '#9B4508' : '#6F655C'}}" />
<text>{{recording ? '结束' : '语音'}}</text>
</view>
<view class="input-tool" bindtap="onImageTap" aria-role="button" aria-label="拍照或选择图片">
<t-icon name="image" size="34rpx" color="#6F655C" />
<text>图片</text>
</view>
<!-- 更多:常见问题与清空聊天收进同一入口,输入区不再为低频动作单占一行 -->
<view class="input-tool {{showMoreMenu ? 'is-open' : ''}}" bindtap="toggleMoreMenu" aria-role="button" aria-label="更多功能" aria-expanded="{{showMoreMenu}}">
<view class="more-dots" aria-hidden="true">
<view class="more-dot"></view>
<view class="more-dot"></view>
<view class="more-dot"></view>
</view>
<text>更多</text>
</view>
</view>
<view
class="send-btn {{inputValue && !isRecognizing ? 'active' : ''}}"
bindtap="sendMessage"
aria-role="button"
aria-label="发送消息"
aria-disabled="{{!inputValue || isRecognizing}}"
>
<text>发送</text>
<t-icon name="chevron-right" size="30rpx" color="{{inputValue && !isRecognizing ? '#FFFFFF' : '#6F655C'}}" />
</view>
</view>
<!-- 更多菜单:向上展开,点遮罩关闭;清空仅在已有记录时出现,仍走原有二次确认 -->
<view class="more-mask" wx:if="{{showMoreMenu}}" bindtap="onCloseMoreMenu" aria-hidden="true"></view>
<view class="more-menu" wx:if="{{showMoreMenu}}" aria-role="menu">
<view class="more-item" bindtap="onMoreQuickQuestions" aria-role="menuitem">
<t-icon name="help-circle" size="30rpx" color="#6F655C" />
<text class="more-item-text">常见问题</text>
</view>
<view class="more-divider" wx:if="{{messages.length}}"></view>
<view class="more-item more-item-muted" wx:if="{{messages.length}}" bindtap="onMoreClearChat" aria-role="menuitem">
<t-icon name="delete" size="30rpx" color="#6F655C" />
<text class="more-item-text">清空聊天记录</text>
</view>
</view>
</view>
</view>