chat.vue 25 KB

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