西藏巴青项目

index.vue 56KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990
  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, costTime) {
  1094. this.pendingPersist = {
  1095. consultSessionId,
  1096. persistBody: { ...persistBody },
  1097. aiReplyContent,
  1098. llmSessionId: llmSessionId != null ? llmSessionId : null,
  1099. costTime: costTime != null ? costTime : null
  1100. }
  1101. },
  1102. flushPendingPersist() {
  1103. const pending = this.pendingPersist
  1104. if (!pending || !pending.consultSessionId || !pending.persistBody || !pending.aiReplyContent) {
  1105. return Promise.resolve()
  1106. }
  1107. return sendAiConsultMessage(pending.consultSessionId, {
  1108. ...pending.persistBody,
  1109. aiReplyContent: pending.aiReplyContent,
  1110. realSessionId: pending.llmSessionId != null ? pending.llmSessionId : null,
  1111. costTime: pending.costTime != null ? pending.costTime : undefined
  1112. })
  1113. .then(() => {
  1114. this.pendingPersist = null
  1115. })
  1116. .catch(() => {})
  1117. },
  1118. persistConsultExchange(persistBody, aiReplyContent, costTime) {
  1119. const reply = (aiReplyContent || '').trim()
  1120. const consultSessionId = this.consultSessionIdForApi()
  1121. if (!consultSessionId || !persistBody || !reply) {
  1122. return Promise.resolve(true)
  1123. }
  1124. const llmSessionId = this.resolveLlmSessionId()
  1125. return sendAiConsultMessage(consultSessionId, {
  1126. ...persistBody,
  1127. aiReplyContent: reply,
  1128. realSessionId: llmSessionId || null,
  1129. costTime: costTime != null ? costTime : undefined
  1130. })
  1131. .then((res) => {
  1132. this.mergePersistResult(res.data, reply)
  1133. if (
  1134. this.pendingPersist &&
  1135. this.pendingPersist.consultSessionId === consultSessionId &&
  1136. this.pendingPersist.aiReplyContent === reply
  1137. ) {
  1138. this.pendingPersist = null
  1139. }
  1140. return true
  1141. })
  1142. .catch((err) => {
  1143. this.queuePendingPersist(consultSessionId, persistBody, reply, llmSessionId, costTime)
  1144. const msg = (err && err.message) || this.$t('aiOnlineConsult.saveSessionFailed')
  1145. uni.showToast({ title: msg, icon: 'none' })
  1146. return false
  1147. })
  1148. },
  1149. async handleSend() {
  1150. if (this.sendDisabled) return
  1151. const text = (this.draft || '').trim()
  1152. if (!text && !this.pendingAttachments.length) {
  1153. uni.showToast({ title: this.$t('aiOnlineConsult.inputOrAttach'), icon: 'none' })
  1154. return
  1155. }
  1156. if (this.pendingAttachments.some((a) => !a.url)) {
  1157. uni.showLoading({ title: this.$t('aiOnlineConsult.uploading'), mask: true })
  1158. try {
  1159. await this.uploadAllPending()
  1160. } catch (e) {
  1161. uni.showToast({ title: this.$t('aiOnlineConsult.uploadFail'), icon: 'none' })
  1162. return
  1163. } finally {
  1164. uni.hideLoading()
  1165. }
  1166. }
  1167. const atts = this.pendingAttachments
  1168. const img = atts.find((a) => a.kind === 'image' && a.url)
  1169. const video = atts.find((a) => a.kind === 'video' && a.url)
  1170. if (img) {
  1171. await this.sendViaLlm({ msgType: MSG_TYPE_IMAGE, content: img.url })
  1172. return
  1173. }
  1174. if (video) {
  1175. await this.sendViaLlm({
  1176. msgType: MSG_TYPE_VIDEO,
  1177. content: video.url,
  1178. mediaDuration: video.mediaDuration
  1179. })
  1180. return
  1181. }
  1182. await this.sendViaLlm({ msgType: MSG_TYPE_TEXT, content: text })
  1183. },
  1184. async sendViaLlm(payload) {
  1185. if (!this.consultSessionIdForApi() || this.sending) return
  1186. let userContent
  1187. if (payload && payload.msgType && payload.msgType !== MSG_TYPE_TEXT) {
  1188. userContent = resolvePayloadUserContent(payload, this.draft)
  1189. } else {
  1190. userContent = buildUserContentForLlm((payload && payload.content) || this.draft, this.pendingAttachments)
  1191. }
  1192. if (!userContent) {
  1193. uni.showToast({ title: this.$t('aiOnlineConsult.inputOrAttach'), icon: 'none' })
  1194. return
  1195. }
  1196. const msgType = (payload && payload.msgType) || MSG_TYPE_TEXT
  1197. const draftText = (this.draft || '').trim()
  1198. const pendingSnapshot = this.pendingAttachments.slice()
  1199. const displayContent =
  1200. msgType !== MSG_TYPE_TEXT
  1201. ? payload.content
  1202. : typeof userContent === 'string'
  1203. ? userContent
  1204. : pendingSnapshot.find((a) => a.kind === 'image' && a.url)
  1205. ? pendingSnapshot.find((a) => a.kind === 'image').url
  1206. : userContent
  1207. const persistBody = buildPersistSendBody(msgType, payload, draftText, pendingSnapshot)
  1208. this.appendLocalMessage(SENDER_ROLE_USER, msgType, displayContent)
  1209. this.clearComposer()
  1210. this.stickToBottom = true
  1211. this.pinScrollToBottom(true)
  1212. const llmSessionId = this.resolveLlmSessionId()
  1213. const body = {
  1214. model: this.model,
  1215. messages: buildMessagesForLlm(this.messages, llmSessionId),
  1216. user: this.llmUserId
  1217. }
  1218. if (llmSessionId) {
  1219. body.session_id = llmSessionId
  1220. }
  1221. let aiReplyContent = ''
  1222. let aiMsg = null
  1223. let costTime = null
  1224. this.abortStreamRequest()
  1225. this.freezeFeedScrollTopForStream()
  1226. this.sending = true
  1227. this.stickToBottom = true
  1228. try {
  1229. const streamResult = await sendChatMessage(body, {
  1230. onReadyTask: (task) => {
  1231. this.streamRequestTask = task
  1232. },
  1233. onSessionId: (llmSid) => {
  1234. this.rememberLlmSessionId(llmSid)
  1235. },
  1236. onDelta: (fullText) => {
  1237. aiReplyContent = fullText
  1238. if (!aiMsg) {
  1239. aiMsg = this.appendLocalMessage(SENDER_ROLE_AI, MSG_TYPE_TEXT, fullText, {
  1240. streaming: true
  1241. })
  1242. this.requestPinScroll()
  1243. } else {
  1244. this.pushStreamText(aiMsg, fullText)
  1245. }
  1246. }
  1247. })
  1248. const llmSid = streamResult.sessionId || null
  1249. if (llmSid) {
  1250. this.rememberLlmSessionId(llmSid)
  1251. }
  1252. costTime = streamResult.durationMs != null ? streamResult.durationMs : null
  1253. this.clearStreamRevealTimer()
  1254. aiReplyContent = (streamResult.content || aiReplyContent || '').trim() || this.$t('aiOnlineConsult.noContent')
  1255. if (!aiMsg) {
  1256. aiMsg = this.appendLocalMessage(SENDER_ROLE_AI, MSG_TYPE_TEXT, aiReplyContent)
  1257. } else {
  1258. this.$set(aiMsg, 'content', aiReplyContent)
  1259. }
  1260. if (aiMsg) {
  1261. this.$set(aiMsg, 'streaming', false)
  1262. }
  1263. } catch (err) {
  1264. let msg = this.$t('aiOnlineConsult.requestFailed')
  1265. if (err && err.message) {
  1266. msg = err.message
  1267. }
  1268. uni.showToast({ title: msg, icon: 'none', duration: 3000 })
  1269. aiReplyContent = this.$t('aiOnlineConsult.callFailed', { msg })
  1270. if (!aiMsg) {
  1271. aiMsg = this.appendLocalMessage(SENDER_ROLE_AI, MSG_TYPE_TEXT, aiReplyContent)
  1272. } else {
  1273. this.$set(aiMsg, 'content', aiReplyContent)
  1274. this.$set(aiMsg, 'streaming', false)
  1275. }
  1276. } finally {
  1277. this.clearStreamRevealTimer()
  1278. this.streamRequestTask = null
  1279. this.sending = false
  1280. this.releaseFeedScrollTopFrozen()
  1281. if (aiMsg && aiMsg.streaming) {
  1282. this.$set(aiMsg, 'streaming', false)
  1283. }
  1284. this.$nextTick(() => this.scheduleScrollToBottom())
  1285. }
  1286. await this.persistConsultExchange(persistBody, (aiReplyContent || '').trim(), costTime)
  1287. },
  1288. validateMediaFile(filePath, fileName, kind) {
  1289. const rule = MEDIA_RULES[kind]
  1290. const ext = extOf(fileName || filePath)
  1291. if (!rule.exts.includes(ext)) {
  1292. uni.showToast({ title: this.$t('aiOnlineConsult.' + rule.errFmt), icon: 'none' })
  1293. return false
  1294. }
  1295. if ((fileName || filePath).includes(',')) {
  1296. uni.showToast({ title: this.$t('aiOnlineConsult.errComma'), icon: 'none' })
  1297. return false
  1298. }
  1299. return true
  1300. },
  1301. checkFileSize(filePath, kind) {
  1302. const rule = MEDIA_RULES[kind]
  1303. return new Promise((resolve) => {
  1304. uni.getFileInfo({
  1305. filePath,
  1306. success: (res) => {
  1307. if (res.size / 1024 / 1024 >= rule.maxMb) {
  1308. uni.showToast({ title: this.$t('aiOnlineConsult.' + rule.errMb), icon: 'none' })
  1309. resolve(false)
  1310. return
  1311. }
  1312. resolve(true)
  1313. },
  1314. fail: () => resolve(true)
  1315. })
  1316. })
  1317. },
  1318. /** 语音:选完即上传并发送(与 PC 端上传语音一致,不走待发送预览) */
  1319. async sendVoiceImmediately(filePath, fileName, nativeFile, mediaDuration) {
  1320. if (!this.consultSessionIdForApi() || this.sending) return
  1321. uni.showLoading({ title: this.$t('aiOnlineConsult.uploading'), mask: true })
  1322. try {
  1323. const url = await uploadFile(filePath, nativeFile)
  1324. await this.sendViaLlm({
  1325. msgType: MSG_TYPE_VOICE,
  1326. content: url,
  1327. mediaDuration: mediaDuration != null ? mediaDuration : undefined
  1328. })
  1329. } catch (e) {
  1330. uni.showToast({ title: this.$t('aiOnlineConsult.uploadFail'), icon: 'none' })
  1331. } finally {
  1332. uni.hideLoading()
  1333. }
  1334. },
  1335. pickImage() {
  1336. uni.chooseImage({
  1337. count: 1,
  1338. sizeType: ['compressed'],
  1339. sourceType: ['album', 'camera'],
  1340. success: async (res) => {
  1341. const path = res.tempFilePaths && res.tempFilePaths[0]
  1342. if (!path) return
  1343. const name = (res.tempFiles && res.tempFiles[0] && res.tempFiles[0].name) || path
  1344. if (!this.validateMediaFile(path, name, 'image')) return
  1345. if (!(await this.checkFileSize(path, 'image'))) return
  1346. this.setPendingAttachment({
  1347. kind: 'image',
  1348. msgType: MSG_TYPE_IMAGE,
  1349. name,
  1350. localPath: path
  1351. })
  1352. },
  1353. fail: () => {
  1354. uni.showToast({ title: this.$t('aiAssistantPage.imagePickFail'), icon: 'none' })
  1355. }
  1356. })
  1357. },
  1358. pickVideo() {
  1359. uni.chooseVideo({
  1360. sourceType: ['album', 'camera'],
  1361. maxDuration: 60,
  1362. success: async (res) => {
  1363. const path = res.tempFilePath
  1364. if (!path) return
  1365. const name = path
  1366. if (!this.validateMediaFile(path, name, 'video')) return
  1367. if (!(await this.checkFileSize(path, 'video'))) return
  1368. this.setPendingAttachment({
  1369. kind: 'video',
  1370. msgType: MSG_TYPE_VIDEO,
  1371. name,
  1372. localPath: path,
  1373. poster: res.thumbTempFilePath || '',
  1374. mediaDuration: res.duration ? Math.round(res.duration) : undefined
  1375. })
  1376. },
  1377. fail: () => {
  1378. uni.showToast({ title: this.$t('aiAssistantPage.videoPickFail'), icon: 'none' })
  1379. }
  1380. })
  1381. },
  1382. pickVoice() {
  1383. // #ifdef H5
  1384. this.pickVoiceH5()
  1385. // #endif
  1386. // #ifndef H5
  1387. if (typeof uni.chooseFile === 'function') {
  1388. uni.chooseFile({
  1389. count: 1,
  1390. extension: ['.mp3', '.m4a', '.wav'],
  1391. success: async (res) => {
  1392. const f = res.tempFiles && res.tempFiles[0]
  1393. if (!f || !f.path) return
  1394. if (!this.validateMediaFile(f.path, f.name || f.path, 'voice')) return
  1395. if (!(await this.checkFileSize(f.path, 'voice'))) return
  1396. this.sendVoiceImmediately(f.path, f.name || f.path, null, undefined)
  1397. },
  1398. fail: () => {
  1399. uni.showToast({ title: this.$t('aiAssistantPage.recordUnsupported'), icon: 'none' })
  1400. }
  1401. })
  1402. } else {
  1403. uni.showToast({ title: this.$t('aiAssistantPage.recordUnsupported'), icon: 'none' })
  1404. }
  1405. // #endif
  1406. },
  1407. pickVoiceH5() {
  1408. const input = document.createElement('input')
  1409. input.type = 'file'
  1410. input.accept = '.mp3,.m4a,.wav,audio/*'
  1411. input.style.display = 'none'
  1412. input.onchange = async (e) => {
  1413. const file = e.target && e.target.files && e.target.files[0]
  1414. if (!file) return
  1415. if (!this.validateMediaFile(file.name, file.name, 'voice')) return
  1416. if (file.size / 1024 / 1024 >= MEDIA_RULES.voice.maxMb) {
  1417. uni.showToast({ title: this.$t('aiOnlineConsult.errVoiceMb'), icon: 'none' })
  1418. return
  1419. }
  1420. this.sendVoiceImmediately('', file.name, file, undefined)
  1421. }
  1422. document.body.appendChild(input)
  1423. input.click()
  1424. setTimeout(() => {
  1425. if (input.parentNode) {
  1426. input.parentNode.removeChild(input)
  1427. }
  1428. }, 1000)
  1429. },
  1430. previewImage(path) {
  1431. const url = mediaUrl(path)
  1432. if (url) {
  1433. uni.previewImage({ urls: [url] })
  1434. }
  1435. },
  1436. stopVoice() {
  1437. if (this.innerAudio) {
  1438. this.innerAudio.stop()
  1439. this.innerAudio.destroy()
  1440. this.innerAudio = null
  1441. }
  1442. this.playingVoiceId = null
  1443. },
  1444. toggleVoice(m) {
  1445. if (!m || !m.content) return
  1446. if (this.playingVoiceId === m.id) {
  1447. this.stopVoice()
  1448. return
  1449. }
  1450. this.stopVoice()
  1451. const audio = uni.createInnerAudioContext()
  1452. audio.src = mediaUrl(m.content)
  1453. audio.onEnded(() => this.stopVoice())
  1454. audio.onError(() => {
  1455. uni.showToast({ title: this.$t('aiOnlineConsult.voicePlayFail'), icon: 'none' })
  1456. this.stopVoice()
  1457. })
  1458. this.innerAudio = audio
  1459. this.playingVoiceId = m.id
  1460. audio.play()
  1461. }
  1462. }
  1463. }
  1464. </script>
  1465. <style lang="scss" scoped>
  1466. @import '@/styles/morandi.scss';
  1467. @import '@/styles/tab-page.scss';
  1468. .assistant-page {
  1469. display: flex;
  1470. flex-direction: column;
  1471. min-width: 0;
  1472. min-height: 100vh;
  1473. height: 100vh;
  1474. overflow: hidden;
  1475. box-sizing: border-box;
  1476. background: $morandi-bg-page;
  1477. }
  1478. .assistant-disclaimer {
  1479. flex-shrink: 0;
  1480. display: flex;
  1481. flex-direction: column;
  1482. gap: 8rpx;
  1483. padding: 16rpx 20rpx;
  1484. background: #fffbeb;
  1485. border-bottom: 1rpx solid #fde68a;
  1486. }
  1487. .assistant-disclaimer__tag {
  1488. font-size: 24rpx;
  1489. font-weight: 600;
  1490. color: #b45309;
  1491. }
  1492. .assistant-disclaimer__txt {
  1493. font-size: 22rpx;
  1494. color: #92400e;
  1495. line-height: 1.45;
  1496. }
  1497. .assistant-feed {
  1498. flex: 1 1 0;
  1499. min-height: 0;
  1500. min-width: 0;
  1501. width: 100%;
  1502. box-sizing: border-box;
  1503. background: $morandi-feed;
  1504. }
  1505. /* #ifdef H5 */
  1506. .assistant-feed ::v-deep .uni-scroll-view,
  1507. .assistant-feed ::v-deep .uni-scroll-view-content {
  1508. height: 100% !important;
  1509. }
  1510. /* #endif */
  1511. .assistant-feed__inner {
  1512. display: flex;
  1513. flex-direction: column;
  1514. gap: 16rpx;
  1515. min-width: 0;
  1516. padding: 16rpx 16rpx 24rpx;
  1517. padding-bottom: calc(340rpx + env(safe-area-inset-bottom));
  1518. box-sizing: border-box;
  1519. }
  1520. .assistant-feed__inner--pending {
  1521. padding-bottom: calc(460rpx + env(safe-area-inset-bottom));
  1522. }
  1523. .assistant-feed__tail {
  1524. height: 1px;
  1525. width: 100%;
  1526. }
  1527. .feed-hint,
  1528. .feed-empty {
  1529. padding: 16rpx 0;
  1530. display: flex;
  1531. justify-content: center;
  1532. }
  1533. .feed-hint__txt,
  1534. .feed-empty__txt {
  1535. font-size: 24rpx;
  1536. color: $morandi-text-muted;
  1537. }
  1538. .chat-date {
  1539. display: flex;
  1540. justify-content: center;
  1541. padding: 8rpx 0;
  1542. }
  1543. .chat-date__txt {
  1544. font-size: 22rpx;
  1545. color: $morandi-text-soft;
  1546. padding: 6rpx 20rpx;
  1547. border-radius: 999rpx;
  1548. background: rgba(255, 255, 255, 0.6);
  1549. }
  1550. .bubble-row {
  1551. display: flex;
  1552. flex-direction: row;
  1553. align-items: flex-end;
  1554. gap: 12rpx;
  1555. width: 100%;
  1556. min-width: 0;
  1557. }
  1558. .bubble-row--bot {
  1559. justify-content: flex-start;
  1560. }
  1561. .bubble-row--user {
  1562. justify-content: flex-end;
  1563. }
  1564. .bubble-avatar {
  1565. flex-shrink: 0;
  1566. width: 56rpx;
  1567. height: 56rpx;
  1568. border-radius: 50%;
  1569. display: flex;
  1570. align-items: center;
  1571. justify-content: center;
  1572. }
  1573. .bubble-avatar--ai {
  1574. background: rgba(34, 197, 94, 0.15);
  1575. }
  1576. .bubble-avatar--user {
  1577. background: rgba(34, 197, 94, 0.22);
  1578. }
  1579. .bubble {
  1580. display: flex;
  1581. flex-direction: column;
  1582. min-width: 0;
  1583. max-width: 72%;
  1584. padding: 16rpx 18rpx;
  1585. border-radius: 16rpx;
  1586. gap: 8rpx;
  1587. box-sizing: border-box;
  1588. }
  1589. .bubble--bot {
  1590. background: $morandi-bg-card-inner;
  1591. border: 1rpx solid $morandi-border-soft;
  1592. }
  1593. .bubble--user {
  1594. background: #bbf7d0;
  1595. border: 1rpx solid #86efac;
  1596. }
  1597. .bubble--thinking {
  1598. min-width: 120rpx;
  1599. }
  1600. .bubble__who {
  1601. font-size: 22rpx;
  1602. font-weight: 600;
  1603. color: $morandi-text-muted;
  1604. }
  1605. .bubble--user .bubble__who {
  1606. color: #166534;
  1607. }
  1608. .bubble__txt {
  1609. font-size: 28rpx;
  1610. line-height: 1.5;
  1611. word-break: break-word;
  1612. overflow-wrap: break-word;
  1613. max-width: 100%;
  1614. min-width: 0;
  1615. color: $morandi-text;
  1616. }
  1617. .bubble__rich {
  1618. display: block;
  1619. width: 100%;
  1620. min-width: 0;
  1621. max-width: 100%;
  1622. overflow: visible;
  1623. box-sizing: border-box;
  1624. }
  1625. .bubble--user .bubble__rich {
  1626. color: #166534;
  1627. }
  1628. .bubble--bot .bubble__rich {
  1629. color: $morandi-text;
  1630. }
  1631. .bubble__img {
  1632. display: block;
  1633. max-width: 360rpx;
  1634. border-radius: 12rpx;
  1635. }
  1636. .bubble__video {
  1637. width: 100%;
  1638. max-width: 360rpx;
  1639. min-height: 200rpx;
  1640. border-radius: 12rpx;
  1641. }
  1642. .bubble__time {
  1643. font-size: 20rpx;
  1644. color: $morandi-text-soft;
  1645. align-self: flex-end;
  1646. }
  1647. .thinking-status {
  1648. display: flex;
  1649. flex-direction: row;
  1650. align-items: center;
  1651. gap: 16rpx;
  1652. margin-top: 8rpx;
  1653. }
  1654. .thinking-txt {
  1655. font-size: 26rpx;
  1656. color: $morandi-text-muted;
  1657. }
  1658. .thinking-dots {
  1659. display: flex;
  1660. flex-direction: row;
  1661. align-items: center;
  1662. gap: 8rpx;
  1663. }
  1664. .thinking-dots__dot {
  1665. width: 12rpx;
  1666. height: 12rpx;
  1667. border-radius: 50%;
  1668. background: #22c55e;
  1669. animation: ai-thinking-dot 1.05s ease-in-out infinite both;
  1670. &:nth-child(2) {
  1671. animation-delay: 0.18s;
  1672. }
  1673. &:nth-child(3) {
  1674. animation-delay: 0.36s;
  1675. }
  1676. }
  1677. @keyframes ai-thinking-dot {
  1678. 0%,
  1679. 80%,
  1680. 100% {
  1681. opacity: 0.35;
  1682. transform: scale(0.85);
  1683. }
  1684. 40% {
  1685. opacity: 1;
  1686. transform: scale(1);
  1687. }
  1688. }
  1689. .bubble__txt--stream {
  1690. white-space: pre-wrap;
  1691. word-break: break-word;
  1692. }
  1693. .voice-msg {
  1694. display: flex;
  1695. flex-direction: row;
  1696. align-items: center;
  1697. gap: 12rpx;
  1698. padding: 12rpx 16rpx;
  1699. border-radius: 12rpx;
  1700. background: $morandi-bg-muted;
  1701. }
  1702. .voice-msg--on {
  1703. background: rgba(34, 197, 94, 0.2);
  1704. }
  1705. .voice-msg__dur {
  1706. font-size: 28rpx;
  1707. font-weight: 600;
  1708. color: $morandi-text;
  1709. }
  1710. .voice-msg__label {
  1711. font-size: 24rpx;
  1712. color: $morandi-text-muted;
  1713. }
  1714. .assistant-composer {
  1715. position: fixed;
  1716. left: 0;
  1717. right: 0;
  1718. bottom: 0;
  1719. z-index: 200;
  1720. display: flex;
  1721. flex-direction: column;
  1722. gap: 12rpx;
  1723. min-width: 0;
  1724. padding: 12rpx 16rpx;
  1725. padding-bottom: calc(12rpx + env(safe-area-inset-bottom));
  1726. background: $morandi-composer;
  1727. border-top: 1rpx solid $morandi-border-soft;
  1728. box-shadow: 0 -8rpx 24rpx rgba(74, 69, 66, 0.06);
  1729. }
  1730. .composer-tools {
  1731. display: flex;
  1732. flex-direction: row;
  1733. flex-wrap: nowrap;
  1734. align-items: center;
  1735. width: 100%;
  1736. min-width: 0;
  1737. gap: 10rpx;
  1738. box-sizing: border-box;
  1739. }
  1740. .composer-model {
  1741. flex: 1;
  1742. min-width: 0;
  1743. height: 64rpx;
  1744. display: flex;
  1745. flex-direction: row;
  1746. align-items: center;
  1747. justify-content: center;
  1748. gap: 6rpx;
  1749. padding: 0 16rpx;
  1750. border-radius: 999rpx;
  1751. background: $morandi-bg-card-inner;
  1752. border: 1rpx solid $morandi-border-soft;
  1753. box-sizing: border-box;
  1754. }
  1755. .composer-model__txt {
  1756. flex: 1;
  1757. min-width: 0;
  1758. font-size: 24rpx;
  1759. line-height: 1.2;
  1760. color: #16a34a;
  1761. font-weight: 600;
  1762. overflow: hidden;
  1763. text-overflow: ellipsis;
  1764. white-space: nowrap;
  1765. }
  1766. .composer-icon-btn {
  1767. flex-shrink: 0;
  1768. width: 64rpx;
  1769. height: 64rpx;
  1770. display: flex;
  1771. align-items: center;
  1772. justify-content: center;
  1773. border-radius: 12rpx;
  1774. background: $morandi-bg-card-inner;
  1775. border: 1rpx solid $morandi-border-soft;
  1776. box-sizing: border-box;
  1777. }
  1778. .assistant-composer--has-pending {
  1779. gap: 10rpx;
  1780. }
  1781. .composer-pending {
  1782. width: 100%;
  1783. white-space: nowrap;
  1784. }
  1785. .composer-pending__track {
  1786. display: inline-flex;
  1787. flex-direction: row;
  1788. align-items: center;
  1789. gap: 12rpx;
  1790. padding: 4rpx 0;
  1791. }
  1792. .composer-pending__item {
  1793. position: relative;
  1794. flex-shrink: 0;
  1795. width: 120rpx;
  1796. height: 120rpx;
  1797. border-radius: 12rpx;
  1798. overflow: hidden;
  1799. background: $morandi-bg-muted;
  1800. border: 1rpx solid $morandi-border-soft;
  1801. }
  1802. .composer-pending__thumb {
  1803. width: 100%;
  1804. height: 100%;
  1805. display: block;
  1806. }
  1807. .composer-pending__thumb--video {
  1808. position: relative;
  1809. width: 100%;
  1810. height: 100%;
  1811. }
  1812. .composer-pending__video-mask {
  1813. position: absolute;
  1814. left: 0;
  1815. top: 0;
  1816. right: 0;
  1817. bottom: 0;
  1818. display: flex;
  1819. align-items: center;
  1820. justify-content: center;
  1821. background: rgba(0, 0, 0, 0.35);
  1822. }
  1823. .composer-pending__thumb--voice {
  1824. display: flex;
  1825. flex-direction: column;
  1826. align-items: center;
  1827. justify-content: center;
  1828. gap: 8rpx;
  1829. padding: 8rpx;
  1830. box-sizing: border-box;
  1831. }
  1832. .composer-pending__voice-name {
  1833. font-size: 18rpx;
  1834. color: $morandi-text-muted;
  1835. max-width: 100%;
  1836. overflow: hidden;
  1837. text-overflow: ellipsis;
  1838. white-space: nowrap;
  1839. }
  1840. .composer-pending__close {
  1841. position: absolute;
  1842. top: 0;
  1843. right: 0;
  1844. width: 40rpx;
  1845. height: 40rpx;
  1846. display: flex;
  1847. align-items: center;
  1848. justify-content: center;
  1849. background: rgba(0, 0, 0, 0.5);
  1850. border-bottom-left-radius: 12rpx;
  1851. z-index: 2;
  1852. }
  1853. .composer-input-row {
  1854. display: flex;
  1855. flex-direction: row;
  1856. flex-wrap: nowrap;
  1857. align-items: flex-end;
  1858. width: 100%;
  1859. gap: 12rpx;
  1860. min-width: 0;
  1861. box-sizing: border-box;
  1862. }
  1863. .composer-input-shell {
  1864. flex: 1;
  1865. min-width: 0;
  1866. min-height: 72rpx;
  1867. max-height: 200rpx;
  1868. padding: 10rpx 16rpx;
  1869. border-radius: 12rpx;
  1870. background: $morandi-bg-card-inner;
  1871. border: 1rpx solid $morandi-border-soft;
  1872. box-sizing: border-box;
  1873. }
  1874. .composer-textarea {
  1875. width: 100%;
  1876. min-height: 48rpx;
  1877. max-height: 180rpx;
  1878. font-size: 28rpx;
  1879. line-height: 1.45;
  1880. color: $morandi-text;
  1881. }
  1882. .composer-textarea-ph {
  1883. color: $morandi-text-muted;
  1884. font-size: 26rpx;
  1885. }
  1886. .composer-send {
  1887. flex-shrink: 0;
  1888. padding: 18rpx 24rpx;
  1889. border-radius: 12rpx;
  1890. background: linear-gradient(90deg, #16a34a, #22c55e);
  1891. box-sizing: border-box;
  1892. }
  1893. .composer-send--disabled {
  1894. opacity: 0.5;
  1895. }
  1896. .composer-send__txt {
  1897. font-size: 26rpx;
  1898. font-weight: 600;
  1899. color: #fff;
  1900. white-space: nowrap;
  1901. }
  1902. </style>