chat.vue 28 KB

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