chat.vue 29 KB

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