AiAssistantModal.vue 80 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417
  1. <template>
  2. <a-modal
  3. :visible="props.visible"
  4. @cancel="emit('close')"
  5. :width="modalWidth"
  6. :footer="null"
  7. destroyOnClose
  8. :closable="showControls"
  9. :zIndex="props.zIndex"
  10. :class="['ai-assistant-modal', { fullscreen: isFullscreen }]"
  11. >
  12. <template #title>
  13. <div :class="['draggable-title', { 'no-drag': isFullscreen }]" @mousedown="onDragStart">"通安智风"大模型</div>
  14. </template>
  15. <!-- 最大化/还原按钮 -->
  16. <div v-if="showControls" class="maximize-btn" @click="toggleFullscreen">
  17. <div :class="['maximize-icon', { minimized: isFullscreen }]"></div>
  18. </div>
  19. <!-- 收起/展开按钮 -->
  20. <div class="collapse-btn" @click="togglePanel">
  21. <div :class="['collapse-icon', { collapsed: panelCollapsed }]"></div>
  22. </div>
  23. <div class="ai-container">
  24. <!-- 左侧任务列表 -->
  25. <div :class="['task-panel-wrapper', { collapsed: panelCollapsed }]">
  26. <TaskListPanel
  27. :taskList="taskList"
  28. :currentTaskId="currentTaskId"
  29. @switch-task="switchTask"
  30. @create-task="createNewTask"
  31. @delete-task="handleDeleteTask"
  32. @pin-task="handlePinTask"
  33. @toggle-skill="toggleSkillPanel"
  34. @toggle-sub-agents="toggleSubAgentPanel"
  35. @toggle-schedules="toggleSchedulePanel"
  36. />
  37. </div>
  38. <!-- 右侧内容区:根据 activePanel 切换显示 -->
  39. <!-- 聊天区域 -->
  40. <template v-if="activePanel === 'chat'">
  41. <div class="chat-panel">
  42. <!-- 顶部任务选择器 -->
  43. <ChatHeader
  44. :currentTask="currentTask"
  45. :panelCollapsed="panelCollapsed"
  46. :canGoPrev="canGoPrev"
  47. :canGoNext="canGoNext"
  48. :currentWordUrl="currentWordUrl"
  49. @go-to-prev="goToPrev"
  50. @go-to-next="goToNext"
  51. @create-task="createNewTask"
  52. @save-title="handleSaveTitle"
  53. @download-word="downloadWordReport"
  54. />
  55. <!-- 附件列表面板 -->
  56. <FileListPanel :visible="showFileList" :files="getCurrentTaskFiles()" @close="showFileList = false" @file-click="openFilePreview" />
  57. <!-- 消息列表 -->
  58. <ChatMessages
  59. ref="chatMessagesRef"
  60. :messages="messages"
  61. @file-preview="openFilePreview"
  62. @download-word="downloadWordFile"
  63. @open-file-preview="handleOpenFilePreview"
  64. @ask-user-submit="handleAskUserSubmit"
  65. @ask-user-cancel="handleAskUserCancel"
  66. @agent-detail-click="handleAgentDetailClick"
  67. />
  68. <!-- 任务进度条 -->
  69. <TodoListBar v-if="showTodoBar" :todos="currentTodos" />
  70. <!-- 输入区域 -->
  71. <ChatInputArea
  72. ref="chatInputRef"
  73. v-model="inputMessage"
  74. :pendingFile="pendingFile"
  75. :loading="loading || !!currentPendingApproval"
  76. :streaming="streaming"
  77. :contextUsed="contextUsed"
  78. :contextMax="contextMax"
  79. :contextPercent="contextPercent"
  80. :contextBreakdown="contextBreakdown"
  81. :usageLimit="usageToday?.limit_tokens ?? 0"
  82. :usageSpent="usageToday?.spent_tokens ?? 0"
  83. :usageRemaining="usageToday?.remaining_tokens ?? 0"
  84. :usageByModel="usageToday?.by_model ?? []"
  85. :initialThinkLevel="thinkLevel"
  86. :initialEditMode="editMode"
  87. :taskList="taskList"
  88. :currentTaskId="currentTaskId"
  89. @send="handleSendMessage"
  90. @stop="stopStreaming"
  91. @file-upload="triggerFileUpload"
  92. @file-change="handleFileUpload"
  93. @remove-pending-file="removePendingFile"
  94. @pending-file-preview="openFilePreview"
  95. @think-level-change="handleThinkLevelChange"
  96. @edit-mode-change="handleEditModeChange"
  97. @update:selected-sessions="handleUpdateSelectedSessions"
  98. @update:selected-skill="handleUpdateSelectedSkill"
  99. />
  100. </div>
  101. <!-- 右侧辅助面板(标签页容器,与 chat-panel 并列,带滑入滑出动画) -->
  102. <Transition name="right-panel-slide" @after-leave="onPanelLeaveEnd">
  103. <RightPanelTabs
  104. v-if="currentRightPanels.tabs.length > 0"
  105. :tabs="currentRightPanels.tabs"
  106. :activeTabId="currentRightPanels.activeTabId"
  107. :messages="messages"
  108. @switch-tab="activateTab"
  109. @close-tab="closeTab"
  110. @save-success="handleSaveSuccess"
  111. @schedule-deleted="handleScheduleDeleted"
  112. @schedule-updated="handleScheduleUpdated"
  113. @open-schedule-session="handleOpenScheduleSession"
  114. />
  115. </Transition>
  116. </template>
  117. <!-- 技能面板 -->
  118. <div v-if="activePanel === 'skill'" class="right-panel full">
  119. <SkillPanel @close="activePanel = 'chat'" />
  120. </div>
  121. <!-- 子智能体面板 -->
  122. <div v-if="activePanel === 'sub-agents'" class="right-panel full">
  123. <SubAgentPanel @close="activePanel = 'chat'" />
  124. </div>
  125. <!-- 定时任务面板 -->
  126. <div v-if="activePanel === 'schedules'" class="right-panel full">
  127. <SchedulePanel
  128. ref="schedulePanelRef"
  129. @close="activePanel = 'chat'"
  130. @open-session="handleOpenScheduleSession"
  131. @data-changed="fetchScheduleListForDetail"
  132. />
  133. </div>
  134. </div>
  135. </a-modal>
  136. </template>
  137. <script setup lang="ts">
  138. import { ref, nextTick, watch, computed, onBeforeUnmount } from 'vue';
  139. import dayjs from 'dayjs';
  140. import {
  141. unifiedStream,
  142. reviewPdfStream,
  143. chatResumeStream,
  144. getHistoryList,
  145. getDetail,
  146. deleteSession,
  147. pinSession,
  148. editSessionTitle,
  149. getContext,
  150. switchThinking,
  151. getModelMsg,
  152. getSessionMode,
  153. putSessionMode,
  154. getTodayUsage,
  155. StreamError,
  156. } from '../api';
  157. import { message, Modal } from 'ant-design-vue';
  158. import TaskListPanel from './chatModal/TaskListPanel.vue';
  159. import ChatHeader from './chatModal/ChatHeader.vue';
  160. import FileListPanel from './chatModal/FileListPanel.vue';
  161. import ChatMessages from './chatModal/ChatMessages.vue';
  162. import type { AgentDetailData } from './chatModal/ChatMessages.vue';
  163. import ChatInputArea from './chatModal/ChatInputArea.vue';
  164. import TodoListBar from './chatModal/TodoListBar.vue';
  165. import SkillPanel from './chatModal/SkillPanel.vue';
  166. import SubAgentPanel from './chatModal/SubAgentPanel.vue';
  167. import SchedulePanel from './chatModal/SchedulePanel.vue';
  168. import RightPanelTabs from './chatModal/RightPanelTabs.vue';
  169. import { getScheduleList } from '../api';
  170. import type { TodayUsage } from '../api';
  171. import type { AttachedFile, Message, Task, RightPanelTab, RightPanelState, SseEvent } from './chatModal/types';
  172. import { isTextFile, isVideoFile, isAudioFile, isWordFile, isExcelFile, isCsvFile } from './chatModal/utils';
  173. interface Props {
  174. visible: boolean;
  175. // 初始即全屏显示(首页等嵌入场景)
  176. defaultFullscreen?: boolean;
  177. // 是否显示窗口控制按钮(最大化/还原、关闭)
  178. showControls?: boolean;
  179. zIndex?: number;
  180. }
  181. interface Emits {
  182. (e: 'close'): void;
  183. }
  184. const props = withDefaults(defineProps<Props>(), {
  185. defaultFullscreen: false,
  186. showControls: true,
  187. });
  188. const emit = defineEmits<Emits>();
  189. const taskList = ref<Task[]>([]);
  190. // 已从接口拉取过的会话 id,用于识别流式期间后端新建的会话
  191. const knownApiSessionIds = new Set<string>();
  192. // 从接口获取会话列表
  193. const fetchSessionList = async () => {
  194. try {
  195. const res = await getHistoryList({});
  196. const sessions = res?.sessions || res?.data || [];
  197. if (Array.isArray(sessions)) {
  198. const apiTasks: Task[] = sessions.map((item: { session_id: string; title: string; updated_at: string; sort_order?: number }) => ({
  199. id: item.session_id,
  200. name: item.title || '未命名会话',
  201. sessionId: item.session_id,
  202. messages: [],
  203. attachedFiles: [],
  204. updatedAt: item.updated_at,
  205. sortOrder: item.sort_order,
  206. }));
  207. // Build lookup maps for O(1) access
  208. const existingTaskMap = new Map(taskList.value.map((t) => [t.id, t]));
  209. const apiTaskIds = new Set(apiTasks.map((t) => t.id));
  210. // 流式中的空白任务:后端已为其创建会话,但前端要等流结束才拿到 session_id。
  211. // 该会话在接口里是一条全新记录,归并回空白任务而不是单独插入,避免列表出现重复条目
  212. let blankStreamingTask: Task | null = taskList.value.find((t) => !t.sessionId && t.isStreaming) || null;
  213. const mergedTasks: Task[] = [];
  214. for (const apiTask of apiTasks) {
  215. if (blankStreamingTask && (blankStreamingTask.pendingSessionId === apiTask.id || !knownApiSessionIds.has(apiTask.id))) {
  216. blankStreamingTask.pendingSessionId = apiTask.id;
  217. blankStreamingTask.name = apiTask.name;
  218. blankStreamingTask.updatedAt = apiTask.updatedAt;
  219. blankStreamingTask.sortOrder = apiTask.sortOrder;
  220. blankStreamingTask = null;
  221. continue;
  222. }
  223. const existing = existingTaskMap.get(apiTask.id);
  224. if (existing) {
  225. // 原地更新以保持对象引用,避免流式回调持有的任务引用失效(isStreaming 等状态丢失)
  226. existing.name = apiTask.name;
  227. existing.updatedAt = apiTask.updatedAt;
  228. existing.sortOrder = apiTask.sortOrder;
  229. mergedTasks.push(existing);
  230. } else {
  231. mergedTasks.push(apiTask);
  232. }
  233. }
  234. apiTasks.forEach((apiTask) => knownApiSessionIds.add(apiTask.id));
  235. const localOnlyTasks = taskList.value.filter((t) => !t.sessionId && !apiTaskIds.has(t.id));
  236. taskList.value = [...localOnlyTasks, ...mergedTasks];
  237. return mergedTasks;
  238. }
  239. } catch (error) {
  240. console.error('获取会话列表失败:', error);
  241. }
  242. return [];
  243. };
  244. const currentTaskId = ref('');
  245. const chatInputRef = ref<InstanceType<typeof ChatInputArea>>();
  246. const chatMessagesRef = ref<InstanceType<typeof ChatMessages>>();
  247. const showFileList = ref(false);
  248. const activePanel = ref<'chat' | 'skill' | 'sub-agents' | 'schedules'>('chat');
  249. const scheduleListForDetail = ref<any[]>([]);
  250. const fetchScheduleListForDetail = async () => {
  251. try {
  252. const res = await getScheduleList();
  253. scheduleListForDetail.value = res?.tasks || res?.data || (Array.isArray(res) ? res : []);
  254. } catch {
  255. scheduleListForDetail.value = [];
  256. }
  257. };
  258. const pendingFile = ref<AttachedFile | null>(null);
  259. const activeFileReader = ref<FileReader | null>(null);
  260. const messages = ref<Message[]>([]);
  261. const usageToday = ref<TodayUsage | null>(null);
  262. const fetchTodayUsage = async () => {
  263. try {
  264. const res = await getTodayUsage();
  265. if (res && typeof res === 'object') {
  266. usageToday.value = res;
  267. }
  268. } catch (e) {
  269. console.error('获取今日用量失败:', e);
  270. }
  271. };
  272. const contextUsed = ref(0);
  273. const contextMax = ref(1000000);
  274. const contextPercent = ref(0);
  275. const thinkLevel = ref('off');
  276. const editMode = ref('full');
  277. const contextBreakdown = ref({ messages: 0, mcp: 0, skills: 0, system_prompt: 0, other: 0 });
  278. const currentTodos = ref<Array<{ content: string; status: string }>>([]);
  279. const showTodoBar = ref(false);
  280. const syncTodoBarFromMessages = () => {
  281. for (let i = messages.value.length - 1; i >= 0; i--) {
  282. const msg = messages.value[i];
  283. if (msg.type === 'ai' && msg.thinkingSteps) {
  284. for (let j = msg.thinkingSteps.length - 1; j >= 0; j--) {
  285. const step = msg.thinkingSteps[j];
  286. if (step.type === 'updated_todo_list' && step.todos) {
  287. currentTodos.value = [...step.todos];
  288. showTodoBar.value = true;
  289. return;
  290. }
  291. }
  292. }
  293. }
  294. showTodoBar.value = false;
  295. currentTodos.value = [];
  296. };
  297. const panelCollapsed = ref(false);
  298. const togglePanel = () => {
  299. panelCollapsed.value = !panelCollapsed.value;
  300. };
  301. const toggleSidePanel = (panel: 'skill' | 'schedules' | 'sub-agents') => {
  302. if (activePanel.value === panel) {
  303. activePanel.value = 'chat';
  304. } else {
  305. activePanel.value = panel;
  306. }
  307. };
  308. // Keep backward-compatible aliases
  309. const toggleSkillPanel = () => toggleSidePanel('skill');
  310. const toggleSchedulePanel = () => toggleSidePanel('schedules');
  311. const toggleSubAgentPanel = () => toggleSidePanel('sub-agents');
  312. const handleOpenScheduleSession = async (sessionId: string, prompt?: string) => {
  313. activePanel.value = 'chat';
  314. await fetchSessionList();
  315. await fetchScheduleListForDetail();
  316. const existing = taskList.value.find((t) => t.sessionId === sessionId);
  317. if (existing) {
  318. await switchTask(existing.id);
  319. } else {
  320. const newTask: Task = {
  321. id: sessionId,
  322. name: '定时任务',
  323. sessionId,
  324. messages: [],
  325. attachedFiles: [],
  326. };
  327. taskList.value.unshift(newTask);
  328. historyLoadedTasks.delete(sessionId);
  329. await switchTask(newTask.id);
  330. }
  331. // 如果有 prompt,自动发送消息
  332. if (prompt) {
  333. inputMessage.value = prompt;
  334. await nextTick();
  335. await handleSendMessage();
  336. }
  337. };
  338. const schedulePanelRef = ref();
  339. const handleScheduleDeleted = () => {
  340. const task = currentTask.value;
  341. if (task?.rightPanels) {
  342. const tab = task.rightPanels.tabs.find((t) => t.type === 'schedule');
  343. if (tab) removeTab(task.rightPanels, tab.id);
  344. }
  345. fetchScheduleListForDetail();
  346. schedulePanelRef.value?.fetchScheduleList?.();
  347. };
  348. const handleScheduleUpdated = async () => {
  349. await fetchScheduleListForDetail();
  350. // 同步标签内任务对象为最新数据(编辑/启停后)
  351. const task = currentTask.value;
  352. const tab = task?.rightPanels?.tabs.find((t) => t.type === 'schedule');
  353. if (tab?.type === 'schedule') {
  354. const fresh = scheduleListForDetail.value.find((s: any) => s.id === tab.task.id);
  355. if (fresh) tab.task = fresh;
  356. }
  357. schedulePanelRef.value?.fetchScheduleList?.();
  358. };
  359. // 标题保存(由 ChatHeader 子组件触发,父组件负责 API 调用和状态更新)
  360. const handleSaveTitle = async (newTitle: string) => {
  361. if (!currentTask.value?.sessionId) return;
  362. try {
  363. await editSessionTitle(currentTask.value.sessionId, newTitle);
  364. currentTask.value.name = newTitle;
  365. message.success('标题修改成功');
  366. } catch {
  367. message.error('标题修改失败');
  368. }
  369. };
  370. const isFullscreen = ref(!!props.defaultFullscreen);
  371. // 响应式视口宽度,用于计算 modal 最大宽度不超过屏幕
  372. const viewportWidth = ref(window.innerWidth);
  373. const onResize = () => {
  374. viewportWidth.value = window.innerWidth;
  375. };
  376. window.addEventListener('resize', onResize);
  377. const currentTask = computed(() => taskList.value.find((t) => t.id === currentTaskId.value));
  378. const currentRightPanels = computed<RightPanelState>(() => {
  379. const task = currentTask.value;
  380. return task?.rightPanels || { tabs: [], activeTabId: null };
  381. });
  382. // 是否有右侧辅助面板(标签页容器)与 chat-panel 并列显示
  383. const hasRightPanel = computed(() => {
  384. if (activePanel.value !== 'chat') return false;
  385. return currentRightPanels.value.tabs.length > 0;
  386. });
  387. // 面板离开动画标记:确保 modal 在面板退出动画结束后才收缩宽度
  388. const isPanelLeaving = ref(false);
  389. const modalShouldExpand = computed(() => hasRightPanel.value || isPanelLeaving.value);
  390. // modal 宽度:全屏100vw / 有右侧面板时1600px(不超视口)/ 默认1400px
  391. const modalWidth = computed(() => {
  392. if (isFullscreen.value) return '100vw';
  393. if (modalShouldExpand.value) return Math.min(1600, viewportWidth.value);
  394. return 1400;
  395. });
  396. // 右侧面板离开动画结束后,允许 modal 宽度收缩
  397. const onPanelLeaveEnd = () => {
  398. isPanelLeaving.value = false;
  399. };
  400. // 监听右侧面板从有到无,标记正在离开状态,防止 modal 宽度提前收缩
  401. watch(hasRightPanel, (newVal, oldVal) => {
  402. if (oldVal && !newVal) {
  403. isPanelLeaving.value = true;
  404. }
  405. });
  406. // 全屏切换,附带缩放动画效果
  407. const toggleFullscreen = () => {
  408. const enteringFs = !isFullscreen.value;
  409. isFullscreen.value = enteringFs;
  410. nextTick(() => {
  411. // 给 modal-content 添加缩放动画类,动画结束后自动移除
  412. const content = document.querySelector<HTMLElement>('.ai-assistant-modal .zxm-modal-content');
  413. if (content) {
  414. const animClass = enteringFs ? 'modal-zoom-in-anim' : 'modal-zoom-out-anim';
  415. content.classList.remove('modal-zoom-in-anim', 'modal-zoom-out-anim');
  416. void content.offsetWidth; // 强制重排,确保动画重新触发
  417. content.classList.add(animClass);
  418. content.addEventListener('animationend', () => content.classList.remove(animClass), { once: true });
  419. }
  420. applyWrapStyles(isFullscreen.value);
  421. draggedEl = null;
  422. if (!isFullscreen.value) {
  423. centerModal();
  424. }
  425. });
  426. };
  427. const inputMessage = ref('');
  428. const selectedSessions = ref<Array<{ id: string; name: string }>>([]);
  429. const selectedSkill = ref<{ name: string; display_name: string } | null>(null);
  430. // 按任务维度的状态存储
  431. const taskPendingApprovals = ref<Map<string, { sessionId: string; threadId: string }>>(new Map());
  432. // loading 和 streaming 共享同一个计算属性,基于当前任务的 isStreaming 状态
  433. const loading = computed(() => {
  434. const currentTask = taskList.value.find((t) => t.id === currentTaskId.value);
  435. return currentTask?.isStreaming ?? false;
  436. });
  437. const streaming = loading;
  438. // 获取当前任务的待审批状态
  439. const currentPendingApproval = computed(() => {
  440. return taskPendingApprovals.value.get(currentTaskId.value);
  441. });
  442. // Non-reactive Map for AbortControllers - only used imperatively, no need for Vue reactivity
  443. const taskAbortControllers = new Map<string, AbortController>();
  444. // 设置任务的AbortController
  445. const setTaskAbortController = (taskId: string, controller: AbortController | null) => {
  446. if (controller) {
  447. taskAbortControllers.set(taskId, controller);
  448. } else {
  449. taskAbortControllers.delete(taskId);
  450. }
  451. };
  452. // 设置任务的审批状态
  453. const setTaskPendingApproval = (taskId: string, sessionId: string, threadId: string) => {
  454. const map = new Map(taskPendingApprovals.value);
  455. map.set(taskId, { sessionId, threadId });
  456. taskPendingApprovals.value = map;
  457. };
  458. // 清除任务的审批状态
  459. const clearTaskPendingApproval = (taskId: string) => {
  460. const map = new Map(taskPendingApprovals.value);
  461. map.delete(taskId);
  462. taskPendingApprovals.value = map;
  463. };
  464. // 停止指定任务的流式传输
  465. const stopTaskStreaming = (taskId: string) => {
  466. const controller = taskAbortControllers.get(taskId);
  467. controller?.abort();
  468. };
  469. const stopStreaming = () => {
  470. stopTaskStreaming(currentTaskId.value);
  471. };
  472. const getCurrentSessionId = (): string => {
  473. const currentTask = taskList.value.find((t) => t.id === currentTaskId.value);
  474. return currentTask?.sessionId || '';
  475. };
  476. // Non-reactive lookup cache - Vue 3 does not track Set mutations on ref<Set>
  477. const historyLoadedTasks = new Set<string>();
  478. const setCurrentSessionId = (sessionId: string) => {
  479. const currentTask = taskList.value.find((t) => t.id === currentTaskId.value);
  480. if (currentTask && currentTask.id !== sessionId) {
  481. taskList.value = taskList.value.filter((t) => t.id !== sessionId);
  482. currentTask.id = sessionId;
  483. currentTask.sessionId = sessionId;
  484. currentTaskId.value = sessionId;
  485. historyLoadedTasks.add(sessionId);
  486. }
  487. };
  488. const switchTask = async (taskId: string) => {
  489. activePanel.value = 'chat';
  490. const currentTask = taskList.value.find((t) => t.id === currentTaskId.value);
  491. if (currentTask) {
  492. currentTask.messages = [...messages.value];
  493. }
  494. currentTaskId.value = taskId;
  495. const newTask = taskList.value.find((t) => t.id === taskId);
  496. if (!newTask) return;
  497. inputMessage.value = '';
  498. pendingFile.value = null;
  499. showFileList.value = false;
  500. if (newTask.sessionId && !historyLoadedTasks.has(taskId)) {
  501. if (newTask.isStreaming) return; // 新任务正在流式中,无需加载历史
  502. try {
  503. const res = await getDetail(newTask.sessionId);
  504. const messages = res?.messages || (Array.isArray(res) ? res : res?.data);
  505. if (Array.isArray(messages)) {
  506. newTask.messages = transformHistoryToMessages(messages);
  507. }
  508. historyLoadedTasks.add(taskId);
  509. } catch (error) {
  510. console.error('加载历史会话失败:', error);
  511. }
  512. }
  513. if (newTask.sessionId) {
  514. fetchContext(newTask.sessionId);
  515. fetchSessionMode(newTask.sessionId);
  516. } else {
  517. contextUsed.value = 0;
  518. contextPercent.value = 0;
  519. contextBreakdown.value = { messages: 0, mcp: 0, skills: 0, system_prompt: 0, other: 0 };
  520. editMode.value = 'full';
  521. }
  522. messages.value = newTask.messages && newTask.messages.length > 0 ? [...newTask.messages] : getDefaultMessages();
  523. syncTodoBarFromMessages();
  524. // 切换任务时检测是否为定时任务会话:自动打开/关闭定时任务详情标签
  525. const scheduleItem = newTask.sessionId ? scheduleListForDetail.value.find((s: any) => s.feedback_session_id === newTask.sessionId) : undefined;
  526. const panelState = getPanelState(newTask);
  527. const existingScheduleTab = panelState.tabs.find((t) => t.type === 'schedule');
  528. if (scheduleItem) {
  529. if (existingScheduleTab) {
  530. panelState.activeTabId = existingScheduleTab.id;
  531. } else {
  532. panelState.tabs.push({ id: 'schedule', type: 'schedule', title: scheduleItem.name || '定时任务', task: scheduleItem });
  533. panelState.activeTabId = 'schedule';
  534. }
  535. } else if (existingScheduleTab) {
  536. removeTab(panelState, existingScheduleTab.id);
  537. }
  538. await nextTick();
  539. chatMessagesRef.value?.forceScrollToBottom();
  540. };
  541. const createNewTask = () => {
  542. const existingBlank = taskList.value.find((t) => !t.sessionId && t.messages.length === 0);
  543. if (existingBlank) {
  544. switchTask(existingBlank.id);
  545. return;
  546. }
  547. const newTask: Task = {
  548. id: `task-${Date.now()}`,
  549. name: '新任务',
  550. sessionId: '',
  551. messages: getDefaultMessages(),
  552. attachedFiles: [],
  553. };
  554. contextUsed.value = 0;
  555. contextPercent.value = 0;
  556. contextBreakdown.value = { messages: 0, mcp: 0, skills: 0, system_prompt: 0, other: 0 };
  557. editMode.value = 'full';
  558. taskList.value.unshift(newTask);
  559. switchTask(newTask.id);
  560. };
  561. const handlePinTask = async (task: Task) => {
  562. if (!task.sessionId) {
  563. message.warning('请先发送消息后再置顶');
  564. return;
  565. }
  566. try {
  567. await pinSession(task.sessionId);
  568. await fetchSessionList();
  569. } catch {
  570. message.error('置顶操作失败');
  571. }
  572. };
  573. const handleThinkLevelChange = async (levelKey: string) => {
  574. try {
  575. await switchThinking(levelKey);
  576. } catch {
  577. message.error('切换思考级别失败');
  578. }
  579. };
  580. const handleUpdateSelectedSessions = (sessions: Array<{ id: string; name: string }>) => {
  581. selectedSessions.value = sessions;
  582. };
  583. const handleUpdateSelectedSkill = (skill: { name: string; display_name: string } | null) => {
  584. selectedSkill.value = skill;
  585. };
  586. const getSkillRefIconUrl = () => {
  587. const val = getComputedStyle(document.documentElement).getPropertyValue('--img-chat-options-skill-icon').trim();
  588. return val.replace(/^url\(["']?/, '').replace(/["']?\)$/, '');
  589. };
  590. const getSessionRefIconUrl = () => {
  591. const val = getComputedStyle(document.documentElement).getPropertyValue('--img-chat-popup-session-icon').trim();
  592. return val.replace(/^url\(["']?/, '').replace(/["']?\)$/, '');
  593. };
  594. const handleEditModeChange = async (modeKey: string) => {
  595. editMode.value = modeKey;
  596. const sessionId = getCurrentSessionId();
  597. if (!sessionId) return;
  598. try {
  599. await putSessionMode(sessionId, modeKey);
  600. } catch {
  601. message.error('切换模式失败');
  602. }
  603. };
  604. const findPendingApprovalTask = (): { taskId: string; approval: { sessionId: string; threadId?: string } } | null => {
  605. // 优先用当前任务 ID 查找
  606. let approval = currentPendingApproval.value;
  607. if (approval) return { taskId: currentTaskId.value, approval };
  608. // 遍历所有审批(可能任务 ID 已变,用 sessionId 做回退匹配)
  609. for (const [taskId, a] of taskPendingApprovals.value.entries()) {
  610. return { taskId, approval: a };
  611. }
  612. return null;
  613. };
  614. const handleAskUserSubmit = async (answers: string[]) => {
  615. // 防重复提交:如果当前任务正在流式中,忽略
  616. const currentTask = taskList.value.find((t) => t.id === currentTaskId.value);
  617. if (currentTask?.isStreaming) return;
  618. const found = findPendingApprovalTask();
  619. // 优先从 taskPendingApprovals 获取,若被清除则从消息的 pendingApprovalData 回退
  620. let sessionId = found?.approval.sessionId;
  621. let threadId = found?.approval.threadId;
  622. const foundTaskId = found?.taskId;
  623. // 查找任务:优先用 foundTaskId,回退到 currentTaskId
  624. let task = foundTaskId ? taskList.value.find((t) => t.id === foundTaskId) : null;
  625. if (!task) task = taskList.value.find((t) => t.id === currentTaskId.value);
  626. if (!task) return;
  627. // 切换到目标任务(如果不在当前视图)
  628. if (task.id !== currentTaskId.value) {
  629. await switchTask(task.id);
  630. }
  631. // 使用正确的消息数组:当前视图用 messages.value,否则用 task.messages
  632. const isViewingTask = currentTaskId.value === task.id;
  633. const sourceArr = isViewingTask ? messages.value : task.messages;
  634. const lastMsg = sourceArr[sourceArr.length - 1];
  635. if (!lastMsg || !lastMsg.isPendingApproval) return;
  636. // 若 taskPendingApprovals 已被清除,从消息的 pendingApprovalData 回退取值
  637. if (!sessionId && lastMsg.pendingApprovalData) {
  638. sessionId = lastMsg.pendingApprovalData.sessionId;
  639. threadId = lastMsg.pendingApprovalData.threadId;
  640. }
  641. if (!sessionId) return;
  642. lastMsg.isPendingApproval = false;
  643. lastMsg.pendingApprovalData = undefined;
  644. lastMsg.isLoading = true;
  645. lastMsg.generateStartTime = Date.now();
  646. const aiMsgIndex = sourceArr.length - 1;
  647. // 强制触发 Vue 响应式更新
  648. if (isViewingTask) {
  649. messages.value = [...sourceArr];
  650. }
  651. task.messages = [...sourceArr];
  652. task.isStreaming = true;
  653. showTodoBar.value = false;
  654. currentTodos.value = [];
  655. const controller = new AbortController();
  656. setTaskAbortController(task.id, controller);
  657. try {
  658. const result = await chatResumeStream(
  659. {
  660. session_id: sessionId,
  661. thread_id: threadId || undefined,
  662. status: 'answered',
  663. answers,
  664. signal: controller.signal,
  665. },
  666. (data: SseEvent) => {
  667. parseSSEData(data, aiMsgIndex, task.id);
  668. if (currentTaskId.value === task.id) scrollToBottomThrottled();
  669. }
  670. );
  671. if (result.session_id) {
  672. setCurrentSessionId(result.session_id);
  673. }
  674. } catch (error) {
  675. if ((error as Error)?.name === 'AbortError') {
  676. lastMsg.isLoading = false;
  677. lastMsg.durationMs = (lastMsg.baseDurationMs || 0) + (lastMsg.generateStartTime ? Date.now() - lastMsg.generateStartTime : 0);
  678. if (!lastMsg.content) {
  679. lastMsg.content = '已停止生成。';
  680. }
  681. } else {
  682. console.error('提交答案失败:', error);
  683. const isStreamError = error instanceof StreamError;
  684. message.error(isStreamError ? error.message : '提交失败,请重试');
  685. if (isStreamError) fetchTodayUsage();
  686. lastMsg.isLoading = false;
  687. lastMsg.durationMs = (lastMsg.baseDurationMs || 0) + (lastMsg.generateStartTime ? Date.now() - lastMsg.generateStartTime : 0);
  688. if (!lastMsg.content) {
  689. lastMsg.content = isStreamError ? error.message : '抱歉,提交请求失败,请稍后重试。';
  690. }
  691. }
  692. } finally {
  693. setTaskAbortController(task.id, null);
  694. task.isStreaming = false;
  695. // 仅当消息不再处于审批状态时才清除(避免 resume 流返回新 interrupt 被误清)
  696. if (!lastMsg.isPendingApproval) {
  697. clearTaskPendingApproval(task.id);
  698. }
  699. if (currentTaskId.value === task.id) {
  700. await scrollToBottom();
  701. }
  702. }
  703. };
  704. const handleAskUserCancel = async () => {
  705. // 防重复操作:如果当前任务正在流式中,忽略
  706. const currentTask = taskList.value.find((t) => t.id === currentTaskId.value);
  707. if (currentTask?.isStreaming) return;
  708. const found = findPendingApprovalTask();
  709. // 优先从 taskPendingApprovals 获取,若被清除则从消息的 pendingApprovalData 回退
  710. let sessionId = found?.approval.sessionId;
  711. let threadId = found?.approval.threadId;
  712. const foundTaskId = found?.taskId;
  713. // 查找任务:优先用 foundTaskId,回退到 currentTaskId
  714. let task = foundTaskId ? taskList.value.find((t) => t.id === foundTaskId) : null;
  715. if (!task) task = taskList.value.find((t) => t.id === currentTaskId.value);
  716. if (!task) return;
  717. // 切换到目标任务(如果不在当前视图)
  718. if (task.id !== currentTaskId.value) {
  719. await switchTask(task.id);
  720. }
  721. // 使用正确的消息数组
  722. const isViewingTask = currentTaskId.value === task.id;
  723. const sourceArr = isViewingTask ? messages.value : task.messages;
  724. const lastMsg = sourceArr[sourceArr.length - 1];
  725. if (!lastMsg || !lastMsg.isPendingApproval) return;
  726. // 若 taskPendingApprovals 已被清除,从消息的 pendingApprovalData 回退取值
  727. if (!sessionId && lastMsg.pendingApprovalData) {
  728. sessionId = lastMsg.pendingApprovalData.sessionId;
  729. threadId = lastMsg.pendingApprovalData.threadId;
  730. }
  731. if (!sessionId) return;
  732. // 冻结累计耗时到 durationMs,避免取消后计时消失
  733. lastMsg.durationMs = (lastMsg.baseDurationMs || 0) + (lastMsg.generateStartTime ? Date.now() - lastMsg.generateStartTime : 0);
  734. lastMsg.isPendingApproval = false;
  735. lastMsg.pendingApprovalData = undefined;
  736. lastMsg.isLoading = false;
  737. lastMsg.content = (lastMsg.content ? lastMsg.content + '\n\n' : '') + '已取消提问。';
  738. task.messages = [...sourceArr];
  739. if (isViewingTask) {
  740. messages.value = task.messages;
  741. }
  742. clearTaskPendingApproval(task.id);
  743. try {
  744. await chatResumeStream(
  745. {
  746. session_id: sessionId,
  747. thread_id: threadId || undefined,
  748. status: 'cancelled',
  749. },
  750. () => {}
  751. );
  752. } catch (error) {
  753. console.error('取消操作失败:', error);
  754. }
  755. task.isStreaming = false;
  756. if (currentTaskId.value === task.id) {
  757. messages.value = task.messages;
  758. await scrollToBottom();
  759. }
  760. };
  761. const handleDeleteTask = (task: Task, _index: number) => {
  762. Modal.confirm({
  763. title: '提示',
  764. content: '是否删除该对话?',
  765. okText: '确认',
  766. cancelText: '取消',
  767. wrapClassName: 'delete-task-confirm-modal',
  768. onOk: async () => {
  769. try {
  770. if (task.sessionId) {
  771. await deleteSession(task.sessionId);
  772. }
  773. const realIndex = taskList.value.findIndex((t) => t.id === task.id);
  774. if (realIndex !== -1) {
  775. taskList.value.splice(realIndex, 1);
  776. }
  777. if (currentTaskId.value === task.id) {
  778. if (taskList.value.length > 0) {
  779. switchTask(taskList.value[0].id);
  780. } else {
  781. messages.value = [];
  782. currentTaskId.value = '';
  783. }
  784. }
  785. message.success('删除成功');
  786. } catch {
  787. message.error('删除失败');
  788. }
  789. },
  790. });
  791. };
  792. const getDefaultMessages = (): Message[] => {
  793. return [];
  794. };
  795. const normalizeLineBreaks = (str: string): string => {
  796. if (!str) return '';
  797. return str.replace(/\\n/g, '\n').replace(/\r\n/g, '\n');
  798. };
  799. const transformHistoryToMessages = (
  800. data: Array<{
  801. role?: string;
  802. type?: string;
  803. content: string;
  804. created_at?: string;
  805. report_url?: string;
  806. report_filename?: string;
  807. citations?: any;
  808. }>
  809. ): Message[] => {
  810. const messages: Message[] = [];
  811. for (const item of data) {
  812. const normalizedContent = normalizeLineBreaks(item.content);
  813. const time = item.created_at ? dayjs(item.created_at).format('HH:mm') : '';
  814. const createdAt = item.created_at || '';
  815. // 新格式:role 字段 (user/assistant)
  816. if (item.role === 'user') {
  817. messages.push({ type: 'user', content: normalizedContent, time, createdAt });
  818. } else if (item.role === 'assistant') {
  819. const msg: Message = { type: 'ai', content: normalizedContent, time, createdAt };
  820. if (item.report_url && item.report_filename) {
  821. msg.downloadFiles = [{ url: item.report_url, filename: item.report_filename }];
  822. }
  823. if (item.citations) {
  824. // 历史接口返回 citations 为扁平数组,SSE 事件返回 { items, model_only },统一归一化
  825. const raw = item.citations;
  826. if (Array.isArray(raw)) {
  827. msg.citations = { items: raw, model_only: raw.length === 0 };
  828. } else {
  829. msg.citations = raw;
  830. }
  831. }
  832. messages.push(msg);
  833. }
  834. // 兼容旧格式:type 字段
  835. else if (item.type === 'user_message') {
  836. messages.push({ type: 'user', content: normalizedContent, time, createdAt });
  837. } else if (item.type === 'model_thinking') {
  838. const lastAiMsg = messages[messages.length - 1];
  839. if (lastAiMsg && lastAiMsg.type === 'ai') {
  840. lastAiMsg.content += normalizedContent;
  841. lastAiMsg.content = lastAiMsg.content.replace(/\|\|\|SPLIT_CONTENT\|\|\|/g, '');
  842. } else {
  843. messages.push({ type: 'ai', content: normalizedContent, time, createdAt });
  844. }
  845. }
  846. }
  847. return messages;
  848. };
  849. const triggerFileUpload = () => {
  850. chatInputRef.value?.fileInputRef?.click();
  851. };
  852. const handleFileUpload = async (event: Event) => {
  853. const target = event.target as HTMLInputElement;
  854. const file = target.files?.[0];
  855. if (!file) return;
  856. if (isVideoFile(file.name) || isAudioFile(file.name)) {
  857. message.warning('不支持上传音频和视频文件');
  858. target.value = '';
  859. return;
  860. }
  861. try {
  862. const newFile: AttachedFile = {
  863. id: `file-${Date.now()}`,
  864. name: file.name,
  865. size: file.size,
  866. type: file.type,
  867. uploadTime: dayjs().format('YYYY-MM-DD HH:mm'),
  868. originalFile: file,
  869. };
  870. // Abort previous FileReader if still in progress
  871. if (activeFileReader.value) {
  872. activeFileReader.value.abort();
  873. activeFileReader.value = null;
  874. }
  875. const reader = new FileReader();
  876. activeFileReader.value = reader;
  877. reader.onload = (e) => {
  878. activeFileReader.value = null;
  879. if (isTextFile(file.name) || isCsvFile(file.name)) {
  880. newFile.content = e.target?.result as string;
  881. } else if (isWordFile(file.name) || isExcelFile(file.name)) {
  882. newFile.arrayBuffer = e.target?.result as ArrayBuffer;
  883. } else {
  884. newFile.preview = e.target?.result as string;
  885. }
  886. };
  887. if (isTextFile(file.name) || isCsvFile(file.name)) {
  888. reader.readAsText(file);
  889. } else if (isWordFile(file.name) || isExcelFile(file.name)) {
  890. reader.readAsArrayBuffer(file);
  891. } else {
  892. reader.readAsDataURL(file);
  893. }
  894. pendingFile.value = newFile;
  895. message.success(`文件 "${file.name}" 已添加,点击发送按钮提交`);
  896. } catch (error) {
  897. console.error('文件处理失败:', error);
  898. message.error('文件处理失败,请重试');
  899. }
  900. target.value = '';
  901. };
  902. const removePendingFile = () => {
  903. pendingFile.value = null;
  904. };
  905. const openFileTab = (file: AttachedFile, editable: boolean) => {
  906. const task = currentTask.value;
  907. if (!task) return;
  908. const state = getPanelState(task);
  909. const existing = state.tabs.find((t) => t.type === 'file' && t.file.id === file.id);
  910. if (existing) {
  911. // 编辑入口可升级已有标签为可编辑;预览入口不降级
  912. if (editable) existing.editable = true;
  913. state.activeTabId = existing.id;
  914. return;
  915. }
  916. openTab({ id: nextTabId(), type: 'file', title: file.name, file, editable });
  917. };
  918. const handleAgentDetailClick = (data: AgentDetailData) => {
  919. const task = currentTask.value;
  920. if (!task) return;
  921. const state = getPanelState(task);
  922. const existing = state.tabs.find(
  923. (t) => t.type === 'agent' && t.messageIndex === data.messageIndex && (t.agentId || '') === (data.agentId || '') && t.agent === data.agent
  924. );
  925. if (existing) {
  926. if (state.activeTabId === existing.id) {
  927. // 保持原交互:再次点击已激活的 agent 则关闭
  928. removeTab(state, existing.id);
  929. } else {
  930. state.activeTabId = existing.id;
  931. }
  932. return;
  933. }
  934. openTab({
  935. id: nextTabId(),
  936. type: 'agent',
  937. title: data.agent,
  938. messageIndex: data.messageIndex,
  939. agent: data.agent,
  940. agentId: data.agentId,
  941. });
  942. };
  943. const openFilePreview = (file: AttachedFile) => {
  944. openFileTab(file, false);
  945. const msgIndex = messages.value.findIndex((m) => m.attachedFile?.id === file.id);
  946. if (msgIndex !== -1) {
  947. nextTick(() => {
  948. const messageElements = chatMessagesRef.value?.messagesRef?.querySelectorAll('.message-wrapper');
  949. if (messageElements && messageElements[msgIndex]) {
  950. (messageElements[msgIndex] as HTMLElement).scrollIntoView({
  951. behavior: 'smooth',
  952. block: 'center',
  953. });
  954. }
  955. });
  956. }
  957. };
  958. const getCurrentTaskFiles = (): AttachedFile[] => {
  959. const currentTask = taskList.value.find((t) => t.id === currentTaskId.value);
  960. return currentTask?.attachedFiles || [];
  961. };
  962. // 右侧辅助面板标签页状态(按任务维度保存,切换任务自动恢复)
  963. let tabSeq = 0;
  964. const nextTabId = () => `panel-${Date.now()}-${tabSeq++}`;
  965. const getPanelState = (task: Task): RightPanelState => {
  966. if (!task.rightPanels) {
  967. task.rightPanels = { tabs: [], activeTabId: null };
  968. }
  969. return task.rightPanels;
  970. };
  971. const openTab = (tab: RightPanelTab) => {
  972. const task = currentTask.value;
  973. if (!task) return;
  974. const state = getPanelState(task);
  975. state.tabs.push(tab);
  976. state.activeTabId = tab.id;
  977. };
  978. const activateTab = (tabId: string) => {
  979. const task = currentTask.value;
  980. if (!task?.rightPanels) return;
  981. if (task.rightPanels.tabs.some((t) => t.id === tabId)) {
  982. task.rightPanels.activeTabId = tabId;
  983. }
  984. };
  985. const removeTab = (state: RightPanelState, tabId: string) => {
  986. const idx = state.tabs.findIndex((t) => t.id === tabId);
  987. if (idx === -1) return;
  988. state.tabs.splice(idx, 1);
  989. if (state.activeTabId === tabId) {
  990. state.activeTabId = state.tabs.length ? (state.tabs[idx] || state.tabs[idx - 1]).id : null;
  991. }
  992. };
  993. const closeTab = (tabId: string) => {
  994. const task = currentTask.value;
  995. if (!task?.rightPanels) return;
  996. removeTab(task.rightPanels, tabId);
  997. };
  998. const currentWordUrl = computed(() => {
  999. return currentTask.value?.wordUrl || '';
  1000. });
  1001. const currentTaskIndex = computed(() => taskList.value.findIndex((t) => t.id === currentTaskId.value));
  1002. const canGoPrev = computed(() => currentTaskIndex.value > 0);
  1003. const canGoNext = computed(() => currentTaskIndex.value >= 0 && currentTaskIndex.value < taskList.value.length - 1);
  1004. const goToPrev = () => {
  1005. if (!canGoPrev.value) return;
  1006. const prevTask = taskList.value[currentTaskIndex.value - 1];
  1007. if (prevTask) switchTask(prevTask.id);
  1008. };
  1009. const goToNext = () => {
  1010. if (!canGoNext.value) return;
  1011. const nextTask = taskList.value[currentTaskIndex.value + 1];
  1012. if (nextTask) switchTask(nextTask.id);
  1013. };
  1014. const downloadWordFile = (url: string) => {
  1015. if (!url) return;
  1016. const a = document.createElement('a');
  1017. a.href = url;
  1018. a.download = '';
  1019. a.target = '_blank';
  1020. document.body.appendChild(a);
  1021. a.click();
  1022. document.body.removeChild(a);
  1023. };
  1024. const downloadWordReport = () => downloadWordFile(currentWordUrl.value);
  1025. const handleOpenFilePreview = (file: AttachedFile) => {
  1026. openFileTab(file, true);
  1027. };
  1028. const handleSaveSuccess = (content: string) => {
  1029. const task = currentTask.value;
  1030. const tab = task?.rightPanels?.tabs.find((t) => t.id === task.rightPanels?.activeTabId);
  1031. if (tab?.type === 'file') {
  1032. tab.file = { ...tab.file, content };
  1033. }
  1034. };
  1035. const handleSendMessage = async () => {
  1036. const hasText = inputMessage.value.trim();
  1037. const hasFile = pendingFile.value;
  1038. if (!hasText) {
  1039. message.warning('请输入消息内容');
  1040. return;
  1041. }
  1042. if (loading.value) return;
  1043. if (currentPendingApproval.value) {
  1044. message.warning('请先审批执行计划');
  1045. return;
  1046. }
  1047. const sessionPrefix = selectedSessions.value.length > 0 ? selectedSessions.value.map((s) => `#session:${s.id}`).join(' ') + ' ' : '';
  1048. const skillPrefix = selectedSkill.value ? `#skill:${selectedSkill.value.name} ` : '';
  1049. const userInput = skillPrefix + sessionPrefix + inputMessage.value.trim();
  1050. let displayContent = inputMessage.value.trim();
  1051. if (selectedSkill.value) {
  1052. const skillIconUrl = getSkillRefIconUrl();
  1053. displayContent = `[<img src="${skillIconUrl}" class="session-ref-icon" /> 技能:${selectedSkill.value.display_name}] ${displayContent}`;
  1054. }
  1055. if (selectedSessions.value.length > 0) {
  1056. const names = selectedSessions.value.map((s) => s.name).join('、');
  1057. const iconUrl = getSessionRefIconUrl();
  1058. displayContent = `[<img src="${iconUrl}" class="session-ref-icon" /> 引用 ${selectedSessions.value.length} 个会话:${names}] ${displayContent}`;
  1059. }
  1060. const fileToSend = pendingFile.value;
  1061. inputMessage.value = '';
  1062. pendingFile.value = null;
  1063. selectedSessions.value = [];
  1064. selectedSkill.value = null;
  1065. try {
  1066. await nextTick();
  1067. chatMessagesRef.value?.forceScrollToBottom();
  1068. if (hasFile) {
  1069. await sendWithAttachment(fileToSend!, userInput, displayContent);
  1070. } else {
  1071. await sendTextOnly(userInput, displayContent);
  1072. }
  1073. } catch (error) {
  1074. console.error('发送消息失败:', error);
  1075. const isStreamError = error instanceof StreamError;
  1076. const errText = isStreamError ? error.message : '发送失败,请重试';
  1077. message.error(errText);
  1078. if (isStreamError) fetchTodayUsage();
  1079. const lastMsg = messages.value[messages.value.length - 1];
  1080. if (lastMsg && lastMsg.type === 'ai' && lastMsg.isLoading) {
  1081. messages.value.pop();
  1082. }
  1083. const errorMsg: Message = {
  1084. type: 'ai',
  1085. content: isStreamError ? error.message : '抱歉,请求失败,请稍后重试。',
  1086. time: dayjs().format('HH:mm'),
  1087. };
  1088. messages.value.push(errorMsg);
  1089. const currentTask = taskList.value.find((t) => t.id === currentTaskId.value);
  1090. if (currentTask) {
  1091. currentTask.messages = [...messages.value];
  1092. }
  1093. } finally {
  1094. await scrollToBottom(true);
  1095. }
  1096. };
  1097. const extractAgentName = (toolName: string): string => {
  1098. const nameMap: Record<string, string> = {
  1099. form_review: '形式审查',
  1100. verify_coal_face_ventilation: '采煤工作面需风量计算核验',
  1101. verify_tunneling_face_ventilation: '掘进工作面需风量计算核验',
  1102. verify_chamber_ventilation: '硐室需风量计算核验',
  1103. verify_other_points_ventilation: '其他地点需风量计算核验',
  1104. check_data_by_gas_report: '瓦斯数据一致性审查',
  1105. check_data_by_face_design: '设计规程一致性审查',
  1106. check_data_by_vent_report: '测风报表一致性审查',
  1107. check_current_month_plan: '日期有效性审查',
  1108. get_key_translate: '计算参数对照',
  1109. calculate_ventilation: '需风量计算',
  1110. get_ventilation_data: '需风量查询',
  1111. recalculate_ventilation: '需风量重计算',
  1112. get_plan_required_wind: '需风量提取',
  1113. get_model_calculated_wind: '三维模型解算风量提取',
  1114. get_sensor_wind: '巷道监测风量提取',
  1115. merge_wind_by_location: '地点风量智能合并',
  1116. check_wind_compliance: '风量检查',
  1117. };
  1118. return nameMap[toolName] || nameMap[toolName.toLowerCase()] || '智能分析助手';
  1119. };
  1120. // 累积所有步骤,保留完整历史
  1121. const upsertStep = (steps: any[], step: any) => {
  1122. steps.push(step);
  1123. };
  1124. const fetchModelMsg = async () => {
  1125. try {
  1126. const res = await getModelMsg();
  1127. if (res?.thinking_level) {
  1128. thinkLevel.value = res.thinking_level;
  1129. }
  1130. } catch (e) {
  1131. console.error('获取模型信息失败:', e);
  1132. }
  1133. };
  1134. const fetchSessionMode = async (sessionId: string) => {
  1135. try {
  1136. const res = await getSessionMode(sessionId);
  1137. if (res?.mode) {
  1138. editMode.value = res.mode;
  1139. }
  1140. } catch (e) {
  1141. console.error('获取会话模式失败:', e);
  1142. }
  1143. };
  1144. const fetchContext = async (sessionId: string) => {
  1145. try {
  1146. const res = await getContext(sessionId);
  1147. contextUsed.value = res?.current_usage ?? 0;
  1148. contextMax.value = res?.total_limit ?? 0;
  1149. contextPercent.value = res?.usage_pct ?? 0;
  1150. contextBreakdown.value = res?.breakdown ?? { messages: 0, mcp: 0, skills: 0, system_prompt: 0, other: 0 };
  1151. } catch (e) {
  1152. console.error('获取上下文容量失败:', e);
  1153. contextUsed.value = 0;
  1154. contextMax.value = 0;
  1155. contextPercent.value = 0;
  1156. contextBreakdown.value = { messages: 0, mcp: 0, skills: 0, system_prompt: 0, other: 0 };
  1157. }
  1158. };
  1159. const handleSSEMessage = (data: any, aiMsgIndex: number, taskId: string) => {
  1160. const streamingTask = taskList.value.find((t) => t.id === taskId);
  1161. if (!streamingTask) return;
  1162. // 当前正在查看流式任务时,新消息被 push 到 messages.value 而非 task.messages
  1163. // 所以需要从 messages.value 读取;否则从任务存储的 messages 读取
  1164. const isViewingTask = currentTaskId.value === taskId;
  1165. const sourceArr = isViewingTask ? messages.value : streamingTask.messages;
  1166. const aiMsg = sourceArr[aiMsgIndex];
  1167. if (!aiMsg) return;
  1168. const normalizedContent = normalizeLineBreaks(data.content || '');
  1169. // 初始化 thinkingSteps 数组
  1170. if (!aiMsg.thinkingSteps) {
  1171. aiMsg.thinkingSteps = [];
  1172. }
  1173. switch (data.type) {
  1174. // token 流式内容 - 直接拼接到消息内容
  1175. case 'token':
  1176. if (normalizedContent) {
  1177. if (data.source === 'subagent' && data.agent_id) {
  1178. // subagent 的输出内容归属到对应的 agent step
  1179. const targetStep = aiMsg.thinkingSteps!.findLast((s) => s.type === 'agent_start' && s.agentId === data.agent_id);
  1180. if (targetStep) {
  1181. targetStep.content = (targetStep.content || '') + normalizedContent;
  1182. }
  1183. } else {
  1184. // main 模型输出,保持原有逻辑
  1185. aiMsg.content += normalizedContent;
  1186. }
  1187. }
  1188. break;
  1189. // thinking / thinking_token - 模型思考过程内容
  1190. case 'thinking':
  1191. case 'thinking_token':
  1192. if (normalizedContent) {
  1193. if (data.source === 'subagent' && data.agent_id) {
  1194. // subagent 的思考内容归属到对应的 agent step
  1195. const targetStep = aiMsg.thinkingSteps!.findLast((s) => s.type === 'agent_start' && s.agentId === data.agent_id);
  1196. if (targetStep) {
  1197. targetStep.thinkingContent = (targetStep.thinkingContent || '') + normalizedContent;
  1198. }
  1199. } else {
  1200. // main 模型思考,保持原有逻辑
  1201. aiMsg.thinkingContent = (aiMsg.thinkingContent || '') + normalizedContent;
  1202. }
  1203. }
  1204. break;
  1205. // 系统进度消息 - 仅当 agent 不是 system 时才作为 thinking step
  1206. case 'progress': {
  1207. if (data.agent && data.agent !== 'system') {
  1208. upsertStep(aiMsg.thinkingSteps!, {
  1209. type: 'executing',
  1210. agent: data.cn_agent || data.agent,
  1211. agentId: data.agent_id,
  1212. message: data.message || '',
  1213. timestamp: Date.now(),
  1214. });
  1215. }
  1216. break;
  1217. }
  1218. // agent 开始处理
  1219. case 'agent_start': {
  1220. upsertStep(aiMsg.thinkingSteps!, {
  1221. type: 'agent_start',
  1222. agent: data.cn_agent || data.agent || '智能助手',
  1223. agentId: data.agent_id,
  1224. subagentType: data.subagent_type,
  1225. message: data.message || '开始处理...',
  1226. timestamp: Date.now(),
  1227. });
  1228. break;
  1229. }
  1230. // agent 任务列表更新(同一 agent 的 todos 更新已有条目,不重复添加)
  1231. case 'agent_todos':
  1232. case 'updated_todo_list': {
  1233. const agentName = data.cn_agent || data.agent || '智能助手';
  1234. const agentId = data.agent_id;
  1235. const existingIdx = aiMsg.thinkingSteps!.findIndex(
  1236. (s) => s.type === 'updated_todo_list' && (agentId ? s.agentId === agentId : s.agent === agentName)
  1237. );
  1238. if (existingIdx !== -1) {
  1239. aiMsg.thinkingSteps![existingIdx].todos = data.todos || [];
  1240. aiMsg.thinkingSteps![existingIdx].timestamp = Date.now();
  1241. } else {
  1242. aiMsg.thinkingSteps!.push({
  1243. type: 'updated_todo_list',
  1244. agent: agentName,
  1245. agentId,
  1246. todos: data.todos || [],
  1247. message: data.message || '任务进度已更新',
  1248. timestamp: Date.now(),
  1249. });
  1250. }
  1251. // todos 与任务绑定:仅当用户正在查看该任务时才更新进度条,避免流式期间切换/新建任务后串台
  1252. if (isViewingTask) {
  1253. currentTodos.value = [...(data.todos || [])];
  1254. showTodoBar.value = true;
  1255. }
  1256. break;
  1257. }
  1258. // agent 执行中(工具调用)
  1259. case 'agent_executing':
  1260. case 'executing': {
  1261. upsertStep(aiMsg.thinkingSteps!, {
  1262. type: 'executing',
  1263. agent: data.cn_agent || data.agent || '智能助手',
  1264. agentId: data.agent_id,
  1265. tool: (data.cn_tools || data.tools || []).join('、'),
  1266. message: data.message || '',
  1267. timestamp: Date.now(),
  1268. });
  1269. break;
  1270. }
  1271. // 工具结果
  1272. case 'agent_tool_result':
  1273. case 'tool_result': {
  1274. upsertStep(aiMsg.thinkingSteps!, {
  1275. type: 'tool_result',
  1276. agent: data.cn_agent || data.agent || '智能助手',
  1277. agentId: data.agent_id,
  1278. tool: data.cn_tool || data.tool || '',
  1279. message: data.message || '执行完成',
  1280. timestamp: Date.now(),
  1281. });
  1282. if (data.download_url) {
  1283. if (!aiMsg.downloadFiles) aiMsg.downloadFiles = [];
  1284. aiMsg.downloadFiles.push({ url: data.download_url, filename: data.filename || '文件' });
  1285. }
  1286. break;
  1287. }
  1288. // agent 完成
  1289. case 'agent_done': {
  1290. upsertStep(aiMsg.thinkingSteps!, {
  1291. type: 'agent_done',
  1292. agent: data.cn_agent || data.agent || '智能助手',
  1293. agentId: data.agent_id,
  1294. message: `${(data.message || '审查完成').replace(/(\d+ms)/g, '')}${data.duration_ms ? `(${(data.duration_ms / 1000).toFixed(0)}s)` : ''}${data.progress ? ` [${data.progress}]` : ''}`,
  1295. timestamp: Date.now(),
  1296. });
  1297. // 累加后端返回的各段耗时,并重置前端计时起点,避免重复计算已验证的时间段
  1298. if (data.duration_ms) {
  1299. aiMsg.baseDurationMs = (aiMsg.baseDurationMs || 0) + data.duration_ms;
  1300. aiMsg.generateStartTime = Date.now();
  1301. }
  1302. if (data.preview) {
  1303. aiMsg.content += data.preview;
  1304. }
  1305. break;
  1306. }
  1307. // 旧格式兼容
  1308. case 'model_thinking':
  1309. if (normalizedContent) {
  1310. aiMsg.content += normalizedContent;
  1311. aiMsg.content = aiMsg.content.replace(/\|\|\|SPLIT_CONTENT\|\|\|/g, '');
  1312. }
  1313. break;
  1314. case 'tool_select': {
  1315. upsertStep(aiMsg.thinkingSteps!, {
  1316. type: 'tool_call',
  1317. agent: data.cn_agent || extractAgentName(normalizedContent),
  1318. agentId: data.agent_id,
  1319. tool: normalizedContent,
  1320. message: `选择工具:${normalizedContent}`,
  1321. timestamp: Date.now(),
  1322. });
  1323. break;
  1324. }
  1325. case 'error':
  1326. upsertStep(aiMsg.thinkingSteps!, {
  1327. type: 'tool_result',
  1328. agent: data.cn_agent || '系统',
  1329. agentId: data.agent_id,
  1330. message: `❌ 执行失败:${normalizedContent}`,
  1331. timestamp: Date.now(),
  1332. });
  1333. aiMsg.isLoading = false;
  1334. streamingTask.isStreaming = false;
  1335. // 后端未返回耗时,冻结前端伪计时
  1336. aiMsg.durationMs = (aiMsg.baseDurationMs || 0) + (aiMsg.generateStartTime ? Date.now() - aiMsg.generateStartTime : 0);
  1337. break;
  1338. case 'citations': {
  1339. aiMsg.citations = {
  1340. items: data.items || [],
  1341. model_only: data.model_only || false,
  1342. message: data.message,
  1343. };
  1344. break;
  1345. }
  1346. case 'word_download':
  1347. if (normalizedContent) {
  1348. aiMsg.wordDownloadUrl = normalizedContent;
  1349. streamingTask.wordUrl = normalizedContent;
  1350. }
  1351. break;
  1352. case 'done':
  1353. if (data.session_id) {
  1354. aiMsg.sessionId = data.session_id;
  1355. fetchContext(data.session_id);
  1356. }
  1357. // 对话结束后刷新今日用量
  1358. fetchTodayUsage();
  1359. aiMsg.durationMs = data.duration_ms
  1360. ? (aiMsg.baseDurationMs || 0) + data.duration_ms
  1361. : (aiMsg.baseDurationMs || 0) + (aiMsg.generateStartTime ? Date.now() - aiMsg.generateStartTime : 0);
  1362. aiMsg.isLoading = false;
  1363. streamingTask.isStreaming = false;
  1364. break;
  1365. case 'system':
  1366. if (normalizedContent) {
  1367. aiMsg.content += normalizedContent.replace(/\n/g, ' \n');
  1368. }
  1369. break;
  1370. case 'interrupt': {
  1371. // 后端各段耗时 + 前端当前段计时,吸收进 baseDurationMs 保证审批继续后计时连续
  1372. const elapsedMs = (aiMsg.baseDurationMs || 0) + (aiMsg.generateStartTime ? Date.now() - aiMsg.generateStartTime : 0);
  1373. aiMsg.baseDurationMs = elapsedMs;
  1374. aiMsg.isLoading = false;
  1375. // 流已结束,等待用户回答;提交答案后 handleAskUserSubmit 会重新置为流式中
  1376. streamingTask.isStreaming = false;
  1377. aiMsg.isPendingApproval = true;
  1378. const interruptSessionId = data.session_id || streamingTask.sessionId;
  1379. aiMsg.pendingApprovalData = {
  1380. message: data.message || '智能体需要您回答一些问题以继续...',
  1381. sessionId: interruptSessionId,
  1382. threadId: data.thread_id,
  1383. interrupts: data.interrupts,
  1384. elapsedMs,
  1385. prevThinkingContent: aiMsg.thinkingContent,
  1386. plan: data.plan,
  1387. ask_user: data.ask_user,
  1388. answers: data.ask_user?.questions?.map(() => '') || [],
  1389. };
  1390. setTaskPendingApproval(taskId, interruptSessionId, data.thread_id || '');
  1391. // 直接初始化 ask_user 答案状态,不依赖 watch(避免任务切换/时序问题)
  1392. if (data.ask_user?.questions) {
  1393. nextTick(() => {
  1394. chatMessagesRef.value?.initAskUserAnswers(aiMsgIndex, data.ask_user!.questions);
  1395. });
  1396. }
  1397. break;
  1398. }
  1399. }
  1400. // 保存到流式任务的 messages,并同步 UI
  1401. // Always create a new array reference to trigger Vue reactivity
  1402. const updatedMessages = isViewingTask ? [...messages.value] : [...streamingTask.messages];
  1403. streamingTask.messages = updatedMessages;
  1404. if (isViewingTask) {
  1405. messages.value = updatedMessages;
  1406. }
  1407. };
  1408. const parseSSEData = (data: SseEvent, aiMsgIndex: number, taskId: string) => {
  1409. handleSSEMessage(data, aiMsgIndex, taskId);
  1410. };
  1411. const sendTextOnly = async (userInput: string, displayContent?: string) => {
  1412. const originTaskId = currentTaskId.value;
  1413. const now = dayjs();
  1414. const userMsg: Message = {
  1415. type: 'user',
  1416. content: displayContent || userInput,
  1417. time: now.format('HH:mm'),
  1418. createdAt: now.toISOString(),
  1419. };
  1420. messages.value.push(userMsg);
  1421. await nextTick();
  1422. chatMessagesRef.value?.forceScrollToBottom();
  1423. const aiMsgIndex = messages.value.length;
  1424. const aiMsg: Message = {
  1425. type: 'ai',
  1426. content: '',
  1427. time: now.format('HH:mm'),
  1428. createdAt: now.toISOString(),
  1429. isLoading: true,
  1430. thinkingSteps: [],
  1431. generateStartTime: Date.now(),
  1432. };
  1433. messages.value.push(aiMsg);
  1434. showTodoBar.value = false;
  1435. currentTodos.value = [];
  1436. const originTask = taskList.value.find((t) => t.id === originTaskId);
  1437. if (originTask) originTask.isStreaming = true;
  1438. const controller = new AbortController();
  1439. setTaskAbortController(originTaskId, controller);
  1440. try {
  1441. const result = await unifiedStream(
  1442. {
  1443. message: userInput,
  1444. session_id: getCurrentSessionId() || undefined,
  1445. mode: editMode.value,
  1446. signal: controller.signal,
  1447. },
  1448. (data: SseEvent) => {
  1449. parseSSEData(data, aiMsgIndex, originTaskId);
  1450. if (currentTaskId.value === originTaskId) scrollToBottomThrottled();
  1451. }
  1452. );
  1453. if (result.session_id) {
  1454. const originTask = taskList.value.find((t) => t.id === originTaskId);
  1455. if (originTask && !originTask.sessionId) {
  1456. originTask.sessionId = result.session_id;
  1457. // 流式期间若列表已用后端标题归并过该任务,则保留后端标题;否则用首条消息命名
  1458. if (originTask.pendingSessionId !== result.session_id) {
  1459. originTask.name = userInput.substring(0, 20) + (userInput.length > 20 ? '...' : '');
  1460. }
  1461. originTask.pendingSessionId = undefined;
  1462. if (originTask.id !== result.session_id) {
  1463. // 将 AbortController 从旧 ID 迁移到新 ID
  1464. const controller = taskAbortControllers.get(originTaskId);
  1465. if (controller) {
  1466. setTaskAbortController(originTaskId, null);
  1467. setTaskAbortController(result.session_id, controller);
  1468. }
  1469. taskList.value = taskList.value.filter((t) => t.id !== result.session_id);
  1470. originTask.id = result.session_id;
  1471. historyLoadedTasks.add(result.session_id);
  1472. // 迁移审批状态 key(任务 ID 变了,审批 Map 的 key 也要跟着变)
  1473. const approvalEntry = taskPendingApprovals.value.get(originTaskId);
  1474. if (approvalEntry) {
  1475. const map = new Map(taskPendingApprovals.value);
  1476. map.delete(originTaskId);
  1477. map.set(result.session_id, approvalEntry);
  1478. taskPendingApprovals.value = map;
  1479. }
  1480. }
  1481. if (currentTaskId.value === originTaskId) {
  1482. currentTaskId.value = result.session_id;
  1483. }
  1484. }
  1485. }
  1486. } catch (error) {
  1487. // 用户主动停止生成
  1488. if ((error as Error)?.name === 'AbortError') {
  1489. const originTask = taskList.value.find((t) => t.id === originTaskId);
  1490. const arr = currentTaskId.value === originTaskId ? messages.value : originTask?.messages;
  1491. const aiMsg = arr?.[aiMsgIndex];
  1492. if (aiMsg) {
  1493. aiMsg.isLoading = false;
  1494. // 后端未返回耗时,冻结前端伪计时
  1495. aiMsg.durationMs = (aiMsg.baseDurationMs || 0) + (aiMsg.generateStartTime ? Date.now() - aiMsg.generateStartTime : 0);
  1496. if (!aiMsg.content) {
  1497. aiMsg.content = '已停止生成。';
  1498. }
  1499. }
  1500. if (originTask && currentTaskId.value !== originTaskId) {
  1501. originTask.messages = [...(arr || [])];
  1502. }
  1503. return;
  1504. }
  1505. throw error;
  1506. } finally {
  1507. // 任务在流结束时可能已被改名为后端 session_id,需要使用最终的 ID 清理状态
  1508. const finalTaskId = originTask?.id || originTaskId;
  1509. setTaskAbortController(finalTaskId, null);
  1510. if (originTask) originTask.isStreaming = false;
  1511. }
  1512. };
  1513. const sendWithAttachment = async (file: AttachedFile, userInput: string, displayContent?: string) => {
  1514. const originTaskId = currentTaskId.value;
  1515. let currentTask = taskList.value.find((t) => t.id === originTaskId);
  1516. if (currentTask) {
  1517. currentTask.attachedFiles.push(file);
  1518. } else {
  1519. throw new Error('未找到当前任务');
  1520. }
  1521. const now = dayjs();
  1522. const userMsg: Message = {
  1523. type: 'user',
  1524. content: displayContent || userInput || `上传了文件:${file.name}`,
  1525. time: now.format('HH:mm'),
  1526. createdAt: now.toISOString(),
  1527. attachedFile: file,
  1528. };
  1529. messages.value.push(userMsg);
  1530. await nextTick();
  1531. chatMessagesRef.value?.forceScrollToBottom();
  1532. const aiMsgIndex = messages.value.length;
  1533. const aiMsg: Message = {
  1534. type: 'ai',
  1535. content: '',
  1536. time: now.format('HH:mm'),
  1537. createdAt: now.toISOString(),
  1538. isLoading: true,
  1539. thinkingSteps: [],
  1540. generateStartTime: Date.now(),
  1541. };
  1542. messages.value.push(aiMsg);
  1543. showTodoBar.value = false;
  1544. currentTodos.value = [];
  1545. if (!file.originalFile) {
  1546. throw new Error('缺少原始文件对象');
  1547. }
  1548. const originTask = taskList.value.find((t) => t.id === originTaskId);
  1549. if (originTask) originTask.isStreaming = true;
  1550. const controller = new AbortController();
  1551. setTaskAbortController(originTaskId, controller);
  1552. try {
  1553. const result = await reviewPdfStream(
  1554. {
  1555. file: file.originalFile!,
  1556. session_id: getCurrentSessionId() || undefined,
  1557. message: userInput || undefined,
  1558. mode: editMode.value,
  1559. signal: controller.signal,
  1560. },
  1561. (data: SseEvent) => {
  1562. parseSSEData(data, aiMsgIndex, originTaskId);
  1563. if (currentTaskId.value === originTaskId) scrollToBottomThrottled();
  1564. }
  1565. );
  1566. if (result.session_id) {
  1567. const originTask = taskList.value.find((t) => t.id === originTaskId);
  1568. if (originTask && !originTask.sessionId) {
  1569. originTask.sessionId = result.session_id;
  1570. if (originTask.pendingSessionId !== result.session_id) {
  1571. const taskName = userInput || `文件:${file.name}`;
  1572. originTask.name = taskName.substring(0, 20) + (taskName.length > 20 ? '...' : '');
  1573. }
  1574. originTask.pendingSessionId = undefined;
  1575. if (originTask.id !== result.session_id) {
  1576. // 将 AbortController 从旧 ID 迁移到新 ID
  1577. const controller = taskAbortControllers.get(originTaskId);
  1578. if (controller) {
  1579. setTaskAbortController(originTaskId, null);
  1580. setTaskAbortController(result.session_id, controller);
  1581. }
  1582. taskList.value = taskList.value.filter((t) => t.id !== result.session_id);
  1583. originTask.id = result.session_id;
  1584. historyLoadedTasks.add(result.session_id);
  1585. // 迁移审批状态 key
  1586. const approvalEntry = taskPendingApprovals.value.get(originTaskId);
  1587. if (approvalEntry) {
  1588. const map = new Map(taskPendingApprovals.value);
  1589. map.delete(originTaskId);
  1590. map.set(result.session_id, approvalEntry);
  1591. taskPendingApprovals.value = map;
  1592. }
  1593. }
  1594. if (currentTaskId.value === originTaskId) {
  1595. currentTaskId.value = result.session_id;
  1596. }
  1597. }
  1598. }
  1599. } catch (error) {
  1600. // 用户主动停止生成
  1601. if ((error as Error)?.name === 'AbortError') {
  1602. const originTask = taskList.value.find((t) => t.id === originTaskId);
  1603. const arr = currentTaskId.value === originTaskId ? messages.value : originTask?.messages;
  1604. const aiMsg = arr?.[aiMsgIndex];
  1605. if (aiMsg) {
  1606. aiMsg.isLoading = false;
  1607. // 后端未返回耗时,冻结前端伪计时
  1608. aiMsg.durationMs = (aiMsg.baseDurationMs || 0) + (aiMsg.generateStartTime ? Date.now() - aiMsg.generateStartTime : 0);
  1609. if (!aiMsg.content) {
  1610. aiMsg.content = '已停止生成。';
  1611. }
  1612. }
  1613. if (originTask && currentTaskId.value !== originTaskId) {
  1614. originTask.messages = [...(arr || [])];
  1615. }
  1616. return;
  1617. }
  1618. throw error;
  1619. } finally {
  1620. // 任务在流结束时可能已被改名为后端 session_id,需要使用最终的 ID 清理状态
  1621. const finalTaskId = originTask?.id || originTaskId;
  1622. setTaskAbortController(finalTaskId, null);
  1623. if (originTask) originTask.isStreaming = false;
  1624. }
  1625. };
  1626. // Throttled version for SSE streaming (no await, uses rAF)
  1627. let scrollRafId: number | null = null;
  1628. const scrollToBottomThrottled = (force = false) => {
  1629. if (scrollRafId) cancelAnimationFrame(scrollRafId);
  1630. scrollRafId = requestAnimationFrame(async () => {
  1631. scrollRafId = null;
  1632. await nextTick();
  1633. if (!force && !chatMessagesRef.value?.isAtBottom) return;
  1634. const el = chatMessagesRef.value?.messagesRef;
  1635. if (el) {
  1636. el.scrollTop = el.scrollHeight - el.clientHeight;
  1637. }
  1638. });
  1639. };
  1640. // Async version for explicit await calls
  1641. const scrollToBottom = async (force = false) => {
  1642. await nextTick();
  1643. if (!force && !chatMessagesRef.value?.isAtBottom) return;
  1644. const el = chatMessagesRef.value?.messagesRef;
  1645. if (el) {
  1646. el.scrollTop = el.scrollHeight - el.clientHeight;
  1647. }
  1648. };
  1649. watch(
  1650. () => props.visible,
  1651. async (newVisible) => {
  1652. if (!newVisible) {
  1653. const currentTask = taskList.value.find((t) => t.id === currentTaskId.value);
  1654. if (currentTask) {
  1655. currentTask.messages = [...messages.value];
  1656. }
  1657. } else {
  1658. await fetchSessionList();
  1659. fetchModelMsg();
  1660. fetchScheduleListForDetail();
  1661. fetchTodayUsage();
  1662. // 去除重复的空白任务,只保留一个
  1663. taskList.value = taskList.value.filter((task, index) => {
  1664. if (task.sessionId) return true;
  1665. return index === taskList.value.findIndex((t) => !t.sessionId);
  1666. });
  1667. // 优先回到关闭前所在的任务(如流式中的新任务),否则默认选中第一条历史记录
  1668. const firstHistoryTask = taskList.value.find((t) => t.sessionId);
  1669. const prevTask = taskList.value.find((t) => t.id === currentTaskId.value);
  1670. let targetTask: Task;
  1671. if (prevTask) {
  1672. targetTask = prevTask;
  1673. } else if (firstHistoryTask) {
  1674. targetTask = firstHistoryTask;
  1675. } else {
  1676. // 没有历史记录时才创建空白新任务
  1677. targetTask = {
  1678. id: `task-${Date.now()}`,
  1679. name: '新任务',
  1680. sessionId: '',
  1681. messages: getDefaultMessages(),
  1682. attachedFiles: [],
  1683. };
  1684. taskList.value.unshift(targetTask);
  1685. }
  1686. currentTaskId.value = targetTask.id;
  1687. // 如果是历史任务,加载其消息
  1688. if (targetTask.sessionId && !historyLoadedTasks.has(targetTask.id)) {
  1689. try {
  1690. const res = await getDetail(targetTask.sessionId);
  1691. const messages = res?.messages || (Array.isArray(res) ? res : res?.data);
  1692. if (Array.isArray(messages)) {
  1693. targetTask.messages = transformHistoryToMessages(messages);
  1694. }
  1695. historyLoadedTasks.add(targetTask.id);
  1696. } catch (error) {
  1697. console.error('加载历史会话失败:', error);
  1698. }
  1699. }
  1700. if (targetTask.sessionId) {
  1701. fetchContext(targetTask.sessionId);
  1702. fetchSessionMode(targetTask.sessionId);
  1703. } else {
  1704. contextUsed.value = 0;
  1705. contextPercent.value = 0;
  1706. contextBreakdown.value = { messages: 0, mcp: 0, skills: 0, system_prompt: 0, other: 0 };
  1707. editMode.value = 'full';
  1708. }
  1709. messages.value = targetTask.messages && targetTask.messages.length > 0 ? [...targetTask.messages] : getDefaultMessages();
  1710. syncTodoBarFromMessages();
  1711. pendingFile.value = null;
  1712. showFileList.value = false;
  1713. inputMessage.value = '';
  1714. await nextTick(() => {
  1715. chatMessagesRef.value?.forceScrollToBottom();
  1716. });
  1717. }
  1718. }
  1719. );
  1720. // 拖拽相关(使用普通变量避免 mousemove 触发 Vue 响应式导致卡顿)
  1721. let isDragging = false;
  1722. let dragStartX = 0;
  1723. let dragStartY = 0;
  1724. let modalStartLeft = 0;
  1725. let modalStartTop = 0;
  1726. let draggedEl: HTMLElement | null = null;
  1727. const findModalWrap = (target: HTMLElement): HTMLElement | null =>
  1728. target.closest<HTMLElement>('.zxm-modal-wrap, .ant-modal-wrap, [class*="modal-wrap"]');
  1729. const queryModalWrap = (): HTMLElement | null => document.querySelector<HTMLElement>('.zxm-modal-wrap, .ant-modal-wrap, [class*="modal-wrap"]');
  1730. // 统一处理 modal-wrap 内联样式:全屏时置顶铺满,否则恢复默认
  1731. const applyWrapStyles = (fullscreen: boolean) => {
  1732. const wraps = document.querySelectorAll<HTMLElement>('.zxm-modal-wrap, .ant-modal-wrap, [class*="modal-wrap"]');
  1733. wraps.forEach((wrap) => {
  1734. wrap.style.position = '';
  1735. wrap.style.left = '';
  1736. wrap.style.top = fullscreen ? '0' : '';
  1737. wrap.style.right = '';
  1738. wrap.style.bottom = '';
  1739. wrap.style.width = '';
  1740. wrap.style.height = '';
  1741. wrap.style.margin = fullscreen ? '0' : '';
  1742. wrap.style.padding = fullscreen ? '0' : '';
  1743. wrap.style.transform = '';
  1744. });
  1745. };
  1746. const centerModal = () => {
  1747. nextTick(() => {
  1748. applyWrapStyles(isFullscreen.value);
  1749. draggedEl = null;
  1750. });
  1751. };
  1752. const onDragStart = (e: MouseEvent) => {
  1753. if (isFullscreen.value) return;
  1754. draggedEl = findModalWrap(e.target as HTMLElement) || queryModalWrap();
  1755. if (!draggedEl) return;
  1756. isDragging = true;
  1757. dragStartX = e.clientX;
  1758. dragStartY = e.clientY;
  1759. const rect = draggedEl.getBoundingClientRect();
  1760. modalStartLeft = rect.left;
  1761. modalStartTop = rect.top;
  1762. draggedEl.style.position = 'fixed';
  1763. draggedEl.style.left = `${rect.left}px`;
  1764. draggedEl.style.top = `${rect.top}px`;
  1765. draggedEl.style.margin = '0';
  1766. draggedEl.style.transform = 'none';
  1767. document.addEventListener('mousemove', onDragMove);
  1768. document.addEventListener('mouseup', onDragEnd);
  1769. };
  1770. const onDragMove = (e: MouseEvent) => {
  1771. if (!isDragging || !draggedEl) return;
  1772. draggedEl.style.left = `${modalStartLeft + (e.clientX - dragStartX)}px`;
  1773. draggedEl.style.top = `${modalStartTop + (e.clientY - dragStartY)}px`;
  1774. };
  1775. const onDragEnd = () => {
  1776. isDragging = false;
  1777. document.removeEventListener('mousemove', onDragMove);
  1778. document.removeEventListener('mouseup', onDragEnd);
  1779. };
  1780. watch(
  1781. () => props.visible,
  1782. (newVisible) => {
  1783. if (newVisible) {
  1784. centerModal();
  1785. }
  1786. }
  1787. );
  1788. onBeforeUnmount(() => {
  1789. document.removeEventListener('mousemove', onDragMove);
  1790. document.removeEventListener('mouseup', onDragEnd);
  1791. window.removeEventListener('resize', onResize);
  1792. // 组件卸载时主动断开所有任务的流式连接
  1793. taskAbortControllers.forEach((controller) => controller.abort());
  1794. // Abort in-flight FileReader if any
  1795. if (activeFileReader.value) {
  1796. activeFileReader.value.abort();
  1797. activeFileReader.value = null;
  1798. }
  1799. });
  1800. </script>
  1801. <style scoped lang="less">
  1802. .ai-container {
  1803. display: flex;
  1804. height: 700px;
  1805. gap: 10px;
  1806. overflow: hidden;
  1807. font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  1808. }
  1809. .collapse-btn {
  1810. position: absolute;
  1811. top: 16px;
  1812. left: 24px;
  1813. z-index: 10;
  1814. width: 32px;
  1815. height: 32px;
  1816. background: #1a6696;
  1817. border-radius: 4px;
  1818. display: flex;
  1819. align-items: center;
  1820. justify-content: center;
  1821. cursor: pointer;
  1822. transition: background 0.3s;
  1823. &:hover {
  1824. background: #1f7ab8;
  1825. }
  1826. .collapse-icon {
  1827. width: 16px;
  1828. height: 16px;
  1829. background-image: var(--img-chat-collapse-icon);
  1830. background-repeat: no-repeat;
  1831. background-size: 100% 100%;
  1832. &.collapsed {
  1833. background-image: var(--img-chat-expand-icon);
  1834. }
  1835. }
  1836. }
  1837. .task-panel-wrapper {
  1838. width: 300px;
  1839. flex-shrink: 0;
  1840. overflow: hidden;
  1841. transition:
  1842. width 0.35s cubic-bezier(0.4, 0, 0.2, 1),
  1843. margin 0.35s cubic-bezier(0.4, 0, 0.2, 1),
  1844. opacity 0.25s ease;
  1845. &.collapsed {
  1846. width: 0;
  1847. margin: 0;
  1848. opacity: 0;
  1849. }
  1850. }
  1851. .chat-panel {
  1852. flex: 1;
  1853. display: flex;
  1854. position: relative;
  1855. flex-direction: column;
  1856. background-image: var(--img-chat-panel-bg);
  1857. background-repeat: no-repeat;
  1858. background-size: 100% 100%;
  1859. border-radius: 4px;
  1860. overflow: hidden;
  1861. min-width: 0;
  1862. }
  1863. .right-panel {
  1864. width: calc(50% - 140px);
  1865. height: 100%;
  1866. display: flex;
  1867. flex-direction: column;
  1868. background-image: var(--img-chat-panel-bg);
  1869. background-repeat: no-repeat;
  1870. background-size: 100% 100%;
  1871. border-radius: 4px;
  1872. &.full {
  1873. flex: 1;
  1874. width: auto;
  1875. min-width: 0;
  1876. }
  1877. flex-shrink: 0;
  1878. }
  1879. /* 右侧面板滑入滑出过渡动画 */
  1880. :deep(.right-panel-slide-enter-active) {
  1881. transition:
  1882. opacity 0.3s ease,
  1883. transform 0.3s ease;
  1884. }
  1885. :deep(.right-panel-slide-leave-active) {
  1886. transition:
  1887. opacity 0.25s ease,
  1888. transform 0.25s ease;
  1889. }
  1890. :deep(.right-panel-slide-enter-from) {
  1891. opacity: 0;
  1892. transform: translateX(30px);
  1893. }
  1894. :deep(.right-panel-slide-leave-to) {
  1895. opacity: 0;
  1896. transform: translateX(30px);
  1897. }
  1898. .draggable-title {
  1899. cursor: grab;
  1900. user-select: none;
  1901. &:active {
  1902. cursor: grabbing;
  1903. }
  1904. &.no-drag {
  1905. cursor: default;
  1906. &:active {
  1907. cursor: default;
  1908. }
  1909. }
  1910. }
  1911. </style>
  1912. <style lang="less">
  1913. .ai-assistant-modal {
  1914. .zxm-modal-content {
  1915. background-image: var(--img-chat-modal-bg);
  1916. background-repeat: no-repeat;
  1917. background-size: 100% 100%;
  1918. background-color: unset !important;
  1919. box-shadow: none;
  1920. padding: 0;
  1921. border: none !important;
  1922. transition: width 0.3s ease;
  1923. }
  1924. /* 全屏切换缩放动画 */
  1925. @keyframes modal-zoom-in {
  1926. from {
  1927. transform: scale(0.85);
  1928. opacity: 0.6;
  1929. }
  1930. to {
  1931. transform: scale(1);
  1932. opacity: 1;
  1933. }
  1934. }
  1935. @keyframes modal-zoom-out {
  1936. from {
  1937. transform: scale(1.15);
  1938. opacity: 0.6;
  1939. }
  1940. to {
  1941. transform: scale(1);
  1942. opacity: 1;
  1943. }
  1944. }
  1945. .zxm-modal-content.modal-zoom-in-anim {
  1946. animation: modal-zoom-in 0.3s ease forwards;
  1947. }
  1948. .zxm-modal-content.modal-zoom-out-anim {
  1949. animation: modal-zoom-out 0.3s ease forwards;
  1950. }
  1951. .zxm-modal-close {
  1952. background-image: var(--img-chat-close-bg);
  1953. background-repeat: no-repeat;
  1954. background-size: 100% 100%;
  1955. top: 12px;
  1956. right: 20px;
  1957. width: 38px;
  1958. height: 38px;
  1959. .zxm-modal-close-x {
  1960. width: 38px;
  1961. height: 38px;
  1962. }
  1963. svg {
  1964. width: 26px;
  1965. height: 26px;
  1966. margin-bottom: 4px;
  1967. }
  1968. }
  1969. .maximize-btn {
  1970. position: absolute;
  1971. top: 12px;
  1972. right: 72px;
  1973. width: 38px;
  1974. height: 38px;
  1975. background-image: var(--img-chat-close-bg);
  1976. background-repeat: no-repeat;
  1977. background-size: 100% 100%;
  1978. display: flex;
  1979. align-items: center;
  1980. justify-content: center;
  1981. cursor: pointer;
  1982. z-index: 10;
  1983. .maximize-icon {
  1984. width: 22px;
  1985. height: 22px;
  1986. background-image: var(--img-chat-maximize-icon);
  1987. background-repeat: no-repeat;
  1988. background-size: 100% 100%;
  1989. &.minimized {
  1990. background-image: var(--img-chat-minimize-icon);
  1991. }
  1992. }
  1993. }
  1994. &.fullscreen {
  1995. top: 0 !important;
  1996. padding: 0 !important;
  1997. max-width: 100vw !important;
  1998. margin: 0 !important;
  1999. background-color: #09172c;
  2000. .zxm-modal-wrap,
  2001. .ant-modal-wrap {
  2002. padding: 0 !important;
  2003. margin: 0 !important;
  2004. top: 0 !important;
  2005. }
  2006. .zxm-modal-content {
  2007. width: 100vw !important;
  2008. height: 100vh !important;
  2009. max-width: 100vw !important;
  2010. margin: 0;
  2011. border-radius: 0;
  2012. overflow: hidden;
  2013. background-image: var(--img-chat-fs-modal-bg);
  2014. }
  2015. .zxm-modal-header {
  2016. height: 90px;
  2017. background-image: var(--img-chat-fs-header-bg) !important;
  2018. background-repeat: no-repeat;
  2019. background-size: 100% 100%;
  2020. margin-bottom: 16px;
  2021. }
  2022. .no-drag {
  2023. cursor: default;
  2024. font-size: 32px !important;
  2025. }
  2026. .zxm-modal-title {
  2027. height: 90px;
  2028. }
  2029. .zxm-modal-body {
  2030. height: calc(100vh - 120px);
  2031. overflow: hidden;
  2032. padding: 0 24px 12px;
  2033. }
  2034. .ai-container {
  2035. height: 100%;
  2036. overflow: hidden;
  2037. }
  2038. .chat-panel {
  2039. background-image: var(--img-chat-fs-panel-bg) !important;
  2040. }
  2041. .chat-header {
  2042. padding: 0 12px;
  2043. height: 50px;
  2044. }
  2045. .collapse-btn {
  2046. top: 60px;
  2047. background-image: var(--img-chat-fs-collapse-btn-bg) !important;
  2048. background-repeat: no-repeat;
  2049. background-size: 100% 100%;
  2050. }
  2051. .task-list-panel {
  2052. padding: 20px;
  2053. background-image: var(--img-chat-fs-task-panel-bg) !important;
  2054. background-repeat: no-repeat !important;
  2055. background-size: 100% 100% !important;
  2056. }
  2057. .options-area {
  2058. gap: 12px;
  2059. }
  2060. .options-area-item {
  2061. background-image: var(--img-chat-fs-options-item-bg) !important;
  2062. background-repeat: no-repeat !important;
  2063. background-size: 100% 100% !important;
  2064. &.active,
  2065. &:active {
  2066. background-image: var(--img-chat-fs-options-item-active-bg) !important;
  2067. }
  2068. .options-img {
  2069. background-image: none !important;
  2070. }
  2071. }
  2072. .chat-header-title {
  2073. height: 40px;
  2074. line-height: 40px;
  2075. position: relative;
  2076. background-image: var(--img-chat-fs-header-title-bg) !important;
  2077. background-repeat: no-repeat !important;
  2078. background-size: auto 100% !important;
  2079. padding: 0 28px;
  2080. &::before {
  2081. content: '';
  2082. position: absolute;
  2083. left: 0;
  2084. top: 50%;
  2085. transform: translateY(-50%);
  2086. width: 40px;
  2087. height: 40px;
  2088. background-image: var(--img-chat-fs-header-title-icon);
  2089. background-repeat: no-repeat;
  2090. background-size: 100% 100%;
  2091. }
  2092. }
  2093. .chat-header-title-wrapper {
  2094. .title-edit-input {
  2095. height: 36px;
  2096. font-size: 16px;
  2097. background: rgba(10, 132, 255, 0.15);
  2098. border-color: rgba(10, 132, 255, 0.6);
  2099. }
  2100. .title-edit-btn {
  2101. width: 24px;
  2102. height: 24px;
  2103. background-size: 16px 16px;
  2104. }
  2105. }
  2106. .chat-input-area {
  2107. margin: 24px;
  2108. }
  2109. .right-panel {
  2110. background-image: var(--img-chat-fs-panel-bg) !important;
  2111. }
  2112. :deep(.panel-tab-bar) {
  2113. padding: 14px 16px 0;
  2114. }
  2115. .schedule-panel,
  2116. .skill-panel,
  2117. .sub-agent-panel {
  2118. background-image: var(--img-chat-fs-panel-bg) !important;
  2119. }
  2120. }
  2121. .zxm-modal-header {
  2122. background-color: unset !important;
  2123. background: unset;
  2124. border: none !important;
  2125. padding: 8px;
  2126. backdrop-filter: unset;
  2127. display: flex;
  2128. justify-content: center;
  2129. }
  2130. .zxm-modal-title {
  2131. width: 100%;
  2132. height: 60px;
  2133. display: flex;
  2134. align-items: center;
  2135. justify-content: center;
  2136. .draggable-title {
  2137. color: #fff;
  2138. font-family: var(--vet-font-family);
  2139. letter-spacing: 3px;
  2140. font-size: 24px;
  2141. font-weight: 100;
  2142. line-height: 1.4;
  2143. }
  2144. }
  2145. .zxm-modal-body {
  2146. padding: 12px 24px;
  2147. }
  2148. }
  2149. .delete-task-confirm-modal {
  2150. .zxm-modal-confirm-title,
  2151. .zxm-modal-confirm-content {
  2152. color: #fff;
  2153. }
  2154. }
  2155. </style>