chat.vue 24 KB

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