chat.vue 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858
  1. <template>
  2. <view class="chat-container">
  3. <!-- 导航栏 -->
  4. <view class="chat-nav" :class="'mascot-' + mascotCode">
  5. <view class="nav-back" @click="goBack">
  6. <text class="nav-back-icon">‹</text>
  7. </view>
  8. <text class="nav-title">{{ isNutrition ? '精准营养助手' : (isHealthCoach ? 'AI 健康管家' : 'AI 家庭助手') }}</text>
  9. <view class="nav-actions">
  10. <view class="mascot-badge" v-if="mascotCode && !isNutrition" @click="showConversations = !showConversations">
  11. <text class="mascot-badge-icon">{{ mascotIcon }}</text>
  12. <text class="mascot-badge-name">{{ mascotName }}</text>
  13. </view>
  14. <text class="nav-action" @click="showConversations = !showConversations" v-else>☰</text>
  15. </view>
  16. </view>
  17. <!-- 会话列表(侧拉) -->
  18. <view class="conv-overlay" v-if="showConversations" @click="showConversations = false"></view>
  19. <view class="conv-sidebar" :class="{ 'conv-sidebar-open': showConversations }">
  20. <view class="conv-header">
  21. <text class="conv-header-title">会话列表</text>
  22. <text class="conv-header-new" @click="newConversation">+ 新会话</text>
  23. </view>
  24. <scroll-view class="conv-list" scroll-y>
  25. <view class="conv-item" v-for="conv in conversations" :key="conv.id"
  26. :class="{ 'conv-item-active': conv.id === currentConversationId }"
  27. @click="switchConversation(conv.id)">
  28. <text class="conv-item-name">{{ conv.name || '新会话' }}</text>
  29. <text class="conv-item-time">{{ formatTime(conv.updated_at) }}</text>
  30. </view>
  31. <BaseEmpty v-if="conversations.length === 0" text="暂无会话" icon="💬" />
  32. </scroll-view>
  33. </view>
  34. <!-- 消息列表 -->
  35. <scroll-view class="message-list" scroll-y :scroll-into-view="scrollToId" scroll-with-animation
  36. @scrolltoupper="loadMoreMessages" id="messageList">
  37. <view class="message-list-inner">
  38. <view class="welcome-card" v-if="messages.length === 0 && !sending">
  39. <view class="welcome-icon">{{ mascotIcon || (isNutrition ? '🥗' : (isHealthCoach ? '🏥' : '🤖')) }}</view>
  40. <text class="welcome-title">{{ isNutrition ? '你好!我是精准营养助手' : (isHealthCoach ? '你好!我是AI健康管家' : ('你好!我是' + (mascotName || '家庭助手'))) }}</text>
  41. <text class="welcome-desc">{{ welcomeSubtitle }}</text>
  42. <view class="welcome-suggestions">
  43. <view class="welcome-suggestion" v-if="!isNutrition && !isHealthCoach" @click="quickQuestion('小明最近任务完成怎么样?')">
  44. <text class="suggestion-icon">📋</text>
  45. <text class="suggestion-text">小明最近任务完成怎么样?</text>
  46. </view>
  47. <view class="welcome-suggestion" v-if="!isNutrition && !isHealthCoach" @click="quickQuestion('我家孩子的能量评分怎么样?')">
  48. <text class="suggestion-icon">⚡</text>
  49. <text class="suggestion-text">孩子的能量评分怎么样?</text>
  50. </view>
  51. <view class="welcome-suggestion" v-if="!isNutrition && !isHealthCoach" @click="quickQuestion('今天有什么需要我做的事情?')">
  52. <text class="suggestion-icon">✅</text>
  53. <text class="suggestion-text">今天有什么需要我做的事情?</text>
  54. </view>
  55. <view class="welcome-suggestion" v-if="isNutrition" @click="quickQuestion('根据报告,我的孩子需要补充哪些营养?')">
  56. <text class="suggestion-icon">🥦</text>
  57. <text class="suggestion-text">根据报告,我的孩子需要补充哪些营养?</text>
  58. </view>
  59. <view class="welcome-suggestion" v-if="isNutrition" @click="quickQuestion('有哪些食物或产品推荐?')">
  60. <text class="suggestion-icon">🛒</text>
  61. <text class="suggestion-text">有哪些食物或产品推荐?</text>
  62. </view>
  63. <view class="welcome-suggestion" v-if="isHealthCoach" @click="quickQuestion('我家孩子挑食怎么办?')">
  64. <text class="suggestion-icon">🍽️</text>
  65. <text class="suggestion-text">我家孩子挑食怎么办?</text>
  66. </view>
  67. <view class="welcome-suggestion" v-if="isHealthCoach" @click="quickQuestion('孩子最近总感冒,怎么调养?')">
  68. <text class="suggestion-icon">🤧</text>
  69. <text class="suggestion-text">孩子最近总感冒,怎么调养?</text>
  70. </view>
  71. <view class="welcome-suggestion" v-if="isHealthCoach" @click="quickQuestion('什么样的体质?如何调理?')">
  72. <text class="suggestion-icon">🔍</text>
  73. <text class="suggestion-text">什么样的体质?如何调理?</text>
  74. </view>
  75. </view>
  76. </view>
  77. <view class="message-group" v-for="(msg, idx) in messages" :key="msg.id">
  78. <!-- 用户消息 -->
  79. <view class="message message-user" v-if="msg.query">
  80. <view class="message-bubble user-bubble">{{ msg.query }}</view>
  81. </view>
  82. <!-- AI 回复 -->
  83. <view class="message message-ai" v-if="msg.answer">
  84. <view class="message-avatar">{{ isHealthCoach ? '🏥' : (mascotIcon || '🤖') }}</view>
  85. <view class="message-bubble ai-bubble">
  86. <text class="ai-answer-text">{{ msg.answer }}</text>
  87. <!-- 推荐卡片 -->
  88. <view class="rec-list" v-if="msg.recommendations && msg.recommendations.length > 0">
  89. <view class="rec-card" v-for="(rec, ri) in msg.recommendations" :key="ri" @click="gotoRec(rec)">
  90. <image class="rec-cover" v-if="rec.coverImage" :src="rec.coverImage" mode="aspectFill" />
  91. <view class="rec-info">
  92. <text class="rec-type-tag">{{ rec.type === 'product' ? '商品' : rec.type === 'activity' ? '活动' : '文章' }}</text>
  93. <text class="rec-name">{{ rec.name }}</text>
  94. <text class="rec-desc">{{ rec.description }}</text>
  95. <text class="rec-price" v-if="rec.price">¥{{ rec.price }}</text>
  96. </view>
  97. </view>
  98. </view>
  99. <!-- AI 任务卡片 -->
  100. <view class="task-list" v-if="msg.tasks && msg.tasks.length > 0">
  101. <AITaskCard v-for="(task, ti) in msg.tasks" :key="ti" :task="task" :conversationId="currentConversationId" @accepted="onTaskAccepted" />
  102. </view>
  103. <!-- 报告来源标识 -->
  104. <view class="source-label" v-if="msg.sourceReport">
  105. 来源:{{ msg.sourceReport.type === 'nutrition' ? '营养报告' : '测评报告' }} #{{ msg.sourceReport.id }}
  106. </view>
  107. </view>
  108. </view>
  109. </view>
  110. <!-- 加载中 -->
  111. <view class="message message-ai" v-if="sending">
  112. <view class="message-avatar">{{ mascotIcon || '🤖' }}</view>
  113. <view class="message-bubble ai-bubble typing">
  114. <text class="typing-dot">.</text>
  115. <text class="typing-dot">.</text>
  116. <text class="typing-dot">.</text>
  117. </view>
  118. </view>
  119. <view id="scrollBottom"></view>
  120. </view>
  121. </scroll-view>
  122. <!-- 输入区 -->
  123. <view class="chat-input-area">
  124. <view class="chat-input-wrap">
  125. <input class="chat-input" v-model="inputText" placeholder="问我关于家庭和孩子的问题..."
  126. :disabled="sending" @confirm="sendMessage" confirm-type="send" />
  127. </view>
  128. <view class="chat-send-btn" :class="{ 'chat-send-active': inputText.trim() }"
  129. @click="sendMessage">
  130. <text class="send-icon">➤</text>
  131. </view>
  132. </view>
  133. </view>
  134. </template>
  135. <script>
  136. import { aiSendMessage, aiGetConversations, aiGetMessages, aiDeleteConversation, aiSendNutritionMessage, aiSendHealthCoachMessage } from '../../utils/api.js'
  137. import BaseEmpty from '../../components/BaseEmpty.vue'
  138. import AITaskCard from '../../components/AITaskCard.vue'
  139. export default {
  140. components: { BaseEmpty, AITaskCard },
  141. data() {
  142. return {
  143. inputText: '',
  144. messages: [],
  145. conversations: [],
  146. currentConversationId: '',
  147. sending: false,
  148. showConversations: false,
  149. scrollToId: '',
  150. pageLoaded: false,
  151. pendingFirstMessage: '',
  152. fromPage: '',
  153. mode: '',
  154. reportId: '',
  155. recommendations: [],
  156. mascotCode: '',
  157. mascotName: '',
  158. mascotIcon: ''
  159. }
  160. },
  161. computed: {
  162. isNutrition: function() {
  163. return this.mode === 'nutrition'
  164. },
  165. isHealthCoach: function() {
  166. return this.mode === 'health'
  167. },
  168. welcomeSubtitle: function() {
  169. if (this.isNutrition) {
  170. return '我可以基于菌群检测报告,为你提供个性化的营养建议和推荐'
  171. }
  172. if (this.isHealthCoach) {
  173. return '专注儿童健康咨询:体质调理、营养喂养、科学保健'
  174. }
  175. if (this.fromPage) {
  176. var pageNames = {
  177. 'pages/body/index': '身',
  178. 'pages/wisdom/index': '智',
  179. 'pages/mind/index': '心',
  180. 'pages/index/index': '首页',
  181. 'pages/index/parent-index': '首页',
  182. 'pages/index/child-index': '首页',
  183. 'pages/profile/profile': '我的',
  184. 'pages/profile/children': '我的',
  185. 'pages/shop/index': '商城',
  186. 'pages/discover/index': '发现'
  187. }
  188. var pageName = pageNames[this.fromPage] || this.fromPage
  189. return '从 ' + pageName + ' 发起,我可以帮你了解:'
  190. }
  191. return '我可以帮你了解孩子的成长情况,比如:'
  192. }
  193. },
  194. onLoad: function(options) {
  195. this.mode = options.mode || ''
  196. this.fromPage = options.fromPage ? decodeURIComponent(options.fromPage) : ''
  197. this.reportId = options.reportId || ''
  198. if (options.firstMessage) {
  199. this.pendingFirstMessage = decodeURIComponent(options.firstMessage)
  200. }
  201. // 加载用户mascot设置
  202. var userInfo = uni.getStorageSync('userInfo')
  203. if (userInfo) {
  204. if (userInfo.mascot === 'xibao') {
  205. this.mascotCode = 'xibao'
  206. this.mascotName = '浠宝'
  207. this.mascotIcon = '🌟'
  208. } else if (userInfo.mascot === 'fubao') {
  209. this.mascotCode = 'fubao'
  210. this.mascotName = '福宝'
  211. this.mascotIcon = '💪'
  212. }
  213. }
  214. this.loadConversations()
  215. // 如果有预填消息,自动发送
  216. var self = this
  217. if (this.pendingFirstMessage) {
  218. this.$nextTick(function() {
  219. self.inputText = self.pendingFirstMessage
  220. self.pendingFirstMessage = ''
  221. self.sendMessage()
  222. })
  223. }
  224. },
  225. onShow() {
  226. if (this.pageLoaded) {
  227. this.loadConversations()
  228. }
  229. this.pageLoaded = true
  230. },
  231. methods: {
  232. goBack() {
  233. uni.navigateBack()
  234. },
  235. onTaskAccepted() {
  236. this.loadConversations()
  237. },
  238. async loadConversations() {
  239. try {
  240. const res = await aiGetConversations()
  241. this.conversations = res.data || []
  242. } catch (e) {
  243. console.log('加载会话列表失败', e)
  244. }
  245. },
  246. async switchConversation(convId) {
  247. this.currentConversationId = convId
  248. this.showConversations = false
  249. this.messages = []
  250. this.$nextTick(() => {
  251. this.scrollToBottom()
  252. })
  253. try {
  254. const res = await aiGetMessages({ conversationId: convId })
  255. this.messages = res.data || []
  256. this.$nextTick(() => {
  257. this.scrollToBottom()
  258. })
  259. } catch (e) {
  260. console.log('加载消息失败', e)
  261. }
  262. },
  263. newConversation() {
  264. this.currentConversationId = ''
  265. this.showConversations = false
  266. this.messages = []
  267. this.inputText = ''
  268. this.$nextTick(() => {
  269. this.scrollToBottom()
  270. })
  271. },
  272. async sendMessage() {
  273. const text = this.inputText.trim()
  274. if (!text || this.sending) return
  275. // 立即显示用户消息
  276. const tempMsg = { id: 'temp_' + Date.now(), query: text, answer: '' }
  277. this.messages.push(tempMsg)
  278. this.inputText = ''
  279. this.sending = true
  280. this.$nextTick(() => {
  281. this.scrollToBottom()
  282. })
  283. try {
  284. var params = {
  285. query: text,
  286. conversationId: this.currentConversationId
  287. }
  288. if (this.reportId) {
  289. params.reportId = this.reportId
  290. }
  291. var res, data
  292. if (this.mode === 'nutrition') {
  293. res = await aiSendNutritionMessage(params)
  294. data = res.data || {}
  295. const lastMsg = this.messages[this.messages.length - 1]
  296. if (lastMsg) {
  297. lastMsg.answer = data.answer || ''
  298. lastMsg.recommendations = data.recommendations || []
  299. lastMsg.tasks = data.tasks || []
  300. if (this.reportId) {
  301. lastMsg.sourceReport = { id: this.reportId, type: 'nutrition' }
  302. }
  303. }
  304. } else if (this.mode === 'health') {
  305. res = await aiSendHealthButlerMessage(params)
  306. data = res.data || {}
  307. const lastMsg = this.messages[this.messages.length - 1]
  308. if (lastMsg) {
  309. lastMsg.answer = data.answer || ''
  310. lastMsg.recommendations = data.recommendations || []
  311. lastMsg.tasks = data.tasks || []
  312. }
  313. } else {
  314. res = await aiSendMessage(params)
  315. data = res.data || {}
  316. const lastMsg = this.messages[this.messages.length - 1]
  317. if (lastMsg) {
  318. lastMsg.answer = data.answer || ''
  319. lastMsg.recommendations = data.recommendations || []
  320. lastMsg.tasks = data.tasks || []
  321. if (this.reportId) {
  322. lastMsg.sourceReport = { id: this.reportId, type: 'assessment' }
  323. }
  324. }
  325. }
  326. // 更新 conversationId(新建会话时 Dify 返回)
  327. if (data.conversationId && !this.currentConversationId) {
  328. this.currentConversationId = data.conversationId
  329. // 刷新会话列表
  330. this.loadConversations()
  331. }
  332. } catch (e) {
  333. // 显示错误
  334. const lastMsg = this.messages[this.messages.length - 1]
  335. if (lastMsg) {
  336. lastMsg.answer = '抱歉,我暂时无法回答,请稍后再试。'
  337. }
  338. } finally {
  339. this.sending = false
  340. this.$nextTick(() => {
  341. this.scrollToBottom()
  342. })
  343. }
  344. },
  345. quickQuestion(text) {
  346. this.inputText = text
  347. this.sendMessage()
  348. },
  349. gotoRec(rec) {
  350. if (rec.url) {
  351. uni.navigateTo({ url: rec.url })
  352. }
  353. },
  354. loadMoreMessages() {
  355. // 分页加载历史(当前简化)
  356. },
  357. scrollToBottom() {
  358. this.scrollToId = 'scrollBottom'
  359. },
  360. formatTime(timestamp) {
  361. if (!timestamp) return ''
  362. const d = new Date(timestamp * 1000)
  363. const now = new Date()
  364. const diff = now - d
  365. if (diff < 86400000) {
  366. return d.getHours().toString().padStart(2, '0') + ':' + d.getMinutes().toString().padStart(2, '0')
  367. }
  368. return (d.getMonth() + 1) + '/' + d.getDate()
  369. }
  370. }
  371. }
  372. </script>
  373. <style scoped>
  374. .chat-container {
  375. display: flex;
  376. flex-direction: column;
  377. height: 100vh;
  378. background: var(--bg, #FFF7ED);
  379. position: relative;
  380. }
  381. /* 导航栏 */
  382. .chat-nav {
  383. display: flex;
  384. align-items: center;
  385. justify-content: space-between;
  386. padding: 88rpx 24rpx 16rpx;
  387. background: #fff;
  388. border-bottom: 1rpx solid var(--border-light, #E2E8F0);
  389. position: relative;
  390. z-index: 100;
  391. }
  392. .chat-nav.mascot-xibao {
  393. background: linear-gradient(135deg, #FFF7ED 0%, #FFE4CC 100%);
  394. border-bottom-color: #FF8C42;
  395. }
  396. .chat-nav.mascot-xibao .nav-title {
  397. color: #D97706;
  398. }
  399. .chat-nav.mascot-fubao {
  400. background: linear-gradient(135deg, #FFFBEB 0%, #FEF3C7 100%);
  401. border-bottom-color: #F59E0B;
  402. }
  403. .chat-nav.mascot-fubao .nav-title {
  404. color: #B45309;
  405. }
  406. .nav-back {
  407. width: 60rpx;
  408. height: 60rpx;
  409. display: flex;
  410. align-items: center;
  411. justify-content: center;
  412. }
  413. .nav-back-icon {
  414. font-size: 40rpx;
  415. color: var(--text, #1E293B);
  416. font-weight: 600;
  417. }
  418. .nav-title {
  419. font-size: 32rpx;
  420. font-weight: 600;
  421. color: var(--text, #1E293B);
  422. }
  423. .nav-actions {
  424. width: 60rpx;
  425. height: 60rpx;
  426. display: flex;
  427. align-items: center;
  428. justify-content: center;
  429. }
  430. .nav-action {
  431. font-size: 36rpx;
  432. color: var(--text-secondary, #64748B);
  433. }
  434. /* 会话列表侧拉 */
  435. .conv-overlay {
  436. position: fixed;
  437. top: 0;
  438. left: 0;
  439. right: 0;
  440. bottom: 0;
  441. background: rgba(0,0,0,0.3);
  442. z-index: 200;
  443. }
  444. .conv-sidebar {
  445. position: fixed;
  446. top: 0;
  447. right: -500rpx;
  448. width: 460rpx;
  449. height: 100vh;
  450. background: #fff;
  451. z-index: 210;
  452. transition: right 0.3s ease;
  453. display: flex;
  454. flex-direction: column;
  455. }
  456. .conv-sidebar-open {
  457. right: 0;
  458. }
  459. .conv-header {
  460. display: flex;
  461. justify-content: space-between;
  462. align-items: center;
  463. padding: 100rpx 24rpx 16rpx;
  464. border-bottom: 1rpx solid var(--border-light, #E2E8F0);
  465. }
  466. .conv-header-title {
  467. font-size: 28rpx;
  468. font-weight: 600;
  469. color: var(--text, #1E293B);
  470. }
  471. .conv-header-new {
  472. font-size: 24rpx;
  473. color: var(--color-primary, #5B9BD5);
  474. font-weight: 500;
  475. }
  476. .conv-list {
  477. flex: 1;
  478. overflow-y: auto;
  479. }
  480. .conv-item {
  481. padding: 20rpx 24rpx;
  482. border-bottom: 1rpx solid var(--border-light, #E2E8F0);
  483. }
  484. .conv-item-active {
  485. background: rgba(91, 155, 213, 0.06);
  486. }
  487. .conv-item-name {
  488. font-size: 26rpx;
  489. color: var(--text, #1E293B);
  490. display: block;
  491. margin-bottom: 6rpx;
  492. overflow: hidden;
  493. text-overflow: ellipsis;
  494. white-space: nowrap;
  495. }
  496. .conv-item-time {
  497. font-size: 20rpx;
  498. color: var(--muted, #94A3B8);
  499. }
  500. /* 消息列表 */
  501. .message-list {
  502. flex: 1;
  503. overflow-y: auto;
  504. padding: 20rpx 24rpx;
  505. }
  506. .message-list-inner {
  507. min-height: 100%;
  508. }
  509. /* 欢迎卡片 */
  510. .welcome-card {
  511. text-align: center;
  512. padding: 60rpx 20rpx 40rpx;
  513. }
  514. .welcome-icon {
  515. font-size: 80rpx;
  516. margin-bottom: 20rpx;
  517. transition: transform 0.3s;
  518. }
  519. .mascot-xibao .welcome-icon {
  520. animation: welcomeFloat 3s ease-in-out infinite;
  521. }
  522. .mascot-fubao .welcome-icon {
  523. animation: welcomeFloat 3s ease-in-out infinite 0.5s;
  524. }
  525. @keyframes welcomeFloat {
  526. 0%, 100% { transform: translateY(0); }
  527. 50% { transform: translateY(-10rpx); }
  528. }
  529. .welcome-title {
  530. font-size: 32rpx;
  531. font-weight: 600;
  532. color: var(--text, #1E293B);
  533. display: block;
  534. margin-bottom: 12rpx;
  535. }
  536. .welcome-desc {
  537. font-size: 24rpx;
  538. color: var(--text-secondary, #64748B);
  539. display: block;
  540. margin-bottom: 32rpx;
  541. }
  542. .welcome-suggestions {
  543. display: flex;
  544. flex-direction: column;
  545. gap: 16rpx;
  546. padding: 0 20rpx;
  547. }
  548. .welcome-suggestion {
  549. display: flex;
  550. align-items: center;
  551. background: #fff;
  552. padding: 20rpx 24rpx;
  553. border-radius: 16rpx;
  554. box-shadow: 0 2rpx 8rpx rgba(0,0,0,0.04);
  555. }
  556. .suggestion-icon {
  557. font-size: 28rpx;
  558. margin-right: 12rpx;
  559. }
  560. .suggestion-text {
  561. font-size: 24rpx;
  562. color: var(--text, #1E293B);
  563. }
  564. /* 消息 */
  565. .message {
  566. margin-bottom: 24rpx;
  567. }
  568. .message-user {
  569. display: flex;
  570. justify-content: flex-end;
  571. }
  572. .message-ai {
  573. display: flex;
  574. align-items: flex-start;
  575. }
  576. .message-avatar {
  577. width: 56rpx;
  578. height: 56rpx;
  579. font-size: 36rpx;
  580. margin-right: 12rpx;
  581. flex-shrink: 0;
  582. display: flex;
  583. align-items: center;
  584. justify-content: center;
  585. border-radius: 50%;
  586. transition: transform 0.2s;
  587. }
  588. .mascot-xibao .message-avatar {
  589. background: linear-gradient(135deg, #FFF7ED 0%, #FFE4CC 100%);
  590. border: 2rpx solid #FF8C42;
  591. }
  592. .mascot-fubao .message-avatar {
  593. background: linear-gradient(135deg, #FFFBEB 0%, #FEF3C7 100%);
  594. border: 2rpx solid #F59E0B;
  595. }
  596. .message-bubble {
  597. max-width: 70%;
  598. padding: 16rpx 20rpx;
  599. font-size: 26rpx;
  600. line-height: 1.6;
  601. border-radius: 16rpx;
  602. word-break: break-word;
  603. }
  604. .user-bubble {
  605. background: var(--color-primary, #5B9BD5);
  606. color: #fff;
  607. border-bottom-right-radius: 4rpx;
  608. }
  609. .ai-bubble {
  610. background: #fff;
  611. color: var(--text, #1E293B);
  612. border-bottom-left-radius: 4rpx;
  613. box-shadow: 0 2rpx 8rpx rgba(0,0,0,0.04);
  614. }
  615. /* 输入区 */
  616. .chat-input-area {
  617. display: flex;
  618. align-items: center;
  619. padding: 16rpx 24rpx;
  620. padding-bottom: calc(16rpx + env(safe-area-inset-bottom));
  621. background: #fff;
  622. border-top: 1rpx solid var(--border-light, #E2E8F0);
  623. }
  624. .chat-input-wrap {
  625. flex: 1;
  626. background: var(--bg, #FFF7ED);
  627. border-radius: 40rpx;
  628. padding: 0 24rpx;
  629. margin-right: 16rpx;
  630. }
  631. .chat-input {
  632. height: 72rpx;
  633. font-size: 26rpx;
  634. color: var(--text, #1E293B);
  635. }
  636. .chat-send-btn {
  637. width: 72rpx;
  638. height: 72rpx;
  639. border-radius: 50%;
  640. background: var(--border-light, #E2E8F0);
  641. display: flex;
  642. align-items: center;
  643. justify-content: center;
  644. flex-shrink: 0;
  645. }
  646. .chat-send-active {
  647. background: var(--color-primary, #5B9BD5);
  648. }
  649. .send-icon {
  650. font-size: 28rpx;
  651. color: #fff;
  652. }
  653. /* 打字动画 */
  654. .typing {
  655. display: flex;
  656. align-items: center;
  657. gap: 4rpx;
  658. min-height: 40rpx;
  659. }
  660. .typing-dot {
  661. font-size: 40rpx;
  662. line-height: 1;
  663. animation: typingBounce 1.4s infinite;
  664. }
  665. .typing-dot:nth-child(2) {
  666. animation-delay: 0.2s;
  667. }
  668. .typing-dot:nth-child(3) {
  669. animation-delay: 0.4s;
  670. }
  671. @keyframes typingBounce {
  672. 0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
  673. 30% { opacity: 1; transform: translateY(-8rpx); }
  674. }
  675. /* 推荐卡片 */
  676. .ai-answer-text {
  677. display: block;
  678. margin-bottom: 16rpx;
  679. line-height: 1.7;
  680. }
  681. .rec-list {
  682. border-top: 1rpx solid var(--border-light, #E2E8F0);
  683. padding-top: 16rpx;
  684. display: flex;
  685. flex-direction: column;
  686. gap: 12rpx;
  687. }
  688. /* 任务卡片列表 */
  689. .task-list {
  690. border-top: 1rpx solid var(--border-light, #E2E8F0);
  691. padding-top: 16rpx;
  692. display: flex;
  693. flex-direction: column;
  694. gap: 12rpx;
  695. }
  696. /* 报告来源标识 */
  697. .source-label {
  698. margin-top: 16rpx;
  699. font-size: 22rpx;
  700. color: var(--muted, #94A3B8);
  701. text-align: right;
  702. }
  703. .rec-card {
  704. display: flex;
  705. flex-direction: row;
  706. background: var(--bg, #FFF7ED);
  707. border-radius: 12rpx;
  708. overflow: hidden;
  709. padding: 12rpx;
  710. }
  711. .rec-cover {
  712. width: 120rpx;
  713. height: 120rpx;
  714. border-radius: 8rpx;
  715. margin-right: 12rpx;
  716. flex-shrink: 0;
  717. background: #E2E8F0;
  718. }
  719. .rec-info {
  720. flex: 1;
  721. display: flex;
  722. flex-direction: column;
  723. gap: 4rpx;
  724. min-width: 0;
  725. }
  726. .rec-type-tag {
  727. display: inline-block;
  728. font-size: 18rpx;
  729. color: var(--color-primary, #5B9BD5);
  730. background: rgba(91, 155, 213, 0.1);
  731. padding: 2rpx 12rpx;
  732. border-radius: 8rpx;
  733. align-self: flex-start;
  734. }
  735. .rec-name {
  736. font-size: 26rpx;
  737. font-weight: 600;
  738. color: var(--text, #1E293B);
  739. overflow: hidden;
  740. text-overflow: ellipsis;
  741. white-space: nowrap;
  742. }
  743. .rec-desc {
  744. font-size: 22rpx;
  745. color: var(--text-secondary, #64748B);
  746. overflow: hidden;
  747. text-overflow: ellipsis;
  748. white-space: nowrap;
  749. }
  750. .rec-price {
  751. font-size: 26rpx;
  752. color: #F97316;
  753. font-weight: 600;
  754. }
  755. /* Mascot badge in nav */
  756. .mascot-badge {
  757. display: flex;
  758. align-items: center;
  759. gap: 4rpx;
  760. padding: 6rpx 16rpx;
  761. background: #EEF2FF;
  762. border-radius: 20rpx;
  763. font-size: 22rpx;
  764. }
  765. .mascot-badge-icon {
  766. font-size: 24rpx;
  767. }
  768. .mascot-badge-name {
  769. color: #6366F1;
  770. font-weight: 500;
  771. }
  772. </style>