chat.vue 27 KB

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