Files
wxapp_escort/pages/ai/aichat.wxml
T

171 lines
6.7 KiB
Plaintext

<view class="chat-container">
<!-- 未登录提示条:提前说明「能不能聊」,把登录入口放在这里,
用户不必等打完字被拦下来才知道要先登录 -->
<view class="login-notice" wx:if="{{authChecked && !isLoggedIn}}">
<text class="login-notice-text">尚未登录,暂时无法与 AI 客服对话</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
>
<!-- 欢迎区:空会话时的落点 -->
<view class="welcome-area" wx:if="{{messages.length === 0}}">
<view class="welcome-icon">
<image class="welcome-icon-img" src="/images/ai-ink.png" mode="aspectFit" />
</view>
<text class="welcome-title">陪诊助手</text>
<text class="welcome-desc">我是您的智能陪诊助手,可以为您解答陪诊相关问题</text>
<view class="question-list">
<view
class="quick-item"
wx:for="{{quickQuestions}}"
wx:key="id"
bindtap="onQuickQuestionTap"
data-question="{{item.text}}"
>
<text>{{item.text}}</text>
<t-icon name="chevron-right" size="26rpx" color="#9B4508" />
</view>
</view>
</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-1" size="36rpx" color="#9B4508" />
</view>
<text class="message-time">{{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">{{item.content}}</text>
<image
wx:if="{{item.contentType === 'image'}}"
class="message-image"
src="{{item.content}}"
mode="widthFix"
bindtap="previewImage"
data-src="{{item.content}}"
/>
</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}}"
>
<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 正在输入 -->
<view class="message-item ai" wx:if="{{isTyping}}">
<view class="message-head">
<view class="avatar">
<image class="avatar-img" src="/images/home-ink.png" mode="aspectFit" />
</view>
</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>
</view>
</view>
</view>
<!-- 底部留白,确保最新消息可见 -->
<view style="height: 40rpx;"></view>
</scroll-view>
<!-- 输入区 -->
<view class="input-area">
<input
class="message-input"
type="text"
value="{{inputValue}}"
placeholder="请输入您的问题..."
placeholder-class="input-placeholder"
confirm-type="send"
bindinput="onInputChange"
bindconfirm="sendMessage"
focus="{{inputFocus}}"
/>
<view class="action-btn send-btn {{inputValue ? 'active' : ''}}" bindtap="sendMessage"
aria-role="button" aria-label="发送消息" aria-disabled="{{!inputValue}}">
<t-icon name="send" size="40rpx" color="{{inputValue ? '#FFFFFF' : '#6F655C'}}" />
</view>
</view>
<!-- 辅助入口:紧贴输入区下方——拇指最容易够到的位置,操作方便。
两者都是低频动作,故做成只描边不填充的暖橙小按钮(圆角与输入框同为 20rpx),
与输入区右侧浅橙底的发送键区分开,不做成裸文字链。
「常见问题」在左、「清空聊天」在右:破坏性动作收在最右端 -->
<view class="tool-bar" wx:if="{{messages.length > 0}}">
<view class="tool-btn" bindtap="showQuickQuestions">
<t-icon name="help-circle" size="26rpx" color="#9B4508" />
<text class="tool-btn-text">常见问题</text>
</view>
<view class="tool-btn" bindtap="clearChat">
<t-icon name="delete" size="26rpx" color="#9B4508" />
<text class="tool-btn-text">清空聊天</text>
</view>
</view>
</view>