ChatMessages.vue 57 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754
  1. <template>
  2. <div class="chat-messages-container">
  3. <div class="chat-messages" ref="messagesRef">
  4. <!-- 新对话缺省图 -->
  5. <div v-if="messages.length === 0" class="welcome-empty">
  6. <img :src="getCssUrl('--img-chat-welcome-img')" class="welcome-img" />
  7. </div>
  8. <div v-for="(message, index) in messages" :key="index" :class="['message-wrapper', message.type]" @mouseleave="copiedMessageIndex = -1">
  9. <!-- AI消息 -->
  10. <div v-if="message.type === 'ai'" class="ai-message">
  11. <div class="message-body">
  12. <!-- 思考过程折叠卡片 -->
  13. <div v-if="message.thinkingSteps && message.thinkingSteps.length > 0" class="thinking-card">
  14. <div class="thinking-duration-bar" @click="toggleThinkingCard(index)">
  15. <span v-if="getDurationText(message)" class="thinking-duration">{{ getDurationText(message) }}</span>
  16. <div :class="['thinking-arrow', { expanded: !collapsedThinking[index] }]">
  17. <img :src="getCssUrl('--img-chat-arrow-icon')" width="12" height="12" />
  18. </div>
  19. </div>
  20. <div v-show="!collapsedThinking[index]">
  21. <div class="thinking-header">
  22. <div class="thinking-header-left">
  23. <div class="thinking-icon"></div>
  24. <span class="thinking-title">思考过程 持续了几秒</span>
  25. </div>
  26. </div>
  27. <!-- thinking_token 思考内容 -->
  28. <div v-if="message.thinkingContent" class="thinking-content-card">
  29. <div class="thinking-content-header" @click="toggleThinkingContent(index)">
  30. <span class="thinking-content-title">模型思考</span>
  31. <div :class="['thinking-arrow', { expanded: !collapsedThinkingContent[index] }]">
  32. <img :src="getCssUrl('--img-chat-arrow-icon')" width="10" height="10" />
  33. </div>
  34. </div>
  35. <div v-show="!collapsedThinkingContent[index]" class="thinking-content-body">
  36. {{ message.thinkingContent }}
  37. </div>
  38. </div>
  39. <div class="thinking-body">
  40. <div
  41. v-for="(group, groupIdx) in groupStepsByAgent(message.thinkingSteps)"
  42. :key="groupIdx"
  43. :class="['agent-group', { expanded: expandedAgents[index + '-' + group.agent] }]"
  44. >
  45. <div class="agent-group-header" @click="toggleAgent(index + '-' + group.agent)">
  46. <div class="agent-group-header-left">
  47. <div class="agent-group-icon"></div>
  48. <span class="agent-group-name">{{ group.agent }}</span>
  49. </div>
  50. <!-- 最新一条执行结果,内联显示 -->
  51. <span v-if="getLatestStepMessage(group)" class="agent-group-latest">
  52. {{ getLatestStepMessage(group) }}
  53. </span>
  54. <div :class="['thinking-arrow', 'agent-arrow', { expanded: expandedAgents[index + '-' + group.agent] }]">
  55. <img :src="getCssUrl('--img-chat-arrow-icon')" width="10" height="10" />
  56. </div>
  57. </div>
  58. <div v-show="expandedAgents[index + '-' + group.agent]" class="agent-group-body">
  59. <div v-for="(step, stepIdx) in group.steps" :key="stepIdx" class="thinking-step">
  60. <!-- agent_start -->
  61. <div v-if="step.type === 'agent_start'" class="step-item step-agent-start">
  62. <div class="step-content">
  63. <span class="step-desc">{{ step.message }}</span>
  64. </div>
  65. </div>
  66. <!-- tool_call -->
  67. <div v-else-if="step.type === 'tool_call'" class="step-item step-tool-call">
  68. <div class="step-content">
  69. <span class="step-label">调用工具:</span>
  70. <span class="step-tool-name">{{ step.tool }}</span>
  71. <span v-if="step.message" class="step-desc">{{ step.message }}</span>
  72. </div>
  73. </div>
  74. <!-- executing -->
  75. <div v-else-if="step.type === 'executing'" class="step-item step-executing">
  76. <div class="step-content">
  77. <span class="step-desc">{{ step.message || '正在执行...' }}</span>
  78. <span v-if="step.tool" class="step-tool-name">{{ step.tool }}</span>
  79. </div>
  80. </div>
  81. <!-- tool_result -->
  82. <div v-else-if="step.type === 'tool_result'" class="step-item step-tool-result">
  83. <div class="step-content">
  84. <span class="step-label">工具结果:</span>
  85. <span class="step-tool-name">{{ step.tool }}</span>
  86. <span class="step-desc">{{ step.message }}</span>
  87. </div>
  88. </div>
  89. <!-- agent_done -->
  90. <div v-else-if="step.type === 'agent_done'" class="step-item step-agent-done">
  91. <div class="step-content">
  92. <span class="step-desc">{{ step.message }}</span>
  93. </div>
  94. </div>
  95. </div>
  96. </div>
  97. </div>
  98. </div>
  99. </div>
  100. </div>
  101. <div v-if="message.content" class="message-text" v-html="renderMarkdown(message.content, tableIcons)"></div>
  102. <div v-if="message.wordDownloadUrl" class="word-download-area">
  103. <a-button type="link" @click="emit('download-word', message.wordDownloadUrl)"> 下载报告文件 (.docx) </a-button>
  104. </div>
  105. <!-- 文件操作卡片 -->
  106. <div v-if="message.downloadFiles?.length" class="download-file-cards">
  107. <div v-for="(file, fIdx) in message.downloadFiles" :key="fIdx" class="download-file-card">
  108. <div class="file-card-info">
  109. <div class="file-card-icon"></div>
  110. <div class="file-card-text">
  111. <span class="file-card-name">{{ file.filename }}</span>
  112. <span class="file-card-hint">点击操作文件</span>
  113. </div>
  114. </div>
  115. <div class="file-card-actions">
  116. <button class="file-action-btn download-btn" @click="handleDownloadFile(file.url, file.filename)">
  117. <img :src="getCssUrl('--img-chat-download-icon-btn')" width="14" height="14" />
  118. <span>下载</span>
  119. </button>
  120. <button v-if="isEditableFile(file.filename)" class="file-action-btn edit-btn" @click="handleEditFile(file.url, file.filename)">
  121. <img :src="getCssUrl('--img-chat-edit-icon')" width="14" height="14" />
  122. <span>编辑</span>
  123. </button>
  124. </div>
  125. </div>
  126. </div>
  127. <div v-if="message.isLoading" class="loading-dots">
  128. <span class="dot"></span>
  129. <span class="dot"></span>
  130. <span class="dot"></span>
  131. </div>
  132. <!-- ask_user 交互提问 UI(分步向导) -->
  133. <div v-if="message.isPendingApproval && message.pendingApprovalData?.ask_user" class="approval-card">
  134. <div class="approval-icon"></div>
  135. <div class="approval-content">
  136. <div class="approval-title">{{ message.pendingApprovalData?.message }}</div>
  137. <!-- 计划内容 -->
  138. <div v-if="message.pendingApprovalData?.plan" class="approval-plan">
  139. <div class="approval-plan-label">执行计划</div>
  140. <div class="approval-plan-content">{{ message.pendingApprovalData.plan }}</div>
  141. </div>
  142. <!-- 步骤指示器 -->
  143. <div v-if="message.pendingApprovalData.ask_user.questions.length > 1" class="ask-user-stepper">
  144. <div
  145. v-for="(_, sIdx) in message.pendingApprovalData.ask_user.questions"
  146. :key="sIdx"
  147. :class="[
  148. 'ask-user-step-dot',
  149. {
  150. active: sIdx === (askUserCurrentStep[index] ?? 0),
  151. completed: sIdx < (askUserCurrentStep[index] ?? 0) || !!(askUserAnswers[index]?.[sIdx] && askUserAnswers[index][sIdx].trim()),
  152. },
  153. ]"
  154. @click="askUserCurrentStep[index] = sIdx"
  155. ></div>
  156. <span class="ask-user-step-text"
  157. >{{ (askUserCurrentStep[index] ?? 0) + 1 }} / {{ message.pendingApprovalData.ask_user.questions.length }}</span
  158. >
  159. </div>
  160. <!-- 当前问题 -->
  161. <div v-if="message.pendingApprovalData.ask_user.questions[askUserCurrentStep[index] ?? 0]" class="ask-user-question">
  162. <div class="ask-user-question-text">
  163. {{ message.pendingApprovalData.ask_user.questions[askUserCurrentStep[index] ?? 0].question }}
  164. <span
  165. v-if="message.pendingApprovalData.ask_user.questions[askUserCurrentStep[index] ?? 0].required !== false"
  166. class="ask-user-required"
  167. >*</span
  168. >
  169. </div>
  170. <!-- multiple_choice 类型 -->
  171. <div
  172. v-if="message.pendingApprovalData.ask_user.questions[askUserCurrentStep[index] ?? 0].type === 'multiple_choice'"
  173. class="ask-user-choices"
  174. >
  175. <div
  176. v-for="(choice, cIdx) in message.pendingApprovalData.ask_user.questions[askUserCurrentStep[index] ?? 0].choices"
  177. :key="cIdx"
  178. :class="[
  179. 'ask-user-choice',
  180. {
  181. selected:
  182. askUserAnswers[index]?.[askUserCurrentStep[index] ?? 0] === getChoiceValue(choice) &&
  183. !askUserOtherSelected[index]?.[askUserCurrentStep[index] ?? 0],
  184. },
  185. ]"
  186. @click="selectChoice(index, askUserCurrentStep[index] ?? 0, choice, message.pendingApprovalData.ask_user.questions.length)"
  187. >
  188. <span>{{ getChoiceValue(choice) }}</span>
  189. </div>
  190. <!-- Other 选项 -->
  191. <div
  192. :class="['ask-user-choice', { selected: askUserOtherSelected[index]?.[askUserCurrentStep[index] ?? 0] }]"
  193. @click="selectOther(index, askUserCurrentStep[index] ?? 0)"
  194. >
  195. <span>其他</span>
  196. </div>
  197. <input
  198. v-if="askUserOtherSelected[index]?.[askUserCurrentStep[index] ?? 0]"
  199. class="ask-user-other-input"
  200. placeholder="请输入..."
  201. :value="askUserAnswers[index]?.[askUserCurrentStep[index] ?? 0]"
  202. @input="askUserAnswers[index][askUserCurrentStep[index] ?? 0] = ($event.target as HTMLInputElement).value"
  203. />
  204. </div>
  205. <!-- text 类型 -->
  206. <div
  207. v-else-if="message.pendingApprovalData.ask_user.questions[askUserCurrentStep[index] ?? 0].type === 'text'"
  208. class="ask-user-text"
  209. >
  210. <textarea
  211. class="ask-user-textarea"
  212. placeholder="请输入..."
  213. :value="askUserAnswers[index]?.[askUserCurrentStep[index] ?? 0]"
  214. @input="askUserAnswers[index][askUserCurrentStep[index] ?? 0] = ($event.target as HTMLTextAreaElement).value"
  215. ></textarea>
  216. </div>
  217. </div>
  218. <!-- 操作按钮 -->
  219. <div class="approval-actions">
  220. <button v-if="(askUserCurrentStep[index] ?? 0) > 0" class="approval-btn nav-btn" @click="goPrevStep(index)">上一步</button>
  221. <button
  222. v-if="(askUserCurrentStep[index] ?? 0) < message.pendingApprovalData.ask_user.questions.length - 1"
  223. class="approval-btn approve-btn"
  224. :disabled="
  225. !isCurrentStepAnswered(
  226. index,
  227. askUserCurrentStep[index] ?? 0,
  228. message.pendingApprovalData.ask_user.questions[askUserCurrentStep[index] ?? 0]
  229. )
  230. "
  231. @click="goNextStep(index, message.pendingApprovalData.ask_user.questions.length)"
  232. >下一步</button
  233. >
  234. <button
  235. v-if="(askUserCurrentStep[index] ?? 0) === message.pendingApprovalData.ask_user.questions.length - 1"
  236. class="approval-btn approve-btn"
  237. :disabled="
  238. !isCurrentStepAnswered(
  239. index,
  240. askUserCurrentStep[index] ?? 0,
  241. message.pendingApprovalData.ask_user.questions[askUserCurrentStep[index] ?? 0]
  242. )
  243. "
  244. @click="handleSubmitAskUser(index)"
  245. >提交</button
  246. >
  247. <button class="approval-btn reject-btn" @click="handleCancelAskUser">取消</button>
  248. </div>
  249. </div>
  250. </div>
  251. </div>
  252. <!-- AI消息操作栏 -->
  253. <div class="message-actions">
  254. <div class="action-btn" @click="copyMessageContent(message.content, index)" :title="copiedMessageIndex === index ? '复制成功' : '复制'">
  255. <img :src="copyIconUrl(index)" width="14" height="14" />
  256. </div>
  257. <span v-if="message.createdAt" class="action-time">{{ formatFullTime(message.createdAt) }}</span>
  258. </div>
  259. </div>
  260. <!-- 用户消息 -->
  261. <div v-else class="user-message">
  262. <div class="message-body">
  263. <div class="message-text" v-html="renderMarkdown(message.content, tableIcons)"></div>
  264. <div v-if="message.attachedFile" class="attached-file-card" @click="emit('file-preview', message.attachedFile)">
  265. <div class="file-icon-card"></div>
  266. <div class="file-info-card">
  267. <div class="file-name-card">{{ message.attachedFile.name }}</div>
  268. <div class="file-size-card">{{ formatFileSize(message.attachedFile.size) }}</div>
  269. </div>
  270. </div>
  271. </div>
  272. <!-- 用户消息操作栏 -->
  273. <div class="message-actions">
  274. <div class="action-btn" @click="copyMessageContent(message.content, index)" :title="copiedMessageIndex === index ? '复制成功' : '复制'">
  275. <img :src="copyIconUrl(index)" width="14" height="14" />
  276. </div>
  277. <span v-if="message.createdAt" class="action-time">{{ formatFullTime(message.createdAt) }}</span>
  278. </div>
  279. </div>
  280. </div>
  281. </div>
  282. <!-- 回到底部按钮 -->
  283. <div v-if="!isAtBottom" class="scroll-to-bottom" @click="scrollToBottom">
  284. <div class="scroll-to-bottom-icon"></div>
  285. </div>
  286. <!-- 表格预览弹窗 -->
  287. <div v-if="showPreviewModal" class="table-preview-overlay" @click.self="closePreview">
  288. <div class="table-preview-modal">
  289. <div class="table-preview-header">
  290. <span class="table-preview-title">表格预览</span>
  291. <div class="table-preview-close" @click="closePreview">
  292. <img :src="getCssUrl('--img-chat-close-icon-btn')" width="16" height="16" />
  293. </div>
  294. </div>
  295. <div class="table-preview-body" v-html="previewTableHtml"></div>
  296. </div>
  297. </div>
  298. </div>
  299. </template>
  300. <script setup lang="ts">
  301. import { ref, reactive, computed, watch, onMounted, onBeforeUnmount } from 'vue';
  302. import dayjs from 'dayjs';
  303. import { renderMarkdown, formatFileSize, tableHtmlToMarkdown, tableHtmlToCsv, isMdFile, isTextFile } from './utils';
  304. import { getToken } from '/@/utils/auth';
  305. import { message } from 'ant-design-vue';
  306. import type { Message, AttachedFile, ThinkingStep } from './types';
  307. // import katex from 'katex';
  308. // import 'katex/dist/katex.min.css';
  309. const getCssUrl = (varName: string) => {
  310. const val = getComputedStyle(document.documentElement).getPropertyValue(varName).trim();
  311. return val.replace(/^url\(["']?/, '').replace(/["']?\)$/, '');
  312. };
  313. const tableIcons = {
  314. copy: getCssUrl('--img-chat-copy-icon'),
  315. download: getCssUrl('--img-chat-download-icon-btn'),
  316. preview: getCssUrl('--img-chat-preview-icon'),
  317. copySuccess: getCssUrl('--img-chat-copy-success-icon'),
  318. };
  319. const copyIconUrl = computed(() => {
  320. const icon = getCssUrl('--img-chat-copy-icon');
  321. const successIcon = getCssUrl('--img-chat-copy-success-icon');
  322. return (index: number) => (copiedMessageIndex.value === index ? successIcon : icon);
  323. });
  324. // 全局计时器 - 每秒刷新一次,用于实时显示思考耗时
  325. const nowTs = ref(Date.now());
  326. let timerInterval: ReturnType<typeof setInterval> | null = null;
  327. const getDurationText = (message: Message): string => {
  328. // 优先使用后端返回的 duration_ms(已包含 baseDurationMs 累加)
  329. if (message.durationMs) {
  330. const totalSec = Math.round(message.durationMs / 1000);
  331. const min = Math.floor(totalSec / 60);
  332. const sec = totalSec % 60;
  333. return `已工作 ${min}分${sec.toString().padStart(2, '0')}秒`;
  334. }
  335. // 审批等待中 - 暂停显示中断前的累计时长
  336. if (message.isPendingApproval && message.pendingApprovalData?.elapsedMs) {
  337. const totalSec = Math.round(message.pendingApprovalData.elapsedMs / 1000);
  338. const min = Math.floor(totalSec / 60);
  339. const sec = totalSec % 60;
  340. return `已工作 ${min}分${sec.toString().padStart(2, '0')}秒`;
  341. }
  342. // 前端实时计时(含中断前累计时长)
  343. if (message.generateStartTime && message.isLoading) {
  344. const baseMs = message.baseDurationMs || 0;
  345. const elapsed = Math.floor((nowTs.value - message.generateStartTime + baseMs) / 1000);
  346. const min = Math.floor(elapsed / 60);
  347. const sec = elapsed % 60;
  348. return `已工作 ${min}分${sec.toString().padStart(2, '0')}秒`;
  349. }
  350. return '';
  351. };
  352. const props = defineProps<{
  353. messages: Message[];
  354. }>();
  355. // 自动初始化 ask_user 答案状态
  356. watch(
  357. () => props.messages,
  358. (msgs) => {
  359. msgs.forEach((msg, idx) => {
  360. if (msg.isPendingApproval && msg.pendingApprovalData?.ask_user?.questions) {
  361. initAskUserAnswers(idx, msg.pendingApprovalData.ask_user.questions);
  362. }
  363. });
  364. },
  365. { immediate: true, deep: true }
  366. );
  367. const emit = defineEmits<{
  368. (e: 'file-preview', file: AttachedFile): void;
  369. (e: 'download-word', url: string): void;
  370. (e: 'open-file-preview', file: AttachedFile): void;
  371. (e: 'ask-user-submit', answers: string[]): void;
  372. (e: 'ask-user-cancel'): void;
  373. }>();
  374. const isEditableFile = (filename: string) => isMdFile(filename) || isTextFile(filename);
  375. const handleDownloadFile = (url: string, filename: string) => {
  376. if (!url) return;
  377. const a = document.createElement('a');
  378. a.href = url;
  379. a.download = filename;
  380. document.body.appendChild(a);
  381. a.click();
  382. document.body.removeChild(a);
  383. };
  384. const handleEditFile = async (url: string, filename: string) => {
  385. try {
  386. const resp = await fetch(url, { headers: { 'X-Access-Token': getToken() } });
  387. if (!resp.ok) throw new Error(`HTTP ${resp.status}`);
  388. const content = await resp.text();
  389. const ext = filename.split('.').pop()?.toLowerCase() || '';
  390. const mimeMap: Record<string, string> = {
  391. md: 'text/markdown',
  392. txt: 'text/plain',
  393. json: 'application/json',
  394. xml: 'text/xml',
  395. yaml: 'text/yaml',
  396. yml: 'text/yaml',
  397. csv: 'text/csv',
  398. };
  399. const file: AttachedFile = {
  400. id: `report-${Date.now()}`,
  401. name: filename,
  402. size: content.length,
  403. type: mimeMap[ext] || 'text/plain',
  404. content,
  405. uploadTime: new Date().toISOString(),
  406. };
  407. emit('open-file-preview', file);
  408. } catch (err) {
  409. console.error('获取文件内容失败:', err);
  410. message.error('获取文件内容失败');
  411. }
  412. };
  413. // ask_user 答案状态(按消息索引存储)
  414. const askUserAnswers = reactive<Record<number, string[]>>({});
  415. const askUserOtherSelected = reactive<Record<number, boolean[]>>({});
  416. const askUserCurrentStep = reactive<Record<number, number>>({});
  417. // choice 可能是字符串或 { value: "..." } 对象,统一提取字符串
  418. const getChoiceValue = (choice: any): string => {
  419. if (typeof choice === 'string') return choice;
  420. if (choice && typeof choice === 'object' && 'value' in choice) return choice.value;
  421. return String(choice);
  422. };
  423. const initAskUserAnswers = (index: number, questions: { question: string; type: string; choices?: any[] }[]) => {
  424. if (askUserAnswers[index]) return;
  425. askUserAnswers[index] = questions.map(() => '');
  426. askUserOtherSelected[index] = questions.map(() => false);
  427. askUserCurrentStep[index] = 0;
  428. };
  429. const isCurrentStepAnswered = (msgIndex: number, qIndex: number, question: { required?: boolean; type: string }) => {
  430. const answers = askUserAnswers[msgIndex];
  431. if (!answers) return false;
  432. if (question.required === false && !answers[qIndex]) return true;
  433. return !!(answers[qIndex] && answers[qIndex].trim() !== '');
  434. };
  435. const goNextStep = (msgIndex: number, totalQuestions: number) => {
  436. if (askUserCurrentStep[msgIndex] < totalQuestions - 1) {
  437. askUserCurrentStep[msgIndex]++;
  438. }
  439. };
  440. const goPrevStep = (msgIndex: number) => {
  441. if (askUserCurrentStep[msgIndex] > 0) {
  442. askUserCurrentStep[msgIndex]--;
  443. }
  444. };
  445. const selectChoice = (msgIndex: number, qIndex: number, choice: any, totalQuestions: number) => {
  446. if (!askUserAnswers[msgIndex]) return;
  447. askUserAnswers[msgIndex][qIndex] = getChoiceValue(choice);
  448. askUserOtherSelected[msgIndex][qIndex] = false;
  449. // 单选自动跳到下一题(非最后一题时)
  450. if (qIndex < totalQuestions - 1) {
  451. goNextStep(msgIndex, totalQuestions);
  452. }
  453. };
  454. const selectOther = (msgIndex: number, qIndex: number) => {
  455. if (!askUserOtherSelected[msgIndex]) return;
  456. askUserOtherSelected[msgIndex][qIndex] = true;
  457. askUserAnswers[msgIndex][qIndex] = '';
  458. };
  459. const handleSubmitAskUser = (index: number) => {
  460. const answers = askUserAnswers[index];
  461. if (!answers) return;
  462. emit('ask-user-submit', [...answers]);
  463. };
  464. const handleCancelAskUser = () => {
  465. emit('ask-user-cancel');
  466. };
  467. const messagesRef = ref<HTMLElement>();
  468. const collapsedThinking = reactive<Record<number, boolean>>({});
  469. const collapsedThinkingContent = reactive<Record<number, boolean>>({});
  470. const expandedAgents = reactive<Record<string, boolean>>({});
  471. const isAtBottom = ref(true);
  472. const copiedMessageIndex = ref(-1);
  473. // 表格预览状态
  474. const previewTableHtml = ref('');
  475. const showPreviewModal = ref(false);
  476. const handleTableAction = (e: Event) => {
  477. const target = (e.target as HTMLElement).closest('.table-action-btn') as HTMLElement;
  478. if (!target) return;
  479. const action = target.dataset.action;
  480. const encodedTable = target.dataset.table;
  481. if (!action || !encodedTable) return;
  482. const tableHtml = decodeURIComponent(encodedTable);
  483. switch (action) {
  484. case 'copy': {
  485. const markdown = tableHtmlToMarkdown(tableHtml);
  486. const doCopy = async () => {
  487. try {
  488. await navigator.clipboard.writeText(markdown);
  489. } catch {
  490. const ta = document.createElement('textarea');
  491. ta.value = markdown;
  492. ta.style.position = 'fixed';
  493. ta.style.opacity = '0';
  494. document.body.appendChild(ta);
  495. ta.select();
  496. document.execCommand('copy');
  497. document.body.removeChild(ta);
  498. }
  499. };
  500. doCopy().then(() => {
  501. const btn = target;
  502. const img = btn.querySelector('img');
  503. const successIcon = btn.dataset.iconSuccess;
  504. const originalIcon = btn.dataset.icon;
  505. if (img && successIcon) {
  506. img.src = successIcon;
  507. btn.title = '复制成功';
  508. const reset = () => {
  509. img.src = originalIcon!;
  510. btn.title = '复制Markdown';
  511. wrapper.removeEventListener('mouseleave', reset);
  512. };
  513. const wrapper = btn.closest('.markdown-table-wrapper')!;
  514. wrapper.addEventListener('mouseleave', reset);
  515. }
  516. });
  517. break;
  518. }
  519. case 'csv': {
  520. const csv = tableHtmlToCsv(tableHtml);
  521. const blob = new Blob([csv], { type: 'text/csv;charset=utf-8;' });
  522. const url = URL.createObjectURL(blob);
  523. const a = document.createElement('a');
  524. a.href = url;
  525. a.download = `table_${Date.now()}.csv`;
  526. a.click();
  527. URL.revokeObjectURL(url);
  528. break;
  529. }
  530. case 'preview': {
  531. previewTableHtml.value = tableHtml;
  532. showPreviewModal.value = true;
  533. break;
  534. }
  535. }
  536. };
  537. const closePreview = () => {
  538. showPreviewModal.value = false;
  539. previewTableHtml.value = '';
  540. };
  541. const checkScrollBottom = () => {
  542. const el = messagesRef.value;
  543. if (!el) return;
  544. const threshold = 50;
  545. isAtBottom.value = el.scrollHeight - el.scrollTop - el.clientHeight < threshold;
  546. };
  547. const scrollToBottom = () => {
  548. const el = messagesRef.value;
  549. if (el) {
  550. el.scrollTop = el.scrollHeight;
  551. }
  552. };
  553. const forceScrollToBottom = () => {
  554. const el = messagesRef.value;
  555. if (el) {
  556. el.scrollTop = el.scrollHeight;
  557. }
  558. isAtBottom.value = true;
  559. };
  560. onMounted(() => {
  561. messagesRef.value?.addEventListener('click', handleTableAction);
  562. messagesRef.value?.addEventListener('scroll', checkScrollBottom);
  563. timerInterval = setInterval(() => {
  564. nowTs.value = Date.now();
  565. }, 1000);
  566. });
  567. onBeforeUnmount(() => {
  568. messagesRef.value?.removeEventListener('click', handleTableAction);
  569. messagesRef.value?.removeEventListener('scroll', checkScrollBottom);
  570. if (timerInterval) {
  571. clearInterval(timerInterval);
  572. timerInterval = null;
  573. }
  574. });
  575. const toggleThinkingCard = (index: number) => {
  576. collapsedThinking[index] = !collapsedThinking[index];
  577. };
  578. const toggleThinkingContent = (index: number) => {
  579. collapsedThinkingContent[index] = !collapsedThinkingContent[index];
  580. };
  581. const toggleAgent = (key: string) => {
  582. expandedAgents[key] = !expandedAgents[key];
  583. };
  584. const getLatestStepMessage = (group: AgentGroup): string => {
  585. if (group.steps.length === 0) return '';
  586. const last = group.steps[group.steps.length - 1];
  587. if (last.type === 'executing') return last.message || '正在执行...';
  588. if (last.type === 'tool_call') return last.message || last.tool || '';
  589. if (last.type === 'tool_result') return last.message || '';
  590. if (last.type === 'agent_start') return last.message || '';
  591. if (last.type === 'agent_done') return last.message || '';
  592. if (last.type === 'updated_todo_list') return '任务列表已更新';
  593. return '';
  594. };
  595. interface AgentGroup {
  596. agent: string;
  597. steps: ThinkingStep[];
  598. }
  599. const groupStepsByAgent = (steps: ThinkingStep[]): AgentGroup[] => {
  600. const groupMap = new Map<string, ThinkingStep[]>();
  601. for (const step of steps) {
  602. const agentName = step.agent || '系统';
  603. if (!groupMap.has(agentName)) {
  604. groupMap.set(agentName, []);
  605. }
  606. groupMap.get(agentName)!.push(step);
  607. }
  608. const result: AgentGroup[] = [];
  609. for (const [agent, agentSteps] of groupMap) {
  610. result.push({ agent, steps: agentSteps });
  611. }
  612. return result;
  613. };
  614. const getAgentCount = (steps: ThinkingStep[]): number => {
  615. const agents = new Set(steps.map((s) => s.agent || '系统'));
  616. return agents.size;
  617. };
  618. const formatFullTime = (createdAt: string) => {
  619. return dayjs(createdAt).format('YYYY-MM-DD HH:mm:ss');
  620. };
  621. const copyMessageContent = async (content: string, index: number) => {
  622. if (!content) return;
  623. try {
  624. await navigator.clipboard.writeText(content);
  625. copiedMessageIndex.value = index;
  626. } catch {
  627. const textarea = document.createElement('textarea');
  628. textarea.value = content;
  629. textarea.style.position = 'fixed';
  630. textarea.style.opacity = '0';
  631. document.body.appendChild(textarea);
  632. textarea.select();
  633. document.execCommand('copy');
  634. document.body.removeChild(textarea);
  635. copiedMessageIndex.value = index;
  636. }
  637. };
  638. defineExpose({ messagesRef, isAtBottom, forceScrollToBottom });
  639. </script>
  640. <style scoped lang="less">
  641. .chat-messages-container {
  642. flex: 1;
  643. position: relative;
  644. display: flex;
  645. flex-direction: column;
  646. overflow: hidden;
  647. }
  648. .chat-messages {
  649. flex: 1;
  650. overflow-y: auto;
  651. padding: 20px;
  652. position: relative;
  653. .welcome-empty {
  654. position: absolute;
  655. top: 50%;
  656. left: 50%;
  657. transform: translate(-50%, -50%);
  658. display: flex;
  659. align-items: center;
  660. justify-content: center;
  661. .welcome-img {
  662. max-width: 300px;
  663. max-height: 300px;
  664. object-fit: contain;
  665. }
  666. }
  667. .message-wrapper {
  668. // margin-bottom: 20px;
  669. .ai-message {
  670. display: flex;
  671. flex-wrap: wrap;
  672. .message-agent {
  673. display: flex;
  674. margin-bottom: 8px;
  675. opacity: 0;
  676. }
  677. .message-body {
  678. padding: 12px 12px 4px 12px;
  679. border-radius: 6px;
  680. width: 100%;
  681. min-width: 0;
  682. overflow: hidden;
  683. /* 思考过程卡片 */
  684. .thinking-card {
  685. margin-bottom: 12px;
  686. overflow: hidden;
  687. .thinking-duration-bar {
  688. display: flex;
  689. align-items: center;
  690. justify-content: space-between;
  691. padding: 8px 14px;
  692. border-bottom: 1px solid rgba(63, 80, 106, 0.3);
  693. cursor: pointer;
  694. user-select: none;
  695. transition: background 0.2s;
  696. &:hover {
  697. background: rgba(10, 132, 255, 0.08);
  698. }
  699. .thinking-duration {
  700. font-size: 16px;
  701. color: #8b949e;
  702. }
  703. .thinking-arrow {
  704. color: #8b949e;
  705. display: flex;
  706. align-items: center;
  707. transition: transform 0.2s;
  708. &.expanded {
  709. transform: rotate(180deg);
  710. }
  711. }
  712. }
  713. .thinking-header {
  714. display: flex;
  715. align-items: center;
  716. padding: 10px 14px;
  717. .thinking-header-left {
  718. display: flex;
  719. align-items: center;
  720. gap: 8px;
  721. }
  722. .thinking-icon {
  723. width: 16px;
  724. height: 16px;
  725. background-image: var(--img-chat-thinking-icon);
  726. background-repeat: no-repeat;
  727. background-size: 100% 100%;
  728. }
  729. .thinking-title {
  730. font-size: 13px;
  731. font-weight: 500;
  732. color: #8b949e;
  733. }
  734. .thinking-count {
  735. font-size: 12px;
  736. color: #8b949e;
  737. background: rgba(10, 132, 255, 0.1);
  738. padding: 1px 6px;
  739. border-radius: 10px;
  740. }
  741. }
  742. .thinking-content-card {
  743. margin: 4px 14px 8px;
  744. border: 1px solid rgba(63, 80, 106, 0.25);
  745. border-radius: 6px;
  746. overflow: hidden;
  747. .thinking-content-header {
  748. display: flex;
  749. align-items: center;
  750. justify-content: space-between;
  751. padding: 8px 12px;
  752. cursor: pointer;
  753. user-select: none;
  754. transition: background 0.2s;
  755. &:hover {
  756. background: rgba(10, 132, 255, 0.08);
  757. }
  758. .thinking-content-title {
  759. font-size: 12px;
  760. font-weight: 500;
  761. color: #8b949e;
  762. }
  763. .thinking-arrow {
  764. display: flex;
  765. align-items: center;
  766. transition: transform 0.2s;
  767. &.expanded {
  768. transform: rotate(180deg);
  769. }
  770. }
  771. }
  772. .thinking-content-body {
  773. padding: 8px 12px;
  774. max-height: 200px;
  775. overflow-y: auto;
  776. font-size: 13px;
  777. line-height: 1.6;
  778. color: #8b949e;
  779. white-space: pre-wrap;
  780. word-break: break-word;
  781. }
  782. }
  783. .thinking-body {
  784. padding: 8px 14px;
  785. .agent-group {
  786. margin-bottom: 8px;
  787. border: 1px solid transparent;
  788. border-radius: 6px;
  789. overflow: hidden;
  790. transition: border-color 0.2s;
  791. &.expanded {
  792. border-color: rgba(63, 80, 106, 0.25);
  793. }
  794. &:last-child {
  795. margin-bottom: 0;
  796. }
  797. .agent-group-header {
  798. display: flex;
  799. align-items: center;
  800. justify-content: space-between;
  801. padding: 8px 12px;
  802. cursor: pointer;
  803. user-select: none;
  804. transition: background 0.2s;
  805. &:hover {
  806. background: rgba(10, 132, 255, 0.1);
  807. }
  808. .agent-group-header-left {
  809. display: flex;
  810. align-items: center;
  811. gap: 8px;
  812. }
  813. .agent-group-icon {
  814. width: 14px;
  815. height: 14px;
  816. background-image: var(--img-chat-agent-icon);
  817. background-repeat: no-repeat;
  818. background-size: 100% 100%;
  819. flex-shrink: 0;
  820. }
  821. .agent-group-name {
  822. font-size: 13px;
  823. font-weight: 500;
  824. color: #fff;
  825. }
  826. .agent-group-latest {
  827. font-size: 12px;
  828. color: #8b949e;
  829. margin-left: 8px;
  830. overflow: hidden;
  831. text-overflow: ellipsis;
  832. white-space: nowrap;
  833. flex: 1;
  834. min-width: 0;
  835. }
  836. .agent-arrow {
  837. margin-left: 8px;
  838. flex-shrink: 0;
  839. display: flex;
  840. align-items: center;
  841. transition: transform 0.2s;
  842. &.expanded {
  843. transform: rotate(180deg);
  844. }
  845. }
  846. }
  847. .agent-group-body {
  848. padding: 4px 12px;
  849. max-height: 300px;
  850. overflow-y: auto;
  851. }
  852. }
  853. .thinking-step {
  854. .step-item {
  855. display: flex;
  856. align-items: flex-start;
  857. padding: 6px 0;
  858. border-bottom: 1px solid rgba(63, 80, 106, 0.15);
  859. &:last-child {
  860. border-bottom: none;
  861. }
  862. .step-content {
  863. flex: 1;
  864. font-size: 13px;
  865. line-height: 1.5;
  866. color: #b0b8c4;
  867. .step-agent-name {
  868. color: #0a84ff;
  869. font-weight: 500;
  870. }
  871. .step-tool-name {
  872. color: #79c0ff;
  873. font-family: monospace;
  874. font-size: 12px;
  875. background: rgba(10, 132, 255, 0.1);
  876. padding: 1px 5px;
  877. border-radius: 3px;
  878. }
  879. .step-label {
  880. color: #8b949e;
  881. }
  882. .step-desc {
  883. color: #b0b8c4;
  884. }
  885. }
  886. }
  887. }
  888. }
  889. }
  890. .message-text {
  891. font-size: 14px;
  892. font-weight: 400;
  893. line-height: 1.6;
  894. color: #e0e6ed;
  895. word-break: break-word;
  896. overflow-wrap: break-word;
  897. :deep(.session-ref-icon) {
  898. width: 14px;
  899. height: 14px;
  900. vertical-align: -2px;
  901. }
  902. :deep(h1),
  903. :deep(h2),
  904. :deep(h3),
  905. :deep(h4),
  906. :deep(h5),
  907. :deep(h6) {
  908. color: #fff;
  909. }
  910. :deep(p) {
  911. margin: 0;
  912. }
  913. :deep(code) {
  914. background: rgba(10, 132, 255, 0.1);
  915. padding: 1px 4px;
  916. border-radius: 3px;
  917. font-size: 12px;
  918. }
  919. :deep(pre) {
  920. background: rgba(10, 132, 255, 0.1);
  921. padding: 8px;
  922. border-radius: 4px;
  923. overflow-x: auto;
  924. margin: 6px 0;
  925. white-space: pre-wrap;
  926. }
  927. :deep(pre code) {
  928. background: transparent;
  929. padding: 0;
  930. }
  931. :deep(ul),
  932. :deep(ol) {
  933. padding-left: 18px;
  934. margin: 4px 0;
  935. }
  936. :deep(blockquote) {
  937. border-left: 3px solid rgba(10, 132, 255, 0.3);
  938. padding-left: 10px;
  939. margin: 6px 0;
  940. color: #8b949e;
  941. }
  942. :deep(table) {
  943. border-collapse: collapse;
  944. margin: 6px 0;
  945. }
  946. :deep(th),
  947. :deep(td) {
  948. border: 1px solid rgba(63, 80, 106, 0.5);
  949. padding: 4px 8px;
  950. }
  951. :deep(th) {
  952. background: rgba(10, 132, 255, 0.1);
  953. }
  954. :deep(strong) {
  955. font-weight: 600;
  956. }
  957. :deep(.markdown-table-wrapper) {
  958. position: relative;
  959. margin: 6px 0;
  960. max-width: 100%;
  961. overflow-x: auto;
  962. .table-actions {
  963. position: absolute;
  964. top: 4px;
  965. right: 4px;
  966. display: flex;
  967. gap: 2px;
  968. opacity: 0;
  969. transition: opacity 0.2s;
  970. z-index: 1;
  971. }
  972. &:hover .table-actions {
  973. opacity: 1;
  974. }
  975. .table-action-btn {
  976. width: 26px;
  977. height: 26px;
  978. display: flex;
  979. align-items: center;
  980. justify-content: center;
  981. border-radius: 4px;
  982. color: #8b949e;
  983. cursor: pointer;
  984. background: rgba(22, 27, 34, 0.8);
  985. backdrop-filter: blur(4px);
  986. transition: all 0.2s;
  987. &:hover {
  988. color: #e0e6ed;
  989. background: rgba(10, 132, 255, 0.3);
  990. }
  991. }
  992. }
  993. }
  994. }
  995. .loading-dots {
  996. display: flex;
  997. align-items: center;
  998. gap: 6px;
  999. padding: 4px 0;
  1000. .dot {
  1001. width: 8px;
  1002. height: 8px;
  1003. border-radius: 50%;
  1004. background: rgba(10, 132, 255, 0.4);
  1005. animation: dot-bounce 1.4s ease-in-out infinite both;
  1006. &:nth-child(1) {
  1007. animation-delay: 0s;
  1008. }
  1009. &:nth-child(2) {
  1010. animation-delay: 0.2s;
  1011. }
  1012. &:nth-child(3) {
  1013. animation-delay: 0.4s;
  1014. }
  1015. }
  1016. }
  1017. @keyframes dot-bounce {
  1018. 0%,
  1019. 80%,
  1020. 100% {
  1021. transform: scale(0.6);
  1022. opacity: 0.4;
  1023. }
  1024. 40% {
  1025. transform: scale(1);
  1026. opacity: 1;
  1027. }
  1028. }
  1029. .approval-card {
  1030. display: flex;
  1031. align-items: flex-start;
  1032. gap: 12px;
  1033. padding: 14px 16px;
  1034. margin-top: 12px;
  1035. background: #002f4a;
  1036. border: 1px solid #005482;
  1037. border-radius: 8px;
  1038. .approval-icon {
  1039. width: 36px;
  1040. height: 36px;
  1041. background-image: var(--img-chat-session-approve-icon);
  1042. background-repeat: no-repeat;
  1043. background-size: 100% 100%;
  1044. flex-shrink: 0;
  1045. }
  1046. .approval-content {
  1047. flex: 1;
  1048. .approval-title {
  1049. font-size: 14px;
  1050. font-weight: 600;
  1051. color: #e0e6ed;
  1052. margin-bottom: 6px;
  1053. }
  1054. .approval-plan {
  1055. margin-bottom: 14px;
  1056. padding: 10px 12px;
  1057. background: rgba(10, 132, 255, 0.08);
  1058. border: 1px solid rgba(10, 132, 255, 0.2);
  1059. border-radius: 6px;
  1060. .approval-plan-label {
  1061. font-size: 12px;
  1062. color: #0a84ff;
  1063. font-weight: 600;
  1064. margin-bottom: 6px;
  1065. }
  1066. .approval-plan-content {
  1067. font-size: 13px;
  1068. color: #c9d1d9;
  1069. line-height: 1.6;
  1070. white-space: pre-wrap;
  1071. }
  1072. }
  1073. .ask-user-question {
  1074. margin-bottom: 14px;
  1075. .ask-user-question-text {
  1076. font-size: 13px;
  1077. color: #c9d1d9;
  1078. margin-bottom: 8px;
  1079. line-height: 1.5;
  1080. .ask-user-required {
  1081. color: #f85149;
  1082. margin-left: 2px;
  1083. }
  1084. }
  1085. .ask-user-choices {
  1086. display: flex;
  1087. flex-direction: column;
  1088. gap: 6px;
  1089. .ask-user-choice {
  1090. display: flex;
  1091. align-items: center;
  1092. padding: 8px 12px;
  1093. background: rgba(255, 255, 255, 0.04);
  1094. border: 1px solid rgba(63, 80, 106, 0.4);
  1095. border-radius: 6px;
  1096. cursor: pointer;
  1097. font-size: 13px;
  1098. color: #c9d1d9;
  1099. transition: all 0.2s;
  1100. &:hover {
  1101. background: rgba(10, 132, 255, 0.1);
  1102. border-color: rgba(10, 132, 255, 0.4);
  1103. }
  1104. &.selected {
  1105. background: rgba(10, 132, 255, 0.15);
  1106. border-color: #0a84ff;
  1107. color: #fff;
  1108. }
  1109. }
  1110. .ask-user-other-input {
  1111. margin-top: 4px;
  1112. padding: 8px 12px;
  1113. font-size: 13px;
  1114. color: #e0e6ed;
  1115. background: rgba(255, 255, 255, 0.06);
  1116. border: 1px solid rgba(63, 80, 106, 0.5);
  1117. border-radius: 6px;
  1118. outline: none;
  1119. width: 100%;
  1120. &:focus {
  1121. border-color: #0a84ff;
  1122. background: rgba(10, 132, 255, 0.08);
  1123. }
  1124. &::placeholder {
  1125. color: #6e7681;
  1126. }
  1127. }
  1128. }
  1129. .ask-user-text {
  1130. .ask-user-textarea {
  1131. width: 100%;
  1132. min-height: 60px;
  1133. padding: 8px 12px;
  1134. font-size: 13px;
  1135. color: #e0e6ed;
  1136. background: rgba(255, 255, 255, 0.06);
  1137. border: 1px solid rgba(63, 80, 106, 0.5);
  1138. border-radius: 6px;
  1139. outline: none;
  1140. resize: vertical;
  1141. font-family: inherit;
  1142. &:focus {
  1143. border-color: #0a84ff;
  1144. background: rgba(10, 132, 255, 0.08);
  1145. }
  1146. &::placeholder {
  1147. color: #6e7681;
  1148. }
  1149. }
  1150. }
  1151. }
  1152. .ask-user-stepper {
  1153. display: flex;
  1154. align-items: center;
  1155. gap: 6px;
  1156. margin-bottom: 14px;
  1157. .ask-user-step-dot {
  1158. width: 8px;
  1159. height: 8px;
  1160. border-radius: 50%;
  1161. background: rgba(63, 80, 106, 0.5);
  1162. cursor: pointer;
  1163. transition: all 0.2s;
  1164. &.active {
  1165. background: #0a84ff;
  1166. width: 20px;
  1167. border-radius: 4px;
  1168. }
  1169. &.completed {
  1170. background: rgba(10, 132, 255, 0.5);
  1171. }
  1172. }
  1173. .ask-user-step-text {
  1174. margin-left: 6px;
  1175. font-size: 12px;
  1176. color: #6e7681;
  1177. }
  1178. }
  1179. .approval-actions {
  1180. display: flex;
  1181. gap: 10px;
  1182. .approval-btn {
  1183. padding: 6px 20px;
  1184. border-radius: 6px;
  1185. font-size: 13px;
  1186. font-weight: 500;
  1187. cursor: pointer;
  1188. border: none;
  1189. transition: all 0.2s;
  1190. &.approve-btn {
  1191. background: #0a84ff;
  1192. color: #fff;
  1193. &:hover:not(:disabled) {
  1194. background: #3a9bfd;
  1195. }
  1196. &:disabled {
  1197. opacity: 0.4;
  1198. cursor: not-allowed;
  1199. }
  1200. }
  1201. &.nav-btn {
  1202. background: rgba(255, 255, 255, 0.08);
  1203. color: #c9d1d9;
  1204. border: 1px solid rgba(63, 80, 106, 0.5);
  1205. &:hover {
  1206. background: rgba(255, 255, 255, 0.15);
  1207. }
  1208. }
  1209. &.reject-btn {
  1210. background: rgba(255, 255, 255, 0.08);
  1211. color: #e0e6ed;
  1212. border: 1px solid rgba(63, 80, 106, 0.5);
  1213. &:hover {
  1214. background: rgba(255, 255, 255, 0.15);
  1215. }
  1216. }
  1217. }
  1218. }
  1219. }
  1220. }
  1221. .download-file-cards {
  1222. display: flex;
  1223. flex-direction: column;
  1224. gap: 8px;
  1225. margin-top: 12px;
  1226. .download-file-card {
  1227. display: flex;
  1228. align-items: center;
  1229. justify-content: space-between;
  1230. padding: 12px 16px;
  1231. background: linear-gradient(135deg, rgba(0, 47, 74, 0.8) 0%, rgba(0, 60, 90, 0.6) 100%);
  1232. border: 1px solid rgba(0, 84, 130, 0.6);
  1233. border-radius: 10px;
  1234. transition: all 0.2s ease;
  1235. &:hover {
  1236. border-color: rgba(10, 132, 255, 0.4);
  1237. box-shadow: 0 2px 12px rgba(0, 0, 0, 0.15);
  1238. }
  1239. .file-card-info {
  1240. display: flex;
  1241. align-items: center;
  1242. gap: 12px;
  1243. min-width: 0;
  1244. flex: 1;
  1245. .file-card-icon {
  1246. width: 36px;
  1247. height: 36px;
  1248. background-image: var(--img-chat-download-icon);
  1249. background-repeat: no-repeat;
  1250. background-size: 100% 100%;
  1251. flex-shrink: 0;
  1252. opacity: 0.9;
  1253. }
  1254. .file-card-text {
  1255. display: flex;
  1256. flex-direction: column;
  1257. gap: 2px;
  1258. min-width: 0;
  1259. .file-card-name {
  1260. font-size: 13px;
  1261. font-weight: 500;
  1262. color: #e0e6ed;
  1263. overflow: hidden;
  1264. text-overflow: ellipsis;
  1265. white-space: nowrap;
  1266. }
  1267. .file-card-hint {
  1268. font-size: 11px;
  1269. color: #6e7681;
  1270. }
  1271. }
  1272. }
  1273. .file-card-actions {
  1274. display: flex;
  1275. gap: 8px;
  1276. flex-shrink: 0;
  1277. .file-action-btn {
  1278. display: inline-flex;
  1279. align-items: center;
  1280. gap: 5px;
  1281. padding: 6px 14px;
  1282. border-radius: 7px;
  1283. font-size: 12px;
  1284. font-weight: 500;
  1285. cursor: pointer;
  1286. border: none;
  1287. transition: all 0.2s ease;
  1288. white-space: nowrap;
  1289. &.download-btn {
  1290. background: rgba(255, 255, 255, 0.08);
  1291. color: #c9d1d9;
  1292. border: 1px solid rgba(63, 80, 106, 0.5);
  1293. &:hover {
  1294. background: rgba(255, 255, 255, 0.14);
  1295. color: #e0e6ed;
  1296. border-color: rgba(63, 80, 106, 0.8);
  1297. }
  1298. }
  1299. &.edit-btn {
  1300. background: linear-gradient(135deg, #0a84ff 0%, #0066cc 100%);
  1301. color: #fff;
  1302. border: 1px solid rgba(10, 132, 255, 0.5);
  1303. box-shadow: 0 2px 6px rgba(10, 132, 255, 0.2);
  1304. &:hover {
  1305. background: linear-gradient(135deg, #3a9bfd 0%, #0a84ff 100%);
  1306. box-shadow: 0 3px 10px rgba(10, 132, 255, 0.35);
  1307. }
  1308. }
  1309. }
  1310. }
  1311. }
  1312. }
  1313. }
  1314. .user-message {
  1315. display: flex;
  1316. flex-wrap: wrap;
  1317. justify-content: flex-end;
  1318. align-items: flex-start;
  1319. .message-agent {
  1320. display: flex;
  1321. margin-bottom: 8px;
  1322. margin-left: 5px;
  1323. }
  1324. .message-body {
  1325. background: rgba(10, 132, 255, 0.15);
  1326. padding: 12px;
  1327. border-radius: 6px 0 6px 6px;
  1328. max-width: 700px;
  1329. min-width: 0;
  1330. overflow: hidden;
  1331. .message-text {
  1332. font-size: 14px;
  1333. font-weight: 400;
  1334. line-height: 1.6;
  1335. color: #e0e6ed;
  1336. word-break: break-word;
  1337. overflow-wrap: break-word;
  1338. :deep(.session-ref-icon) {
  1339. width: 14px;
  1340. height: 14px;
  1341. vertical-align: -2px;
  1342. }
  1343. :deep(h1, h2, h3, h4, h5, h6) {
  1344. color: #fff;
  1345. }
  1346. :deep(p) {
  1347. margin: 0;
  1348. }
  1349. :deep(code) {
  1350. background: rgba(0, 0, 0, 0.2);
  1351. padding: 1px 4px;
  1352. border-radius: 3px;
  1353. font-size: 12px;
  1354. }
  1355. :deep(pre) {
  1356. background: rgba(0, 0, 0, 0.2);
  1357. padding: 8px;
  1358. border-radius: 4px;
  1359. overflow-x: auto;
  1360. margin: 6px 0;
  1361. white-space: pre-wrap;
  1362. }
  1363. :deep(pre code) {
  1364. background: transparent;
  1365. padding: 0;
  1366. }
  1367. }
  1368. .attached-file-card {
  1369. margin-top: 10px;
  1370. background: rgba(255, 255, 255, 0.08);
  1371. border-radius: 6px;
  1372. display: flex;
  1373. align-items: center;
  1374. gap: 10px;
  1375. padding: 8px;
  1376. cursor: pointer;
  1377. transition: all 0.3s;
  1378. &:hover {
  1379. background: rgba(255, 255, 255, 0.15);
  1380. }
  1381. .file-icon-card {
  1382. width: 32px;
  1383. height: 32px;
  1384. background-image: var(--img-chat-attach-icon);
  1385. background-repeat: no-repeat;
  1386. background-size: 100% 100%;
  1387. flex-shrink: 0;
  1388. }
  1389. .file-info-card {
  1390. flex: 1;
  1391. min-width: 0;
  1392. .file-name-card {
  1393. font-size: 12px;
  1394. font-weight: 400;
  1395. line-height: 1.4;
  1396. color: #e0e6ed;
  1397. overflow: hidden;
  1398. text-overflow: ellipsis;
  1399. white-space: nowrap;
  1400. margin-bottom: 2px;
  1401. }
  1402. .file-size-card {
  1403. font-size: 11px;
  1404. font-weight: 400;
  1405. line-height: 1.3;
  1406. color: #8b949e;
  1407. }
  1408. }
  1409. }
  1410. }
  1411. }
  1412. .ai-message,
  1413. .user-message {
  1414. .message-actions {
  1415. display: flex;
  1416. align-items: center;
  1417. gap: 8px;
  1418. width: 100%;
  1419. opacity: 0;
  1420. transition: opacity 0.2s;
  1421. .action-btn {
  1422. width: 26px;
  1423. height: 26px;
  1424. display: flex;
  1425. align-items: center;
  1426. justify-content: center;
  1427. border-radius: 4px;
  1428. color: #8b949e;
  1429. cursor: pointer;
  1430. transition: all 0.2s;
  1431. &:hover {
  1432. color: #e0e6ed;
  1433. background: rgba(10, 132, 255, 0.15);
  1434. }
  1435. }
  1436. .action-time {
  1437. font-size: 12px;
  1438. color: #8b949e;
  1439. }
  1440. }
  1441. &:hover .message-actions {
  1442. opacity: 1;
  1443. }
  1444. }
  1445. .ai-message .message-actions {
  1446. padding: 0 0 0 10px;
  1447. }
  1448. .user-message .message-actions {
  1449. padding: 4px 0 0 0;
  1450. justify-content: flex-end;
  1451. }
  1452. }
  1453. }
  1454. /* 表格预览弹窗 */
  1455. .table-preview-overlay {
  1456. position: fixed;
  1457. top: 0;
  1458. left: 0;
  1459. width: 100%;
  1460. height: 100%;
  1461. background: rgba(0, 0, 0, 0.6);
  1462. display: flex;
  1463. align-items: center;
  1464. justify-content: center;
  1465. z-index: 1000;
  1466. }
  1467. .table-preview-modal {
  1468. background: #1a1f2e;
  1469. border: 1px solid rgba(63, 80, 106, 0.5);
  1470. border-radius: 8px;
  1471. width: 90%;
  1472. max-width: 1200px;
  1473. max-height: 700px;
  1474. display: flex;
  1475. flex-direction: column;
  1476. overflow: hidden;
  1477. .table-preview-header {
  1478. display: flex;
  1479. justify-content: space-between;
  1480. align-items: center;
  1481. padding: 12px 16px;
  1482. border-bottom: 1px solid rgba(63, 80, 106, 0.3);
  1483. flex-shrink: 0;
  1484. .table-preview-title {
  1485. font-size: 15px;
  1486. font-weight: 500;
  1487. color: #e0e6ed;
  1488. }
  1489. .table-preview-close {
  1490. width: 32px;
  1491. height: 32px;
  1492. display: flex;
  1493. align-items: center;
  1494. justify-content: center;
  1495. border-radius: 4px;
  1496. color: #8b949e;
  1497. cursor: pointer;
  1498. transition: all 0.2s;
  1499. &:hover {
  1500. color: #e0e6ed;
  1501. background: rgba(10, 132, 255, 0.15);
  1502. }
  1503. }
  1504. }
  1505. :deep(.table-preview-body) {
  1506. padding: 20px;
  1507. overflow: auto;
  1508. flex: 1;
  1509. table {
  1510. width: 100%;
  1511. border-collapse: collapse;
  1512. }
  1513. th,
  1514. td {
  1515. border: 1px solid #3f506a;
  1516. padding: 10px 14px;
  1517. text-align: left;
  1518. color: #e0e6ed;
  1519. font-size: 14px;
  1520. }
  1521. th {
  1522. background: #1e2538;
  1523. font-weight: 600;
  1524. }
  1525. tbody tr {
  1526. &:nth-child(even) td {
  1527. background: rgba(10, 132, 255, 0.04);
  1528. }
  1529. &:hover td {
  1530. background: rgba(10, 132, 255, 0.1);
  1531. }
  1532. }
  1533. }
  1534. }
  1535. .scroll-to-bottom {
  1536. position: absolute;
  1537. bottom: 20px;
  1538. left: 50%;
  1539. transform: translateX(-50%);
  1540. z-index: 10;
  1541. .scroll-to-bottom-icon {
  1542. width: 40px;
  1543. height: 40px;
  1544. border-radius: 50%;
  1545. background: rgba(255, 255, 255, 0.15);
  1546. backdrop-filter: blur(4px);
  1547. background-image: var(--img-chat-scroll-bottom);
  1548. background-repeat: no-repeat;
  1549. background-size: 20px 20px;
  1550. background-position: center;
  1551. cursor: pointer;
  1552. transition: all 0.2s;
  1553. &:hover {
  1554. background-color: rgba(255, 255, 255, 0.25);
  1555. }
  1556. }
  1557. }
  1558. </style>