MiniChat.vue 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516
  1. <!-- eslint-disable vue/no-v-html -->
  2. <template>
  3. <div class="btn" @click="showAIChat">
  4. <div style="display: flex; flex-direction: row" class="btn-header">
  5. <img src="@/assets/images/vent/home/wakeBtn.png" />
  6. </div>
  7. </div>
  8. <div class="container">
  9. <div v-if="isShowChatBroad" class="mini-chat">
  10. <!-- 左侧折叠区域 -->
  11. <div class="left-side" :class="{ collapsed: isFold }" id="leftSide">
  12. <div
  13. class="addBtn"
  14. :style="{
  15. backgroundColor: isFold ? '' : '#2cb6ff',
  16. width: isFold ? '20px' : 'auto',
  17. }"
  18. @click="addNew"
  19. >
  20. <SvgIcon v-if="isFold" name="add" size="20" :color="''" />
  21. <span v-if="!isFold" class="btn-text">添加新对话</span>
  22. </div>
  23. <div v-if="isFold" class="historyBtn" @click="addNew">
  24. <SvgIcon v-if="isFold" name="history" size="20" :color="''" />
  25. </div>
  26. <div v-else class="historyBtn1">
  27. <span v-if="!isFold" class="btn-text">历史对话</span>
  28. <a-list style="width: 136px" :split="false" :data-source="sessionHistory" :scroll="190" class="custom-list">
  29. <template #renderItem="{ item }">
  30. <a-list-item
  31. class="session-item"
  32. :style="{
  33. padding: '8px 10px 0 8px',
  34. color: '#5e7081',
  35. fontSize: '10px',
  36. position: 'relative', // 新增定位
  37. }"
  38. >
  39. <!-- 新增flex布局容器 -->
  40. <div style="width: 100%">
  41. <div v-if="editingId !== item.id" class="text-container">
  42. <span class="edit-text" @click="sessionsHistory(item.id)">{{ item.name }}</span>
  43. <div class="btn-container">
  44. <EditOutlined class="edit-icon" @click="startEditing(item)" />
  45. <DeleteOutlined class="delete-icon" @click="startDelete(item)" />
  46. </div>
  47. </div>
  48. <!-- 输入框 -->
  49. <a-input
  50. size="small"
  51. v-else
  52. v-model:value="editText"
  53. v-focus
  54. @blur="handleSave(item)"
  55. @keyup.enter="handleSave(item)"
  56. class="edit-input"
  57. />
  58. </div>
  59. </a-list-item>
  60. </template>
  61. </a-list>
  62. </div>
  63. <div class="foldBtn" @click="fold">
  64. <SvgIcon v-if="isFold" name="Fold1" size="20" :color="''" />
  65. <SvgIcon v-else name="unfold" size="20" :color="''" />
  66. </div>
  67. </div>
  68. <!-- 右侧对话框 -->
  69. <div class="right-side">
  70. <div class="title"> 智能问答 </div>
  71. <!-- 对话区域 -->
  72. <div class="dialog-area" ref="dialogAreaRef">
  73. <div
  74. v-for="message in messageHistory"
  75. :key="message.id"
  76. class="flex items-center w-100%"
  77. :style="{ alignSelf: message.type === 'user' ? 'flex-end' : 'flex-start' }"
  78. >
  79. <template v-if="message.type === 'user'">
  80. <div class="flex-grow-1"></div>
  81. <div class="message-wrapper user-message-wrapper">
  82. <div class="ask-message">{{ message.parsedContent }}</div>
  83. <div class="copy-icon-container">
  84. <CopyOutlined class="copy-icon" @click="copyToClipboard(message.parsedContent)" title="复制消息" />
  85. <EditOutlined class="copy-icon" @click="editAsk(message.parsedContent)" title="重新编辑" />
  86. </div>
  87. </div>
  88. </template>
  89. <template v-else>
  90. <SvgIcon size="40" class="answerIcon" name="ai-logo" />
  91. <div class="message-wrapper ai-message-wrapper">
  92. <div class="answer-message">
  93. <div v-if="message.parsedContentR1" class="thinking-section">
  94. <div class="thinking-header" @click="isShow(message)">
  95. <span class="thinking-title"
  96. >思考过程:<RightOutlined v-if="!message.isShowThink" /> <DownOutlined v-if="message.isShowThink"
  97. /></span>
  98. </div>
  99. <div v-show="message.isShowThink" class="color-gray font-size-12px" v-html="message.parsedContentR1"></div>
  100. </div>
  101. <div v-if="message.parsedContent" v-html="message.parsedContent"> </div>
  102. </div>
  103. <div class="copy-icon-container">
  104. <CopyOutlined class="copy-icon" @click="copyToClipboard(message.parsedContent)" title="复制消息" />
  105. <RedoOutlined class="copy-icon" @click="refresh()" title="重新生成" />
  106. </div>
  107. </div>
  108. </template>
  109. </div>
  110. <!-- 建议信息 -->
  111. <div v-for="(item, index) in suggestList" :key="index" class="suggestion-item" @click="handleSuggestClick(item)">
  112. <span class="suggestion-text">{{ item }}</span>
  113. <a-icon type="right" class="suggestion-arrow" />
  114. </div>
  115. </div>
  116. <!-- 底部输入区 -->
  117. <div class="input-area">
  118. <a-textarea v-model:value="inputText" placeholder="请输入你的问题" @keyup.enter="handleSend(inputText)" class="ant-input" auto-size />
  119. <div class="ctrl-btn">
  120. <div class="input-controls">
  121. <button class="control-btn" :class="{ active: isThinking }" @click="toggleThinking">深度思考</button>
  122. <button class="control-btn" @click="stopReq()">停止响应</button>
  123. </div>
  124. <div class="action-bar">
  125. <Space>
  126. <Button class="control-btn1" size="small" @mouseenter="showModal(true)">
  127. <template #icon>
  128. <SvgIcon name="send-file" />
  129. </template>
  130. </Button>
  131. <Button class="control-btn2" size="small" @click="handleSend(inputText)">
  132. <template #icon>
  133. <SvgIcon name="send" />
  134. </template>
  135. </Button>
  136. </Space>
  137. </div>
  138. </div>
  139. <!-- 右侧文件上传区 -->
  140. <div v-if="open" @mouseenter="showModal(true)" @mouseleave="showModal(false)" class="file-upload">
  141. <!-- 上传按钮 -->
  142. <a-upload
  143. class="custom-upload"
  144. name="file"
  145. :multiple="false"
  146. :before-upload="handleBeforeUpload"
  147. :file-list="fileList"
  148. :remove="handleRemove"
  149. accept=".pdf,.docx,.xlsx,.xls"
  150. >
  151. <a-button class="upload-btn">
  152. <UploadOutlined></UploadOutlined>
  153. 从本地上传
  154. </a-button>
  155. </a-upload>
  156. </div>
  157. </div>
  158. </div>
  159. </div>
  160. <div class="doc" v-if="isShowDoc">
  161. <div class="close"> <button class="closeBtn" @click="close">关闭</button></div>
  162. <!-- 已上传文件列表 -->
  163. <div class="file-list" v-if="uploadedFiles.length">
  164. <div class="file-item" v-for="file in uploadedFiles" :key="file.id">
  165. <div class="file-info">
  166. <div class="file-name" :title="file.name">{{ file.name }}</div>
  167. </div>
  168. <div class="file-actions">
  169. <button class="btn btn-preview" @click="previewFile(file)"> <i class="fas fa-eye"></i> 预览 </button>
  170. <button class="btn btn-delete" @click="deleteFile(file.id)"> <i class="fas fa-trash"></i> 删除 </button>
  171. </div>
  172. </div>
  173. </div>
  174. <!-- 预览内容 -->
  175. <div class="pre-container">
  176. <!-- PDF预览 -->
  177. <VueOfficePdf v-if="fileType === 'pdf'" :src="fileUrl" @rendered="handleRendered" @error="handleError" />
  178. <!-- Word文档预览 -->
  179. <VueOfficeDocx v-else-if="fileType === 'docx'" :src="fileUrl" @rendered="handleRendered" @error="handleError" />
  180. <!-- Excel预览 -->
  181. <VueOfficeExcel
  182. v-else-if="fileType === 'xlsx' || fileType === 'xls'"
  183. :options="{ xls: true }"
  184. :src="fileUrl"
  185. @rendered="handleRendered"
  186. @error="handleError"
  187. />
  188. <!-- 不支持的文件类型 -->
  189. <div v-else class="unsupported">
  190. <p>不支持预览该文件类型: {{ fileType }}</p>
  191. </div>
  192. <!-- 加载状态 -->
  193. <div v-if="loading" class="loading">
  194. <p>文件加载中...</p>
  195. </div>
  196. </div>
  197. </div>
  198. </div>
  199. </template>
  200. <script lang="ts" setup>
  201. import VueOfficePdf from '@vue-office/pdf';
  202. import VueOfficeDocx from '@vue-office/docx';
  203. import VueOfficeExcel from '@vue-office/excel';
  204. import { ref, onMounted, nextTick } from 'vue';
  205. import { SvgIcon } from '../Icon';
  206. import { Space, Button, Modal, Input, message } from 'ant-design-vue';
  207. // import AIChat from './index.vue';
  208. import { useUserStore } from '/@/store/modules/user';
  209. import {
  210. EditOutlined,
  211. DeleteOutlined,
  212. UploadOutlined,
  213. CopyOutlined,
  214. RightOutlined,
  215. DownOutlined,
  216. FastForwardFilled,
  217. RedoOutlined,
  218. } from '@ant-design/icons-vue';
  219. import { createVNode } from 'vue';
  220. import { marked } from 'marked';
  221. import katex from 'katex';
  222. import 'katex/dist/katex.min.css';
  223. import '@vue-office/excel/lib/index.css';
  224. import '@vue-office/docx/lib/index.css';
  225. const TextArea = Input.TextArea; // 直接导入TextArea组件使用时打包报错
  226. const inputText = ref(''); // 输入框内容
  227. const refreshText = ref(''); //重新生成文本
  228. const sessionHistory = ref([]);
  229. const isShowChatBroad = ref(false);
  230. const editingId = ref<number | null>(null);
  231. const editText = ref('');
  232. const currentSessionID = ref('');
  233. const taskID = ref('');
  234. const messageID = ref('');
  235. const open = ref<boolean>(false);
  236. const isThinking = ref(false); //深度思考是否开启
  237. const Thinking = ref(false);
  238. const isShowDoc = ref(false);
  239. const fileType = ref('');
  240. const fileUrl = ref('');
  241. const APIKEY = ref('Bearer app-tSFRUnv0Qkbtik1dwtlhnpkd');
  242. interface ListItem {
  243. id: number;
  244. name?: string;
  245. }
  246. interface Message {
  247. id: string; // 唯一标识(可用时间戳生成)
  248. type: 'user' | 'system' | 'response';
  249. content: String; // 原始 Markdown 字符串(用于拼接)
  250. parsedContent: String; // 解析后的 HTML(用于渲染)
  251. contentR1: String; // 原始思考过程 Markdown
  252. parsedContentR1: String; // 解析后的思考过程 HTML
  253. timestamp: number; // 排序依据
  254. isShowThink: boolean; //深度思考展示
  255. }
  256. // 定义消息历史数组类型
  257. const messageHistory = ref<Message[]>([]);
  258. const isFold = ref(true); // 是否折叠
  259. const userid = useUserStore().getUserInfo.id as string;
  260. const filePath = ref(''); // 绑定输入框值
  261. const uploadedFiles = ref([]);
  262. const showConfirmBtn = ref(false); // 控制确认按钮显示状态
  263. const fileList = ref([]);
  264. const suggestList = ref([]); //建议列表
  265. const loading = ref(false);
  266. // 文件预览
  267. const handleRendered = () => {
  268. loading.value = false;
  269. console.log('文件渲染完成');
  270. };
  271. const handleError = (error) => {
  272. loading.value = false;
  273. console.error('文件预览错误:', error);
  274. };
  275. function previewFile(data) {
  276. fileType.value = data.name.split('.').pop().toLowerCase();
  277. fileUrl.value = data.source_url;
  278. }
  279. function deleteFile(fileId) {
  280. // 确认删除
  281. if (confirm('确定要删除这个文件吗?')) {
  282. uploadedFiles.value = uploadedFiles.value.filter((file) => file.id !== fileId);
  283. }
  284. }
  285. //启用深度思考
  286. const toggleThinking = () => {
  287. isThinking.value = !isThinking.value;
  288. if (isThinking.value) {
  289. APIKEY.value = 'Bearer app-kprgsFKtySM4Wjxs0ZGzaNFN';
  290. } else {
  291. APIKEY.value = 'Bearer app-tSFRUnv0Qkbtik1dwtlhnpkd';
  292. }
  293. };
  294. // 折叠思考过程
  295. const isShow = (message) => {
  296. message.isShowThink = !message.isShowThink;
  297. };
  298. const dialogAreaRef = ref(null);
  299. // 滚动到底部的方法
  300. const scrollToBottom = async () => {
  301. // 等待 DOM 更新(如消息渲染完成)
  302. await nextTick();
  303. if (dialogAreaRef.value) {
  304. const el = dialogAreaRef.value;
  305. // 关键:scrollTop = scrollHeight(滚动内容总高度)
  306. el.scrollTop = el.scrollHeight;
  307. }
  308. };
  309. // 点击建议项时的处理函数
  310. const handleSuggestClick = (text) => {
  311. // 将选中的建议填充到文本框
  312. inputText.value = text;
  313. };
  314. function showAIChat() {
  315. isShowChatBroad.value = !isShowChatBroad.value;
  316. if (isShowChatBroad) {
  317. isShowDoc.value = false;
  318. }
  319. }
  320. //复制消息
  321. function copyToClipboard(text) {
  322. if (!text || text.trim() === '') {
  323. message.warn('没有可复制的内容');
  324. return;
  325. }
  326. // 2. 创建临时textarea 元素
  327. const textarea = document.createElement('textarea');
  328. textarea.value = text;
  329. textarea.style.position = 'fixed';
  330. textarea.style.top = '-999px';
  331. textarea.style.left = '-999px';
  332. textarea.style.width = '200px';
  333. textarea.style.height = '200px';
  334. document.body.appendChild(textarea);
  335. try {
  336. textarea.select();
  337. textarea.setSelectionRange(0, text.length);
  338. const isSuccessful = document.execCommand('copy');
  339. if (isSuccessful) {
  340. message.success('复制成功!');
  341. } else {
  342. throw new Error('复制命令执行失败');
  343. }
  344. } catch (err) {
  345. console.error('复制失败:', err);
  346. message.error('复制失败,请手动复制');
  347. } finally {
  348. document.body.removeChild(textarea);
  349. }
  350. }
  351. const initMarked = () => {
  352. marked.setOptions({
  353. gfm: true, // 启用GitHub风格的Markdown,包含表格
  354. breaks: false, // 禁用换行符转换
  355. });
  356. };
  357. // LaTeX 公式渲染(内部使用)
  358. const renderLatexInHtml = (html) => {
  359. // 匹配块级公式($$...$$)
  360. const blockRegex = /\$\$(.*?)\$\$/gs;
  361. // 匹配行内公式($...$)
  362. const inlineRegex = /\$(.*?)\$/g;
  363. // // 替换块级公式(居中显示)
  364. html = html.replace(blockRegex, (match, formula) => {
  365. matchCount++;
  366. console.log(`块级公式匹配第 ${matchCount} 次:`, formula); // 查看匹配次数和内容
  367. return katex.renderToString(formula.trim(), {
  368. displayMode: true,
  369. throwOnError: false,
  370. strict: false,
  371. trust: true,
  372. });
  373. });
  374. // 替换行内公式(行内显示)
  375. html = html.replace(inlineRegex, (match, formula) => {
  376. return katex.renderToString(formula.trim(), {
  377. displayMode: false,
  378. throwOnError: false,
  379. strict: false,
  380. });
  381. });
  382. return html;
  383. };
  384. // Markdown + LaTeX 解析
  385. const parseMarkdownWithLatex = (mdStr) => {
  386. if (!mdStr) return '';
  387. try {
  388. let html = marked(mdStr); // Markdown → HTML
  389. html = renderLatexInHtml(html); // 替换公式
  390. return html;
  391. } catch (error) {
  392. console.error('解析失败:', error);
  393. return mdStr; // 降级显示原始字符串
  394. }
  395. };
  396. //重新生成
  397. const refresh = () => {
  398. handleSend(refreshText.value);
  399. };
  400. //重新编辑
  401. const editAsk = (data) => {
  402. inputText.value = data;
  403. };
  404. //获取消息列表
  405. async function handleSend(data) {
  406. refreshText.value = data;
  407. inputText.value = '';
  408. if (isThinking) {
  409. messageHistory.value.push({
  410. id: `user_${Date.now()}`,
  411. type: 'user',
  412. content: '',
  413. parsedContent: data,
  414. contentR1: '',
  415. parsedContentR1: '',
  416. timestamp: Date.now(),
  417. isShowThink: true,
  418. });
  419. } else {
  420. messageHistory.value.push({
  421. id: `user_${Date.now()}`,
  422. type: 'user',
  423. content: '',
  424. parsedContent: data,
  425. contentR1: '',
  426. parsedContentR1: '',
  427. timestamp: Date.now(),
  428. isShowThink: false,
  429. });
  430. }
  431. try {
  432. const response = await fetch('http://39.97.59.228:8000/v1/chat-messages', {
  433. method: 'POST',
  434. headers: {
  435. 'Content-Type': 'application/json',
  436. Authorization: APIKEY.value,
  437. },
  438. body: JSON.stringify({
  439. conversation_id: currentSessionID.value ? currentSessionID.value : '',
  440. query: data,
  441. response_mode: 'streaming',
  442. user: userid,
  443. inputs: {},
  444. }),
  445. });
  446. if (!response.ok) {
  447. throw new Error(`HTTP error! status: ${response.status}`);
  448. }
  449. const decoder = new TextDecoder('utf-8');
  450. const reader = response.body.getReader();
  451. let textBuffer = ''; // 使用字符串缓冲区来累积数据
  452. // 在组件中定义
  453. const currentProcessingMessage = ref(null);
  454. if (isThinking) {
  455. const newMessage = {
  456. id: `response_${Date.now()}`,
  457. type: 'response',
  458. content: '',
  459. parsedContent: '',
  460. contentR1: '',
  461. parsedContentR1: '',
  462. timestamp: Date.now(),
  463. isShowThink: true,
  464. };
  465. messageHistory.value.push(newMessage);
  466. currentProcessingMessage.value = newMessage; // 保存引用
  467. } else {
  468. const newMessage = {
  469. id: `response_${Date.now()}`,
  470. type: 'response',
  471. content: '',
  472. parsedContent: '',
  473. contentR1: '',
  474. parsedContentR1: '',
  475. timestamp: Date.now(),
  476. isShowThink: false,
  477. };
  478. messageHistory.value.push(newMessage);
  479. currentProcessingMessage.value = newMessage; // 保存引用
  480. }
  481. while (true) {
  482. const { done, value } = await reader.read();
  483. if (done) {
  484. if (textBuffer) {
  485. processLine(textBuffer);
  486. }
  487. break;
  488. }
  489. textBuffer += decoder.decode(value, { stream: true });
  490. // 处理每一行数据
  491. let lineIndex;
  492. while ((lineIndex = textBuffer.indexOf('\n')) !== -1) {
  493. const line = textBuffer.substring(0, lineIndex).trim();
  494. textBuffer = textBuffer.substring(lineIndex + 1);
  495. if (line) {
  496. processLine(line);
  497. }
  498. }
  499. }
  500. function processLine(line) {
  501. if (line.startsWith('data: ')) {
  502. try {
  503. const jsonStr = line.substring('data: '.length);
  504. const data = JSON.parse(jsonStr);
  505. switch (data.event) {
  506. case 'message':
  507. if (data.answer) {
  508. const targetMessage = messageHistory.value.find((msg) => msg.id === currentProcessingMessage.value.id);
  509. if (!targetMessage) break;
  510. let currentChunk = data.answer;
  511. // 检查是否包含起始标签
  512. const startIndex = currentChunk.indexOf('<think>');
  513. if (startIndex !== -1) {
  514. // 找到起始标签:将标签前的内容作为正文
  515. if (startIndex > 0) {
  516. targetMessage.content += currentChunk.substring(0, startIndex);
  517. targetMessage.parsedContent = parseMarkdownWithLatex(targetMessage.content);
  518. }
  519. // 进入思考模式,将标签后的内容追加到contentR1
  520. Thinking.value = true;
  521. const remainingContent = currentChunk.substring(startIndex + '<think>'.length);
  522. if (remainingContent) {
  523. targetMessage.contentR1 += remainingContent;
  524. targetMessage.parsedContentR1 = parseMarkdownWithLatex(targetMessage.contentR1);
  525. }
  526. } else if (Thinking.value) {
  527. // 结束标签
  528. const endIndex = currentChunk.indexOf('</think>');
  529. if (endIndex !== -1) {
  530. // 找到结束标签:标签前的内容追加到contentR1
  531. if (endIndex > 0) {
  532. targetMessage.contentR1 += currentChunk.substring(0, endIndex);
  533. targetMessage.parsedContentR1 = parseMarkdownWithLatex(targetMessage.contentR1);
  534. }
  535. // 将标签后的内容作为正文
  536. const remainingContent = currentChunk.substring(endIndex + '</think>'.length);
  537. if (remainingContent) {
  538. targetMessage.content += remainingContent;
  539. targetMessage.parsedContent = parseMarkdownWithLatex(targetMessage.content);
  540. }
  541. targetMessage.content += currentChunk;
  542. Thinking.value = false;
  543. targetMessage.isShowThink = false;
  544. } else {
  545. // 没有结束标签,继续追加到contentR1
  546. targetMessage.contentR1 += currentChunk;
  547. targetMessage.parsedContentR1 = parseMarkdownWithLatex(targetMessage.contentR1);
  548. }
  549. } else {
  550. targetMessage.content += currentChunk;
  551. targetMessage.parsedContent = parseMarkdownWithLatex(targetMessage.content);
  552. }
  553. scrollToBottom(); // 每次接收消息都滚动
  554. }
  555. if (data.task_id && !taskID.value) taskID.value = data.task_id;
  556. if (data.conversation_id && !currentSessionID.value) currentSessionID.value = data.conversation_id;
  557. if (data.message_id && !messageID.value) {
  558. messageID.value = data.message_id;
  559. }
  560. break;
  561. }
  562. } catch (error) {
  563. console.warn('Error parsing stream chunk:', error, 'Chunk:', line);
  564. }
  565. }
  566. }
  567. getNextSuggest();
  568. } catch (error) {
  569. console.error('Error in handleSend:', error);
  570. // 在 UI 上显示错误信息
  571. messageHistory.value.push({
  572. id: `system_${Date.now()}`,
  573. type: 'system',
  574. content: '',
  575. parsedContent: '请求错误',
  576. contentR1: '',
  577. parsedContentR1: '',
  578. timestamp: Date.now(),
  579. isShowThink: false,
  580. });
  581. }
  582. }
  583. //创建新对话
  584. async function addNew() {
  585. messageHistory.value = [];
  586. currentSessionID.value = '';
  587. taskID.value = '';
  588. messageID.value = '';
  589. }
  590. // 上传文件
  591. const showModal = (data) => {
  592. open.value = data;
  593. };
  594. const close = () => {
  595. isShowDoc.value = false;
  596. };
  597. // 上传文件
  598. const handleBeforeUpload = async (file) => {
  599. const formData = new FormData();
  600. formData.append('file', file);
  601. formData.append('user', userid);
  602. try {
  603. const response = await fetch(`http://39.97.59.228:8000/v1/files/upload`, {
  604. method: 'POST',
  605. headers: {
  606. Authorization: APIKEY.value,
  607. },
  608. body: formData,
  609. });
  610. const result = await response.json();
  611. if (response.ok) {
  612. const linkText = `[${result.name}](${result.source_url})`;
  613. // inputText.value += `\n${linkText}`;
  614. uploadedFiles.value.push(result);
  615. isShowDoc.value = true;
  616. previewFile(result);
  617. } else {
  618. message.error(`上传失败: ${result.message || '网络错误'}`);
  619. }
  620. } catch (error) {
  621. console.error('保存失败:', error);
  622. message.error('上传失败,请重试');
  623. }
  624. return false;
  625. };
  626. const handleRemove = (file) => {
  627. const index = fileList.value.findIndex((item) => item.uid === file.uid);
  628. if (index !== -1) {
  629. fileList.value.splice(index, 1);
  630. }
  631. };
  632. //停止响应
  633. async function stopReq() {
  634. try {
  635. let response = await fetch(`http://39.97.59.228:8000/v1/chat-messages/${taskID.value}/stop`, {
  636. method: 'POST',
  637. headers: {
  638. 'Content-Type': 'application/json',
  639. Authorization: APIKEY.value,
  640. },
  641. body: JSON.stringify({
  642. user: userid,
  643. }),
  644. });
  645. if (!response) {
  646. throw new Error('Network response was not ok');
  647. }
  648. } catch (error) {
  649. console.error('保存失败:', error);
  650. }
  651. }
  652. //获取具体会话记录
  653. async function sessionsHistory(id: string, retryCount = 0) {
  654. const API_KEYS = ['Bearer app-tSFRUnv0Qkbtik1dwtlhnpkd', 'Bearer app-kprgsFKtySM4Wjxs0ZGzaNFN'];
  655. // 最大重试次数
  656. const maxRetries = API_KEYS.length - 1;
  657. try {
  658. let response = await fetch(`http://39.97.59.228:8000/v1/messages?conversation_id=${id}&user=${userid}`, {
  659. method: 'GET',
  660. headers: {
  661. 'Content-Type': 'application/json',
  662. Authorization: API_KEYS[retryCount],
  663. },
  664. });
  665. if (!response.ok) {
  666. throw new Error(`HTTP ${response.status}: ${response.statusText}`);
  667. }
  668. const data = await response.json();
  669. if (data.data.length > 0) {
  670. messageHistory.value = [];
  671. data.data.forEach((item: any) => {
  672. currentSessionID.value = item.conversation_id;
  673. messageHistory.value.push({
  674. id: `user_${Date.now()}`,
  675. type: 'user',
  676. content: '',
  677. parsedContent: item.query,
  678. contentR1: '',
  679. parsedContentR1: '',
  680. timestamp: Date.now(),
  681. isShowThink: false,
  682. });
  683. const answer = item.answer;
  684. // 查找<think>
  685. const startIndex = answer.indexOf('<think>');
  686. const endIndex = answer.indexOf('</think>');
  687. let content = '';
  688. let contentR1 = '';
  689. // 根据标签判断
  690. if (startIndex !== -1 && endIndex !== -1) {
  691. content = answer.substring(0, startIndex) + answer.substring(endIndex + '</think>'.length);
  692. contentR1 = answer.substring(startIndex + '<think>'.length, endIndex);
  693. } else if (startIndex !== -1) {
  694. // 只有起始标签
  695. content = answer.substring(0, startIndex);
  696. contentR1 = answer.substring(startIndex + '<think>'.length);
  697. } else if (endIndex !== -1) {
  698. // 只有结束标签
  699. content = answer.substring(endIndex + '</think>'.length);
  700. contentR1 = answer.substring(0, endIndex);
  701. } else {
  702. // 没有标签
  703. content = answer;
  704. }
  705. // 添加到消息历史
  706. messageHistory.value.push({
  707. id: `system_${Date.now()}`,
  708. type: 'system',
  709. content: '',
  710. parsedContent: parseMarkdownWithLatex(content.trim()),
  711. contentR1: '',
  712. parsedContentR1: parseMarkdownWithLatex(contentR1.trim()),
  713. timestamp: Date.now(),
  714. isShowThink: contentR1.length > 0, // 如果有思考内容则显示
  715. });
  716. });
  717. }
  718. } catch (error) {
  719. // 判断是否达到最大重试次数
  720. if (retryCount < maxRetries) {
  721. console.warn(`请求失败,正在尝试第 ${retryCount + 2} 个 API Key...`);
  722. return sessionsHistory(id, retryCount + 1);
  723. } else {
  724. console.error('所有 API Key 均尝试失败:', error);
  725. throw error;
  726. }
  727. }
  728. editingId.value = null;
  729. }
  730. //获取下一轮建议问题列表
  731. //停止响应
  732. async function getNextSuggest() {
  733. console.log(messageID.value, '123');
  734. try {
  735. let response = await fetch(`http://39.97.59.228:8000/v1/messages/${messageID.value}/suggested?user=${userid}`, {
  736. method: 'GET',
  737. headers: {
  738. 'Content-Type': 'application/json',
  739. Authorization: APIKEY.value,
  740. },
  741. });
  742. const data = await response.json();
  743. suggestList.value = data.data;
  744. if (!response) {
  745. throw new Error('Network response was not ok');
  746. }
  747. } catch (error) {
  748. console.error('保存失败:', error);
  749. }
  750. }
  751. //编辑标题
  752. const startEditing = (item: ListItem) => {
  753. editingId.value = item.id;
  754. editText.value = item.name || '';
  755. };
  756. // 保存修改
  757. const handleSave = async (item: ListItem) => {
  758. try {
  759. let response = await fetch(`http://39.97.59.228:8000/v1/conversations/${item.id}/name`, {
  760. method: 'POST',
  761. headers: {
  762. 'Content-Type': 'application/json',
  763. Authorization: APIKEY.value,
  764. },
  765. body: JSON.stringify({
  766. name: editText.value,
  767. user: userid,
  768. }),
  769. });
  770. if (!response.ok) {
  771. throw new Error('Network response was not ok');
  772. }
  773. item.name = editText.value;
  774. } catch (error) {
  775. console.error('保存失败:', error);
  776. }
  777. editingId.value = null;
  778. };
  779. // 删除会话
  780. const startDelete = async (item: ListItem) => {
  781. Modal.confirm({
  782. title: '确认删除',
  783. content: `确定要删除会话 "${item.name || '新会话'}" 吗?此操作不可撤销。`,
  784. okText: '确认',
  785. cancelText: '取消',
  786. onOk: async () => {
  787. // 原有删除逻辑不变
  788. try {
  789. let response = await fetch(`http://39.97.59.228:8000/v1/conversations/${item.id}`, {
  790. method: 'DELETE',
  791. headers: {
  792. 'Content-Type': 'application/json',
  793. Authorization: APIKEY.value,
  794. },
  795. body: JSON.stringify({
  796. user: userid,
  797. }),
  798. });
  799. if (!response.ok) {
  800. throw new Error('Network response was not ok');
  801. }
  802. getHistoryList();
  803. } catch (error) {
  804. console.error('删除失败:', error);
  805. Modal.error({
  806. title: '删除失败',
  807. content: '删除会话时出现错误,请稍后重试。',
  808. });
  809. }
  810. },
  811. });
  812. };
  813. const fold = () => {
  814. isFold.value = !isFold.value;
  815. if (!isFold.value) {
  816. getHistoryList();
  817. }
  818. };
  819. // 获取历史会话列表
  820. async function getHistoryList() {
  821. sessionHistory.value = [];
  822. try {
  823. // 并行请求两个接口,提升效率
  824. const [response1, response2] = await Promise.all([
  825. // 第一个请求
  826. fetch(`http://39.97.59.228:8000/v1/conversations?user=${userid}`, {
  827. method: 'get',
  828. headers: {
  829. 'Content-Type': 'application/json',
  830. Authorization: 'Bearer app-tSFRUnv0Qkbtik1dwtlhnpkd',
  831. },
  832. }),
  833. // 第二个请求
  834. fetch(`http://39.97.59.228:8000/v1/conversations?user=${userid}`, {
  835. method: 'get',
  836. headers: {
  837. 'Content-Type': 'application/json',
  838. Authorization: 'Bearer app-kprgsFKtySM4Wjxs0ZGzaNFN',
  839. },
  840. }),
  841. ]);
  842. // 检查响应是否成功
  843. if (!response1.ok || !response2.ok) {
  844. throw new Error('接口请求失败');
  845. }
  846. // 解析两个响应的JSON数据
  847. const [data1, data2] = await Promise.all([response1.json(), response2.json()]);
  848. // 合并两个数组(核心修改:用扩展运算符合并)
  849. // 确保 data1.data 和 data2.data 都是数组(防止接口返回异常)
  850. const list1 = Array.isArray(data1.data) ? data1.data : [];
  851. const list2 = Array.isArray(data2.data) ? data2.data : [];
  852. // 合并数组并赋值给 sessionHistory
  853. sessionHistory.value = [...list1, ...list2];
  854. sessionHistory.value.forEach((item) => {
  855. currentSessionID.value = item.id;
  856. });
  857. console.log(sessionHistory.value, '历史数据');
  858. } catch (error) {
  859. console.error('获取历史数据失败:', error);
  860. // 错误处理(比如提示用户)
  861. }
  862. }
  863. //格式化消息
  864. const formatMessage = (text) => {
  865. if (!text) return '';
  866. let formatted = text
  867. // 处理换行
  868. .replace(/\n\n/g, '<br>')
  869. .replace(/\n###/g, '<br>')
  870. .replace(/###/g, '')
  871. .replace(/---/g, '')
  872. .replace(/^- /gm, '<br> - ')
  873. // 处理粗体
  874. .replace(/\*\*(.*?)\*\*/g, '<strong>$1</strong>')
  875. // 处理斜体
  876. .replace(/\*(.*?)\*/g, '<em>$1</em>')
  877. // 处理行内代码
  878. .replace(/`([^`]+)`/g, '<code>$1</code>');
  879. return formatted;
  880. };
  881. // 初始化按钮定位
  882. onMounted(() => {
  883. getHistoryList();
  884. // 初始化(仅执行一次)
  885. initMarked();
  886. });
  887. </script>
  888. <style lang="less" scoped>
  889. .btn-header {
  890. width: 40px;
  891. height: 40px;
  892. margin-right: 5px;
  893. margin-bottom: 5px;
  894. }
  895. .container {
  896. display: flex;
  897. flex-direction: row;
  898. }
  899. .mini-chat {
  900. display: flex;
  901. min-width: none;
  902. width: 950px;
  903. height: 85%;
  904. border-radius: 4px;
  905. position: fixed;
  906. top: 50px;
  907. right: 20px;
  908. padding: 10px;
  909. background-color: #0a1a2f;
  910. background-image: linear-gradient(to bottom, #0b69b6 1%, #0a1a2f 100%), linear-gradient(to left, #0b69b6, #0a1a2f),
  911. linear-gradient(to top, #0b69b6, #0a1a2f), linear-gradient(to right, #0b69b6, #0a1a2f);
  912. background-size: 100% 5px, 5px 100%, 100% 5px, 5px 100%;
  913. background-position: top left, top right, bottom right, bottom left;
  914. background-repeat: no-repeat;
  915. z-index: 9999999;
  916. color: #fff;
  917. }
  918. .doc {
  919. display: flex;
  920. flex-direction: column;
  921. min-width: 600px;
  922. height: 85%;
  923. border-radius: 4px;
  924. position: fixed;
  925. top: 50px;
  926. right: 51%;
  927. padding: 10px;
  928. background-color: #0a1a2f;
  929. background-image: linear-gradient(to bottom, #0b69b6 1%, #0a1a2f 100%), linear-gradient(to left, #0b69b6, #0a1a2f),
  930. linear-gradient(to top, #0b69b6, #0a1a2f), linear-gradient(to right, #0b69b6, #0a1a2f);
  931. background-size: 100% 5px, 5px 100%, 100% 5px, 5px 100%;
  932. background-position: top left, top right, bottom right, bottom left;
  933. background-repeat: no-repeat;
  934. z-index: 9999999;
  935. color: #fff;
  936. }
  937. .close {
  938. display: flex;
  939. justify-content: flex-end;
  940. align-items: center;
  941. width: 100%;
  942. padding: 1px;
  943. border-radius: 8px;
  944. }
  945. .closeBtn {
  946. background-color: #007bff;
  947. color: white;
  948. border: none;
  949. border-radius: 4px;
  950. cursor: pointer;
  951. transition: all 0.3s ease;
  952. }
  953. .closeBtn:hover {
  954. background-color: #0056b3;
  955. }
  956. .left-side {
  957. background: #0c2842;
  958. transition: width 0.5s ease; /* 平滑过渡动画 */
  959. width: 140px; /* 展开时宽度 */
  960. position: relative; /* 用于按钮定位 */
  961. }
  962. .left-side.collapsed {
  963. width: 40px; /* 折叠时宽度 */
  964. }
  965. .addBtn {
  966. height: 30px;
  967. position: absolute;
  968. background-size: 100% 100%;
  969. background-position: center;
  970. padding: 2px;
  971. right: 10px;
  972. bottom: 40px;
  973. left: 10px;
  974. align-items: center;
  975. border-radius: 3px;
  976. cursor: pointer;
  977. }
  978. .custom-list {
  979. height: 650px;
  980. overflow-y: auto;
  981. }
  982. .text-container {
  983. display: flex;
  984. justify-content: space-between;
  985. width: 100%;
  986. overflow: hidden;
  987. }
  988. .btn-container {
  989. display: flex;
  990. }
  991. .jeecg-layout-header-action span[role='img'] {
  992. padding: 0;
  993. }
  994. .text-ellipsis {
  995. flex: 1;
  996. }
  997. .edit-text {
  998. overflow: hidden;
  999. text-overflow: ellipsis;
  1000. white-space: nowrap;
  1001. width: 90px;
  1002. color: #fff;
  1003. font-size: 12px;
  1004. cursor: pointer;
  1005. }
  1006. .edit-icon {
  1007. flex-shrink: 0;
  1008. margin-left: auto;
  1009. line-height: 23px;
  1010. }
  1011. .delete-icon {
  1012. flex-shrink: 0;
  1013. margin-left: auto;
  1014. line-height: 23px;
  1015. }
  1016. .edit-icon:hover {
  1017. color: #1890ff !important;
  1018. cursor: pointer;
  1019. }
  1020. .delete-icon:hover {
  1021. color: #1890ff !important;
  1022. cursor: pointer;
  1023. }
  1024. .edit-input {
  1025. font-size: 10px;
  1026. }
  1027. .btn-text-bg {
  1028. width: 14px;
  1029. height: 14px;
  1030. position: absolute;
  1031. background-size: 100% 100%;
  1032. right: 10px;
  1033. top: 10px;
  1034. left: 10px;
  1035. bottom: 10px;
  1036. }
  1037. .btn-text {
  1038. margin-left: 3px;
  1039. font-size: 12px;
  1040. color: #fff;
  1041. white-space: nowrap;
  1042. margin-left: 30px;
  1043. line-height: 29px;
  1044. }
  1045. .historyBtn {
  1046. width: 20px;
  1047. height: 20px;
  1048. position: absolute;
  1049. background-size: 100% 100%;
  1050. background-position: center;
  1051. padding: 2px;
  1052. right: 10px;
  1053. top: 10px;
  1054. }
  1055. .historyBtn1 {
  1056. width: 20px;
  1057. height: 20px;
  1058. position: absolute;
  1059. background-size: 100% 100%;
  1060. background-position: center;
  1061. left: 3px;
  1062. }
  1063. .divider0 {
  1064. border-bottom: 1px solid #1074c1;
  1065. width: auto;
  1066. margin: 0 10px;
  1067. height: 13%;
  1068. display: block;
  1069. background: transparent;
  1070. }
  1071. .foldBtn {
  1072. width: 20px;
  1073. height: 20px;
  1074. position: absolute;
  1075. background-size: 100% 100%;
  1076. background-position: center;
  1077. padding: 2px;
  1078. right: 10px;
  1079. bottom: 10px;
  1080. cursor: pointer;
  1081. }
  1082. .right-side {
  1083. flex: 1;
  1084. display: flex;
  1085. flex-direction: column;
  1086. width: calc(100% - 134px) !important;
  1087. .title {
  1088. text-align: center;
  1089. font-size: 14px;
  1090. padding: 5px;
  1091. }
  1092. .dialog-area {
  1093. flex: 1;
  1094. gap: 30px;
  1095. overflow-y: auto;
  1096. padding: 5px;
  1097. display: flex;
  1098. flex-direction: column;
  1099. color: #fff;
  1100. .ask-message {
  1101. padding: 10px;
  1102. border-radius: 5px;
  1103. background: #0c2842;
  1104. max-width: 300px;
  1105. min-width: 50px;
  1106. white-space: pre-wrap;
  1107. word-wrap: break-word;
  1108. overflow-wrap: break-word;
  1109. overflow: auto;
  1110. line-height: 1.5;
  1111. }
  1112. .answer-message {
  1113. padding: 10px;
  1114. border-radius: 5px;
  1115. background: #0c2842;
  1116. max-width: 90%;
  1117. }
  1118. }
  1119. .input-area {
  1120. margin: 10px 10px 20px 10px;
  1121. padding: 10px;
  1122. background-color: #043256;
  1123. border: 1px solid #2cb6ff;
  1124. border-radius: 5px;
  1125. display: flex;
  1126. flex-direction: column;
  1127. justify-content: space-between;
  1128. gap: 5px;
  1129. height: 25%;
  1130. }
  1131. /* 文件列表容器 */
  1132. .uploaded-files {
  1133. padding: 8px;
  1134. background-color: #f5f5f5;
  1135. border-radius: 4px;
  1136. min-height: 40px;
  1137. }
  1138. /* 单个文件项 */
  1139. .file-item {
  1140. display: inline-flex;
  1141. align-items: center;
  1142. padding: 4px 8px;
  1143. margin-right: 8px;
  1144. margin-bottom: 8px;
  1145. background-color: #fff;
  1146. border: 1px solid #e9e9e9;
  1147. border-radius: 4px;
  1148. }
  1149. /* 文件名 */
  1150. .file-name {
  1151. margin-left: 8px;
  1152. margin-right: 8px;
  1153. max-width: 150px;
  1154. white-space: nowrap;
  1155. overflow: hidden;
  1156. text-overflow: ellipsis;
  1157. }
  1158. .ant-input {
  1159. border: none;
  1160. background-color: rgba(255, 255, 255, 0) !important;
  1161. color: #fff;
  1162. }
  1163. .ant-input:focus {
  1164. border: none; /* 聚焦时无边框 */
  1165. outline: none; /* 聚焦时无轮廓 */
  1166. box-shadow: none; /* 移除可能存在的阴影效果 */
  1167. }
  1168. .ctrl-btn {
  1169. display: flex;
  1170. flex-direction: row;
  1171. justify-content: space-between;
  1172. }
  1173. .question-input {
  1174. background-color: #1e293b !important;
  1175. border-color: #334155 !important;
  1176. color: #e2e8f0 !important;
  1177. border-radius: 8px !important;
  1178. padding: 12px 16px !important;
  1179. font-size: 14px !important;
  1180. }
  1181. .question-input::placeholder {
  1182. color: #64748b !important;
  1183. }
  1184. .control-btn {
  1185. height: 25px;
  1186. background-color: #043256;
  1187. border: 1px solid #2cb6ff;
  1188. color: #fff;
  1189. font-size: 10px;
  1190. margin-right: 10px;
  1191. cursor: pointer;
  1192. transition: background-color 0.2s ease; /* 平滑过渡效果 */
  1193. }
  1194. /* 激活状态样式(点击后) */
  1195. .control-btn.active {
  1196. background-color: #2cb6ff; /* 蓝色背景(Ant Design 主色) */
  1197. color: white; /* 白色文字 */
  1198. }
  1199. .control-btn1 {
  1200. height: 20px;
  1201. background-color: #234a6b;
  1202. border: 1px solid #234a6b;
  1203. color: #fff;
  1204. font-size: 10px;
  1205. margin-right: 10px;
  1206. cursor: pointer;
  1207. transition: all 0.2s;
  1208. }
  1209. .control-btn2 {
  1210. height: 20px;
  1211. background-color: #2cb6ff;
  1212. border: 1px solid #2cb6ff;
  1213. color: #fff;
  1214. font-size: 10px;
  1215. margin-right: 10px;
  1216. cursor: pointer;
  1217. transition: all 0.2s;
  1218. }
  1219. /* 文件上传区 */
  1220. .file-upload {
  1221. position: absolute;
  1222. right: 20px;
  1223. bottom: 70px;
  1224. width: 180px;
  1225. display: flex;
  1226. flex-direction: column;
  1227. gap: 10px;
  1228. border: 1px solid #2cb6ff;
  1229. background-color: #234a6b;
  1230. border-radius: 6px;
  1231. padding: 10px;
  1232. }
  1233. .input-container {
  1234. position: relative;
  1235. display: flex;
  1236. align-items: center;
  1237. width: 100%;
  1238. }
  1239. .file-input {
  1240. flex: 1;
  1241. background-color: #234a6b;
  1242. border-color: #2cb6ff !important;
  1243. color: #e2e8f0 !important;
  1244. border-radius: 6px !important;
  1245. font-size: 10px !important;
  1246. padding-right: 70px !important;
  1247. height: 36px !important;
  1248. width: 100% !important;
  1249. }
  1250. .confirm-btn {
  1251. position: absolute;
  1252. right: 5px;
  1253. background-color: #2cb6ff;
  1254. border: none;
  1255. color: #fff;
  1256. border-radius: 4px;
  1257. font-size: 12px;
  1258. padding: 4px 10px;
  1259. cursor: pointer;
  1260. transition: all 0.2s;
  1261. height: 28px;
  1262. }
  1263. .confirm-btn:hover {
  1264. background-color: #2cb6ff;
  1265. }
  1266. .custom-upload {
  1267. width: 100%;
  1268. padding: 0 !important;
  1269. }
  1270. .upload-btn {
  1271. background-color: #234a6b !important;
  1272. border: 1px solid #2188c3 !important;
  1273. color: #dbeafe !important;
  1274. border-radius: 6px !important;
  1275. font-size: 12px !important;
  1276. cursor: pointer;
  1277. transition: all 0.2s;
  1278. padding: 8px 0 !important;
  1279. width: 190% !important;
  1280. height: 36px !important;
  1281. box-sizing: border-box !important;
  1282. }
  1283. .upload-btn:hover {
  1284. background-color: #1f84bd !important;
  1285. color: #fff !important;
  1286. }
  1287. .custom-upload .ant-upload-select:hover .ant-btn {
  1288. border-color: #1f84bd !important;
  1289. }
  1290. .message-wrapper.ai-message-wrapper {
  1291. display: flex;
  1292. align-items: flex-start;
  1293. }
  1294. .answerIcon {
  1295. flex: 0 0 45px;
  1296. }
  1297. .suggestion-item {
  1298. height: 30px;
  1299. margin-left: 45px;
  1300. display: flex;
  1301. align-items: center;
  1302. justify-content: space-between;
  1303. padding: 10px 16px;
  1304. border: 1px solid #1890ff;
  1305. color: white;
  1306. border-radius: 4px;
  1307. cursor: pointer;
  1308. width: 33%;
  1309. font-size: 12px;
  1310. }
  1311. .thinking-section {
  1312. border-left: 3px solid #e5e7eb;
  1313. padding-left: 12px;
  1314. margin-bottom: 16px;
  1315. }
  1316. .thinking-header {
  1317. display: flex;
  1318. justify-content: space-between;
  1319. align-items: center;
  1320. padding: 8px 0;
  1321. cursor: pointer;
  1322. user-select: none;
  1323. }
  1324. .thinking-title {
  1325. font-size: 14px;
  1326. font-weight: 500;
  1327. color: #6b7280;
  1328. }
  1329. }
  1330. </style>
  1331. <style scoped>
  1332. .zxm-popover-inner-content {
  1333. padding: 1px;
  1334. }
  1335. .message-wrapper {
  1336. display: flex;
  1337. align-items: flex-start;
  1338. position: relative;
  1339. }
  1340. .user-message-wrapper {
  1341. flex-direction: row-reverse;
  1342. }
  1343. .ai-message-wrapper {
  1344. flex-direction: row;
  1345. }
  1346. /* 鼠标滑过 .message-wrapper 时,显示图标 */
  1347. .ai-message-wrapper:hover .copy-icon-container {
  1348. opacity: 1;
  1349. visibility: visible;
  1350. }
  1351. .user-message-wrapper:hover .copy-icon-container {
  1352. opacity: 1;
  1353. visibility: visible;
  1354. }
  1355. .copy-icon {
  1356. font-size: 16px;
  1357. color: #666;
  1358. cursor: pointer;
  1359. }
  1360. /* 默认隐藏,hover 时显示 */
  1361. .copy-icon-container {
  1362. position: absolute;
  1363. display: flex;
  1364. flex-direction: row;
  1365. bottom: -20px;
  1366. right: 15%;
  1367. opacity: 0;
  1368. visibility: hidden;
  1369. transition: all 0.3s ease;
  1370. z-index: 10;
  1371. }
  1372. /* 复制图标样式 */
  1373. .copy-icon {
  1374. font-size: 16px;
  1375. cursor: pointer;
  1376. margin-right: 20%;
  1377. float: right;
  1378. color: #fff;
  1379. }
  1380. .message-wrapper:hover .copy-icon {
  1381. opacity: 1;
  1382. }
  1383. .copy-icon:hover {
  1384. color: #1890ff;
  1385. }
  1386. ::v-deep table {
  1387. border-collapse: collapse;
  1388. width: 100%;
  1389. margin: 10px 0;
  1390. border: 1px solid #333;
  1391. }
  1392. ::v-deep th {
  1393. border: 1px solid #333;
  1394. background-color: #234a6b;
  1395. padding: 5px;
  1396. text-align: center;
  1397. }
  1398. ::v-deep td {
  1399. border: 1px solid #ddd;
  1400. padding: 8px 12px;
  1401. text-align: center;
  1402. }
  1403. </style>
  1404. <style scoped>
  1405. /* 已上传文件列表 */
  1406. .file-list {
  1407. margin-top: 20px;
  1408. }
  1409. .pre-container {
  1410. flex: 1;
  1411. width: 100%;
  1412. height: 100%;
  1413. overflow: auto;
  1414. }
  1415. .vue-office-excel {
  1416. background: #fff !important;
  1417. }
  1418. .file-item {
  1419. display: flex;
  1420. align-items: center;
  1421. padding: 12px 15px;
  1422. background-color: #ddd;
  1423. border-radius: 6px;
  1424. margin-bottom: 10px;
  1425. transition: background-color 0.2s ease;
  1426. }
  1427. .file-item:hover {
  1428. background-color: #f0f2f5;
  1429. }
  1430. .file-info {
  1431. flex: 1;
  1432. overflow: hidden;
  1433. }
  1434. .file-name {
  1435. font-size: 15px;
  1436. color: #1d2129;
  1437. white-space: nowrap;
  1438. overflow: hidden;
  1439. text-overflow: ellipsis;
  1440. margin-bottom: 3px;
  1441. }
  1442. .file-actions {
  1443. display: flex;
  1444. gap: 10px;
  1445. }
  1446. .btn {
  1447. padding: 0px 15px;
  1448. margin-left: 10px;
  1449. border-radius: 4px;
  1450. border: none;
  1451. font-size: 14px;
  1452. cursor: pointer;
  1453. transition: all 0.2s ease;
  1454. }
  1455. .btn-preview {
  1456. background-color: #165dff;
  1457. color: white;
  1458. }
  1459. .btn-preview:hover {
  1460. background-color: #0d47a1;
  1461. }
  1462. .btn-delete {
  1463. background-color: #f2f3f5;
  1464. color: #4e5969;
  1465. }
  1466. .btn-delete:hover {
  1467. background-color: #e5e6eb;
  1468. color: #1d2129;
  1469. }
  1470. </style>