西藏巴青项目

index.vue 56KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985
  1. <template>
  2. <view :key="layoutKey" :class="pageRootClass" class="assistant-page">
  3. <view v-if="disclaimer" class="assistant-disclaimer">
  4. <text class="text-body assistant-disclaimer__tag">{{ $t('aiOnlineConsult.disclaimerTitle') }}</text>
  5. <text class="text-body assistant-disclaimer__txt">{{ disclaimer }}</text>
  6. </view>
  7. <scroll-view
  8. ref="feedScroll"
  9. id="assistant-feed"
  10. class="assistant-feed"
  11. :style="feedScrollStyle"
  12. scroll-y
  13. enable-back-to-top
  14. :scroll-top="feedScrollTopBind"
  15. :scroll-into-view="feedScrollIntoView"
  16. :scroll-with-animation="!sending"
  17. :upper-threshold="80"
  18. @scrolltoupper="onScrollToUpper"
  19. @scroll="onFeedScroll"
  20. >
  21. <view
  22. id="assistant-feed-inner"
  23. class="assistant-feed__inner"
  24. :class="{ 'assistant-feed__inner--pending': pendingAttachments.length }"
  25. >
  26. <view v-if="loadingOlder" class="feed-hint">
  27. <text class="text-body feed-hint__txt">{{ $t('aiOnlineConsult.loadingMore') }}</text>
  28. </view>
  29. <view v-if="noMoreOlder && messages.length" class="feed-hint">
  30. <text class="text-body feed-hint__txt">{{ $t('aiOnlineConsult.noMoreHistory') }}</text>
  31. </view>
  32. <view v-if="messagesLoading && !messages.length" class="feed-hint">
  33. <text class="text-body feed-hint__txt">{{ $t('aiOnlineConsult.creatingSession') }}</text>
  34. </view>
  35. <block v-if="messageGroups.length">
  36. <block v-for="(group, gi) in messageGroups" :key="'g-' + gi">
  37. <view class="chat-date">
  38. <text class="text-body chat-date__txt">{{ group.dateLabel }}</text>
  39. </view>
  40. <view
  41. v-for="m in group.items"
  42. :key="m.id"
  43. :id="'msg-' + m.id"
  44. class="bubble-row"
  45. :class="isUserMessage(m) ? 'bubble-row--user' : 'bubble-row--bot'"
  46. >
  47. <view v-if="!isUserMessage(m)" class="bubble-avatar bubble-avatar--ai">
  48. <up-icon name="star-fill" color="#22C55E" :size="18" />
  49. </view>
  50. <view class="bubble" :class="isUserMessage(m) ? 'bubble--user' : 'bubble--bot'">
  51. <text v-if="!isUserMessage(m)" class="text-body bubble__who">{{ $t('aiAssistantPage.assistantBubble') }}</text>
  52. <text v-else class="text-body bubble__who">{{ $t('aiAssistantPage.userBubble') }}</text>
  53. <text
  54. v-if="m.msgType === 1 && isUserMessage(m)"
  55. class="text-body bubble__txt"
  56. >{{ userTextContent(m) }}</text>
  57. <text
  58. v-else-if="m.msgType === 1 && !isUserMessage(m) && m.streaming"
  59. :key="'stream-' + m.id + '-' + (m.streamRenderKey || 0)"
  60. class="text-body bubble__txt bubble__txt--stream"
  61. >{{ plainTextContent(m) }}</text>
  62. <view
  63. v-else-if="m.msgType === 1 && !isUserMessage(m)"
  64. class="bubble__rich"
  65. >
  66. <mp-html
  67. :key="m.id"
  68. :content="aiRichHtml(m)"
  69. :tag-style="mpHtmlTagStyle"
  70. :container-style="mpHtmlContainerStyle"
  71. :scroll-table="true"
  72. :selectable="true"
  73. :preview-img="true"
  74. @load="onBubbleMediaLoad"
  75. />
  76. </view>
  77. <image
  78. v-else-if="m.msgType === 2"
  79. class="bubble__img"
  80. :src="mediaUrl(m.content)"
  81. mode="widthFix"
  82. @load="onBubbleMediaLoad"
  83. @click="previewImage(m.content)"
  84. />
  85. <video
  86. v-else-if="m.msgType === 3"
  87. class="bubble__video"
  88. :src="mediaUrl(m.content)"
  89. controls
  90. />
  91. <view
  92. v-else-if="m.msgType === 4"
  93. class="voice-msg"
  94. :class="{ 'voice-msg--on': playingVoiceId === m.id }"
  95. role="button"
  96. @click="toggleVoice(m)"
  97. >
  98. <text class="text-body voice-msg__dur">{{ formatVoiceDuration(m.mediaDuration) }}</text>
  99. <text class="voice-msg__label">{{ $t('aiOnlineConsult.msgVoice') }}</text>
  100. </view>
  101. <text v-else class="text-body bubble__txt">{{ plainTextContent(m) }}</text>
  102. <text class="text-body bubble__time">{{ formatMsgTime(m.sendTime) }}</text>
  103. </view>
  104. <view v-if="isUserMessage(m)" class="bubble-avatar bubble-avatar--user">
  105. <up-icon name="account-fill" color="#16a34a" :size="18" />
  106. </view>
  107. </view>
  108. </block>
  109. </block>
  110. <view v-else-if="sessionReady && !messagesLoading" class="feed-empty">
  111. <text class="text-body feed-empty__txt">{{ $t('aiOnlineConsult.emptyChat') }}</text>
  112. </view>
  113. <view v-if="showThinking" class="bubble-row bubble-row--bot">
  114. <view class="bubble-avatar bubble-avatar--ai">
  115. <up-icon name="star-fill" color="#22C55E" :size="18" />
  116. </view>
  117. <view class="bubble bubble--bot bubble--thinking">
  118. <text class="text-body bubble__who">{{ $t('aiAssistantPage.assistantBubble') }}</text>
  119. <view class="thinking-status">
  120. <text class="text-body thinking-txt">{{ $t('aiOnlineConsult.thinking') }}</text>
  121. <view class="thinking-dots" aria-hidden="true">
  122. <view class="thinking-dots__dot" />
  123. <view class="thinking-dots__dot" />
  124. <view class="thinking-dots__dot" />
  125. </view>
  126. </view>
  127. </view>
  128. </view>
  129. <view id="msg-tail" class="assistant-feed__tail" />
  130. </view>
  131. </scroll-view>
  132. <view
  133. v-if="sessionReady"
  134. class="assistant-composer"
  135. :class="{ 'assistant-composer--has-pending': pendingAttachments.length }"
  136. >
  137. <!-- 待发送预览(在模型/工具行上方) -->
  138. <scroll-view
  139. v-if="pendingAttachments.length"
  140. class="composer-pending"
  141. scroll-x
  142. :show-scrollbar="false"
  143. >
  144. <view class="composer-pending__track">
  145. <view
  146. v-for="(a, i) in pendingAttachments"
  147. :key="a.id"
  148. class="composer-pending__item"
  149. >
  150. <image
  151. v-if="a.kind === 'image'"
  152. class="composer-pending__thumb"
  153. :src="a.localPath"
  154. mode="aspectFill"
  155. />
  156. <view v-else-if="a.kind === 'video'" class="composer-pending__thumb composer-pending__thumb--video">
  157. <image
  158. v-if="a.poster"
  159. class="composer-pending__thumb"
  160. :src="a.poster"
  161. mode="aspectFill"
  162. />
  163. <view class="composer-pending__video-mask">
  164. <up-icon name="play-circle" color="#ffffff" :size="28" />
  165. </view>
  166. </view>
  167. <view v-else class="composer-pending__thumb composer-pending__thumb--voice">
  168. <up-icon name="mic" color="#16a34a" :size="28" />
  169. <text class="composer-pending__voice-name">{{ pendingShortName(a.name) }}</text>
  170. </view>
  171. <view class="composer-pending__close" role="button" @click.stop="removeAttachment(i)">
  172. <up-icon name="close" color="#ffffff" :size="12" />
  173. </view>
  174. </view>
  175. </view>
  176. </scroll-view>
  177. <!-- 模型 + 图片 / 视频 / 语音 -->
  178. <view class="composer-tools">
  179. <view class="composer-model" role="button" @click="openModelPicker">
  180. <up-icon :name="currentModelOption.icon" color="#16a34a" :size="20" />
  181. <text class="composer-model__txt">{{ currentModelOption.short }}</text>
  182. <up-icon name="arrow-down" color="#6b7f72" :size="12" />
  183. </view>
  184. <view class="composer-icon-btn" role="button" @click="pickImage">
  185. <up-icon name="photo" color="#22C55E" :size="24" />
  186. </view>
  187. <!-- <view class="composer-icon-btn" role="button" @click="pickVideo">
  188. <up-icon name="play-circle" color="#22C55E" :size="24" />
  189. </view>
  190. <view class="composer-icon-btn" role="button" @click="pickVoice">
  191. <up-icon name="mic" color="#22C55E" :size="24" />
  192. </view> -->
  193. </view>
  194. <view class="composer-input-row">
  195. <view class="composer-input-shell">
  196. <textarea
  197. v-model="draft"
  198. class="composer-textarea"
  199. :placeholder="$t('aiOnlineConsult.draftPlaceholder')"
  200. placeholder-class="composer-textarea-ph"
  201. maxlength="2000"
  202. :disabled="sending"
  203. :cursor-spacing="16"
  204. :show-confirm-bar="false"
  205. auto-height
  206. />
  207. </view>
  208. <view
  209. :class="['composer-send', { 'composer-send--disabled': sendDisabled }]"
  210. role="button"
  211. @click="handleSend"
  212. >
  213. <text class="text-body composer-send__txt">
  214. {{ sending ? $t('aiOnlineConsult.thinking') : $t('aiOnlineConsult.send') }}
  215. </text>
  216. </view>
  217. </view>
  218. </view>
  219. </view>
  220. </template>
  221. <script>
  222. import UIcon from 'uview-plus/components/u-icon/u-icon.vue'
  223. import tabPage from '@/mixins/tabPage'
  224. import { ensureApiToken } from '@/utils/apiAuth'
  225. import { uploadFile } from '@/utils/upload'
  226. import { useUserStore } from '@/store/user'
  227. import {
  228. MSG_TYPE_TEXT,
  229. MSG_TYPE_IMAGE,
  230. MSG_TYPE_VIDEO,
  231. MSG_TYPE_VOICE,
  232. MESSAGE_PAGE_SIZE,
  233. resolveSessionId,
  234. resolveConsultSessionId,
  235. resolveLlmSessionIdFromRow,
  236. resolveLlmSessionId as resolveLlmSessionIdUtil,
  237. normalizeSessionRow,
  238. isUserMessage,
  239. mediaUrl,
  240. normalizeMessage,
  241. formatMsgTime,
  242. formatVoiceDuration,
  243. buildMessageGroups
  244. } from '@/utils/aiConsult'
  245. import {
  246. MODEL_OPTION_DEFS,
  247. MEDIA_RULES,
  248. SENDER_ROLE_USER,
  249. SENDER_ROLE_AI,
  250. genLocalId,
  251. extOf,
  252. buildUserContentForLlm,
  253. buildMessagesForLlm,
  254. resolvePayloadUserContent,
  255. buildPersistSendBody,
  256. findLastLocalExchangeIndexes
  257. } from '@/utils/aiLlmChat'
  258. import {
  259. createAiConsultSession,
  260. listAiConsultMessages,
  261. sendAiConsultMessage,
  262. sendChatMessage
  263. } from '@/api/diseaseTreatment/aiOnlineConsult'
  264. import {
  265. markdownToHtml,
  266. MP_HTML_TAG_STYLE,
  267. MP_HTML_CONTAINER_STYLE
  268. } from '@/utils/chatMarkdown'
  269. const LLM_SESSION_STORAGE_PREFIX = 'ai_consult_llm_session_'
  270. export default {
  271. components: {
  272. 'up-icon': UIcon
  273. },
  274. mixins: [tabPage],
  275. data() {
  276. return {
  277. navTitleKey: 'aiAssistantPage.title',
  278. sessionId: '',
  279. sessionRow: null,
  280. sessionReady: false,
  281. disclaimer: '',
  282. messages: [],
  283. draft: '',
  284. model: 'auto',
  285. pendingAttachments: [],
  286. pendingPersist: null,
  287. messagesLoading: false,
  288. loadingOlder: false,
  289. noMoreOlder: false,
  290. sending: false,
  291. feedScrollTop: 0,
  292. feedScrollTopFrozen: null,
  293. feedScrollIntoView: '',
  294. _pageAlive: true,
  295. scrollTopNonce: 0,
  296. scrollBottomTimer: null,
  297. feedHeightPx: 0,
  298. _pinScrollRaf: null,
  299. _lastStreamScrollAt: 0,
  300. _streamRevealTimer: null,
  301. stickToBottom: true,
  302. /** 首次滚底完成前,不因 scroll 事件把 stickToBottom 置为 false */
  303. scrollPinReady: false,
  304. playingVoiceId: null,
  305. innerAudio: null,
  306. mpHtmlTagStyle: MP_HTML_TAG_STYLE,
  307. mpHtmlContainerStyle: MP_HTML_CONTAINER_STYLE,
  308. streamRequestTask: null
  309. }
  310. },
  311. computed: {
  312. feedScrollStyle() {
  313. if (this.feedHeightPx > 0) {
  314. return { height: this.feedHeightPx + 'px' }
  315. }
  316. return { height: '100%' }
  317. },
  318. /** 流式期间冻结 scroll-top,避免重渲染把列表拽回顶部 */
  319. feedScrollTopBind() {
  320. if (typeof this.feedScrollTopFrozen === 'number') {
  321. return this.feedScrollTopFrozen
  322. }
  323. return this.feedScrollTop
  324. },
  325. modelOptions() {
  326. return MODEL_OPTION_DEFS.map((o) => ({
  327. value: o.value,
  328. icon: o.icon,
  329. label: this.$t('aiOnlineConsult.' + o.labelKey),
  330. short: this.$t('aiOnlineConsult.' + o.shortKey),
  331. desc: this.$t('aiOnlineConsult.' + o.descKey)
  332. }))
  333. },
  334. currentModelOption() {
  335. return this.modelOptions.find((o) => o.value === this.model) || this.modelOptions[0]
  336. },
  337. messageGroups() {
  338. return buildMessageGroups(this.messages, (k, p) => this.$t(k, p))
  339. },
  340. sendDisabled() {
  341. const t = (this.draft || '').trim()
  342. return this.sending || !this.sessionId || (!t && !this.pendingAttachments.length)
  343. },
  344. showThinking() {
  345. if (!this.sending) {
  346. return false
  347. }
  348. return !this.messages.some((m) => m.senderRole === SENDER_ROLE_AI && m.streaming)
  349. },
  350. llmUserId() {
  351. const store = useUserStore()
  352. return store.state.name ? String(store.state.name) : String(store.state.id || 'user')
  353. }
  354. },
  355. watch: {
  356. sessionReady() {
  357. this.$nextTick(() => this.updateFeedHeight())
  358. },
  359. disclaimer() {
  360. this.$nextTick(() => this.updateFeedHeight())
  361. },
  362. feedHeightPx(val) {
  363. if (val > 0 && !this.sending) {
  364. this.$nextTick(() => this.pinScrollToBottom(true))
  365. }
  366. },
  367. 'messages.length'(len) {
  368. if (len > 0 && this.stickToBottom && !this.loadingOlder && !this.sending) {
  369. this.$nextTick(() => this.scheduleScrollToBottom())
  370. }
  371. }
  372. },
  373. onLoad(query) {
  374. this.stickToBottom = true
  375. this.scrollPinReady = false
  376. if (!ensureApiToken()) return
  377. const raw = query && (query.sessionId || query.id || '')
  378. if (raw) {
  379. try {
  380. this.sessionId = decodeURIComponent(raw)
  381. } catch (e) {
  382. this.sessionId = raw
  383. }
  384. let llmFromQuery = ''
  385. if (query && query.llmSessionId) {
  386. try {
  387. llmFromQuery = decodeURIComponent(query.llmSessionId)
  388. } catch (e) {
  389. llmFromQuery = String(query.llmSessionId)
  390. }
  391. }
  392. this.sessionRow = normalizeSessionRow(
  393. {
  394. id: this.sessionId,
  395. realSessionId: this.sessionId,
  396. llmSessionId: llmFromQuery || null
  397. },
  398. llmFromQuery ? { [this.sessionId]: llmFromQuery } : null
  399. )
  400. if (llmFromQuery) {
  401. this.saveLlmSessionId(this.sessionId, llmFromQuery)
  402. }
  403. this.hydrateLlmSessionId(this.sessionRow)
  404. this.sessionId = this.consultSessionIdForApi() || this.sessionId
  405. this.sessionReady = !!this.sessionId
  406. this.loadMessages(false)
  407. this.$nextTick(() => this.updateFeedHeight())
  408. return
  409. }
  410. this.initNewSession()
  411. },
  412. onShow() {
  413. this.stickToBottom = true
  414. this.updateFeedHeight()
  415. if (this.sessionReady && this.messages.length && !this.messagesLoading && !this.loadingOlder) {
  416. this.scheduleScrollToBottom()
  417. }
  418. },
  419. onReady() {
  420. this.updateFeedHeight()
  421. this.$nextTick(() => {
  422. if (this.messages.length && !this.messagesLoading) {
  423. this.scheduleScrollToBottom()
  424. }
  425. })
  426. },
  427. mounted() {
  428. this.bindH5WheelScroll()
  429. },
  430. // #ifdef VUE3
  431. beforeUnmount() {
  432. this._pageAlive = false
  433. this.unbindH5WheelScroll()
  434. },
  435. // #endif
  436. // #ifndef VUE3
  437. beforeDestroy() {
  438. this._pageAlive = false
  439. this.unbindH5WheelScroll()
  440. },
  441. // #endif
  442. onUnload() {
  443. this._pageAlive = false
  444. if (this.scrollBottomTimer) {
  445. clearTimeout(this.scrollBottomTimer)
  446. this.scrollBottomTimer = null
  447. }
  448. this.clearStreamRevealTimer()
  449. this.abortStreamRequest()
  450. this.flushPendingPersist()
  451. this.stopVoice()
  452. this.unbindH5WheelScroll()
  453. },
  454. methods: {
  455. isUserMessage,
  456. mediaUrl,
  457. formatMsgTime,
  458. formatVoiceDuration,
  459. userTextContent(m) {
  460. if (!m || m.content == null) {
  461. return ''
  462. }
  463. return typeof m.content === 'string' ? m.content : String(m.content)
  464. },
  465. plainTextContent(m) {
  466. if (!m || m.content == null) {
  467. return ''
  468. }
  469. if (typeof m.content === 'string') {
  470. return m.content
  471. }
  472. if (Array.isArray(m.content)) {
  473. const part = m.content.find((p) => p && p.type === 'text' && p.text)
  474. return part ? part.text : ''
  475. }
  476. return String(m.content)
  477. },
  478. aiRichHtml(m) {
  479. const raw = this.plainTextContent(m)
  480. return markdownToHtml(raw)
  481. },
  482. openModelPicker() {
  483. const labels = this.modelOptions.map((o) => o.label)
  484. uni.showActionSheet({
  485. title: this.$t('aiOnlineConsult.pickModel'),
  486. itemList: labels,
  487. success: (res) => {
  488. const opt = this.modelOptions[res.tapIndex]
  489. if (opt) {
  490. this.model = opt.value
  491. }
  492. }
  493. })
  494. },
  495. pendingShortName(name) {
  496. const n = String(name || '')
  497. if (n.length <= 12) return n
  498. return n.slice(-12)
  499. },
  500. revokeAttachmentPreview(a) {
  501. if (a && a.objectUrl && typeof URL !== 'undefined') {
  502. try {
  503. URL.revokeObjectURL(a.objectUrl)
  504. } catch (e) {
  505. /* ignore */
  506. }
  507. }
  508. },
  509. removeAttachment(i) {
  510. const a = this.pendingAttachments[i]
  511. this.revokeAttachmentPreview(a)
  512. this.pendingAttachments.splice(i, 1)
  513. },
  514. setPendingAttachment(item) {
  515. this.pendingAttachments.forEach((a) => this.revokeAttachmentPreview(a))
  516. this.pendingAttachments = [
  517. {
  518. id: genLocalId(),
  519. kind: item.kind,
  520. msgType: item.msgType,
  521. name: item.name,
  522. localPath: item.localPath,
  523. poster: item.poster || '',
  524. nativeFile: item.nativeFile || null,
  525. objectUrl: item.objectUrl || '',
  526. mediaDuration: item.mediaDuration,
  527. url: ''
  528. }
  529. ]
  530. },
  531. uploadAllPending() {
  532. const tasks = this.pendingAttachments.map((a) => {
  533. if (a.url) {
  534. return Promise.resolve(a.url)
  535. }
  536. return uploadFile(a.localPath, a.nativeFile).then((url) => {
  537. a.url = url
  538. return url
  539. })
  540. })
  541. return Promise.all(tasks)
  542. },
  543. initNewSession() {
  544. uni.showLoading({ mask: true })
  545. createAiConsultSession({})
  546. .then((res) => {
  547. const data = res.data || {}
  548. this.sessionId = resolveSessionId(data)
  549. this.clearLlmSessionId(this.sessionId)
  550. this.sessionRow = normalizeSessionRow({
  551. ...data,
  552. id: this.sessionId,
  553. realSessionId: this.sessionId,
  554. llmSessionId: null,
  555. sessionTitle: data.sessionTitle
  556. })
  557. this.sessionReady = !!this.sessionId
  558. if (data.disclaimer) {
  559. this.disclaimer = data.disclaimer
  560. }
  561. this.$nextTick(() => this.updateFeedHeight())
  562. })
  563. .catch(() => {
  564. uni.navigateBack()
  565. })
  566. .finally(() => {
  567. uni.hideLoading()
  568. })
  569. },
  570. consultSessionIdForApi() {
  571. return resolveConsultSessionId(this.sessionRow) || this.sessionId || null
  572. },
  573. loadMessages(older) {
  574. const consultSid = this.consultSessionIdForApi()
  575. if (!consultSid) return
  576. const beforeId = older && this.messages.length ? this.messages[0].id : undefined
  577. if (older) {
  578. this.loadingOlder = true
  579. } else {
  580. this.messagesLoading = true
  581. }
  582. listAiConsultMessages(consultSid, {
  583. beforeId,
  584. pageSize: MESSAGE_PAGE_SIZE
  585. })
  586. .then((res) => {
  587. const batch = (res.data || []).map((m) => normalizeMessage(m))
  588. if (older) {
  589. if (!batch.length) {
  590. this.noMoreOlder = true
  591. } else {
  592. const feedEl = this.getH5ScrollableEl()
  593. const prevScrollHeight = feedEl ? feedEl.scrollHeight : 0
  594. const prevScrollTop = feedEl ? feedEl.scrollTop : 0
  595. this.messages = batch.concat(this.messages)
  596. if (batch.length < MESSAGE_PAGE_SIZE) {
  597. this.noMoreOlder = true
  598. }
  599. if (feedEl && prevScrollHeight > 0) {
  600. this.$nextTick(() => {
  601. feedEl.scrollTop = feedEl.scrollHeight - prevScrollHeight + prevScrollTop
  602. })
  603. }
  604. }
  605. } else {
  606. this.messages = batch
  607. if (!batch.length) {
  608. this.noMoreOlder = true
  609. }
  610. this.$nextTick(() => {
  611. this.scheduleScrollToBottom()
  612. })
  613. }
  614. })
  615. .finally(() => {
  616. this.messagesLoading = false
  617. this.loadingOlder = false
  618. if (!older) {
  619. this.$nextTick(() => {
  620. this.scheduleScrollToBottom()
  621. })
  622. }
  623. })
  624. },
  625. onScrollToUpper() {
  626. if (this.loadingOlder || this.noMoreOlder || !this.messages.length) return
  627. this.loadMessages(true)
  628. },
  629. bindH5WheelScroll() {
  630. // #ifdef H5
  631. if (this._h5DocWheel) {
  632. return
  633. }
  634. this._h5DocWheel = (e) => this.handleH5DocumentWheel(e)
  635. document.addEventListener('wheel', this._h5DocWheel, { passive: false, capture: true })
  636. window.addEventListener('resize', this.updateFeedHeight)
  637. // #endif
  638. },
  639. unbindH5WheelScroll() {
  640. // #ifdef H5
  641. if (this._h5DocWheel) {
  642. document.removeEventListener('wheel', this._h5DocWheel, { capture: true })
  643. this._h5DocWheel = null
  644. }
  645. window.removeEventListener('resize', this.updateFeedHeight)
  646. // #endif
  647. },
  648. updateFeedHeight() {
  649. if (!this._pageAlive) {
  650. return
  651. }
  652. uni.getSystemInfo({
  653. success: (sys) => {
  654. if (!this._pageAlive) {
  655. return
  656. }
  657. const winH = sys.windowHeight || sys.screenHeight || 600
  658. const discEstimate = this.disclaimer ? 56 : 0
  659. const compEstimate = this.sessionReady ? 150 : 0
  660. this.feedHeightPx = Math.max(160, Math.floor(winH - discEstimate - compEstimate))
  661. this.$nextTick(() => {
  662. if (!this._pageAlive) {
  663. return
  664. }
  665. try {
  666. const q = uni.createSelectorQuery().in(this)
  667. q.select('.assistant-disclaimer').boundingClientRect()
  668. if (this.sessionReady) {
  669. q.select('.assistant-composer').boundingClientRect()
  670. }
  671. q.exec((rects) => {
  672. if (!this._pageAlive || !rects) {
  673. return
  674. }
  675. const discH = (rects[0] && rects[0].height) || discEstimate
  676. const compH = this.sessionReady ? (rects[1] && rects[1].height) || compEstimate : 0
  677. const next = Math.max(160, Math.floor(winH - discH - compH))
  678. if (next !== this.feedHeightPx) {
  679. this.feedHeightPx = next
  680. if (!this.sending) {
  681. this.$nextTick(() => this.pinScrollToBottom(true))
  682. }
  683. }
  684. })
  685. } catch (e) {
  686. /* H5 节点未挂载时 query 可能抛错,保留估算高度 */
  687. }
  688. })
  689. }
  690. })
  691. },
  692. requestPinScroll() {
  693. if (!this._pageAlive || (!this.stickToBottom && !this.sending)) {
  694. return
  695. }
  696. if (this._pinScrollRaf) {
  697. return
  698. }
  699. const raf = typeof requestAnimationFrame === 'function' ? requestAnimationFrame : (fn) => setTimeout(fn, 16)
  700. this._pinScrollRaf = raf(() => {
  701. this._pinScrollRaf = null
  702. if (this.sending) {
  703. this.scrollStreamToBottom()
  704. } else {
  705. this.pinScrollToBottom()
  706. }
  707. })
  708. },
  709. /** 流式输出:仅改原生滚动位置,不动 feedScrollTop,避免与 scroll-view 打架抖动 */
  710. scrollStreamToBottom() {
  711. if (!this._pageAlive) {
  712. return
  713. }
  714. const el = this.getH5ScrollableEl()
  715. if (el) {
  716. const maxTop = this.getH5FeedMaxScrollTop()
  717. const target = maxTop != null ? maxTop : Math.max(0, el.scrollHeight - el.clientHeight)
  718. if (Math.abs(el.scrollTop - target) > 2) {
  719. el.scrollTop = target
  720. }
  721. return
  722. }
  723. const now = Date.now()
  724. if (this._lastStreamScrollAt && now - this._lastStreamScrollAt < 150) {
  725. return
  726. }
  727. this._lastStreamScrollAt = now
  728. this.syncFeedScrollTop()
  729. },
  730. getH5FeedMaxScrollTop() {
  731. const el = this.getH5ScrollableEl()
  732. if (!el) {
  733. return null
  734. }
  735. const root = this.getFeedScrollEl()
  736. const content = root && root.querySelector ? root.querySelector('.uni-scroll-view-content') : null
  737. const scrollHeight = content ? Math.max(content.scrollHeight, el.scrollHeight) : el.scrollHeight
  738. const clientHeight = el.clientHeight || (content && content.clientHeight) || 0
  739. if (clientHeight <= 0) {
  740. return null
  741. }
  742. return Math.max(0, Math.ceil(scrollHeight - clientHeight))
  743. },
  744. applyFeedScrollTop(maxTop, force) {
  745. this.scrollTopNonce = this.scrollTopNonce ? 0 : 1
  746. const nextTop = maxTop + this.scrollTopNonce
  747. if (force || this.feedScrollTop !== nextTop) {
  748. this.feedScrollTop = nextTop
  749. } else {
  750. this.scrollTopNonce = this.scrollTopNonce ? 0 : 1
  751. this.feedScrollTop = maxTop + this.scrollTopNonce
  752. }
  753. if (this.stickToBottom) {
  754. this.scrollPinReady = true
  755. }
  756. },
  757. scrollIntoViewTail() {
  758. if (!this._pageAlive) {
  759. return
  760. }
  761. this.feedScrollIntoView = ''
  762. this.$nextTick(() => {
  763. if (!this._pageAlive) {
  764. return
  765. }
  766. this.feedScrollIntoView = 'msg-tail'
  767. setTimeout(() => {
  768. if (this._pageAlive) {
  769. this.feedScrollIntoView = ''
  770. }
  771. }, 120)
  772. })
  773. },
  774. freezeFeedScrollTopForStream() {
  775. const el = this.getH5ScrollableEl()
  776. if (el) {
  777. this.feedScrollTopFrozen = el.scrollTop
  778. return
  779. }
  780. this.feedScrollTopFrozen = this.feedScrollTop
  781. },
  782. releaseFeedScrollTopFrozen() {
  783. this.feedScrollTopFrozen = null
  784. },
  785. syncFeedScrollTop(force) {
  786. if (!this._pageAlive || typeof this.feedScrollTopFrozen === 'number') {
  787. return
  788. }
  789. const h5Max = this.getH5FeedMaxScrollTop()
  790. if (h5Max != null) {
  791. this.applyFeedScrollTop(h5Max, !!force)
  792. return
  793. }
  794. try {
  795. uni.createSelectorQuery()
  796. .in(this)
  797. .select('#assistant-feed-inner')
  798. .boundingClientRect()
  799. .select('#assistant-feed')
  800. .boundingClientRect()
  801. .exec((res) => {
  802. if (!this._pageAlive || !res) {
  803. return
  804. }
  805. const inner = res[0]
  806. const viewport = res[1]
  807. if (!inner || !viewport || inner.height <= 0 || viewport.height <= 0) {
  808. return
  809. }
  810. const maxTop = Math.max(0, Math.ceil(inner.height - viewport.height))
  811. this.applyFeedScrollTop(maxTop, !!force)
  812. })
  813. } catch (e) {
  814. /* ignore */
  815. }
  816. },
  817. pinScrollToBottom(force) {
  818. if (!this._pageAlive) {
  819. return
  820. }
  821. if (this.sending) {
  822. this.scrollStreamToBottom()
  823. return
  824. }
  825. const run = () => {
  826. if (!this._pageAlive) {
  827. return
  828. }
  829. this.scrollIntoViewTail()
  830. const apply = () => this.syncFeedScrollTop(!!force)
  831. apply()
  832. this.$nextTick(apply)
  833. const raf = typeof requestAnimationFrame === 'function' ? requestAnimationFrame : null
  834. if (raf) {
  835. raf(() => raf(apply))
  836. }
  837. }
  838. if (force) {
  839. run()
  840. return
  841. }
  842. this.$nextTick(run)
  843. },
  844. getFeedScrollEl() {
  845. const ref = this.$refs.feedScroll
  846. if (!ref) {
  847. return null
  848. }
  849. if (ref.$el) {
  850. return ref.$el
  851. }
  852. return ref
  853. },
  854. getH5ScrollableEl() {
  855. const root = this.getFeedScrollEl()
  856. if (!root || typeof document === 'undefined') {
  857. return null
  858. }
  859. const prefer = root.querySelector('.uni-scroll-view') || root.querySelector('.uni-scroll-view-content')
  860. if (prefer) {
  861. return prefer
  862. }
  863. const nodes = root.querySelectorAll('*')
  864. for (let i = 0; i < nodes.length; i++) {
  865. const el = nodes[i]
  866. if (el.scrollHeight > el.clientHeight + 1) {
  867. return el
  868. }
  869. }
  870. return root
  871. },
  872. handleH5DocumentWheel(e) {
  873. if (!e) {
  874. return
  875. }
  876. const root = this.getFeedScrollEl()
  877. if (!root || !e.target || !root.contains(e.target)) {
  878. return
  879. }
  880. const el = this.getH5ScrollableEl()
  881. if (!el || el.scrollHeight <= el.clientHeight + 1) {
  882. return
  883. }
  884. const maxTop = el.scrollHeight - el.clientHeight
  885. const next = Math.max(0, Math.min(maxTop, el.scrollTop + e.deltaY))
  886. if (Math.abs(next - el.scrollTop) < 0.5) {
  887. return
  888. }
  889. el.scrollTop = next
  890. e.preventDefault()
  891. e.stopPropagation()
  892. },
  893. onBubbleMediaLoad() {
  894. if (this.sending || !this.stickToBottom) {
  895. return
  896. }
  897. this.pinScrollToBottom(true)
  898. },
  899. onFeedScroll(e) {
  900. if (e && e.detail && e.detail.scrollTop != null && e.detail.scrollTop < 40) {
  901. this.onScrollToUpper()
  902. }
  903. if (this.sending || this.messagesLoading || this.loadingOlder || !this.scrollPinReady) {
  904. return
  905. }
  906. let scrollTop = e.detail && e.detail.scrollTop
  907. const el = this.getH5ScrollableEl()
  908. if (el && el.scrollHeight > el.clientHeight + 20) {
  909. if (scrollTop == null) {
  910. scrollTop = el.scrollTop
  911. }
  912. const dist = el.scrollHeight - el.clientHeight - (scrollTop || 0)
  913. this.stickToBottom = dist < 100
  914. }
  915. },
  916. scheduleScrollToBottom(immediate = true) {
  917. if (!this._pageAlive) {
  918. return
  919. }
  920. this.stickToBottom = true
  921. if (immediate) {
  922. this.pinScrollToBottom(true)
  923. }
  924. if (this.sending) {
  925. return
  926. }
  927. const delays =
  928. typeof document !== 'undefined' ? [80, 250, 600, 1200, 2000] : [120, 400, 900, 1500]
  929. delays.forEach((ms) => {
  930. setTimeout(() => {
  931. if (!this._pageAlive || this.sending) {
  932. return
  933. }
  934. if (!this.stickToBottom && this.scrollPinReady) {
  935. return
  936. }
  937. this.pinScrollToBottom(true)
  938. }, ms)
  939. })
  940. },
  941. clearComposer() {
  942. this.draft = ''
  943. this.pendingAttachments.forEach((a) => this.revokeAttachmentPreview(a))
  944. this.pendingAttachments = []
  945. },
  946. llmSessionStorageKey(consultSessionId) {
  947. return LLM_SESSION_STORAGE_PREFIX + consultSessionId
  948. },
  949. loadLlmSessionId(consultSessionId) {
  950. if (!consultSessionId) {
  951. return null
  952. }
  953. try {
  954. return uni.getStorageSync(this.llmSessionStorageKey(consultSessionId)) || null
  955. } catch (e) {
  956. return null
  957. }
  958. },
  959. saveLlmSessionId(consultSessionId, llmSessionId) {
  960. if (!consultSessionId || !llmSessionId) {
  961. return
  962. }
  963. try {
  964. uni.setStorageSync(this.llmSessionStorageKey(consultSessionId), String(llmSessionId))
  965. } catch (e) {
  966. /* ignore */
  967. }
  968. },
  969. clearLlmSessionId(consultSessionId) {
  970. if (!consultSessionId) {
  971. return
  972. }
  973. try {
  974. uni.removeStorageSync(this.llmSessionStorageKey(consultSessionId))
  975. } catch (e) {
  976. /* ignore */
  977. }
  978. },
  979. hydrateLlmSessionId(sessionRow) {
  980. if (!sessionRow) {
  981. return
  982. }
  983. const sid = resolveConsultSessionId(sessionRow)
  984. const fromList = resolveLlmSessionIdFromRow(sessionRow)
  985. if (fromList && !sessionRow.llmSessionId) {
  986. sessionRow.llmSessionId = fromList
  987. this.saveLlmSessionId(sid, fromList)
  988. }
  989. const stored = this.loadLlmSessionId(sid)
  990. if (stored && !sessionRow.llmSessionId) {
  991. sessionRow.llmSessionId = stored
  992. }
  993. },
  994. resolveLlmSessionId() {
  995. return resolveLlmSessionIdUtil(this.sessionRow, (consultId) => this.loadLlmSessionId(consultId))
  996. },
  997. rememberLlmSessionId(llmSessionId) {
  998. if (!llmSessionId || !this.sessionRow) {
  999. return
  1000. }
  1001. const v = String(llmSessionId)
  1002. this.sessionRow.llmSessionId = v
  1003. this.saveLlmSessionId(resolveConsultSessionId(this.sessionRow), v)
  1004. },
  1005. abortStreamRequest() {
  1006. if (this.streamRequestTask && typeof this.streamRequestTask.abort === 'function') {
  1007. try {
  1008. this.streamRequestTask.abort()
  1009. } catch (e) {
  1010. /* ignore */
  1011. }
  1012. }
  1013. this.streamRequestTask = null
  1014. },
  1015. clearStreamRevealTimer() {
  1016. if (this._streamRevealTimer) {
  1017. clearTimeout(this._streamRevealTimer)
  1018. this._streamRevealTimer = null
  1019. }
  1020. },
  1021. /** 流式正文:小步即时更新;网关缓冲导致一次写入很多字时做打字机展开 */
  1022. pushStreamText(aiMsg, targetText) {
  1023. if (!aiMsg) {
  1024. return
  1025. }
  1026. const next = targetText == null ? '' : String(targetText)
  1027. const prev = aiMsg.content == null ? '' : String(aiMsg.content)
  1028. if (next === prev) {
  1029. return
  1030. }
  1031. if (!next.startsWith(prev)) {
  1032. this.$set(aiMsg, 'content', next)
  1033. this.$set(aiMsg, 'streamRenderKey', (aiMsg.streamRenderKey || 0) + 1)
  1034. this.requestPinScroll()
  1035. return
  1036. }
  1037. const jump = next.length - prev.length
  1038. if (jump <= 8) {
  1039. this.$set(aiMsg, 'content', next)
  1040. this.$set(aiMsg, 'streamRenderKey', (aiMsg.streamRenderKey || 0) + 1)
  1041. this.requestPinScroll()
  1042. return
  1043. }
  1044. this.clearStreamRevealTimer()
  1045. let pos = prev.length
  1046. const step = () => {
  1047. if (!this._pageAlive || !aiMsg.streaming) {
  1048. this._streamRevealTimer = null
  1049. this.$set(aiMsg, 'content', next)
  1050. this.$set(aiMsg, 'streamRenderKey', (aiMsg.streamRenderKey || 0) + 1)
  1051. return
  1052. }
  1053. pos = Math.min(pos + 3, next.length)
  1054. this.$set(aiMsg, 'content', next.slice(0, pos))
  1055. this.$set(aiMsg, 'streamRenderKey', (aiMsg.streamRenderKey || 0) + 1)
  1056. this.requestPinScroll()
  1057. if (pos < next.length) {
  1058. this._streamRevealTimer = setTimeout(step, 20)
  1059. } else {
  1060. this._streamRevealTimer = null
  1061. }
  1062. }
  1063. step()
  1064. },
  1065. appendLocalMessage(senderRole, msgType, content, extra) {
  1066. const msg = {
  1067. id: genLocalId(),
  1068. senderRole,
  1069. msgType: msgType || MSG_TYPE_TEXT,
  1070. content,
  1071. sendTime: new Date().toISOString(),
  1072. ...(extra || {})
  1073. }
  1074. this.messages.push(msg)
  1075. return msg
  1076. },
  1077. mergePersistResult(data, aiReplyContent) {
  1078. if (!data) return
  1079. const { userIdx, aiIdx } = findLastLocalExchangeIndexes(this.messages)
  1080. if (data.userMessage && userIdx >= 0) {
  1081. const norm = normalizeMessage(data.userMessage)
  1082. const row = this.messages[userIdx]
  1083. row.id = norm.id
  1084. if (norm.sendTime) row.sendTime = norm.sendTime
  1085. }
  1086. if (data.aiMessage && aiIdx >= 0) {
  1087. const norm = normalizeMessage(data.aiMessage)
  1088. const row = this.messages[aiIdx]
  1089. row.id = norm.id
  1090. if (norm.sendTime) row.sendTime = norm.sendTime
  1091. }
  1092. },
  1093. queuePendingPersist(consultSessionId, persistBody, aiReplyContent, llmSessionId) {
  1094. this.pendingPersist = {
  1095. consultSessionId,
  1096. persistBody: { ...persistBody },
  1097. aiReplyContent,
  1098. llmSessionId: llmSessionId != null ? llmSessionId : null
  1099. }
  1100. },
  1101. flushPendingPersist() {
  1102. const pending = this.pendingPersist
  1103. if (!pending || !pending.consultSessionId || !pending.persistBody || !pending.aiReplyContent) {
  1104. return Promise.resolve()
  1105. }
  1106. return sendAiConsultMessage(pending.consultSessionId, {
  1107. ...pending.persistBody,
  1108. aiReplyContent: pending.aiReplyContent,
  1109. realSessionId: pending.llmSessionId != null ? pending.llmSessionId : null
  1110. })
  1111. .then(() => {
  1112. this.pendingPersist = null
  1113. })
  1114. .catch(() => {})
  1115. },
  1116. persistConsultExchange(persistBody, aiReplyContent) {
  1117. const reply = (aiReplyContent || '').trim()
  1118. const consultSessionId = this.consultSessionIdForApi()
  1119. if (!consultSessionId || !persistBody || !reply) {
  1120. return Promise.resolve(true)
  1121. }
  1122. const llmSessionId = this.resolveLlmSessionId()
  1123. return sendAiConsultMessage(consultSessionId, {
  1124. ...persistBody,
  1125. aiReplyContent: reply,
  1126. realSessionId: llmSessionId || null
  1127. })
  1128. .then((res) => {
  1129. this.mergePersistResult(res.data, reply)
  1130. if (
  1131. this.pendingPersist &&
  1132. this.pendingPersist.consultSessionId === consultSessionId &&
  1133. this.pendingPersist.aiReplyContent === reply
  1134. ) {
  1135. this.pendingPersist = null
  1136. }
  1137. return true
  1138. })
  1139. .catch((err) => {
  1140. this.queuePendingPersist(consultSessionId, persistBody, reply, llmSessionId)
  1141. const msg = (err && err.message) || this.$t('aiOnlineConsult.saveSessionFailed')
  1142. uni.showToast({ title: msg, icon: 'none' })
  1143. return false
  1144. })
  1145. },
  1146. async handleSend() {
  1147. if (this.sendDisabled) return
  1148. const text = (this.draft || '').trim()
  1149. if (!text && !this.pendingAttachments.length) {
  1150. uni.showToast({ title: this.$t('aiOnlineConsult.inputOrAttach'), icon: 'none' })
  1151. return
  1152. }
  1153. if (this.pendingAttachments.some((a) => !a.url)) {
  1154. uni.showLoading({ title: this.$t('aiOnlineConsult.uploading'), mask: true })
  1155. try {
  1156. await this.uploadAllPending()
  1157. } catch (e) {
  1158. uni.showToast({ title: this.$t('aiOnlineConsult.uploadFail'), icon: 'none' })
  1159. return
  1160. } finally {
  1161. uni.hideLoading()
  1162. }
  1163. }
  1164. const atts = this.pendingAttachments
  1165. const img = atts.find((a) => a.kind === 'image' && a.url)
  1166. const video = atts.find((a) => a.kind === 'video' && a.url)
  1167. if (img) {
  1168. await this.sendViaLlm({ msgType: MSG_TYPE_IMAGE, content: img.url })
  1169. return
  1170. }
  1171. if (video) {
  1172. await this.sendViaLlm({
  1173. msgType: MSG_TYPE_VIDEO,
  1174. content: video.url,
  1175. mediaDuration: video.mediaDuration
  1176. })
  1177. return
  1178. }
  1179. await this.sendViaLlm({ msgType: MSG_TYPE_TEXT, content: text })
  1180. },
  1181. async sendViaLlm(payload) {
  1182. if (!this.consultSessionIdForApi() || this.sending) return
  1183. let userContent
  1184. if (payload && payload.msgType && payload.msgType !== MSG_TYPE_TEXT) {
  1185. userContent = resolvePayloadUserContent(payload, this.draft)
  1186. } else {
  1187. userContent = buildUserContentForLlm((payload && payload.content) || this.draft, this.pendingAttachments)
  1188. }
  1189. if (!userContent) {
  1190. uni.showToast({ title: this.$t('aiOnlineConsult.inputOrAttach'), icon: 'none' })
  1191. return
  1192. }
  1193. const msgType = (payload && payload.msgType) || MSG_TYPE_TEXT
  1194. const draftText = (this.draft || '').trim()
  1195. const pendingSnapshot = this.pendingAttachments.slice()
  1196. const displayContent =
  1197. msgType !== MSG_TYPE_TEXT
  1198. ? payload.content
  1199. : typeof userContent === 'string'
  1200. ? userContent
  1201. : pendingSnapshot.find((a) => a.kind === 'image' && a.url)
  1202. ? pendingSnapshot.find((a) => a.kind === 'image').url
  1203. : userContent
  1204. const persistBody = buildPersistSendBody(msgType, payload, draftText, pendingSnapshot)
  1205. this.appendLocalMessage(SENDER_ROLE_USER, msgType, displayContent)
  1206. this.clearComposer()
  1207. this.stickToBottom = true
  1208. this.pinScrollToBottom(true)
  1209. const llmSessionId = this.resolveLlmSessionId()
  1210. const body = {
  1211. model: this.model,
  1212. messages: buildMessagesForLlm(this.messages, llmSessionId),
  1213. user: this.llmUserId
  1214. }
  1215. if (llmSessionId) {
  1216. body.session_id = llmSessionId
  1217. }
  1218. let aiReplyContent = ''
  1219. let aiMsg = null
  1220. this.abortStreamRequest()
  1221. this.freezeFeedScrollTopForStream()
  1222. this.sending = true
  1223. this.stickToBottom = true
  1224. try {
  1225. const streamResult = await sendChatMessage(body, {
  1226. onReadyTask: (task) => {
  1227. this.streamRequestTask = task
  1228. },
  1229. onSessionId: (llmSid) => {
  1230. this.rememberLlmSessionId(llmSid)
  1231. },
  1232. onDelta: (fullText) => {
  1233. aiReplyContent = fullText
  1234. if (!aiMsg) {
  1235. aiMsg = this.appendLocalMessage(SENDER_ROLE_AI, MSG_TYPE_TEXT, fullText, {
  1236. streaming: true
  1237. })
  1238. this.requestPinScroll()
  1239. } else {
  1240. this.pushStreamText(aiMsg, fullText)
  1241. }
  1242. }
  1243. })
  1244. const llmSid = streamResult.sessionId || null
  1245. if (llmSid) {
  1246. this.rememberLlmSessionId(llmSid)
  1247. }
  1248. this.clearStreamRevealTimer()
  1249. aiReplyContent = (streamResult.content || aiReplyContent || '').trim() || this.$t('aiOnlineConsult.noContent')
  1250. if (!aiMsg) {
  1251. aiMsg = this.appendLocalMessage(SENDER_ROLE_AI, MSG_TYPE_TEXT, aiReplyContent)
  1252. } else {
  1253. this.$set(aiMsg, 'content', aiReplyContent)
  1254. }
  1255. if (aiMsg) {
  1256. this.$set(aiMsg, 'streaming', false)
  1257. }
  1258. } catch (err) {
  1259. let msg = this.$t('aiOnlineConsult.requestFailed')
  1260. if (err && err.message) {
  1261. msg = err.message
  1262. }
  1263. uni.showToast({ title: msg, icon: 'none', duration: 3000 })
  1264. aiReplyContent = this.$t('aiOnlineConsult.callFailed', { msg })
  1265. if (!aiMsg) {
  1266. aiMsg = this.appendLocalMessage(SENDER_ROLE_AI, MSG_TYPE_TEXT, aiReplyContent)
  1267. } else {
  1268. this.$set(aiMsg, 'content', aiReplyContent)
  1269. this.$set(aiMsg, 'streaming', false)
  1270. }
  1271. } finally {
  1272. this.clearStreamRevealTimer()
  1273. this.streamRequestTask = null
  1274. this.sending = false
  1275. this.releaseFeedScrollTopFrozen()
  1276. if (aiMsg && aiMsg.streaming) {
  1277. this.$set(aiMsg, 'streaming', false)
  1278. }
  1279. this.$nextTick(() => this.scheduleScrollToBottom())
  1280. }
  1281. await this.persistConsultExchange(persistBody, (aiReplyContent || '').trim())
  1282. },
  1283. validateMediaFile(filePath, fileName, kind) {
  1284. const rule = MEDIA_RULES[kind]
  1285. const ext = extOf(fileName || filePath)
  1286. if (!rule.exts.includes(ext)) {
  1287. uni.showToast({ title: this.$t('aiOnlineConsult.' + rule.errFmt), icon: 'none' })
  1288. return false
  1289. }
  1290. if ((fileName || filePath).includes(',')) {
  1291. uni.showToast({ title: this.$t('aiOnlineConsult.errComma'), icon: 'none' })
  1292. return false
  1293. }
  1294. return true
  1295. },
  1296. checkFileSize(filePath, kind) {
  1297. const rule = MEDIA_RULES[kind]
  1298. return new Promise((resolve) => {
  1299. uni.getFileInfo({
  1300. filePath,
  1301. success: (res) => {
  1302. if (res.size / 1024 / 1024 >= rule.maxMb) {
  1303. uni.showToast({ title: this.$t('aiOnlineConsult.' + rule.errMb), icon: 'none' })
  1304. resolve(false)
  1305. return
  1306. }
  1307. resolve(true)
  1308. },
  1309. fail: () => resolve(true)
  1310. })
  1311. })
  1312. },
  1313. /** 语音:选完即上传并发送(与 PC 端上传语音一致,不走待发送预览) */
  1314. async sendVoiceImmediately(filePath, fileName, nativeFile, mediaDuration) {
  1315. if (!this.consultSessionIdForApi() || this.sending) return
  1316. uni.showLoading({ title: this.$t('aiOnlineConsult.uploading'), mask: true })
  1317. try {
  1318. const url = await uploadFile(filePath, nativeFile)
  1319. await this.sendViaLlm({
  1320. msgType: MSG_TYPE_VOICE,
  1321. content: url,
  1322. mediaDuration: mediaDuration != null ? mediaDuration : undefined
  1323. })
  1324. } catch (e) {
  1325. uni.showToast({ title: this.$t('aiOnlineConsult.uploadFail'), icon: 'none' })
  1326. } finally {
  1327. uni.hideLoading()
  1328. }
  1329. },
  1330. pickImage() {
  1331. uni.chooseImage({
  1332. count: 1,
  1333. sizeType: ['compressed'],
  1334. sourceType: ['album', 'camera'],
  1335. success: async (res) => {
  1336. const path = res.tempFilePaths && res.tempFilePaths[0]
  1337. if (!path) return
  1338. const name = (res.tempFiles && res.tempFiles[0] && res.tempFiles[0].name) || path
  1339. if (!this.validateMediaFile(path, name, 'image')) return
  1340. if (!(await this.checkFileSize(path, 'image'))) return
  1341. this.setPendingAttachment({
  1342. kind: 'image',
  1343. msgType: MSG_TYPE_IMAGE,
  1344. name,
  1345. localPath: path
  1346. })
  1347. },
  1348. fail: () => {
  1349. uni.showToast({ title: this.$t('aiAssistantPage.imagePickFail'), icon: 'none' })
  1350. }
  1351. })
  1352. },
  1353. pickVideo() {
  1354. uni.chooseVideo({
  1355. sourceType: ['album', 'camera'],
  1356. maxDuration: 60,
  1357. success: async (res) => {
  1358. const path = res.tempFilePath
  1359. if (!path) return
  1360. const name = path
  1361. if (!this.validateMediaFile(path, name, 'video')) return
  1362. if (!(await this.checkFileSize(path, 'video'))) return
  1363. this.setPendingAttachment({
  1364. kind: 'video',
  1365. msgType: MSG_TYPE_VIDEO,
  1366. name,
  1367. localPath: path,
  1368. poster: res.thumbTempFilePath || '',
  1369. mediaDuration: res.duration ? Math.round(res.duration) : undefined
  1370. })
  1371. },
  1372. fail: () => {
  1373. uni.showToast({ title: this.$t('aiAssistantPage.videoPickFail'), icon: 'none' })
  1374. }
  1375. })
  1376. },
  1377. pickVoice() {
  1378. // #ifdef H5
  1379. this.pickVoiceH5()
  1380. // #endif
  1381. // #ifndef H5
  1382. if (typeof uni.chooseFile === 'function') {
  1383. uni.chooseFile({
  1384. count: 1,
  1385. extension: ['.mp3', '.m4a', '.wav'],
  1386. success: async (res) => {
  1387. const f = res.tempFiles && res.tempFiles[0]
  1388. if (!f || !f.path) return
  1389. if (!this.validateMediaFile(f.path, f.name || f.path, 'voice')) return
  1390. if (!(await this.checkFileSize(f.path, 'voice'))) return
  1391. this.sendVoiceImmediately(f.path, f.name || f.path, null, undefined)
  1392. },
  1393. fail: () => {
  1394. uni.showToast({ title: this.$t('aiAssistantPage.recordUnsupported'), icon: 'none' })
  1395. }
  1396. })
  1397. } else {
  1398. uni.showToast({ title: this.$t('aiAssistantPage.recordUnsupported'), icon: 'none' })
  1399. }
  1400. // #endif
  1401. },
  1402. pickVoiceH5() {
  1403. const input = document.createElement('input')
  1404. input.type = 'file'
  1405. input.accept = '.mp3,.m4a,.wav,audio/*'
  1406. input.style.display = 'none'
  1407. input.onchange = async (e) => {
  1408. const file = e.target && e.target.files && e.target.files[0]
  1409. if (!file) return
  1410. if (!this.validateMediaFile(file.name, file.name, 'voice')) return
  1411. if (file.size / 1024 / 1024 >= MEDIA_RULES.voice.maxMb) {
  1412. uni.showToast({ title: this.$t('aiOnlineConsult.errVoiceMb'), icon: 'none' })
  1413. return
  1414. }
  1415. this.sendVoiceImmediately('', file.name, file, undefined)
  1416. }
  1417. document.body.appendChild(input)
  1418. input.click()
  1419. setTimeout(() => {
  1420. if (input.parentNode) {
  1421. input.parentNode.removeChild(input)
  1422. }
  1423. }, 1000)
  1424. },
  1425. previewImage(path) {
  1426. const url = mediaUrl(path)
  1427. if (url) {
  1428. uni.previewImage({ urls: [url] })
  1429. }
  1430. },
  1431. stopVoice() {
  1432. if (this.innerAudio) {
  1433. this.innerAudio.stop()
  1434. this.innerAudio.destroy()
  1435. this.innerAudio = null
  1436. }
  1437. this.playingVoiceId = null
  1438. },
  1439. toggleVoice(m) {
  1440. if (!m || !m.content) return
  1441. if (this.playingVoiceId === m.id) {
  1442. this.stopVoice()
  1443. return
  1444. }
  1445. this.stopVoice()
  1446. const audio = uni.createInnerAudioContext()
  1447. audio.src = mediaUrl(m.content)
  1448. audio.onEnded(() => this.stopVoice())
  1449. audio.onError(() => {
  1450. uni.showToast({ title: this.$t('aiOnlineConsult.voicePlayFail'), icon: 'none' })
  1451. this.stopVoice()
  1452. })
  1453. this.innerAudio = audio
  1454. this.playingVoiceId = m.id
  1455. audio.play()
  1456. }
  1457. }
  1458. }
  1459. </script>
  1460. <style lang="scss" scoped>
  1461. @import '@/styles/morandi.scss';
  1462. @import '@/styles/tab-page.scss';
  1463. .assistant-page {
  1464. display: flex;
  1465. flex-direction: column;
  1466. min-width: 0;
  1467. min-height: 100vh;
  1468. height: 100vh;
  1469. overflow: hidden;
  1470. box-sizing: border-box;
  1471. background: $morandi-bg-page;
  1472. }
  1473. .assistant-disclaimer {
  1474. flex-shrink: 0;
  1475. display: flex;
  1476. flex-direction: column;
  1477. gap: 8rpx;
  1478. padding: 16rpx 20rpx;
  1479. background: #fffbeb;
  1480. border-bottom: 1rpx solid #fde68a;
  1481. }
  1482. .assistant-disclaimer__tag {
  1483. font-size: 24rpx;
  1484. font-weight: 600;
  1485. color: #b45309;
  1486. }
  1487. .assistant-disclaimer__txt {
  1488. font-size: 22rpx;
  1489. color: #92400e;
  1490. line-height: 1.45;
  1491. }
  1492. .assistant-feed {
  1493. flex: 1 1 0;
  1494. min-height: 0;
  1495. min-width: 0;
  1496. width: 100%;
  1497. box-sizing: border-box;
  1498. background: $morandi-feed;
  1499. }
  1500. /* #ifdef H5 */
  1501. .assistant-feed ::v-deep .uni-scroll-view,
  1502. .assistant-feed ::v-deep .uni-scroll-view-content {
  1503. height: 100% !important;
  1504. }
  1505. /* #endif */
  1506. .assistant-feed__inner {
  1507. display: flex;
  1508. flex-direction: column;
  1509. gap: 16rpx;
  1510. min-width: 0;
  1511. padding: 16rpx 16rpx 24rpx;
  1512. padding-bottom: calc(340rpx + env(safe-area-inset-bottom));
  1513. box-sizing: border-box;
  1514. }
  1515. .assistant-feed__inner--pending {
  1516. padding-bottom: calc(460rpx + env(safe-area-inset-bottom));
  1517. }
  1518. .assistant-feed__tail {
  1519. height: 1px;
  1520. width: 100%;
  1521. }
  1522. .feed-hint,
  1523. .feed-empty {
  1524. padding: 16rpx 0;
  1525. display: flex;
  1526. justify-content: center;
  1527. }
  1528. .feed-hint__txt,
  1529. .feed-empty__txt {
  1530. font-size: 24rpx;
  1531. color: $morandi-text-muted;
  1532. }
  1533. .chat-date {
  1534. display: flex;
  1535. justify-content: center;
  1536. padding: 8rpx 0;
  1537. }
  1538. .chat-date__txt {
  1539. font-size: 22rpx;
  1540. color: $morandi-text-soft;
  1541. padding: 6rpx 20rpx;
  1542. border-radius: 999rpx;
  1543. background: rgba(255, 255, 255, 0.6);
  1544. }
  1545. .bubble-row {
  1546. display: flex;
  1547. flex-direction: row;
  1548. align-items: flex-end;
  1549. gap: 12rpx;
  1550. width: 100%;
  1551. min-width: 0;
  1552. }
  1553. .bubble-row--bot {
  1554. justify-content: flex-start;
  1555. }
  1556. .bubble-row--user {
  1557. justify-content: flex-end;
  1558. }
  1559. .bubble-avatar {
  1560. flex-shrink: 0;
  1561. width: 56rpx;
  1562. height: 56rpx;
  1563. border-radius: 50%;
  1564. display: flex;
  1565. align-items: center;
  1566. justify-content: center;
  1567. }
  1568. .bubble-avatar--ai {
  1569. background: rgba(34, 197, 94, 0.15);
  1570. }
  1571. .bubble-avatar--user {
  1572. background: rgba(34, 197, 94, 0.22);
  1573. }
  1574. .bubble {
  1575. display: flex;
  1576. flex-direction: column;
  1577. min-width: 0;
  1578. max-width: 72%;
  1579. padding: 16rpx 18rpx;
  1580. border-radius: 16rpx;
  1581. gap: 8rpx;
  1582. box-sizing: border-box;
  1583. }
  1584. .bubble--bot {
  1585. background: $morandi-bg-card-inner;
  1586. border: 1rpx solid $morandi-border-soft;
  1587. }
  1588. .bubble--user {
  1589. background: #bbf7d0;
  1590. border: 1rpx solid #86efac;
  1591. }
  1592. .bubble--thinking {
  1593. min-width: 120rpx;
  1594. }
  1595. .bubble__who {
  1596. font-size: 22rpx;
  1597. font-weight: 600;
  1598. color: $morandi-text-muted;
  1599. }
  1600. .bubble--user .bubble__who {
  1601. color: #166534;
  1602. }
  1603. .bubble__txt {
  1604. font-size: 28rpx;
  1605. line-height: 1.5;
  1606. word-break: break-word;
  1607. overflow-wrap: break-word;
  1608. max-width: 100%;
  1609. min-width: 0;
  1610. color: $morandi-text;
  1611. }
  1612. .bubble__rich {
  1613. display: block;
  1614. width: 100%;
  1615. min-width: 0;
  1616. max-width: 100%;
  1617. overflow: visible;
  1618. box-sizing: border-box;
  1619. }
  1620. .bubble--user .bubble__rich {
  1621. color: #166534;
  1622. }
  1623. .bubble--bot .bubble__rich {
  1624. color: $morandi-text;
  1625. }
  1626. .bubble__img {
  1627. display: block;
  1628. max-width: 360rpx;
  1629. border-radius: 12rpx;
  1630. }
  1631. .bubble__video {
  1632. width: 100%;
  1633. max-width: 360rpx;
  1634. min-height: 200rpx;
  1635. border-radius: 12rpx;
  1636. }
  1637. .bubble__time {
  1638. font-size: 20rpx;
  1639. color: $morandi-text-soft;
  1640. align-self: flex-end;
  1641. }
  1642. .thinking-status {
  1643. display: flex;
  1644. flex-direction: row;
  1645. align-items: center;
  1646. gap: 16rpx;
  1647. margin-top: 8rpx;
  1648. }
  1649. .thinking-txt {
  1650. font-size: 26rpx;
  1651. color: $morandi-text-muted;
  1652. }
  1653. .thinking-dots {
  1654. display: flex;
  1655. flex-direction: row;
  1656. align-items: center;
  1657. gap: 8rpx;
  1658. }
  1659. .thinking-dots__dot {
  1660. width: 12rpx;
  1661. height: 12rpx;
  1662. border-radius: 50%;
  1663. background: #22c55e;
  1664. animation: ai-thinking-dot 1.05s ease-in-out infinite both;
  1665. &:nth-child(2) {
  1666. animation-delay: 0.18s;
  1667. }
  1668. &:nth-child(3) {
  1669. animation-delay: 0.36s;
  1670. }
  1671. }
  1672. @keyframes ai-thinking-dot {
  1673. 0%,
  1674. 80%,
  1675. 100% {
  1676. opacity: 0.35;
  1677. transform: scale(0.85);
  1678. }
  1679. 40% {
  1680. opacity: 1;
  1681. transform: scale(1);
  1682. }
  1683. }
  1684. .bubble__txt--stream {
  1685. white-space: pre-wrap;
  1686. word-break: break-word;
  1687. }
  1688. .voice-msg {
  1689. display: flex;
  1690. flex-direction: row;
  1691. align-items: center;
  1692. gap: 12rpx;
  1693. padding: 12rpx 16rpx;
  1694. border-radius: 12rpx;
  1695. background: $morandi-bg-muted;
  1696. }
  1697. .voice-msg--on {
  1698. background: rgba(34, 197, 94, 0.2);
  1699. }
  1700. .voice-msg__dur {
  1701. font-size: 28rpx;
  1702. font-weight: 600;
  1703. color: $morandi-text;
  1704. }
  1705. .voice-msg__label {
  1706. font-size: 24rpx;
  1707. color: $morandi-text-muted;
  1708. }
  1709. .assistant-composer {
  1710. position: fixed;
  1711. left: 0;
  1712. right: 0;
  1713. bottom: 0;
  1714. z-index: 200;
  1715. display: flex;
  1716. flex-direction: column;
  1717. gap: 12rpx;
  1718. min-width: 0;
  1719. padding: 12rpx 16rpx;
  1720. padding-bottom: calc(12rpx + env(safe-area-inset-bottom));
  1721. background: $morandi-composer;
  1722. border-top: 1rpx solid $morandi-border-soft;
  1723. box-shadow: 0 -8rpx 24rpx rgba(74, 69, 66, 0.06);
  1724. }
  1725. .composer-tools {
  1726. display: flex;
  1727. flex-direction: row;
  1728. flex-wrap: nowrap;
  1729. align-items: center;
  1730. width: 100%;
  1731. min-width: 0;
  1732. gap: 10rpx;
  1733. box-sizing: border-box;
  1734. }
  1735. .composer-model {
  1736. flex: 1;
  1737. min-width: 0;
  1738. height: 64rpx;
  1739. display: flex;
  1740. flex-direction: row;
  1741. align-items: center;
  1742. justify-content: center;
  1743. gap: 6rpx;
  1744. padding: 0 16rpx;
  1745. border-radius: 999rpx;
  1746. background: $morandi-bg-card-inner;
  1747. border: 1rpx solid $morandi-border-soft;
  1748. box-sizing: border-box;
  1749. }
  1750. .composer-model__txt {
  1751. flex: 1;
  1752. min-width: 0;
  1753. font-size: 24rpx;
  1754. line-height: 1.2;
  1755. color: #16a34a;
  1756. font-weight: 600;
  1757. overflow: hidden;
  1758. text-overflow: ellipsis;
  1759. white-space: nowrap;
  1760. }
  1761. .composer-icon-btn {
  1762. flex-shrink: 0;
  1763. width: 64rpx;
  1764. height: 64rpx;
  1765. display: flex;
  1766. align-items: center;
  1767. justify-content: center;
  1768. border-radius: 12rpx;
  1769. background: $morandi-bg-card-inner;
  1770. border: 1rpx solid $morandi-border-soft;
  1771. box-sizing: border-box;
  1772. }
  1773. .assistant-composer--has-pending {
  1774. gap: 10rpx;
  1775. }
  1776. .composer-pending {
  1777. width: 100%;
  1778. white-space: nowrap;
  1779. }
  1780. .composer-pending__track {
  1781. display: inline-flex;
  1782. flex-direction: row;
  1783. align-items: center;
  1784. gap: 12rpx;
  1785. padding: 4rpx 0;
  1786. }
  1787. .composer-pending__item {
  1788. position: relative;
  1789. flex-shrink: 0;
  1790. width: 120rpx;
  1791. height: 120rpx;
  1792. border-radius: 12rpx;
  1793. overflow: hidden;
  1794. background: $morandi-bg-muted;
  1795. border: 1rpx solid $morandi-border-soft;
  1796. }
  1797. .composer-pending__thumb {
  1798. width: 100%;
  1799. height: 100%;
  1800. display: block;
  1801. }
  1802. .composer-pending__thumb--video {
  1803. position: relative;
  1804. width: 100%;
  1805. height: 100%;
  1806. }
  1807. .composer-pending__video-mask {
  1808. position: absolute;
  1809. left: 0;
  1810. top: 0;
  1811. right: 0;
  1812. bottom: 0;
  1813. display: flex;
  1814. align-items: center;
  1815. justify-content: center;
  1816. background: rgba(0, 0, 0, 0.35);
  1817. }
  1818. .composer-pending__thumb--voice {
  1819. display: flex;
  1820. flex-direction: column;
  1821. align-items: center;
  1822. justify-content: center;
  1823. gap: 8rpx;
  1824. padding: 8rpx;
  1825. box-sizing: border-box;
  1826. }
  1827. .composer-pending__voice-name {
  1828. font-size: 18rpx;
  1829. color: $morandi-text-muted;
  1830. max-width: 100%;
  1831. overflow: hidden;
  1832. text-overflow: ellipsis;
  1833. white-space: nowrap;
  1834. }
  1835. .composer-pending__close {
  1836. position: absolute;
  1837. top: 0;
  1838. right: 0;
  1839. width: 40rpx;
  1840. height: 40rpx;
  1841. display: flex;
  1842. align-items: center;
  1843. justify-content: center;
  1844. background: rgba(0, 0, 0, 0.5);
  1845. border-bottom-left-radius: 12rpx;
  1846. z-index: 2;
  1847. }
  1848. .composer-input-row {
  1849. display: flex;
  1850. flex-direction: row;
  1851. flex-wrap: nowrap;
  1852. align-items: flex-end;
  1853. width: 100%;
  1854. gap: 12rpx;
  1855. min-width: 0;
  1856. box-sizing: border-box;
  1857. }
  1858. .composer-input-shell {
  1859. flex: 1;
  1860. min-width: 0;
  1861. min-height: 72rpx;
  1862. max-height: 200rpx;
  1863. padding: 10rpx 16rpx;
  1864. border-radius: 12rpx;
  1865. background: $morandi-bg-card-inner;
  1866. border: 1rpx solid $morandi-border-soft;
  1867. box-sizing: border-box;
  1868. }
  1869. .composer-textarea {
  1870. width: 100%;
  1871. min-height: 48rpx;
  1872. max-height: 180rpx;
  1873. font-size: 28rpx;
  1874. line-height: 1.45;
  1875. color: $morandi-text;
  1876. }
  1877. .composer-textarea-ph {
  1878. color: $morandi-text-muted;
  1879. font-size: 26rpx;
  1880. }
  1881. .composer-send {
  1882. flex-shrink: 0;
  1883. padding: 18rpx 24rpx;
  1884. border-radius: 12rpx;
  1885. background: linear-gradient(90deg, #16a34a, #22c55e);
  1886. box-sizing: border-box;
  1887. }
  1888. .composer-send--disabled {
  1889. opacity: 0.5;
  1890. }
  1891. .composer-send__txt {
  1892. font-size: 26rpx;
  1893. font-weight: 600;
  1894. color: #fff;
  1895. white-space: nowrap;
  1896. }
  1897. </style>