BusinessRecord.vue 82 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056
  1. <template>
  2. <div
  3. ref="recordRootRef"
  4. :style="recordRootStyle"
  5. :class="{ 'text-left': record.isAI, 'text-right': record.isUser, 'text-center': record.isTips }"
  6. >
  7. <transition name="slow-fade">
  8. <QuestionSource
  9. v-if="record.questionSource && record.questionSource.length"
  10. :questionFrom="record.questionSource"
  11. />
  12. </transition>
  13. <div
  14. v-if="businessScopeOutsideRow"
  15. ref="businessScopeOutsideRef"
  16. class="business-scope-content-outside"
  17. >
  18. <ScopeContent
  19. :content="businessScopeOutsideRow.content"
  20. :forcePending="isScopeForcePending"
  21. :exiting="businessScopeOutsideRow.exiting"
  22. scope-source="outside"
  23. @auto-exit="handleScopeAutoExit(businessScopeOutsideRow)"
  24. />
  25. </div>
  26. <Transition name="business-record-body-fade" appear>
  27. <div
  28. v-if="shouldRenderBusinessRecordBody"
  29. class="business-record-body"
  30. :style="businessRecordBodyStyle"
  31. :class="{
  32. 'is-scope-exiting': isScopeExitCompensating,
  33. 'is-scope-exit-transition-disabled': isScopeExitBodyTransitionDisabled,
  34. }"
  35. >
  36. <div
  37. v-if="showUserAttachments"
  38. class="ba-message-attachments"
  39. :class="{ desktop: !isMobileDevice }"
  40. >
  41. <div
  42. v-for="attachment in userAttachments"
  43. :key="attachment.id || attachment.url"
  44. class="ba-message-attachment"
  45. :class="{ 'is-image': attachment.isImage, 'is-file': !attachment.isImage }"
  46. >
  47. <ImageContent
  48. v-if="attachment.isImage && attachment.url"
  49. :image-urls="previewableUserAttachmentUrls"
  50. :preview-index="getUserAttachmentPreviewIndex(attachment)"
  51. :compact="true"
  52. :activeReveal="false"
  53. :showDownloadButton="false"
  54. />
  55. <template v-else>
  56. <div class="ba-message-attachment-icon">{{
  57. getAttachmentExtension(attachment.name)
  58. }}</div>
  59. <div class="ba-message-attachment-info">
  60. <div class="ba-message-attachment-name">{{ attachment.name }}</div>
  61. <div class="ba-message-attachment-size">{{
  62. formatAttachmentSize(attachment.size)
  63. }}</div>
  64. </div>
  65. </template>
  66. </div>
  67. </div>
  68. <div
  69. v-if="shouldRenderRecordLine"
  70. :class="{
  71. 'ba-record-me': record.isUser,
  72. 'ba-record-ai': record.isAI,
  73. 'is-loading': isBusinessLoading,
  74. 'is-interrupted': showInterruptedState,
  75. 'chat-record-tips': record.isTips,
  76. 'with-feedback-margin': true,
  77. 'with-feedback-margin-rated':
  78. localFeedback === FeedbackType.Like || localFeedback === FeedbackType.Dislike,
  79. 'full-mode': type == 'full',
  80. desktop: !isMobileDevice,
  81. }"
  82. class="chat-record-line record--business business-record"
  83. ref="elRef"
  84. >
  85. <div class="tips-title" v-if="record.isTips">
  86. <div class="tips-deco" />
  87. <div class="tips-deco mirror" />
  88. 温馨提示
  89. </div>
  90. <ReasoningWidget
  91. v-if="record.isAI && record.reasoningContent !== undefined"
  92. :reasoningContent="record.reasoningContent"
  93. :status="reasoningStatus"
  94. />
  95. <div class="content" :class="{ isTip: record.isTips }" ref="contentRef">
  96. <span v-if="showInterruptedState" class="request-interrupted-text">请求已取消</span>
  97. <DotsAnim v-else-if="showLoadingDots" />
  98. <template v-else>
  99. <template
  100. v-for="(row, index) in visibleInlineDisplayRecordRows"
  101. :key="row.id || index"
  102. >
  103. <TextContent
  104. :content="row.content"
  105. v-if="shouldRenderTextContentRow(row)"
  106. :instant="shouldRenderTextInstantly"
  107. :blockMarkdown="true"
  108. :activeTypewriter="shouldDriveTypewriter"
  109. :paused="false"
  110. :scopeExitCompensating="isScopeExitCompensating"
  111. :enableRevealFade="false"
  112. :initialMinWidth="scopeExitWidth"
  113. @typingFinished="handleTypingFinished(row.id)"
  114. @typingStateChange="handleTypingStateChange(row.id, $event)"
  115. />
  116. <FormContent :content="row.content" v-if="row.type === RecordRowTypes.Form" />
  117. <LinkURLContent :content="row.content" v-if="row.type === RecordRowTypes.LinkURL" />
  118. <ImageContent
  119. :content="row.content"
  120. v-if="row.type === RecordRowTypes.ImageContent"
  121. :activeReveal="shouldDriveTypewriter && !isImageRowFullyRevealed(row)"
  122. @revealFinished="handleImageRevealFinished(row.id)"
  123. @revealStateChange="handleImageRevealStateChange(row.id, $event)"
  124. />
  125. <OfficeURLContent
  126. :content="row.content"
  127. v-if="row.type === RecordRowTypes.OfficeURL"
  128. />
  129. <div
  130. v-if="row.type === RecordRowTypes.Scope"
  131. class="scope-content-shell"
  132. :ref="(el) => setScopeRowRef(row, el)"
  133. >
  134. <ScopeContent
  135. :content="row.content"
  136. :forcePending="isScopeForcePending"
  137. :exiting="row.exiting"
  138. scope-source="inline"
  139. @auto-exit="handleScopeAutoExit(row)"
  140. />
  141. </div>
  142. <PolicyMatch
  143. v-if="row.type === RecordRowTypes.PolicyTable"
  144. :policyContent="row.content"
  145. :recordMode="true"
  146. :sessionId="policyMatchSessionId"
  147. />
  148. <PolicyListUpdatedMatch
  149. v-if="row.type === RecordRowTypes.PolicyListUpdated"
  150. :content="row.content"
  151. :recordMode="true"
  152. :sessionId="policyMatchSessionId"
  153. />
  154. <QuestionCard
  155. v-if="row.type === RecordRowTypes.QuestionCards"
  156. :content="row.content"
  157. :recordMode="true"
  158. :sessionId="policyMatchSessionId"
  159. />
  160. <div
  161. v-if="row.type === RecordRowTypes.RefLinks && getRefLinkItems(row.content).length"
  162. class="ba-ref-links-summary"
  163. :class="{ desktop: !isMobileDevice }"
  164. >
  165. <div class="ba-ref-links-summary-title">参考资料</div>
  166. <div class="ba-ref-links-row">
  167. <div class="ba-ref-links-chip-list">
  168. <a
  169. v-for="(item, refIndex) in getRefLinkItems(row.content)"
  170. :key="`${item.title}-${refIndex}`"
  171. class="ba-ref-links-chip"
  172. :href="item.linkUrl"
  173. target="_blank"
  174. rel="noopener noreferrer"
  175. @click="handleRefLinkChipClick($event, item)"
  176. >
  177. <span class="ba-ref-links-chip-index">[{{ refIndex + 1 }}]</span>
  178. <span class="ba-ref-links-chip-title">{{
  179. item.title || item.type || "参考资料"
  180. }}</span>
  181. </a>
  182. </div>
  183. <button
  184. type="button"
  185. class="ba-ref-links-more"
  186. @click.stop="openRefLinksPanel(row.content)"
  187. >
  188. 更多
  189. </button>
  190. </div>
  191. </div>
  192. </template>
  193. <!-- media display holder -->
  194. <div
  195. class="media-row"
  196. :class="{ 'mt-1': visibleInlineDisplayRecordRows.length === 0 }"
  197. v-if="headMedia.type"
  198. >
  199. <div
  200. class="media-placeholder head-media"
  201. @click="
  202. (e) => {
  203. openPreview(headMedia, 0, e);
  204. }
  205. "
  206. >
  207. <img
  208. :src="headMedia.type === 'image' ? headMedia.url : headMedia.preview"
  209. @error="handleError"
  210. />
  211. <div v-if="headMedia.type === 'video'" class="play-button"></div>
  212. </div>
  213. </div>
  214. <div
  215. class="rest-media-wrapper"
  216. :class="{ 'pa-0': restMedia.length == 1 }"
  217. v-if="restMedia.length"
  218. >
  219. <div
  220. class="media-placeholder"
  221. :class="{
  222. several: restMedia.length > 1 && restMedia.length <= 4,
  223. multi: restMedia.length > 4,
  224. }"
  225. v-for="(each, index) in restMedia"
  226. :key="index"
  227. @click="
  228. (e) => {
  229. openPreview(each, index + 1, e);
  230. }
  231. "
  232. >
  233. <img
  234. :src="each.type === 'image' ? each.url : each.preview"
  235. @error="handleError"
  236. />
  237. <div v-if="each.type === 'video'" class="play-button"></div>
  238. </div>
  239. </div>
  240. <!-- media display holder end -->
  241. </template>
  242. </div>
  243. <div class="tips-wrap" v-if="record.isTips">
  244. <div class="tip" v-for="(item, index) in tips.tipItems" :key="index">
  245. <div class="title">
  246. <span class="order">{{ index + 1 }}</span> {{ item.title }}
  247. </div>
  248. <div class="content">{{ item.content }}</div>
  249. </div>
  250. <div class="tip-footer">{{ tips.tipFooter }}</div>
  251. </div>
  252. <BarAnim v-if="state === MessageState.Update" />
  253. <transition name="slow-fade">
  254. <References
  255. v-if="showReferences && record.references && record.references.length"
  256. :questions="record.references"
  257. />
  258. </transition>
  259. <transition name="slow-fade">
  260. <RelatedQuestions
  261. v-if="
  262. showRelatedQuestions && record.relatedQuestions && record.relatedQuestions.length
  263. "
  264. :questions="record.relatedQuestions"
  265. />
  266. </transition>
  267. <div v-if="showSessionReadableLogButton" class="session-readable-log-row">
  268. <button type="button" class="session-readable-log-btn" @click="openSessionReadableLog">
  269. 打开日志
  270. </button>
  271. </div>
  272. </div>
  273. <transition name="slow-fade">
  274. <FeedbackWidget
  275. v-if="shouldRenderFeedback"
  276. :id="record.id"
  277. :feedback="localFeedback"
  278. :content="copyableContent"
  279. @change="handleFeedbackChange"
  280. />
  281. </transition>
  282. </div>
  283. </Transition>
  284. </div>
  285. <Teleport to="body">
  286. <div v-if="refLinksPanelVisible" class="ref-links-viewer-modal">
  287. <transition name="ref-links-panel">
  288. <div v-if="refLinksPanelVisible" class="ref-links-viewer-content">
  289. <div class="ref-links-viewer-header">
  290. <div class="ref-links-viewer-title">参考资料</div>
  291. <button type="button" class="ref-links-viewer-close" @click.stop="closeRefLinksPanel">
  292. <svg
  293. width="14"
  294. height="14"
  295. viewBox="0 0 14 14"
  296. fill="none"
  297. xmlns="http://www.w3.org/2000/svg"
  298. >
  299. <path
  300. d="M1 1L13 13M13 1L1 13"
  301. stroke="currentColor"
  302. stroke-width="1.5"
  303. stroke-linecap="round"
  304. stroke-linejoin="round"
  305. />
  306. </svg>
  307. </button>
  308. </div>
  309. <div class="ref-links-viewer-list">
  310. <div
  311. v-for="(item, index) in activeRefLinks"
  312. :key="`${item.title}-${index}`"
  313. class="ref-links-card"
  314. >
  315. <div class="ref-links-card-head">
  316. <div class="ref-links-card-title">{{ item.title || "参考资料" }}</div>
  317. <div v-if="item.type" class="ref-links-card-tag">{{ item.type }}</div>
  318. </div>
  319. <!-- 来源元信息:发布机构 / 发布或更新时间(见接口文档 §9 source 统一字段) -->
  320. <div v-if="getRefLinkMeta(item)" class="ref-links-card-content">
  321. {{ getRefLinkMeta(item) }}
  322. </div>
  323. <div v-if="item.content" class="ref-links-card-content">{{ item.content }}</div>
  324. <a
  325. v-if="item.linkUrl"
  326. class="ref-links-card-link"
  327. :href="item.linkUrl"
  328. target="_blank"
  329. rel="noopener noreferrer"
  330. >
  331. 查看详情
  332. <svg
  333. width="12"
  334. height="12"
  335. viewBox="0 0 12 12"
  336. fill="none"
  337. xmlns="http://www.w3.org/2000/svg"
  338. >
  339. <path
  340. d="M1.33333 12C0.966667 12 0.652778 11.8694 0.391667 11.6083C0.130556 11.3472 0 11.0333 0 10.6667V1.33333C0 0.966667 0.130556 0.652778 0.391667 0.391667C0.652778 0.130556 0.966667 0 1.33333 0H6V1.33333H1.33333V10.6667H10.6667V6H12V10.6667C12 11.0333 11.8694 11.3472 11.6083 11.6083C11.3472 11.8694 11.0333 12 10.6667 12H1.33333ZM4.46667 8.46667L3.53333 7.53333L9.73333 1.33333H7.33333V0H12V4.66667H10.6667V2.26667L4.46667 8.46667Z"
  341. fill="#3525CD"
  342. />
  343. </svg>
  344. </a>
  345. </div>
  346. </div>
  347. </div>
  348. </transition>
  349. </div>
  350. </Teleport>
  351. <DislikeDialog v-model:visible="showDislikeDialog" @confirm="handleDislikeConfirm" />
  352. <Toast :message="toastMessage" />
  353. </template>
  354. <script setup lang="ts">
  355. import {
  356. computed,
  357. inject,
  358. onBeforeUnmount,
  359. onMounted,
  360. nextTick,
  361. provide,
  362. ref,
  363. watch,
  364. getCurrentInstance,
  365. } from "vue";
  366. import { MessageState } from "../stream-message-coordinator";
  367. import { FeedbackType, From } from "@/types/record";
  368. import { writeDmsFeedback } from "@/network/api/dms/chat-sessions-dms";
  369. import DotsAnim from "../Common/DotsAnim.vue";
  370. import BarAnim from "../Common/BarAnim.vue";
  371. import FeedbackWidget from "../Common/FeedbackWidget.vue";
  372. import DislikeDialog from "../Common/DislikeDialog.vue";
  373. import Toast from "../Common/Toast.vue";
  374. import QuestionSource from "../Common/QuestionSourceWidget.vue";
  375. import defaultImage from "@/assets/img_break.svg";
  376. import { computedOriginContentPosition, getQueryObj, sleep } from "../utils";
  377. import { isMobile } from "@/utils";
  378. import ReasoningWidget from "../Common/ReasoningWidget.vue";
  379. import RelatedQuestions from "../Common/RelatedQuestionsWidget.vue";
  380. import References from "../Common/References.vue";
  381. import TextContent from "./TextContent.vue";
  382. import FormContent from "./FormContent.vue";
  383. import LinkURLContent from "./LinkURLContent.vue";
  384. import ImageContent from "./ImageContent.vue";
  385. import OfficeURLContent from "./OfficeURLContent.vue";
  386. import ScopeContent from "./ScopeContent.vue";
  387. import PolicyMatch from "./PolicyMatch.vue";
  388. import PolicyListUpdatedMatch from "./PolicyListUpdatedMatch.vue";
  389. import QuestionCard from "./QuestionCard.vue";
  390. import {
  391. parseRefLinksContent,
  392. RecordRowTypes,
  393. StreamXMLFilter,
  394. type RefLinkItem,
  395. } from "@/utils/stream-xml-filter";
  396. import { jsonrepair } from "jsonrepair";
  397. import { isInterruptedEmptyScopeMessage } from "@/utils/interrupted-message";
  398. import {
  399. splitStreamingTextContentRows,
  400. trimDisplayTextContentEnd,
  401. trimDisplayTextContentStart,
  402. } from "./text-content-utils";
  403. import {
  404. isEmptyScopeRow,
  405. isRemovableEmptyScopeStatusRow,
  406. isRemovableScopePreludeTextRow,
  407. mergeScopeRecordRow,
  408. resolveBusinessScopeOutsideRow,
  409. shouldForcePendingScope,
  410. } from "@/utils/scope-record-rows";
  411. import { createModalMutex, MODAL_MUTEX_KEY } from "../business-assistant/modal-mutex";
  412. enum RecordRowStates {
  413. Pending = "pending",
  414. Displaying = "displaying",
  415. Displayed = "displayed",
  416. }
  417. // 定义 displayRecordRow 类型
  418. type DisplayRecordRow = {
  419. id: number;
  420. type: RecordRowTypes;
  421. state: RecordRowStates;
  422. content: string;
  423. [key: string]: any;
  424. };
  425. interface Props {
  426. aspect?: string;
  427. record?: any;
  428. content?: string;
  429. options?: { option: string }[];
  430. theme?: any;
  431. state?: MessageState | string | number;
  432. rect?: {
  433. top: number;
  434. height: number;
  435. };
  436. type?: string;
  437. human?: any;
  438. isLastRecord?: boolean;
  439. sessionViewedBefore?: boolean;
  440. sessionId?: string;
  441. enableFeedback?: boolean;
  442. }
  443. const props = withDefaults(defineProps<Props>(), {
  444. aspect: "16/9",
  445. rect: () => ({
  446. top: 0,
  447. height: 0,
  448. }),
  449. type: "default",
  450. });
  451. const emit = defineEmits([
  452. "changeIdleState",
  453. "feedback",
  454. "displayContentChange",
  455. "displayMediaChange",
  456. "refreshScroll",
  457. "scopeExitStateChange",
  458. "scopeHeightLockChange",
  459. "typewriterStateChange",
  460. ]);
  461. const policyMatchSessionId = computed(
  462. () => props.record?.session || props.sessionId || globalThis.currentSession || ""
  463. );
  464. const recordRootRef = ref<HTMLElement | null>(null);
  465. const businessScopeOutsideRef = ref<HTMLElement | null>(null);
  466. const textAnimWrapper = ref();
  467. const showTextAnim = ref(false);
  468. const localFeedback = ref<FeedbackType>(FeedbackType.None);
  469. const showDislikeDialog = ref(false);
  470. const toastMessage = ref("");
  471. let pendingDislikeRecordId: string | number | null = null;
  472. let toastTimer: ReturnType<typeof setTimeout> | undefined;
  473. const isFormQueryMode = getQueryObj("mode") === "form";
  474. const showRelatedQuestions = ref(false);
  475. const showReferences = ref(false);
  476. const refLinksPanelVisible = ref(false);
  477. const activeRefLinks = ref<RefLinkItem[]>([]);
  478. // 互斥面板管理
  479. const businessRecordInstanceId = `BR-${Math.random().toString(36).slice(2, 7)}`;
  480. const refLinksModalId = Symbol(`${businessRecordInstanceId}:ref-links`);
  481. const modalMutex = inject(MODAL_MUTEX_KEY, null) ?? createModalMutex();
  482. provide(MODAL_MUTEX_KEY, modalMutex);
  483. let unregisterRefLinksModal: (() => void) | undefined;
  484. function showToast(message: string) {
  485. toastMessage.value = message;
  486. if (toastTimer) clearTimeout(toastTimer);
  487. toastTimer = setTimeout(() => {
  488. toastMessage.value = "";
  489. }, 3000);
  490. }
  491. function openDislikeDialog(recordId: string | number) {
  492. pendingDislikeRecordId = recordId;
  493. showDislikeDialog.value = true;
  494. }
  495. // 反馈写入 DMS 的问答记录(栏目 1889 的 c_feedback_*),按 c_record_id 定位那一行。
  496. // recordId 就是 AI 消息 id,与写入时的 c_record_id 是同一个值(见 chat-sessions-dms.ts)
  497. function submitLikeFeedback(recordId: string | number) {
  498. void writeDmsFeedback({
  499. recordId: String(recordId),
  500. sessionId: policyMatchSessionId.value,
  501. status: FeedbackType.Like,
  502. });
  503. }
  504. function cancelFeedback(recordId: string | number) {
  505. void writeDmsFeedback({
  506. recordId: String(recordId),
  507. sessionId: policyMatchSessionId.value,
  508. status: FeedbackType.None,
  509. });
  510. }
  511. function handleDislikeConfirm(option: string, remark: string) {
  512. if (pendingDislikeRecordId === null) return;
  513. void writeDmsFeedback({
  514. recordId: String(pendingDislikeRecordId),
  515. sessionId: policyMatchSessionId.value,
  516. status: FeedbackType.Dislike,
  517. option,
  518. remark,
  519. });
  520. localFeedback.value = FeedbackType.Dislike;
  521. pendingDislikeRecordId = null;
  522. }
  523. provide("feedbackControl", { openDislikeDialog, submitLikeFeedback, cancelFeedback });
  524. provide("dislikeDialogControl", { openDislikeDialog });
  525. provide("toastControl", { showToast });
  526. const { setFormOptions } = inject("formOptionsControl") as any;
  527. const instance = getCurrentInstance();
  528. const $mediaViewer = instance?.proxy?.$mediaViewer as any;
  529. const record = computed(() => {
  530. let _record = props.record;
  531. if (!_record) return {};
  532. _record.isUser = _record.role === "user" || _record.from === From.User;
  533. _record.isAI = _record.role === "ai" || _record.from === From.AI;
  534. _record.isTips = _record.from === From.Tips;
  535. return _record;
  536. });
  537. const xmlFilter = new StreamXMLFilter({
  538. customProcessor: new Map([
  539. [
  540. RecordRowTypes.UIForm,
  541. (payload: { schema: string; attrs: Record<string, string> }) => {
  542. setFormOptions({
  543. visible: true,
  544. enable: true,
  545. mode: "form",
  546. schema: JSON.parse(jsonrepair(payload.schema)) || [],
  547. title: payload.attrs.title,
  548. });
  549. },
  550. ],
  551. ]),
  552. });
  553. const { stopSpeech, handleEndSpeech } = inject("speechControl") as any;
  554. let isEffectHumanState: any;
  555. const mediaList = computed(() => props.record?.mediaList);
  556. const userAttachments = computed(() => (record.value.isUser ? record.value.attachments || [] : []));
  557. const previewableUserAttachmentUrls = computed(() =>
  558. userAttachments.value
  559. .filter((attachment) => attachment.isImage && attachment.url)
  560. .map((attachment) => String(attachment.url || "").trim())
  561. .filter(Boolean)
  562. );
  563. const showUserAttachments = computed(() => userAttachments.value.length > 0);
  564. const displayMediaList = ref<any[]>([]);
  565. const isMobileDevice = isMobile();
  566. enum SchedulerTaskState {
  567. Idle = "idle",
  568. }
  569. const getRefLinkItems = (content: string) => parseRefLinksContent(content);
  570. // 复制按钮只应复制可读正文:去掉 <scope>、<!-- POLICY_TABLE -->、<ref_links>、
  571. // <question-cards>、<image-scope>(企业微信二维码)等协议标记,
  572. // 避免复制出一大段 JSON 或图片地址。
  573. //
  574. // 注意不能用 getStreamPlainText():它对整段内容做一次性解析,而过滤器在遇到
  575. // <!-- POLICY_TABLE 时会把同批 buffer 里位于它之前的内容直接当纯文本输出,
  576. // 导致 scope 标记被当成正文保留下来。这里直接剥离标记,结果与内容分片方式无关。
  577. const copyableContent = computed(() => {
  578. const raw = String(record.value.content || props.content || "");
  579. return raw
  580. .replace(/<scope\b[^>]*>[\s\S]*?<\/scope>\s*/gi, "")
  581. .replace(/<ref_links\b[^>]*>[\s\S]*?<\/ref_links>\s*/gi, "")
  582. .replace(/<question-cards\b[^>]*>[\s\S]*?<\/question-cards>\s*/gi, "")
  583. .replace(/<image-scope\b[^>]*>[\s\S]*?<\/image-scope>\s*/gi, "")
  584. .replace(/<!--\s*POLICY_TABLE[\s\S]*?POLICY_TABLE\s*-->\s*/gi, "")
  585. .replace(/<\/?silence\b[^>]*>/gi, "")
  586. .replace(/<\/?scope\b[^>]*>/gi, "")
  587. .replace(/\n{3,}/g, "\n\n")
  588. .trim();
  589. });
  590. // 参考资料卡片的元信息行:发布机构 + 发布/更新时间。
  591. // 字段来自接口文档 §9「原始 source 对象中的统一字段」,经 originalData 透传。
  592. const getRefLinkMeta = (item: any) => {
  593. const data = item?.originalData || {};
  594. const parts: string[] = [];
  595. if (data.publisher) {
  596. parts.push(String(data.publisher));
  597. }
  598. const published = data.published_text || data.updated_text;
  599. if (published) {
  600. parts.push(/^\d{8}$/.test(String(published))
  601. ? `${String(published).replace(/(\d{4})(\d{2})(\d{2})/, "$1-$2-$3")} 更新`
  602. : String(published));
  603. }
  604. return parts.join(" · ");
  605. };
  606. const handleRefLinkChipClick = (event: MouseEvent, item: RefLinkItem) => {
  607. if (item.linkUrl) {
  608. return;
  609. }
  610. event.preventDefault();
  611. };
  612. const openRefLinksPanel = async (content: string) => {
  613. const items = getRefLinkItems(content);
  614. if (!items.length) {
  615. return;
  616. }
  617. const openTicket = modalMutex.requestOpen(refLinksModalId);
  618. await nextTick();
  619. if (!modalMutex.isCurrentRequest(refLinksModalId, openTicket)) return;
  620. activeRefLinks.value = items;
  621. refLinksPanelVisible.value = true;
  622. emitRefLinksPanelWidth();
  623. };
  624. const closeRefLinksPanel = () => {
  625. refLinksPanelVisible.value = false;
  626. modalMutex.release(refLinksModalId);
  627. emitRefLinksPanelWidth();
  628. };
  629. const emitRefLinksPanelWidth = () => {
  630. document.dispatchEvent(
  631. new CustomEvent("refLinksPanelWidthChange", {
  632. detail: { width: refLinksPanelVisible.value ? 480 : 0 },
  633. })
  634. );
  635. };
  636. watch(
  637. () => mediaList.value,
  638. (val) => {
  639. if (!val || val.length === 0 || timer) {
  640. return;
  641. }
  642. displayMediaList.value = val;
  643. }
  644. );
  645. const headMedia = computed(() => {
  646. if (!displayMediaList.value || displayMediaList.value.length === 0) {
  647. return {};
  648. }
  649. return displayMediaList.value[0];
  650. });
  651. const restMedia = computed(() => {
  652. if (!displayMediaList.value || displayMediaList.value.length === 0) {
  653. return [];
  654. }
  655. return displayMediaList.value.slice(1);
  656. });
  657. const getAttachmentExtension = (name: string) => name.split(".").pop()?.toUpperCase() || "FILE";
  658. const formatAttachmentSize = (size: number) => {
  659. if (!Number.isFinite(size) || size <= 0) {
  660. return "";
  661. }
  662. if (size >= 1024 * 1024) {
  663. return `${(size / 1024 / 1024).toFixed(2)} MB`;
  664. }
  665. return `${Math.max(1, Math.round(size / 1024))} KB`;
  666. };
  667. const reasoningStatus = computed(() => {
  668. let status = "";
  669. if (
  670. (record.value.state === MessageState.Sending || record.value.state === MessageState.Success) &&
  671. !record.value.content
  672. ) {
  673. status = "thinking";
  674. } else {
  675. status = "certain";
  676. }
  677. return status;
  678. });
  679. const showInterruptedState = computed(() =>
  680. isInterruptedEmptyScopeMessage({
  681. ...record.value,
  682. state: props.state ?? record.value.state,
  683. })
  684. );
  685. const displayContent = ref("");
  686. const originContent = ref(props.content || "");
  687. const count = ref(0);
  688. const mediaCount = ref(0);
  689. const hasVisibleAnswerContent = ref(false);
  690. const textRowTypingFinished = ref<Record<number, boolean>>({});
  691. const textRowTypingActive = ref<Record<number, boolean>>({});
  692. const imageRowRevealFinished = ref<Record<number, boolean>>({});
  693. const imageRowRevealActive = ref<Record<number, boolean>>({});
  694. // displayRecordRows 类型增强
  695. const displayRecordRows = ref<DisplayRecordRow[]>([]);
  696. const updateRecordRowIndex = ref(0);
  697. const activeRecordState = computed(() => props.state ?? record.value.state);
  698. const isForcePendingState = computed(
  699. () =>
  700. String(activeRecordState.value || "")
  701. .trim()
  702. .toLowerCase() === "forcepending"
  703. );
  704. const hasRecordTextContent = computed(
  705. () => String(record.value.content || props.content || "").trim().length > 0
  706. );
  707. const shouldRenderTextInstantly = computed(() => !record.value.isAI || !!record.value.history);
  708. const canAnimateAiText = computed(
  709. () =>
  710. record.value.isAI &&
  711. !record.value.history &&
  712. !!props.isLastRecord &&
  713. activeRecordState.value !== MessageState.Stop
  714. );
  715. const isScopeForcePending = computed(() =>
  716. shouldForcePendingScope(
  717. activeRecordState.value,
  718. hasVisibleAnswerContent.value,
  719. MessageState.Finish,
  720. MessageState.Stop
  721. )
  722. );
  723. const isBusinessLoading = computed(() => {
  724. return (
  725. record.value.isAI &&
  726. isForcePendingState.value &&
  727. !hasRecordTextContent.value &&
  728. !hasVisibleAnswerContent.value
  729. );
  730. });
  731. const showLoadingDots = computed(() => {
  732. const hasNoDisplayedContent =
  733. displayRecordRows.value.length === 0 &&
  734. !showTextAnim.value &&
  735. displayMediaList.value.length === 0;
  736. return hasNoDisplayedContent && isBusinessLoading.value;
  737. });
  738. let timer: any;
  739. let mediaTimer: any;
  740. let lastRecordResizeObserver: ResizeObserver | null = null;
  741. let lastObservedRecordHeight = 0;
  742. const gapTime = 30;
  743. const scopeExitFadeDurationMs = 300;
  744. const scopeExitCollapseDurationMs = scopeExitFadeDurationMs;
  745. let scopeExitTimer: number | null = null;
  746. let scopeExitRevision = 0;
  747. const scopeExitDebugStartedAt = performance.now();
  748. const scopeRowElementMap = new WeakMap<DisplayRecordRow, HTMLElement>();
  749. const recordHeightLock = ref<number | null>(null);
  750. const scopeExitHeight = ref(0);
  751. const scopeExitWidth = ref(0);
  752. const isScopeExitCompensating = computed(() => scopeExitHeight.value > 0);
  753. const isScopeExitBodyTransitionDisabled = ref(false);
  754. const isLastAiStreamingRecord = computed(
  755. () =>
  756. props.isLastRecord &&
  757. record.value.isAI &&
  758. activeRecordState.value !== MessageState.Finish &&
  759. activeRecordState.value !== MessageState.Stop
  760. );
  761. const scopeExitBodyGapPx = 8;
  762. const businessRecordBodyStyle = computed(() => ({
  763. "--scope-exit-offset": `${scopeExitHeight.value + (isScopeExitCompensating.value ? scopeExitBodyGapPx : 0)}px`,
  764. }));
  765. const recordRootStyle = computed(() => ({
  766. width: "100%",
  767. minHeight: recordHeightLock.value !== null ? `${recordHeightLock.value}px` : undefined,
  768. overflow: recordHeightLock.value !== null ? "hidden" : undefined,
  769. }));
  770. let changeFlag = 1;
  771. const customFormType = ref("");
  772. const businessScopeOutsideRow = computed(() => {
  773. const scopeRow = resolveBusinessScopeOutsideRow({
  774. variant: "business",
  775. record: record.value,
  776. displayRecordRows: displayRecordRows.value,
  777. hasVisibleAnswerContent: hasVisibleAnswerContent.value,
  778. activeRecordState: activeRecordState.value,
  779. finishState: MessageState.Finish,
  780. stopState: MessageState.Stop,
  781. allowFallbackPendingScope: !record.value.history,
  782. });
  783. if (
  784. scopeRow &&
  785. scopeRow.type === RecordRowTypes.Scope &&
  786. !scopeRow.exiting &&
  787. (activeRecordState.value === MessageState.Finish ||
  788. activeRecordState.value === MessageState.Stop)
  789. ) {
  790. return null;
  791. }
  792. if (record.value.history && hasHistoricalNonScopeContent.value) {
  793. return null;
  794. }
  795. return scopeRow;
  796. });
  797. const isOutsideScopeExiting = computed(() => Boolean(businessScopeOutsideRow.value?.exiting));
  798. const shouldRenderBusinessRecordBody = computed(() => true);
  799. const handleScopeAutoExit = (scopeRow: DisplayRecordRow | null) => {
  800. beginScopeExit(scopeRow);
  801. };
  802. const hasPolicyTableRow = computed(() =>
  803. displayRecordRows.value.some(
  804. (row) =>
  805. row.type === RecordRowTypes.PolicyTable || row.type === RecordRowTypes.PolicyListUpdated
  806. )
  807. );
  808. const hasHistoricalNonScopeContent = computed(() => {
  809. if (!record.value.history) {
  810. return false;
  811. }
  812. const rawContent = String(record.value.content || props.content || "");
  813. const contentWithoutScopes = rawContent
  814. .replace(/<\/?silence\b[^>]*>/gi, "")
  815. .replace(/<scope\b[^>]*>[\s\S]*?<\/scope>/gi, "");
  816. return contentWithoutScopes.trim().length > 0;
  817. });
  818. const hasRenderableNonScopeContent = computed(
  819. () =>
  820. hasHistoricalNonScopeContent.value ||
  821. hasInlineRenderableContent.value ||
  822. showLoadingDots.value ||
  823. showInterruptedState.value ||
  824. !!headMedia.value.type ||
  825. restMedia.value.length > 0 ||
  826. record.value.isTips ||
  827. activeRecordState.value === MessageState.Update ||
  828. showReferences.value ||
  829. showRelatedQuestions.value ||
  830. hasPolicyTableRow.value
  831. );
  832. const shouldRenderScopeRow = (row: DisplayRecordRow | null | undefined) => {
  833. if (!row || row.type !== RecordRowTypes.Scope) {
  834. return false;
  835. }
  836. if (record.value.history && hasRenderableNonScopeContent.value) {
  837. return false;
  838. }
  839. if (
  840. isEmptyScopeRow(row) &&
  841. (activeRecordState.value === MessageState.Finish ||
  842. activeRecordState.value === MessageState.Stop) &&
  843. !row.exiting
  844. ) {
  845. return false;
  846. }
  847. return (
  848. row.exiting ||
  849. (activeRecordState.value !== MessageState.Finish &&
  850. activeRecordState.value !== MessageState.Stop)
  851. );
  852. };
  853. const shouldRenderTextContentRow = (row: DisplayRecordRow) =>
  854. row.type === RecordRowTypes.Text && !isScopeExitCompensating.value;
  855. const visibleDisplayRecordRows = computed(() =>
  856. displayRecordRows.value.filter(
  857. (row) => row.type !== RecordRowTypes.Scope || shouldRenderScopeRow(row)
  858. )
  859. );
  860. const inlineDisplayRecordRows = computed(() => {
  861. const outsideRow = businessScopeOutsideRow.value;
  862. if (!outsideRow) {
  863. return visibleDisplayRecordRows.value;
  864. }
  865. return visibleDisplayRecordRows.value.filter((row) => row !== outsideRow);
  866. });
  867. const isTextRowFullyCompleted = (row: DisplayRecordRow) =>
  868. // 文本行完成条件只认打字机动画结束事件(textRowTypingFinished[row.id])。
  869. // 不能依赖 row.state === Displayed:段落边界(breakAfter)会把上一行提前标记为
  870. // Displayed,但此时打字机可能还没播完最后几个字,会导致下一行提前开始渲染。
  871. row.type !== RecordRowTypes.Text || textRowTypingFinished.value[row.id] === true;
  872. const isImageRowFullyRevealed = (row: DisplayRecordRow) =>
  873. row.type !== RecordRowTypes.ImageContent || imageRowRevealFinished.value[row.id];
  874. const hasUnfinishedRevealRows = computed(() =>
  875. inlineDisplayRecordRows.value.some(
  876. (row) =>
  877. (row.type === RecordRowTypes.Text && !isTextRowFullyCompleted(row)) ||
  878. (row.type === RecordRowTypes.ImageContent && !isImageRowFullyRevealed(row))
  879. )
  880. );
  881. const shouldDriveTypewriter = computed(
  882. () =>
  883. canAnimateAiText.value &&
  884. // F073:正文本身是真实增量流式到达的,再逐字重放等于凭空多等一遍 —— 关掉打字机
  885. // (TextContent 的 `instant || !activeTypewriter` 分支会转成即时渲染)
  886. !record.value.contentStreaming &&
  887. (activeRecordState.value !== MessageState.Finish || hasUnfinishedRevealRows.value)
  888. );
  889. const isSessionReadableLogButtonEnabled =
  890. import.meta.env.MODE === "production" || import.meta.env.MODE === "development";
  891. const showSessionReadableLogButton = computed(
  892. () =>
  893. isSessionReadableLogButtonEnabled &&
  894. globalThis.policyMode !== "zhaoshang" &&
  895. record.value.isAI &&
  896. activeRecordState.value === MessageState.Finish
  897. );
  898. const shouldWaitForTypewriterCompletion = computed(
  899. () => canAnimateAiText.value && hasUnfinishedRevealRows.value
  900. );
  901. // 反馈组件显示策略:
  902. // - 非 AI 消息:永不显示
  903. // - 已评价(赞/踩/未选中):始终显示
  904. // - 历史会话(sessionViewedBefore)的 AI 消息:始终显示(不需要等动画)
  905. // - 新消息:等 SSE 流结束 + 打字机/媒体动画都结束才显示
  906. const shouldRenderFeedback = computed(() => {
  907. if (!record.value.isAI) return false;
  908. if (localFeedback.value !== FeedbackType.None) return true;
  909. if (props.sessionViewedBefore) return true;
  910. if (activeRecordState.value !== MessageState.Finish) return false;
  911. // 打字机 / 图片 reveal 还没结束:不显示
  912. if (shouldWaitForTypewriterCompletion.value) return false;
  913. // 媒体列表(图片/视频)还在渐进式加载:不显示
  914. if ((mediaList.value?.length || 0) > displayMediaList.value.length) return false;
  915. return true;
  916. });
  917. const emitTypewriterStateChange = (isTypingActive: boolean) => {
  918. console.log("[BusinessRecord][typewriter-state]", {
  919. recordId: record.value.id,
  920. isLastRecord: props.isLastRecord,
  921. isAI: record.value.isAI,
  922. isTypingActive,
  923. textRowTypingActive: { ...textRowTypingActive.value },
  924. imageRowRevealActive: { ...imageRowRevealActive.value },
  925. });
  926. emit("typewriterStateChange", {
  927. recordId: record.value.id,
  928. isTypingActive,
  929. });
  930. };
  931. const syncTypewriterState = () => {
  932. const isTypingActive = Boolean(
  933. props.isLastRecord &&
  934. record.value.isAI &&
  935. (Object.values(textRowTypingActive.value).some(Boolean) ||
  936. Object.values(imageRowRevealActive.value).some(Boolean))
  937. );
  938. console.log("[BusinessRecord][typewriter-sync]", {
  939. recordId: record.value.id,
  940. isLastRecord: props.isLastRecord,
  941. isAI: record.value.isAI,
  942. isTypingActive,
  943. });
  944. emitTypewriterStateChange(isTypingActive);
  945. };
  946. const visibleInlineDisplayRecordRows = computed(() => {
  947. if (!shouldDriveTypewriter.value && !hasUnfinishedRevealRows.value) {
  948. return inlineDisplayRecordRows.value;
  949. }
  950. const visibleRows: DisplayRecordRow[] = [];
  951. let revealBlocked = false;
  952. for (const row of inlineDisplayRecordRows.value) {
  953. if (revealBlocked) {
  954. continue;
  955. }
  956. if (row.type === RecordRowTypes.Text) {
  957. visibleRows.push(row);
  958. if (!isTextRowFullyCompleted(row)) {
  959. revealBlocked = true;
  960. }
  961. continue;
  962. }
  963. visibleRows.push(row);
  964. if (row.type === RecordRowTypes.ImageContent && !isImageRowFullyRevealed(row)) {
  965. revealBlocked = true;
  966. }
  967. }
  968. return visibleRows;
  969. });
  970. const hasInlineRenderableContent = computed(() =>
  971. inlineDisplayRecordRows.value.some((row) => {
  972. if (row.type === RecordRowTypes.Text) {
  973. return String(row.content || "").trim().length > 0;
  974. }
  975. return row.type !== RecordRowTypes.Scope && !!row.content;
  976. })
  977. );
  978. const shouldRenderRecordLine = computed(() => {
  979. if (showInterruptedState.value) {
  980. return true;
  981. }
  982. if (
  983. record.value.isAI &&
  984. !hasInlineRenderableContent.value &&
  985. !businessScopeOutsideRow.value &&
  986. !hasPolicyTableRow.value
  987. ) {
  988. return false;
  989. }
  990. if (!businessScopeOutsideRow.value) {
  991. return true;
  992. }
  993. return (
  994. inlineDisplayRecordRows.value.length > 0 ||
  995. showLoadingDots.value ||
  996. showInterruptedState.value ||
  997. !!headMedia.value.type ||
  998. restMedia.value.length > 0 ||
  999. record.value.isTips ||
  1000. activeRecordState.value === MessageState.Update ||
  1001. showReferences.value ||
  1002. showRelatedQuestions.value
  1003. );
  1004. });
  1005. const tips = ref({
  1006. tipItems: [
  1007. {
  1008. title: "携带资料",
  1009. content: "就诊前请准备好身份证件、就诊卡(如有)、以往的病历、检查报告和正在使用的药物清单。",
  1010. },
  1011. {
  1012. title: "体格检查",
  1013. content: "请您明天穿着宽松舒适、无金属的衣物,以便进行体格检查。",
  1014. },
  1015. {
  1016. title: "陪同人员",
  1017. content: "建议您有家人或朋友陪同前来,以确保检查过程的便利和舒适。",
  1018. },
  1019. ],
  1020. tipFooter: "如果您有任何紧急情况或疑问,请联系我们0592-5050505(科室导诊台电话)",
  1021. });
  1022. const clearExistingTimer = () => {
  1023. if (timer) {
  1024. clearInterval(timer);
  1025. timer = null;
  1026. }
  1027. };
  1028. const stripSilenceTags = (input: string) => {
  1029. return String(input || "").replace(/<\/?silence\b[^>]*>/gi, "");
  1030. };
  1031. const processTextSections = (input: string) => {
  1032. recordParser(input);
  1033. };
  1034. const isQuestionAnswersContent = (content: string) => {
  1035. const trimmed = String(content || "").trim();
  1036. if (!trimmed.startsWith("{")) {
  1037. return false;
  1038. }
  1039. try {
  1040. const parsed = JSON.parse(trimmed);
  1041. return !!parsed && Array.isArray(parsed.answers);
  1042. } catch {
  1043. return false;
  1044. }
  1045. };
  1046. const processRecordSections = (input: string) => {
  1047. input = String(input || "");
  1048. if (!input) {
  1049. return;
  1050. }
  1051. if (record.value.isUser && isQuestionAnswersContent(input)) {
  1052. updateLastRecordRow(input, RecordRowTypes.QuestionCards, RecordRowStates.Displayed);
  1053. return;
  1054. }
  1055. const policyStartToken = "<!-- POLICY_TABLE";
  1056. const policyEndToken = "POLICY_TABLE -->";
  1057. let rest = input;
  1058. while (rest.length > 0) {
  1059. const policyStart = rest.indexOf(policyStartToken);
  1060. if (policyStart === -1) {
  1061. processTextSections(rest);
  1062. return;
  1063. }
  1064. const normalText = rest.slice(0, policyStart);
  1065. if (normalText) {
  1066. processTextSections(normalText);
  1067. }
  1068. const policyEnd = rest.indexOf(policyEndToken, policyStart);
  1069. if (policyEnd === -1) {
  1070. recordParser(rest.slice(policyStart));
  1071. return;
  1072. }
  1073. recordParser(rest.slice(policyStart, policyEnd + policyEndToken.length));
  1074. rest = rest.slice(policyEnd + policyEndToken.length);
  1075. }
  1076. };
  1077. /**
  1078. * 诊断(仅非生产):**已经显示过的内容**被改小或被删掉时打一行。
  1079. *
  1080. * 为什么只盯这两种:用户报的「一小段重新渲染」在渲染层只可能来自两类操作 ——
  1081. * ① 整条消息被重置重解析(已有 `[record] 内容被整块重写` 那行)
  1082. * ② 某一行**已经显示过**的内容被改写 / 被删除(就是这里)
  1083. * 纯追加(流式增长)不会重渲任何已有内容,所以完全不必打点(打了每帧都会刷屏)。
  1084. */
  1085. const debugRowMutation = (
  1086. what: string,
  1087. row: DisplayRecordRow | undefined,
  1088. before: string,
  1089. after: string
  1090. ) => {
  1091. if (import.meta.env.MODE === "production") {
  1092. return;
  1093. }
  1094. console.warn(`[record] ${what}`, {
  1095. rowId: row?.id,
  1096. type: row?.type,
  1097. before: String(before ?? "").length,
  1098. after: String(after ?? "").length,
  1099. head: String(before ?? "").slice(0, 40),
  1100. });
  1101. };
  1102. /**
  1103. * 关闭一行文本:去掉尾部空白,并在**真的变短**时打一行诊断
  1104. * —— 变短意味着这一行已经显示过的内容被改写,会重渲(纯追加不会)。
  1105. */
  1106. const closeTextRow = (row: DisplayRecordRow) => {
  1107. const before = row.content;
  1108. const after = trimDisplayTextContentEnd(before);
  1109. if (after !== before) {
  1110. debugRowMutation("行内容被回缩(关闭行时去尾空白)", row, before, after);
  1111. }
  1112. row.content = after;
  1113. };
  1114. const resetDisplayContent = () => {
  1115. if (textAnimWrapper.value) {
  1116. textAnimWrapper.value.innerHTML = "";
  1117. }
  1118. displayContent.value = "";
  1119. displayRecordRows.value = [];
  1120. textRowTypingFinished.value = {};
  1121. textRowTypingActive.value = {};
  1122. imageRowRevealFinished.value = {};
  1123. imageRowRevealActive.value = {};
  1124. hasVisibleAnswerContent.value = false;
  1125. // ⚠️ scope 退场补偿态也要清:`isScopeExitCompensating` 为真时**正文行是隐藏的**
  1126. // (见 shouldRenderTextContentRow),残留会让重写后的正文整段不显示
  1127. clearScopeExitTimer();
  1128. scopeExitHeight.value = 0;
  1129. scopeExitWidth.value = 0;
  1130. recordHeightLock.value = null;
  1131. count.value = 0;
  1132. };
  1133. const clearScopeExitTimer = () => {
  1134. if (scopeExitTimer === null) {
  1135. return;
  1136. }
  1137. window.clearTimeout(scopeExitTimer);
  1138. scopeExitTimer = null;
  1139. };
  1140. const getScopeExitSource = (scopeRow: DisplayRecordRow) =>
  1141. scopeRow === businessScopeOutsideRow.value ? "outside" : "inline";
  1142. const getScopeRowElement = (scopeRow: DisplayRecordRow | null) => {
  1143. if (!scopeRow) {
  1144. return null;
  1145. }
  1146. if (scopeRow === businessScopeOutsideRow.value) {
  1147. return businessScopeOutsideRef.value;
  1148. }
  1149. return scopeRowElementMap.get(scopeRow) || null;
  1150. };
  1151. const getScopeContentWidth = (scopeEl: HTMLElement | null) => {
  1152. const scopeContentEl = scopeEl?.querySelector<HTMLElement>(".scope-content-wrap") || scopeEl;
  1153. const width = scopeContentEl ? Math.ceil(scopeContentEl.getBoundingClientRect().width) : 0;
  1154. return Number.isFinite(width) && width > 0 ? width : 0;
  1155. };
  1156. const setScopeRowRef = (scopeRow: DisplayRecordRow, el: HTMLElement | null) => {
  1157. if (el) {
  1158. scopeRowElementMap.set(scopeRow, el);
  1159. } else {
  1160. scopeRowElementMap.delete(scopeRow);
  1161. }
  1162. };
  1163. const finalizeScopeExit = async (
  1164. exitingRow: DisplayRecordRow,
  1165. scopeSource: string,
  1166. exitHeight: number,
  1167. shouldLockRecordHeight: boolean,
  1168. exitRevision: number
  1169. ) => {
  1170. if (exitRevision !== scopeExitRevision) {
  1171. return;
  1172. }
  1173. const rowIndex = displayRecordRows.value.indexOf(exitingRow);
  1174. if (rowIndex !== -1 && displayRecordRows.value[rowIndex]?.exiting) {
  1175. displayRecordRows.value.splice(rowIndex, 1);
  1176. }
  1177. scopeExitHeight.value = 0;
  1178. scopeExitWidth.value = 0;
  1179. emit("scopeExitStateChange", {
  1180. recordId: record.value.id,
  1181. active: false,
  1182. });
  1183. await nextTick();
  1184. window.requestAnimationFrame(() => {
  1185. if (exitRevision !== scopeExitRevision) {
  1186. return;
  1187. }
  1188. isScopeExitBodyTransitionDisabled.value = false;
  1189. });
  1190. };
  1191. const beginScopeExit = (scopeRow: DisplayRecordRow | null) => {
  1192. if (!scopeRow || scopeRow.type !== RecordRowTypes.Scope || scopeRow.exiting) {
  1193. return;
  1194. }
  1195. if (!String(scopeRow.content || "").includes("</scope>")) {
  1196. return;
  1197. }
  1198. const scopeEl = getScopeRowElement(scopeRow);
  1199. const exitHeight = scopeEl ? Math.ceil(scopeEl.getBoundingClientRect().height) : 0;
  1200. const exitWidth = getScopeContentWidth(scopeEl);
  1201. const shouldLockRecordHeight = props.isLastRecord && exitHeight > 0;
  1202. const scopeSource = getScopeExitSource(scopeRow);
  1203. if (shouldLockRecordHeight && recordHeightLock.value === null) {
  1204. const recordEl = recordRootRef.value;
  1205. recordHeightLock.value = recordEl ? Math.ceil(recordEl.getBoundingClientRect().height) : null;
  1206. }
  1207. scopeRow.exiting = true;
  1208. scopeExitHeight.value = exitHeight;
  1209. scopeExitWidth.value = exitWidth;
  1210. isScopeExitBodyTransitionDisabled.value = true;
  1211. if (import.meta.env.MODE !== "production") {
  1212. // 诊断用:`isScopeExitCompensating` 为真时**所有正文行都不渲染**(见 shouldRenderTextContentRow),
  1213. // 补偿结束再挂回来。如果这一步发生在正文已经流出一段之后,观感就是「一小段正文重渲」。
  1214. // 出问题时看这行的 `已渲染正文行数`:>0 就说明确实有已显示的正文被藏起来又挂回。
  1215. console.warn("[record] scope 退场补偿开始(正文行会暂时隐藏)", {
  1216. exitHeight,
  1217. textRows: displayRecordRows.value.filter((row) => row.type === RecordRowTypes.Text).length,
  1218. policyRows: displayRecordRows.value.filter((row) => row.type === RecordRowTypes.PolicyTable).length,
  1219. });
  1220. }
  1221. emit("scopeHeightLockChange", {
  1222. recordId: record.value.id,
  1223. active: shouldLockRecordHeight && exitHeight > 0,
  1224. height: exitHeight,
  1225. });
  1226. emit("scopeExitStateChange", {
  1227. recordId: record.value.id,
  1228. active: true,
  1229. });
  1230. const exitingRow = scopeRow;
  1231. const exitRevision = ++scopeExitRevision;
  1232. clearScopeExitTimer();
  1233. scopeExitTimer = window.setTimeout(() => {
  1234. scopeExitTimer = null;
  1235. if (exitRevision !== scopeExitRevision) {
  1236. return;
  1237. }
  1238. void finalizeScopeExit(
  1239. exitingRow,
  1240. scopeSource,
  1241. exitHeight,
  1242. shouldLockRecordHeight,
  1243. exitRevision
  1244. );
  1245. }, scopeExitCollapseDurationMs);
  1246. };
  1247. const updateDisplayContent = (newVal: string) => {
  1248. for (let i = 0; i < displayContent.value.length; i++) {
  1249. if (displayContent.value[i] !== newVal[i]) {
  1250. displayContent.value =
  1251. displayContent.value.substring(0, i) + newVal[i] + displayContent.value.substring(i + 1);
  1252. }
  1253. }
  1254. };
  1255. const syncRecordHeightLock = () => {
  1256. if (!isLastAiStreamingRecord.value) {
  1257. return;
  1258. }
  1259. const recordEl = recordRootRef.value;
  1260. if (!recordEl) {
  1261. return;
  1262. }
  1263. const nextHeight = Math.ceil(recordEl.getBoundingClientRect().height);
  1264. if (!Number.isFinite(nextHeight) || nextHeight <= 0) {
  1265. return;
  1266. }
  1267. recordHeightLock.value = Math.max(recordHeightLock.value ?? 0, nextHeight);
  1268. };
  1269. const scopeTitleReg = /title\s*=\s*(['"]?)([^'"\s>]+)\1/i;
  1270. const updateLastRecordRow = (
  1271. text: string,
  1272. type = RecordRowTypes.Text,
  1273. state = RecordRowStates.Displaying
  1274. ) => {
  1275. let lastRow = displayRecordRows.value[displayRecordRows.value.length - 1];
  1276. if (type === RecordRowTypes.Text) {
  1277. text = stripSilenceTags(text);
  1278. if (!lastRow || lastRow.state === RecordRowStates.Displayed || lastRow.type !== type) {
  1279. text = trimDisplayTextContentStart(text);
  1280. }
  1281. if (text.length === 0) {
  1282. return;
  1283. }
  1284. }
  1285. const removeTrailingScopePreludeTextRows = () => {
  1286. while (displayRecordRows.value.length > 0) {
  1287. const trailingRow = displayRecordRows.value[displayRecordRows.value.length - 1];
  1288. if (!isRemovableScopePreludeTextRow(trailingRow)) {
  1289. break;
  1290. }
  1291. debugRowMutation("删除行(scope 前导)", trailingRow, trailingRow.content, "");
  1292. displayRecordRows.value.pop();
  1293. }
  1294. lastRow = displayRecordRows.value[displayRecordRows.value.length - 1];
  1295. };
  1296. const removeTrailingEmptyScopeStatusRows = () => {
  1297. while (displayRecordRows.value.length > 0) {
  1298. const trailingRow = displayRecordRows.value[displayRecordRows.value.length - 1];
  1299. if (!isRemovableEmptyScopeStatusRow(trailingRow)) {
  1300. break;
  1301. }
  1302. if (trailingRow.type === RecordRowTypes.Scope && !trailingRow.exiting) {
  1303. beginScopeExit(trailingRow);
  1304. break;
  1305. }
  1306. debugRowMutation("删除行(空 scope 状态)", trailingRow, trailingRow.content, "");
  1307. displayRecordRows.value.pop();
  1308. }
  1309. lastRow = displayRecordRows.value[displayRecordRows.value.length - 1];
  1310. };
  1311. if (type === RecordRowTypes.Scope) {
  1312. removeTrailingScopePreludeTextRows();
  1313. }
  1314. if (
  1315. type === RecordRowTypes.Scope &&
  1316. mergeScopeRecordRow(displayRecordRows.value, { type, content: text, state })
  1317. ) {
  1318. return;
  1319. }
  1320. // 已经有一个空的 scope 但还在流式更新时,允许直接复用它并替换标题。
  1321. if (
  1322. type === RecordRowTypes.Scope &&
  1323. lastRow &&
  1324. lastRow.type === RecordRowTypes.Scope &&
  1325. isEmptyScopeRow(lastRow)
  1326. ) {
  1327. lastRow.content = text;
  1328. lastRow.state = state;
  1329. return;
  1330. }
  1331. const hasVisibleContent =
  1332. type === RecordRowTypes.Text ? String(text || "").trim().length > 0 : !!text;
  1333. if (type !== RecordRowTypes.Scope && hasVisibleContent) {
  1334. hasVisibleAnswerContent.value = true;
  1335. removeTrailingEmptyScopeStatusRows();
  1336. }
  1337. if (type === RecordRowTypes.Text) {
  1338. const currentTextContent =
  1339. lastRow && lastRow.type === RecordRowTypes.Text && lastRow.state !== RecordRowStates.Displayed
  1340. ? lastRow.content
  1341. : "";
  1342. const segments = splitStreamingTextContentRows(currentTextContent, text);
  1343. if (segments.length === 0) {
  1344. return;
  1345. }
  1346. if (lastRow && lastRow.type === RecordRowTypes.Scope && !lastRow.exiting) {
  1347. beginScopeExit(lastRow);
  1348. }
  1349. for (const segment of segments) {
  1350. lastRow = displayRecordRows.value[displayRecordRows.value.length - 1];
  1351. if (!lastRow || lastRow.state === RecordRowStates.Displayed || lastRow.type !== type) {
  1352. if (lastRow && lastRow.type !== type) {
  1353. if (lastRow.type === RecordRowTypes.Text) {
  1354. closeTextRow(lastRow);
  1355. }
  1356. lastRow.state = RecordRowStates.Displayed;
  1357. }
  1358. displayRecordRows.value.push({
  1359. id: updateRecordRowIndex.value++,
  1360. type: type,
  1361. content: "",
  1362. state: RecordRowStates.Pending,
  1363. });
  1364. lastRow = displayRecordRows.value[displayRecordRows.value.length - 1];
  1365. if (type === RecordRowTypes.Text) {
  1366. textRowTypingFinished.value[lastRow.id] = true;
  1367. }
  1368. }
  1369. const segmentContent =
  1370. lastRow.content.length === 0
  1371. ? trimDisplayTextContentStart(segment.content)
  1372. : segment.content;
  1373. if (segmentContent.length > 0) {
  1374. lastRow.content += segmentContent;
  1375. textRowTypingFinished.value[lastRow.id] = false;
  1376. }
  1377. lastRow.state = state;
  1378. if (segment.breakAfter) {
  1379. closeTextRow(lastRow);
  1380. lastRow.state = RecordRowStates.Displayed;
  1381. }
  1382. }
  1383. return;
  1384. }
  1385. if (!lastRow || lastRow.state === RecordRowStates.Displayed || lastRow.type !== type) {
  1386. if (lastRow && lastRow.type !== type) {
  1387. if (lastRow.type === RecordRowTypes.Text) {
  1388. closeTextRow(lastRow);
  1389. }
  1390. lastRow.state = RecordRowStates.Displayed;
  1391. }
  1392. displayRecordRows.value.push({
  1393. id: updateRecordRowIndex.value++,
  1394. type: type,
  1395. content: "",
  1396. state: RecordRowStates.Pending,
  1397. });
  1398. lastRow = displayRecordRows.value[displayRecordRows.value.length - 1];
  1399. if (type === RecordRowTypes.Text) {
  1400. textRowTypingFinished.value[lastRow.id] = true;
  1401. } else if (type === RecordRowTypes.ImageContent) {
  1402. imageRowRevealFinished.value[lastRow.id] = !shouldDriveTypewriter.value;
  1403. }
  1404. }
  1405. if (type === RecordRowTypes.Text && text.length > 0) {
  1406. textRowTypingFinished.value[lastRow.id] = false;
  1407. }
  1408. lastRow.content = text;
  1409. lastRow.state = state;
  1410. };
  1411. const getLastRecordRow = () => {
  1412. if (displayRecordRows.value.length === 0) {
  1413. return null;
  1414. }
  1415. return displayRecordRows.value[displayRecordRows.value.length - 1];
  1416. };
  1417. // 优化和修正逻辑,确保 <form> 区间处理更严谨
  1418. const handleTimerTick = (val: string) => {
  1419. if (count.value >= val.length) {
  1420. clearExistingTimer();
  1421. if (record.value.state === MessageState.Finish) {
  1422. handleFinishEvent();
  1423. }
  1424. return;
  1425. }
  1426. updateDisplayContent(val);
  1427. // 判断当前字符是否存在,防止越界
  1428. if (typeof val[count.value] !== "undefined") {
  1429. showTextAnim.value = false;
  1430. // 添加当前字符到动画显示区
  1431. addText(val[count.value]);
  1432. // 通知外部内容有变化
  1433. emit("displayContentChange");
  1434. // 计数器自增,准备下一个字符
  1435. count.value++;
  1436. }
  1437. };
  1438. watch(
  1439. () => record.value.content,
  1440. (val) => {
  1441. clearExistingTimer();
  1442. if (!val || showInterruptedState.value) {
  1443. changeFlag++;
  1444. resetDisplayContent();
  1445. return;
  1446. }
  1447. /**
  1448. * ⚠️ 内容**不是纯追加**时必须整体重置再全量解析。
  1449. *
  1450. * 这里的增量解析只吃「比上次多出来的那一段」(`val.slice(count)`),
  1451. * 所以消息内容被**整块重写**(不是往后追加)时,切出来的会是新内容的**中段**——
  1452. * 那段中段会被当正文渲染出来(踩过:参考资料 JSON 的中段变成一坨文本显示在界面上)。
  1453. *
  1454. * 会整块重写的场景(F073 起):
  1455. * - 流式收尾的**卡片重排**(把政策卡片挪到正文之上)
  1456. * - `answer_end` 与增量拼接不一致时的整块重建
  1457. * - 撤草稿(内容被截短回基线)
  1458. * 纯追加(流式 delta / answer_end 的尾缀补齐)仍走增量路径,不重置、不闪。
  1459. */
  1460. if (!val.startsWith(originContent.value)) {
  1461. changeFlag++;
  1462. resetDisplayContent();
  1463. xmlFilter.reset(); // 解析器也是有状态的(buffer / 未闭合标签),一并清
  1464. if (import.meta.env.MODE !== "production") {
  1465. // 诊断用:整块重写会让整条消息重新解析(观感上是"内容被换掉")。
  1466. // 出问题时看这行就知道是哪个长度差触发的。
  1467. console.warn("[record] 内容被整块重写,已重置并全量重解析", {
  1468. before: originContent.value.length,
  1469. after: val.length,
  1470. });
  1471. }
  1472. }
  1473. const diffText = val.slice(count.value);
  1474. processRecordSections(diffText);
  1475. originContent.value = val;
  1476. count.value = val.length;
  1477. timer = setInterval(() => handleTimerTick(val), gapTime);
  1478. }
  1479. );
  1480. /**
  1481. * F073:流式轮收尾(`contentStreaming` 由真变假)时,把**已经在屏幕上的文本行**补记为
  1482. * 「打字完成」—— 它们在流式期间是**即时渲染**的(打字机关着),早就完整显示过了。
  1483. *
  1484. * 不补记的后果(2026-09-21 用户报的两个观感问题都源于此):
  1485. * ① `hasUnfinishedRevealRows` 恒为真 → `shouldDriveTypewriter` 在收尾那一刻翻真
  1486. * ② `visibleInlineDisplayRecordRows` 于是走「阻塞」分支:**最后一条未完成文本行之后的行**
  1487. * (正文之后就是 notices / 参考资料那几行)被从 DOM 里拿掉 → 容器变矮 → 滚动位置被钳制,
  1488. * 视图突然跳一下;随后挂回来时又是**新组件实例**
  1489. * ③ 新实例走 TextContent 的 `watch-initial` → `startTypewriter(0)` 把内容重打一遍,
  1490. * 并上报「打字中」→ 上级据此把视图**拽到最后一条 AI 消息的顶部**("瞬间返回到回答顶部")
  1491. *
  1492. * 非流式轮(mock / 旧后端)从不置 `contentStreaming`,这个 watch 不会触发,行为不变。
  1493. */
  1494. const markStreamedRowsAsTypingFinished = () => {
  1495. let changed = false;
  1496. for (const row of displayRecordRows.value) {
  1497. if (row.type !== RecordRowTypes.Text) continue;
  1498. if (textRowTypingFinished.value[row.id] !== true) {
  1499. textRowTypingFinished.value[row.id] = true;
  1500. changed = true;
  1501. }
  1502. textRowTypingActive.value[row.id] = false;
  1503. }
  1504. if (changed) {
  1505. syncTypewriterState();
  1506. }
  1507. };
  1508. watch(
  1509. () => record.value.contentStreaming,
  1510. (val, oldVal) => {
  1511. if (oldVal && !val) {
  1512. markStreamedRowsAsTypingFinished();
  1513. }
  1514. }
  1515. );
  1516. // 反馈组件显示由 shouldRenderFeedback 控制:历史会话立即展示,
  1517. // 新消息等打字机/媒体动画结束(triggerMediaAndFeedback 内把
  1518. // localFeedback 切到 Unselected)后才展示。
  1519. watch(
  1520. () => record.value.state,
  1521. async (val) => {
  1522. if (val === MessageState.Stop) {
  1523. changeFlag++;
  1524. if (timer) {
  1525. clearInterval(timer);
  1526. timer = null;
  1527. }
  1528. if (mediaTimer) {
  1529. clearInterval(mediaTimer);
  1530. }
  1531. await sleep(200);
  1532. let rawContent = computedOriginContentPosition(
  1533. record.value.originContent,
  1534. displayContent.value
  1535. );
  1536. stopSpeech({ answer: rawContent, record_id: record.value.id });
  1537. } else if (!timer && val === MessageState.Finish) {
  1538. handleFinishEvent();
  1539. }
  1540. }
  1541. );
  1542. const addMediaList = (localMediaList: any[], successCallback: Function) => {
  1543. if (!localMediaList || localMediaList.length === 0) {
  1544. successCallback();
  1545. return;
  1546. }
  1547. if (mediaTimer) {
  1548. clearInterval(mediaTimer);
  1549. }
  1550. mediaTimer = setInterval(() => {
  1551. if (mediaCount.value >= localMediaList.length) {
  1552. clearInterval(mediaTimer);
  1553. successCallback();
  1554. return;
  1555. }
  1556. mediaCount.value++;
  1557. displayMediaList.value = localMediaList.slice(0, mediaCount.value);
  1558. }, gapTime);
  1559. };
  1560. const addText = (text: string) => {
  1561. if (record.value.state === MessageState.Stop) {
  1562. return;
  1563. }
  1564. if (isMobileDevice) {
  1565. displayContent.value += text;
  1566. updateLastRecordRow(text);
  1567. return;
  1568. }
  1569. if (!textAnimWrapper.value) {
  1570. return;
  1571. }
  1572. let textSpan = document.createElement("span");
  1573. let regex = /^[a-zA-Z0-9 ]+$/;
  1574. if (regex.test(text)) {
  1575. textSpan.className = "entry-anim quick";
  1576. } else {
  1577. textSpan.className = "entry-anim";
  1578. }
  1579. textSpan.innerHTML = text;
  1580. textAnimWrapper.value.appendChild(textSpan);
  1581. let currentFlag = changeFlag;
  1582. const onAnimationEnd = () => {
  1583. if (currentFlag !== changeFlag) {
  1584. return;
  1585. }
  1586. textSpan.remove();
  1587. displayContent.value += text;
  1588. updateLastRecordRow(text);
  1589. if (textAnimWrapper.value.innerHTML === "") {
  1590. showTextAnim.value = false;
  1591. }
  1592. };
  1593. setTimeout(onAnimationEnd, 200);
  1594. };
  1595. // Handle TextContent typing finished
  1596. const handleTypingFinished = (rowId: number) => {
  1597. textRowTypingFinished.value[rowId] = true;
  1598. textRowTypingActive.value[rowId] = false;
  1599. console.log("[BusinessRecord][typing-finished]", {
  1600. recordId: record.value.id,
  1601. rowId,
  1602. isLastRecord: props.isLastRecord,
  1603. });
  1604. syncTypewriterState();
  1605. emit("refreshScroll");
  1606. };
  1607. const handleTypingStateChange = (rowId: number, isTypingActive: boolean) => {
  1608. textRowTypingActive.value[rowId] = isTypingActive;
  1609. if (isTypingActive) {
  1610. textRowTypingFinished.value[rowId] = false;
  1611. }
  1612. console.log("[BusinessRecord][typing-state-change]", {
  1613. recordId: record.value.id,
  1614. rowId,
  1615. isTypingActive,
  1616. isLastRecord: props.isLastRecord,
  1617. });
  1618. syncTypewriterState();
  1619. };
  1620. const handleImageRevealFinished = (rowId: number) => {
  1621. imageRowRevealFinished.value[rowId] = true;
  1622. imageRowRevealActive.value[rowId] = false;
  1623. console.log("[BusinessRecord][image-reveal-finished]", {
  1624. recordId: record.value.id,
  1625. rowId,
  1626. isLastRecord: props.isLastRecord,
  1627. });
  1628. syncTypewriterState();
  1629. emit("refreshScroll");
  1630. };
  1631. const handleImageRevealStateChange = (rowId: number, isRevealActive: boolean) => {
  1632. imageRowRevealActive.value[rowId] = isRevealActive;
  1633. if (isRevealActive) {
  1634. imageRowRevealFinished.value[rowId] = false;
  1635. }
  1636. console.log("[BusinessRecord][image-reveal-state-change]", {
  1637. recordId: record.value.id,
  1638. rowId,
  1639. isRevealActive,
  1640. isLastRecord: props.isLastRecord,
  1641. });
  1642. syncTypewriterState();
  1643. };
  1644. const openSessionReadableLog = () => {
  1645. const sessionId = localStorage.getItem("ba_current_session_id");
  1646. if (!sessionId) {
  1647. return;
  1648. }
  1649. const date = new Date().toLocaleDateString("en-CA");
  1650. window.open(
  1651. `https://qingpu-data-api.metamaker.cn/llms/qingpu/debug/session-readable-log?date=${date}&session_id=${sessionId}`
  1652. );
  1653. };
  1654. const observeLastRecordHeight = () => {
  1655. lastRecordResizeObserver?.disconnect();
  1656. lastRecordResizeObserver = null;
  1657. lastObservedRecordHeight = 0;
  1658. const target = recordRootRef.value;
  1659. if (!target || typeof ResizeObserver === "undefined") {
  1660. return;
  1661. }
  1662. lastObservedRecordHeight = target.getBoundingClientRect().height;
  1663. syncRecordHeightLock();
  1664. lastRecordResizeObserver = new ResizeObserver((entries) => {
  1665. const nextHeight = entries[0]?.contentRect.height ?? target.getBoundingClientRect().height;
  1666. if (!props.isLastRecord) {
  1667. lastObservedRecordHeight = nextHeight;
  1668. return;
  1669. }
  1670. syncRecordHeightLock();
  1671. const heightGrowth = nextHeight - lastObservedRecordHeight;
  1672. if (lastObservedRecordHeight > 0 && heightGrowth > 0) {
  1673. emit("refreshScroll", { heightGrowth });
  1674. }
  1675. lastObservedRecordHeight = nextHeight;
  1676. });
  1677. lastRecordResizeObserver.observe(target);
  1678. };
  1679. const handleFinishEvent = () => {
  1680. if (showInterruptedState.value) {
  1681. return;
  1682. }
  1683. handleEndSpeech({
  1684. answer: record.value.originContent,
  1685. record_id: record.value.id,
  1686. });
  1687. const triggerMediaAndFeedback = async () => {
  1688. addMediaList(mediaList.value, async () => {
  1689. if (props.enableFeedback && !isFormQueryMode && localFeedback.value === FeedbackType.None) {
  1690. localFeedback.value = FeedbackType.Unselected;
  1691. }
  1692. if (record.value.references && record.value.references.length) {
  1693. showReferences.value = true;
  1694. }
  1695. if (record.value.relatedQuestions && record.value.relatedQuestions.length) {
  1696. await sleep(500);
  1697. showRelatedQuestions.value = true;
  1698. }
  1699. });
  1700. emit("displayMediaChange");
  1701. };
  1702. const waitAllTypingFinished = () => {
  1703. if (!shouldWaitForTypewriterCompletion.value) {
  1704. triggerMediaAndFeedback();
  1705. return;
  1706. }
  1707. setTimeout(waitAllTypingFinished, 100);
  1708. };
  1709. waitAllTypingFinished();
  1710. };
  1711. watch(
  1712. isLastAiStreamingRecord,
  1713. (isStreaming) => {
  1714. if (!isStreaming) {
  1715. recordHeightLock.value = null;
  1716. return;
  1717. }
  1718. syncRecordHeightLock();
  1719. },
  1720. { immediate: true }
  1721. );
  1722. onMounted(() => {
  1723. unregisterRefLinksModal = modalMutex.register(refLinksModalId, {
  1724. close: closeRefLinksPanel,
  1725. isOpen: () => refLinksPanelVisible.value,
  1726. });
  1727. observeLastRecordHeight();
  1728. const initialContent = props.content || "";
  1729. if (initialContent && !showInterruptedState.value) {
  1730. processRecordSections(initialContent);
  1731. originContent.value = initialContent;
  1732. count.value = initialContent.length;
  1733. }
  1734. });
  1735. onBeforeUnmount(() => {
  1736. closeRefLinksPanel();
  1737. unregisterRefLinksModal?.();
  1738. emitTypewriterStateChange(false);
  1739. lastRecordResizeObserver?.disconnect();
  1740. lastRecordResizeObserver = null;
  1741. clearScopeExitTimer();
  1742. scopeExitRevision += 1;
  1743. if (!isEffectHumanState || !props.human) {
  1744. return;
  1745. }
  1746. if (isEffectHumanState.getTaskState == SchedulerTaskState.Idle) {
  1747. return;
  1748. }
  1749. if (isEffectHumanState != props.human.getCurrentState) {
  1750. return;
  1751. }
  1752. if (timer) {
  1753. clearInterval(timer);
  1754. timer = null;
  1755. }
  1756. props.human.setMainAnimationNameImmediateEffective(
  1757. props.human.getIdlePoses[0],
  1758. SchedulerTaskState.Idle
  1759. );
  1760. });
  1761. let formBuffer = "";
  1762. function recordParser(input: string) {
  1763. const resultRows = xmlFilter.processChunk(input);
  1764. resultRows.forEach((row) => {
  1765. updateLastRecordRow(row.content, row.type, RecordRowStates.Displaying);
  1766. });
  1767. }
  1768. // 流式处理文本,自动分段
  1769. // 处理流式和完整输入,支持断续和完整的 val
  1770. function openPreview(media: any, index: number, e: any) {
  1771. emit("changeIdleState", "interruptSpeech");
  1772. let rect = e.currentTarget?.getBoundingClientRect?.() || e.target.getBoundingClientRect();
  1773. $mediaViewer.openModal({
  1774. index,
  1775. media: { ...media, rect },
  1776. list: record.value.mediaList,
  1777. });
  1778. }
  1779. const getUserAttachmentPreviewIndex = (attachment: any) => {
  1780. const url = String(attachment?.url || "").trim();
  1781. if (!url) {
  1782. return 0;
  1783. }
  1784. const index = previewableUserAttachmentUrls.value.findIndex((item) => item === url);
  1785. return index >= 0 ? index : 0;
  1786. };
  1787. function handleError(e: any) {
  1788. e.target.style.objectFit = "none";
  1789. e.target.src = defaultImage;
  1790. }
  1791. async function handleFeedbackChange(feedback: FeedbackType) {
  1792. localFeedback.value = feedback;
  1793. // [已移除] 反馈统计埋点:统计接口(老接口)已按用户要求删除(2026-09-18)。
  1794. // 反馈本身仍写入 DMS(见 submitLikeFeedback / cancelFeedback / handleDislikeConfirm)
  1795. emit("feedback", feedback, record.value.id);
  1796. }
  1797. </script>
  1798. <style lang="scss">
  1799. @use "./record-theme.scss";
  1800. .record-modal-wrap {
  1801. position: fixed;
  1802. background: rgba(0, 0, 0, 0.7);
  1803. top: 0;
  1804. left: 0;
  1805. width: 100vw;
  1806. height: 100vh;
  1807. z-index: 200;
  1808. }
  1809. .chat-record-line {
  1810. font-size: 15px;
  1811. pointer-events: auto;
  1812. transition: all 0.3s ease-in-out;
  1813. animation: slide-up-fade 0.3s forwards cubic-bezier(0.22, 1, 0.36, 1);
  1814. &.with-feedback-margin {
  1815. padding-bottom: 8px;
  1816. }
  1817. &.with-feedback-margin-rated {
  1818. padding-bottom: 8px;
  1819. }
  1820. }
  1821. .chat-record-me {
  1822. background: rgba(176, 198, 253, 0.18);
  1823. color: #333333;
  1824. text-align: center;
  1825. /* title/h5_regular */
  1826. font-family: PingFang SC;
  1827. font-style: normal;
  1828. font-weight: 400;
  1829. line-height: 24px;
  1830. padding: 12px 15px 12px 15px;
  1831. border-radius: 16px 16px 4px 16px;
  1832. margin-bottom: 12px;
  1833. backdrop-filter: blur(4px);
  1834. -webkit-backdrop-filter: blur(4px);
  1835. display: inline-block;
  1836. margin-left: 10px;
  1837. align-self: flex-end;
  1838. flex-shrink: 0;
  1839. text-align: left;
  1840. position: relative;
  1841. transform-origin: right bottom;
  1842. span {
  1843. &::selection {
  1844. background: rgba(24, 144, 255, 0.24);
  1845. }
  1846. }
  1847. &.full-mode {
  1848. // background-color: rgba(176, 198, 253, 0.65);
  1849. // color: #303133;
  1850. }
  1851. &.desktop {
  1852. color: #000;
  1853. box-shadow: 0px 4px 8px 0px rgba(0, 0, 0, 0.04);
  1854. background: linear-gradient(180deg, rgba(222, 231, 255, 0.1) 0%, rgba(222, 231, 255, 0.2) 100%);
  1855. position: relative;
  1856. &:before {
  1857. content: "";
  1858. position: absolute;
  1859. inset: 0;
  1860. border-radius: inherit;
  1861. padding: 1px;
  1862. /* 控制描边厚度 */
  1863. background: radial-gradient(
  1864. 70.66% 143.6% at 37.72% 0%,
  1865. #ffffff 0%,
  1866. rgba(255, 255, 255, 0) 100%
  1867. );
  1868. /* 关键:中间镂空,仅保留“描边” */
  1869. -webkit-mask:
  1870. linear-gradient(#000 0 0) content-box,
  1871. linear-gradient(#000 0 0);
  1872. -webkit-mask-composite: xor;
  1873. mask:
  1874. linear-gradient(#000 0 0) content-box,
  1875. linear-gradient(#000 0 0);
  1876. mask-composite: exclude;
  1877. pointer-events: none;
  1878. /* 不挡交互 */
  1879. z-index: 1;
  1880. /* 在内容之上 */
  1881. }
  1882. }
  1883. }
  1884. .chat-record-ai {
  1885. min-width: 45px;
  1886. // background: rgba(255, 255, 255, 0.75);
  1887. position: relative;
  1888. // box-shadow: inset 1px 1px 44px rgba(255, 255, 255, 0.17), inset 0px -10px 25px rgba(255, 255, 255, 0.2), inset 0px 4px 19px rgba(255, 255, 255, 0.36);
  1889. border-radius: 0px 10px 10px 10px;
  1890. color: rgba(48, 49, 51, 1);
  1891. /* title/h5_regular */
  1892. font-family: PingFang SC;
  1893. font-style: normal;
  1894. font-weight: 400;
  1895. line-height: 24px;
  1896. // padding: 12px 15px 12px 15px;
  1897. margin-bottom: 12px;
  1898. // backdrop-filter: blur(8px);
  1899. // -webkit-backdrop-filter: blur(8px);
  1900. margin-right: 10px;
  1901. display: inline-block;
  1902. text-align: left;
  1903. flex-shrink: 0;
  1904. transform-origin: left bottom;
  1905. span {
  1906. &::selection {
  1907. background: rgb(200, 204, 207);
  1908. }
  1909. }
  1910. &.full-mode {
  1911. background-color: rgba(255, 255, 255, 0.5);
  1912. }
  1913. }
  1914. .record--business.ba-record-ai.is-loading {
  1915. background: transparent;
  1916. box-shadow: none;
  1917. padding: 0;
  1918. }
  1919. .business-scope-content-outside {
  1920. display: block;
  1921. margin-bottom: 8px;
  1922. text-align: left;
  1923. }
  1924. .business-record-body {
  1925. min-width: 0;
  1926. max-width: 100%;
  1927. transition: transform 300ms cubic-bezier(0.22, 1, 0.36, 1);
  1928. will-change: transform;
  1929. }
  1930. .business-record-body.is-scope-exit-transition-disabled {
  1931. transition: none !important;
  1932. }
  1933. .business-record-body.is-scope-exiting {
  1934. transform: translateY(calc(var(--scope-exit-offset, 0px) * -1));
  1935. }
  1936. .session-readable-log-row {
  1937. display: flex;
  1938. margin-top: 8px;
  1939. }
  1940. .session-readable-log-btn {
  1941. border: 0;
  1942. border-radius: 999px;
  1943. padding: 6px 12px;
  1944. background: rgba(53, 37, 205, 0.08);
  1945. color: #3525cd;
  1946. font-size: 12px;
  1947. line-height: 1.4;
  1948. cursor: pointer;
  1949. }
  1950. .session-readable-log-btn:hover {
  1951. background: rgba(53, 37, 205, 0.14);
  1952. }
  1953. .ba-ref-links-summary {
  1954. width: 100%;
  1955. margin-top: 12px;
  1956. padding-top: 12px;
  1957. border-top: 1px solid rgba(199, 196, 216, 0.2);
  1958. color: #141b2b;
  1959. }
  1960. .ba-ref-links-summary-title {
  1961. margin-bottom: 8px;
  1962. color: rgba(70, 69, 85, 0.6);
  1963. font-size: 12px;
  1964. font-weight: 500;
  1965. line-height: 1.4;
  1966. }
  1967. .ba-ref-links-row {
  1968. display: flex;
  1969. align-items: center;
  1970. gap: 8px;
  1971. max-width: 100%;
  1972. min-width: 0;
  1973. }
  1974. .ba-ref-links-chip-list {
  1975. display: flex;
  1976. align-items: center;
  1977. gap: 8px;
  1978. max-width: 100%;
  1979. min-width: 0;
  1980. overflow-x: hidden;
  1981. overflow-y: hidden;
  1982. }
  1983. .ba-ref-links-chip {
  1984. display: inline-flex;
  1985. align-items: center;
  1986. gap: 4px;
  1987. min-width: 0;
  1988. max-width: 198px;
  1989. height: 25px;
  1990. padding: 3px 8px;
  1991. border-radius: 4px;
  1992. background: rgb(225, 232, 252);
  1993. color: #3525cd;
  1994. font-size: 12px;
  1995. font-weight: 500;
  1996. line-height: 18px;
  1997. white-space: nowrap;
  1998. text-decoration: none;
  1999. flex-shrink: 0;
  2000. }
  2001. .ba-ref-links-chip-index {
  2002. color: #3525cd;
  2003. font-weight: 500;
  2004. flex-shrink: 0;
  2005. }
  2006. .ba-ref-links-chip-title {
  2007. min-width: 0;
  2008. overflow: hidden;
  2009. text-overflow: ellipsis;
  2010. max-width: 198px;
  2011. }
  2012. .ba-ref-links-more {
  2013. height: 25px;
  2014. padding: 3px 10px;
  2015. border-radius: 4px;
  2016. outline: none;
  2017. border: none;
  2018. background: rgb(225, 232, 252);
  2019. color: #3525cd;
  2020. font-size: 12px;
  2021. font-weight: 700;
  2022. line-height: 18px;
  2023. cursor: pointer;
  2024. flex-shrink: 0;
  2025. }
  2026. .ba-ref-links-more:hover {
  2027. background: #e2dfff;
  2028. }
  2029. .ref-links-viewer-modal {
  2030. position: fixed;
  2031. inset: 0;
  2032. z-index: 220;
  2033. pointer-events: none;
  2034. }
  2035. .ref-links-viewer-content {
  2036. position: absolute;
  2037. top: 0;
  2038. right: 0;
  2039. bottom: 0;
  2040. width: 480px;
  2041. max-width: 100vw;
  2042. background: #ffffff;
  2043. box-shadow: -12px 0 32px rgba(20, 27, 43, 0.12);
  2044. display: flex;
  2045. flex-direction: column;
  2046. overflow: hidden;
  2047. pointer-events: auto;
  2048. }
  2049. .ref-links-viewer-header {
  2050. display: flex;
  2051. align-items: center;
  2052. justify-content: space-between;
  2053. gap: 16px;
  2054. padding: 24px 24px 12px;
  2055. flex-shrink: 0;
  2056. }
  2057. .ref-links-viewer-title {
  2058. color: #141b2b;
  2059. font-size: 24px;
  2060. font-weight: 500;
  2061. line-height: 1.4;
  2062. }
  2063. .ref-links-viewer-close {
  2064. width: 40px;
  2065. height: 40px;
  2066. border: 0;
  2067. border-radius: 999px;
  2068. background: transparent;
  2069. color: #464555;
  2070. display: inline-flex;
  2071. align-items: center;
  2072. justify-content: center;
  2073. cursor: pointer;
  2074. }
  2075. .ref-links-viewer-close:hover {
  2076. background: rgba(53, 37, 205, 0.06);
  2077. }
  2078. .ref-links-viewer-list {
  2079. display: flex;
  2080. flex-direction: column;
  2081. gap: 16px;
  2082. padding: 0 24px 32px;
  2083. overflow-y: auto;
  2084. min-height: 0;
  2085. }
  2086. .ref-links-card {
  2087. display: flex;
  2088. flex-direction: column;
  2089. gap: 8px;
  2090. padding: 24px;
  2091. border: 1px solid #e9edff;
  2092. border-radius: 12px;
  2093. background: #ffffff;
  2094. box-shadow: 0 1px 1.75px rgba(0, 0, 0, 0.05);
  2095. }
  2096. .ref-links-card-head {
  2097. display: flex;
  2098. align-items: flex-start;
  2099. justify-content: space-between;
  2100. gap: 12px;
  2101. }
  2102. .ref-links-card-title {
  2103. min-width: 0;
  2104. color: #141b2b;
  2105. font-size: 16px;
  2106. font-weight: 500;
  2107. line-height: 1.6;
  2108. -webkit-line-clamp: 1;
  2109. -webkit-box-orient: vertical;
  2110. display: -webkit-box;
  2111. overflow: hidden;
  2112. text-overflow: ellipsis;
  2113. white-space: nowrap;
  2114. }
  2115. .ref-links-card-tag {
  2116. max-width: 92px;
  2117. padding: 2px 8px;
  2118. border-radius: 4px;
  2119. background: rgba(225, 232, 253, 1);
  2120. color: #3525cd;
  2121. font-size: 12px;
  2122. font-weight: 500;
  2123. line-height: 1.4;
  2124. overflow: hidden;
  2125. text-overflow: ellipsis;
  2126. white-space: nowrap;
  2127. flex-shrink: 0;
  2128. }
  2129. .ref-links-card-content {
  2130. color: #464555;
  2131. font-size: 12px;
  2132. font-weight: 500;
  2133. line-height: 1.6;
  2134. -webkit-line-clamp: 2;
  2135. -webkit-box-orient: vertical;
  2136. display: -webkit-box;
  2137. overflow: hidden;
  2138. text-overflow: ellipsis;
  2139. }
  2140. .ref-links-card-link {
  2141. display: inline-flex;
  2142. align-items: center;
  2143. gap: 4px;
  2144. width: max-content;
  2145. color: #3525cd;
  2146. font-size: 12px;
  2147. font-weight: 700;
  2148. line-height: 1.4;
  2149. margin-top: 8px;
  2150. text-decoration: none;
  2151. }
  2152. .ref-links-card-link:hover {
  2153. text-decoration: underline;
  2154. text-underline-offset: 4px;
  2155. }
  2156. .ref-links-panel-enter-active,
  2157. .ref-links-panel-leave-active {
  2158. transition: transform 0.25s cubic-bezier(0.22, 1, 0.36, 1);
  2159. }
  2160. .ref-links-panel-enter-from,
  2161. .ref-links-panel-leave-to {
  2162. transform: translateX(100%);
  2163. }
  2164. .chat-record-me .session-readable-log-row {
  2165. justify-content: flex-end;
  2166. }
  2167. .chat-record-ai .session-readable-log-row {
  2168. justify-content: flex-start;
  2169. }
  2170. .scope-content-shell {
  2171. display: block;
  2172. width: 100%;
  2173. min-width: 0;
  2174. }
  2175. .business-record-body-fade-enter-active,
  2176. .business-record-body-fade-leave-active {
  2177. transition:
  2178. opacity 300ms cubic-bezier(0.22, 1, 0.36, 1),
  2179. transform 300ms cubic-bezier(0.22, 1, 0.36, 1);
  2180. }
  2181. .business-record-body-fade-enter-from,
  2182. .business-record-body-fade-leave-to {
  2183. opacity: 0;
  2184. }
  2185. .business-record-body-fade-enter-to,
  2186. .business-record-body-fade-leave-from {
  2187. opacity: 1;
  2188. }
  2189. .ba-message-attachments {
  2190. display: flex;
  2191. flex-wrap: wrap;
  2192. justify-content: flex-end;
  2193. align-self: flex-end;
  2194. gap: 8px;
  2195. width: 100%;
  2196. margin-bottom: 12px;
  2197. pointer-events: auto;
  2198. clear: both;
  2199. &.desktop {
  2200. max-width: min(420px, 60vw);
  2201. margin-left: auto;
  2202. }
  2203. }
  2204. .ba-message-attachment {
  2205. position: relative;
  2206. overflow: hidden;
  2207. border: 1px solid rgba(199, 196, 216, 0.3);
  2208. border-radius: 12px;
  2209. background: #ffffff;
  2210. box-shadow: 0 1px 1.75px rgba(0, 0, 0, 0.05);
  2211. }
  2212. .ba-message-attachment.is-image {
  2213. width: 68px;
  2214. height: 68px;
  2215. padding: 0;
  2216. border: 0;
  2217. background: transparent;
  2218. box-shadow: none;
  2219. }
  2220. .ba-message-attachment.is-image :deep(.image-content-wrap) {
  2221. width: 100%;
  2222. height: 100%;
  2223. margin: 0;
  2224. }
  2225. .ba-message-attachment.is-file {
  2226. min-width: 180px;
  2227. max-width: 240px;
  2228. min-height: 68px;
  2229. display: flex;
  2230. align-items: center;
  2231. gap: 10px;
  2232. padding: 10px;
  2233. }
  2234. .ba-message-attachment-icon {
  2235. width: 40px;
  2236. height: 40px;
  2237. border-radius: 8px;
  2238. background: rgba(53, 37, 205, 0.1);
  2239. color: #3525cd;
  2240. display: flex;
  2241. align-items: center;
  2242. justify-content: center;
  2243. flex-shrink: 0;
  2244. font-size: 10px;
  2245. font-weight: 600;
  2246. }
  2247. .ba-message-attachment-info {
  2248. min-width: 0;
  2249. flex: 1;
  2250. }
  2251. .ba-message-attachment-name {
  2252. overflow: hidden;
  2253. color: #141b2b;
  2254. font-size: 13px;
  2255. font-weight: 500;
  2256. line-height: 1.4;
  2257. text-overflow: ellipsis;
  2258. white-space: nowrap;
  2259. }
  2260. .ba-message-attachment-size {
  2261. margin-top: 3px;
  2262. color: #464555;
  2263. font-size: 12px;
  2264. line-height: 1.4;
  2265. }
  2266. .chat-record-tips {
  2267. min-width: 45px;
  2268. background: linear-gradient(180deg, #e0e7ff 0%, #f4f7ff 100%);
  2269. border: 3px solid #ffffff;
  2270. border-radius: 16px;
  2271. position: relative;
  2272. // box-shadow: inset 1px 1px 44px rgba(255, 255, 255, 0.17), inset 0px -10px 25px rgba(255, 255, 255, 0.2), inset 0px 4px 19px rgba(255, 255, 255, 0.36);
  2273. color: #0a0b0d;
  2274. /* title/h5_regular */
  2275. font-family: PingFang SC;
  2276. font-size: 15px;
  2277. font-style: normal;
  2278. font-weight: 400;
  2279. line-height: 24px;
  2280. padding: 22px 15px 12px 15px;
  2281. margin-top: 40px;
  2282. margin-bottom: 12px;
  2283. backdrop-filter: blur(8px);
  2284. -webkit-backdrop-filter: blur(8px);
  2285. margin-right: 30px;
  2286. margin-left: 30px;
  2287. display: inline-block;
  2288. text-align: left;
  2289. flex-shrink: 0;
  2290. transform-origin: center bottom;
  2291. span {
  2292. &::selection {
  2293. background: rgb(200, 204, 207);
  2294. }
  2295. }
  2296. &.full-mode {
  2297. background-color: rgba(255, 255, 255, 0.5);
  2298. }
  2299. .tips-title {
  2300. position: absolute;
  2301. font-size: 14px;
  2302. line-height: 24px;
  2303. top: -15px;
  2304. padding: 5px 60px;
  2305. color: #fff;
  2306. left: 50%;
  2307. transform: translateX(-50%);
  2308. border-radius: 0 0 10px 10px;
  2309. margin-bottom: 8px;
  2310. font-weight: bold;
  2311. word-break: keep-all;
  2312. .tips-deco {
  2313. position: absolute;
  2314. width: 90%;
  2315. height: 100%;
  2316. left: 0;
  2317. top: 0;
  2318. z-index: -1;
  2319. &.mirror {
  2320. transform: scaleX(-100%);
  2321. left: auto;
  2322. right: 0;
  2323. }
  2324. &:before {
  2325. position: absolute;
  2326. content: "";
  2327. width: 0;
  2328. height: 0;
  2329. left: -9px;
  2330. border-top: 0 solid transparent;
  2331. border-left: 6px solid transparent;
  2332. border-right: 6px solid transparent;
  2333. border-bottom: 13px solid #0013c3;
  2334. }
  2335. &:after {
  2336. position: absolute;
  2337. content: "";
  2338. width: 100%;
  2339. height: 100%;
  2340. left: 0;
  2341. top: 0;
  2342. background: linear-gradient(180deg, #485bff 0%, #3e51f5 100%);
  2343. transform: skewX(10deg);
  2344. border-radius: 0 0 0 8px;
  2345. }
  2346. }
  2347. }
  2348. }
  2349. .business-record .content {
  2350. line-height: 24px;
  2351. text-align: left;
  2352. flex-shrink: 0;
  2353. display: block;
  2354. width: 100%;
  2355. max-width: 100%;
  2356. min-width: 0;
  2357. box-sizing: border-box;
  2358. word-break: break-word;
  2359. user-select: text;
  2360. &.isTip {
  2361. display: none;
  2362. }
  2363. a {
  2364. color: rgba(255, 255, 255, 1);
  2365. }
  2366. p:last-child {
  2367. margin-bottom: 0;
  2368. }
  2369. }
  2370. .request-interrupted-status {
  2371. display: inline-flex;
  2372. align-items: center;
  2373. min-height: 28px;
  2374. padding: 2px 10px;
  2375. border-radius: 6px;
  2376. border: 1px solid rgba(148, 163, 184, 0.28);
  2377. background: rgba(248, 250, 252, 0.9);
  2378. color: #64748b;
  2379. font-size: 13px;
  2380. line-height: 22px;
  2381. user-select: text;
  2382. }
  2383. .tips-wrap {
  2384. padding-top: 5px;
  2385. .tip {
  2386. .title {
  2387. display: flex;
  2388. font-size: 14px;
  2389. line-height: 24px;
  2390. color: #333;
  2391. font-weight: bold;
  2392. margin-bottom: 6px;
  2393. .order {
  2394. display: flex;
  2395. justify-content: center;
  2396. align-items: center;
  2397. width: 22px;
  2398. height: 22px;
  2399. border-radius: 3px;
  2400. color: #fff;
  2401. background: linear-gradient(180deg, #485bff 0%, #3e51f5 100%);
  2402. margin-right: 8px;
  2403. font-family: PingFang SC;
  2404. }
  2405. }
  2406. & + .tip {
  2407. margin-top: 16px;
  2408. }
  2409. }
  2410. .tip-footer {
  2411. margin-top: 16px;
  2412. font-weight: bold;
  2413. }
  2414. }
  2415. @keyframes word-disappear {
  2416. 0% {
  2417. opacity: 1;
  2418. transform: scale(1);
  2419. }
  2420. 100% {
  2421. opacity: 0;
  2422. transform: scale(0.5);
  2423. }
  2424. }
  2425. .entry-anim {
  2426. height: 14px;
  2427. line-height: 14px;
  2428. animation: text-fading 0.2s linear forwards;
  2429. &.quick {
  2430. animation: text-fading 0.1s linear forwards;
  2431. }
  2432. &.block {
  2433. height: 0;
  2434. display: block;
  2435. }
  2436. &.block + .block {
  2437. margin-top: 14px;
  2438. }
  2439. }
  2440. .recognizing-anim {
  2441. margin-left: -4px;
  2442. }
  2443. @media screen and (width > 768px) {
  2444. .desktop {
  2445. .business-record .content {
  2446. color: rgba(255, 255, 255, 1);
  2447. a {
  2448. color: rgba(255, 255, 255, 1);
  2449. }
  2450. }
  2451. }
  2452. }
  2453. @media (max-width: 767px) {
  2454. .ba-ref-links-summary {
  2455. max-width: 100%;
  2456. }
  2457. .ref-links-viewer-content {
  2458. left: 0;
  2459. width: 100vw;
  2460. height: 100dvh;
  2461. box-shadow: none;
  2462. }
  2463. .ref-links-viewer-header {
  2464. padding: 32px 16px 12px;
  2465. }
  2466. .ref-links-viewer-title {
  2467. font-size: 24px;
  2468. }
  2469. .ref-links-viewer-close {
  2470. width: 40px;
  2471. height: 40px;
  2472. }
  2473. .ref-links-viewer-list {
  2474. gap: 12px;
  2475. padding: 0 16px 32px;
  2476. }
  2477. .ref-links-card {
  2478. padding: 16px;
  2479. box-shadow: none;
  2480. }
  2481. .ref-links-card-head {
  2482. align-items: flex-start;
  2483. }
  2484. .ref-links-card-title {
  2485. font-size: 14px;
  2486. }
  2487. }
  2488. @keyframes text-fading {
  2489. 0% {
  2490. opacity: 0;
  2491. // filter: blur(40px);
  2492. }
  2493. 100% {
  2494. opacity: 1;
  2495. // filter: blur(0);
  2496. }
  2497. }
  2498. .thinking-anim {
  2499. display: inline-flex;
  2500. height: 21px;
  2501. vertical-align: top;
  2502. align-items: center;
  2503. .random-text {
  2504. margin-left: -4px;
  2505. min-width: 14px;
  2506. height: 14px;
  2507. line-height: 14px;
  2508. background-color: rgba(0, 0, 0, 0.6);
  2509. color: white;
  2510. text-align: left;
  2511. vertical-align: top;
  2512. }
  2513. .insert-block {
  2514. width: 14px;
  2515. height: 14px;
  2516. background-color: rgba(0, 0, 0, 0.6);
  2517. }
  2518. .lds-ellipsis {
  2519. display: inline-block;
  2520. position: relative;
  2521. width: 80px;
  2522. height: 80px;
  2523. transform: scale(0.4);
  2524. }
  2525. .lds-ellipsis div {
  2526. position: absolute;
  2527. top: 33px;
  2528. width: 13px;
  2529. height: 13px;
  2530. border-radius: 50%;
  2531. background: rgba(0, 0, 0, 0.6);
  2532. animation-timing-function: cubic-bezier(0, 1, 1, 0);
  2533. }
  2534. .lds-ellipsis div:nth-child(1) {
  2535. left: 8px;
  2536. background: gray;
  2537. animation: lds-ellipsis1 0.8s infinite;
  2538. }
  2539. .lds-ellipsis div:nth-child(2) {
  2540. left: 8px;
  2541. animation: lds-ellipsis2 0.8s infinite;
  2542. }
  2543. .lds-ellipsis div:nth-child(3) {
  2544. left: 32px;
  2545. animation: lds-ellipsis3 0.8s infinite;
  2546. }
  2547. .lds-ellipsis div:nth-child(4) {
  2548. left: 56px;
  2549. animation: lds-ellipsis4 0.8s infinite;
  2550. }
  2551. @keyframes lds-ellipsis1 {
  2552. 0% {
  2553. transform: scale(2);
  2554. border-radius: 50%;
  2555. }
  2556. 75% {
  2557. transform: scale(2.5);
  2558. border-radius: 4px;
  2559. }
  2560. 100% {
  2561. transform: scale(2);
  2562. border-radius: 50%;
  2563. }
  2564. }
  2565. @keyframes lds-ellipsis2 {
  2566. 0% {
  2567. opacity: 0.5;
  2568. transform: translate(24px, 0) scale(1.5);
  2569. }
  2570. 75% {
  2571. transform: translate(0, 0) scale(2);
  2572. }
  2573. 100% {
  2574. opacity: 1;
  2575. transform: translate(0, 0) scale(1);
  2576. }
  2577. }
  2578. @keyframes lds-ellipsis3 {
  2579. 0% {
  2580. opacity: 0.25;
  2581. transform: translate(24px, 0) scale(1);
  2582. }
  2583. 100% {
  2584. opacity: 0.5;
  2585. transform: translate(0, 0) scale(1.5);
  2586. }
  2587. }
  2588. @keyframes lds-ellipsis4 {
  2589. 0% {
  2590. opacity: 0;
  2591. transform: scale(0);
  2592. }
  2593. 100% {
  2594. opacity: 0.25;
  2595. transform: scale(1);
  2596. }
  2597. }
  2598. }
  2599. .media-row {
  2600. display: block;
  2601. margin-top: 8px;
  2602. margin-bottom: 8px;
  2603. }
  2604. .rest-media-wrapper {
  2605. width: 140px;
  2606. margin-bottom: 4px;
  2607. border-radius: 8px;
  2608. background-color: white;
  2609. display: flex;
  2610. flex-wrap: wrap;
  2611. padding: 4px;
  2612. box-sizing: border-box;
  2613. }
  2614. .media-placeholder {
  2615. width: 140px;
  2616. height: 140px;
  2617. animation: zoom-in 0.3s forwards ease-in-out;
  2618. border-radius: 8px;
  2619. overflow: hidden;
  2620. position: relative;
  2621. background: white;
  2622. .play-button {
  2623. position: absolute;
  2624. top: 50%;
  2625. left: 50%;
  2626. transform: translate(-50%, -50%);
  2627. width: 40px;
  2628. height: 40px;
  2629. border-radius: 50%;
  2630. background-color: rgba(0, 0, 0, 0.6);
  2631. background-image: url(@/assets/play-button.svg);
  2632. background-size: 100% 100%;
  2633. display: flex;
  2634. align-items: center;
  2635. justify-content: center;
  2636. cursor: pointer;
  2637. z-index: 10;
  2638. }
  2639. &.head-media {
  2640. width: 140px;
  2641. height: 140px;
  2642. }
  2643. &.several {
  2644. width: 64.5px;
  2645. height: 64.5px;
  2646. margin-top: 3px;
  2647. margin-right: 3px;
  2648. &:nth-child(1),
  2649. &:nth-child(2) {
  2650. margin-top: 0;
  2651. }
  2652. &:nth-child(2n) {
  2653. margin-right: 0;
  2654. }
  2655. .play-button {
  2656. width: 36px;
  2657. height: 36px;
  2658. }
  2659. }
  2660. &.multi {
  2661. width: 42px;
  2662. height: 42px;
  2663. margin-top: 3px;
  2664. margin-right: 3px;
  2665. &:nth-child(1),
  2666. &:nth-child(2),
  2667. &:nth-child(3) {
  2668. margin-top: 0;
  2669. }
  2670. &:nth-child(3n) {
  2671. margin-right: 0;
  2672. }
  2673. .play-button {
  2674. width: 24px;
  2675. height: 24px;
  2676. }
  2677. }
  2678. img {
  2679. width: 100%;
  2680. height: 100%;
  2681. object-fit: cover;
  2682. }
  2683. video {
  2684. width: 100%;
  2685. height: 100%;
  2686. object-fit: cover;
  2687. }
  2688. }
  2689. @keyframes zoom-in {
  2690. 0% {
  2691. transform: scale(0.5);
  2692. opacity: 0;
  2693. }
  2694. 100% {
  2695. transform: scale(1);
  2696. opacity: 1;
  2697. }
  2698. }
  2699. @keyframes slide-up-fade {
  2700. 0% {
  2701. transform: translateY(12px);
  2702. opacity: 0;
  2703. }
  2704. 100% {
  2705. transform: translateY(0);
  2706. opacity: 1;
  2707. }
  2708. }
  2709. </style>