chat.vue 26 KB

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