cleanProgress.vue 73 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267
  1. <template>
  2. <div :class="prefixCls" class="case-clean-progress">
  3. <!-- 清洗流程公共顶栏:品牌 / 案件 / 模板库 / 下载管理 / 窗口控制 -->
  4. <CaseFlowTopBar />
  5. <div class="page-body">
  6. <div class="page-header">
  7. <div class="page-header__main">
  8. <span class="page-title-icon">
  9. <Icon icon="i-ant-design:database-outlined" :size="19" />
  10. </span>
  11. <div class="page-title-wrap">
  12. <div class="page-title">{{ isComplete ? '数据清洗结果' : '数据清洗进行中' }}</div>
  13. <div class="page-subtitle">{{ pageSubtitle }}</div>
  14. </div>
  15. </div>
  16. <div v-if="!isComplete" class="page-header__actions">
  17. <Button class="stop-clean-btn" danger :loading="stopping" @click="handleStopClean">
  18. {{ stopping ? '正在停止…' : '停止清洗' }}
  19. </Button>
  20. <span class="sse-pill" :class="{ 'is-on': sseConnected }">
  21. <span class="sse-dot"></span>
  22. {{ sseConnected ? '实时推送已连接' : '实时推送未连接' }}
  23. </span>
  24. </div>
  25. </div>
  26. <div class="progress-layout" :class="{ 'is-fused': isFused }">
  27. <div class="progress-card">
  28. <template v-if="!isComplete">
  29. <div class="run-layout">
  30. <aside class="run-side">
  31. <div class="run-head">
  32. <span class="run-live"></span>
  33. <div class="run-head__text">
  34. <div class="run-title">任务执行中</div>
  35. <div class="run-subtitle">{{ progressStatusText }}</div>
  36. </div>
  37. </div>
  38. <div class="run-summary">
  39. <div class="run-ring">
  40. <div class="progress-ring">
  41. <svg viewBox="0 0 120 120">
  42. <circle cx="60" cy="60" r="50" class="ring-bg" />
  43. <circle
  44. cx="60"
  45. cy="60"
  46. r="50"
  47. class="ring-value"
  48. :style="{
  49. strokeDasharray: `${RING_CIRCUMFERENCE}`,
  50. strokeDashoffset: `${RING_CIRCUMFERENCE - progressDash}`,
  51. }"
  52. />
  53. </svg>
  54. <div class="progress-value">
  55. <strong>{{ overallProgress }}<small>%</small></strong>
  56. <span>{{ currentStepLabel }}</span>
  57. </div>
  58. </div>
  59. </div>
  60. <div class="run-summary__stats">
  61. <div class="run-stat-line">
  62. <span class="run-stat-line__label">导入成功</span>
  63. <strong class="run-stat-line__value is-success">{{ displaySuccessCount }}</strong>
  64. </div>
  65. <div class="run-stat-line">
  66. <span class="run-stat-line__label">导入失败</span>
  67. <strong class="run-stat-line__value is-fail">{{ displayFailCount }}</strong>
  68. </div>
  69. </div>
  70. </div>
  71. <div class="run-steps">
  72. <div
  73. v-for="(step, index) in runSteps"
  74. :key="step.title"
  75. class="run-step"
  76. :class="{
  77. 'is-done': activeStep > index,
  78. 'is-active': activeStep === index,
  79. 'is-pending': activeStep < index,
  80. }"
  81. >
  82. <div class="run-step__rail">
  83. <span class="run-step__dot">{{ activeStep > index ? '✓' : index + 1 }}</span>
  84. <span v-if="index < runSteps.length - 1" class="run-step__line"></span>
  85. <span v-else-if="activeStep === index" class="run-step__line run-step__line--tail"></span>
  86. <span v-if="activeStep === index" class="run-step__flow" aria-hidden="true"></span>
  87. </div>
  88. <div class="run-step__body">
  89. <div class="run-step__head">
  90. <span class="run-step__title">{{ step.title }}</span>
  91. <span class="run-step__status">
  92. <i v-if="activeStep === index" class="run-step__status-dot"></i>
  93. {{ activeStep > index ? '已完成' : activeStep === index ? '进行中' : '待执行' }}
  94. </span>
  95. </div>
  96. <div class="run-step__desc">{{ step.desc }}</div>
  97. </div>
  98. </div>
  99. </div>
  100. </aside>
  101. <section class="run-log" :class="{ 'is-govern': shouldRunGovernAfterClean && activeStep >= 2 }">
  102. <TaskLogList
  103. :logs="taskLog"
  104. title="处理日志"
  105. live
  106. console-style
  107. fill
  108. empty-text="等待任务推送,处理记录将实时写入这里"
  109. />
  110. </section>
  111. </div>
  112. <!-- 融合模式的出口:SSE 推送中断(后端重启/网络断开),进度无法继续更新 -->
  113. <div v-if="aiStageTimeout && !isComplete" class="ai-timeout-banner">
  114. <span class="ai-timeout-text">
  115. AI
  116. 清洗进度推送已中断(连接断开或后端已重启)。稍后可在「数据治理」查看已入库结果,或改用手动清洗处理这批文件。
  117. </span>
  118. <Button type="link" size="small" @click="goManualClean">改为手动清洗</Button>
  119. </div>
  120. </template>
  121. <template v-else>
  122. <div class="progress-complete-layout">
  123. <div class="complete-summary" :class="{ 'is-failed': governFailed }">
  124. <div class="complete-icon" :class="{ 'is-failed': governFailed }">
  125. {{ governFailed ? '!' : '✓' }}
  126. </div>
  127. <div class="complete-main">
  128. <div class="complete-title" :class="{ 'is-failed': governFailed }">{{ completeTitle }}</div>
  129. <div class="complete-desc">{{ completeDesc }}</div>
  130. <div class="complete-meta">
  131. <span v-if="currentCleanBatchId" class="complete-meta__item">批次 {{ currentCleanBatchId }}</span>
  132. <span class="complete-meta__item">共 {{ taskLog.length }} 条日志</span>
  133. <span class="complete-meta__item">任务耗时 {{ taskDurationText }}</span>
  134. </div>
  135. </div>
  136. <div class="complete-stats">
  137. <div class="complete-stat">
  138. <span class="complete-stat__value is-success">{{ displaySuccessCount }}</span>
  139. <span class="complete-stat__label">导入成功(条)</span>
  140. </div>
  141. <span class="complete-stat__divider"></span>
  142. <div class="complete-stat">
  143. <!-- 失败数固定用红色(与成功数的绿色对应),0 也保持红色,避免完成态一眼看不出哪一项是失败口径 -->
  144. <span class="complete-stat__value is-fail">{{ displayFailCount }}</span>
  145. <span class="complete-stat__label">导入失败(条)</span>
  146. </div>
  147. <!-- AI 无法清洗的表:同属失败语义,单独明示 -->
  148. <template v-if="unableCount > 0">
  149. <span class="complete-stat__divider"></span>
  150. <div class="complete-stat">
  151. <span class="complete-stat__value is-warn">{{ unableCount }}</span>
  152. <span class="complete-stat__label">未清洗(表)</span>
  153. </div>
  154. </template>
  155. <span class="complete-stat__divider"></span>
  156. <div class="complete-stat">
  157. <span class="complete-stat__value is-rate">{{ successRate }}</span>
  158. <span class="complete-stat__label">成功率</span>
  159. </div>
  160. </div>
  161. <div class="complete-actions">
  162. <Button class="complete-log" @click="handleViewLog">查看清洗日志</Button>
  163. <Button type="primary" class="complete-result" @click="handleViewResult">查看结果</Button>
  164. </div>
  165. </div>
  166. <div class="progress-log progress-log--complete">
  167. <TaskLogList :logs="taskLog" title="任务日志" console-style fill empty-text="本次任务暂无日志" />
  168. </div>
  169. </div>
  170. </template>
  171. </div>
  172. </div>
  173. </div>
  174. <CleanLogModal v-model:open="logModalOpen" :file-infos="currentCleanFiles" :batch-id="currentCleanBatchId" />
  175. </div>
  176. </template>
  177. <script lang="ts" setup name="ViewsDataCleanProgress">
  178. import { computed, nextTick, onBeforeUnmount, onMounted, ref, watch } from 'vue';
  179. import { useRoute } from 'vue-router';
  180. import { Button, Modal } from 'ant-design-vue';
  181. import { Icon } from '@/core/components/Icon';
  182. import { useGo } from '@/core/hooks/web/usePage';
  183. import { PageEnum } from '@/core/enums/pageEnum';
  184. import { useDesign } from '@/core/hooks/web/useDesign';
  185. import { useMessage } from '@/core/hooks/web/useMessage';
  186. import { useEmitter, useUserStore } from '@/core/store/modules/case';
  187. import { getToken } from '@/core/utils/auth';
  188. import { markAnalysisDataChanged } from '@/core/logics/analysisRefreshPrompt';
  189. import {
  190. calcTask,
  191. doClean,
  192. getGovernConfList,
  193. getGovernTaskSseUrl,
  194. smartCleanStatus,
  195. stopClean,
  196. stopSmartClean,
  197. testSse,
  198. } from '@/case/api/govern/governApi';
  199. import CleanLogModal from './components/CleanLogModal.vue';
  200. import CaseFlowTopBar from './components/CaseFlowTopBar.vue';
  201. import TaskLogList from './components/TaskLogList.vue';
  202. import type { SmartCleanReviewItem, SmartCleanStatusVO } from '@/case/api/govern/types/dto';
  203. import type { FileInfo } from '@/types/api';
  204. import {
  205. clearImportProgress,
  206. clearLegacyTaskLogStorage,
  207. getActiveImportProgress,
  208. getImportProgressEventSource,
  209. resetImportProgressRuntimeState,
  210. saveImportProgress,
  211. setImportProgressEventSource,
  212. useImportProgressRuntimeState,
  213. type TaskLogItem,
  214. } from './importProgressSession';
  215. const { prefixCls } = useDesign('case-clean-progress');
  216. const go = useGo();
  217. const emitter = useEmitter();
  218. const userStore = useUserStore();
  219. const { createMessage } = useMessage();
  220. const CASE_DATA_REFRESH_EVENT = 'case-data:refresh';
  221. const CASE_IMPORT_FILE_REFRESH_EVENT = 'case-import-file:refresh';
  222. const FILE_INFO_STORAGE_KEY = 'case_clean_file_infos';
  223. const IMPORT_FILE_INFO_STORAGE_KEY = 'case_clean_import_file_infos';
  224. const RECLEAN_CONTEXT_STORAGE_KEY = 'case_clean_reclean_context';
  225. /** 清洗完成跳转统计页时的一次性上下文:目标页签 + 清洗来源(自主/智能) */
  226. const CLEAN_RESULT_CONTEXT_KEY = 'case_clean_result_context';
  227. const GOVERN_START_TASK_PROCESS = 1;
  228. const {
  229. progress,
  230. activeStep,
  231. currentFileName,
  232. currentCleanFiles,
  233. currentCleanBatchId,
  234. sseConnected,
  235. sseError,
  236. cleanTaskStarted,
  237. calcTaskTriggered,
  238. cleanTaskFinished,
  239. governTaskStarted,
  240. governTaskFinished,
  241. shouldRunGovernAfterClean,
  242. governCompleteNotified,
  243. successCount,
  244. failCount,
  245. cleanStatsSnapshot,
  246. } = useImportProgressRuntimeState();
  247. const sseMessages = ref<string[]>([]);
  248. /**
  249. * 处理日志:清洗 + 治理统一成一条时间线,只存在本页内存里。
  250. * 页面退出即清空;不落 localStorage,也不在导入文件页提供历史日志入口。
  251. */
  252. const taskLog = ref<TaskLogItem[]>([]);
  253. const taskLogBatchId = ref('');
  254. const governFailed = ref(false);
  255. let taskLogSeq = 0;
  256. const logModalOpen = ref(false);
  257. /**
  258. * 执行中左侧的步骤说明:activeStep 0/1(开启治理时含 2)与之一一对应。
  259. * 「数据治理」只在治理设置开启自动治理时展示;未开启时流程只有「读取数据 → 清洗入库」两步。
  260. */
  261. const runSteps = computed(() => {
  262. const steps = [
  263. { title: '读取数据', desc: '解析上传文件与工作表' },
  264. { title: '清洗入库', desc: '按模板清洗并写入案件库' },
  265. ];
  266. if (shouldRunGovernAfterClean.value) {
  267. steps.push({ title: '数据治理', desc: '去重、关系识别与分类树统计' });
  268. }
  269. return steps;
  270. });
  271. let eventSource = getImportProgressEventSource();
  272. /**
  273. * 清洗 100% 后等待数据治理收尾的兜底:
  274. * 治理未启动 / 启动失败 / 进度不再推送 / SSE 断流 / AI 终态消息丢失时,页面不能永远停在「执行中」
  275. * —— 超过静默期就按清洗完成处理,用户仍能进结果页(治理可在数据页手动补跑)。
  276. */
  277. const COMPLETION_FALLBACK_GRACE_MS = 15_000;
  278. /** 治理压根没启动时用更短的静默期(终端消息里 101→103→102 基本同刻到达,等 3s 足够) */
  279. const COMPLETION_FALLBACK_QUICK_MS = 3_000;
  280. const completionFallback = ref(false);
  281. let completionFallbackTimer: ReturnType<typeof setTimeout> | undefined;
  282. /** 最近一次收到任务事件(cmd 101/102/103)的时间戳:区分「任务在跑只是慢」与「任务没动静」 */
  283. let lastTaskActivityAt = 0;
  284. let completionFallbackNotified = false;
  285. const closeSse = () => {
  286. const activeEventSource = eventSource || getImportProgressEventSource();
  287. activeEventSource?.close();
  288. if (getImportProgressEventSource() === activeEventSource) {
  289. setImportProgressEventSource(null);
  290. }
  291. eventSource = null;
  292. sseConnected.value = false;
  293. };
  294. /**
  295. * 进度环几何:r=50 → 周长 2πr≈314.159。
  296. * dasharray 必须固定为「整圈」,只滚动 dashoffset 才能得到与百分比一致的弧长;
  297. * 旧写法 `dasharray: `${dash} 314`` + `offset: 314 - dash` 会让弧长与进度错位
  298. * (50% 时弧长为 0 → 圆环上的进度颜色整段空白)。
  299. */
  300. const RING_CIRCUMFERENCE = 2 * Math.PI * 50;
  301. const progressDash = computed(() => (overallProgress.value / 100) * RING_CIRCUMFERENCE);
  302. const currentStepLabel = computed(() => {
  303. if (shouldRunGovernAfterClean.value && activeStep.value >= 2) return '数据治理';
  304. if (activeStep.value >= 1) return '清洗入库';
  305. return '读取数据';
  306. });
  307. const progressStatusText = computed(() => {
  308. if (governFailed.value) return '数据治理失败';
  309. if (stopping.value) return '正在停止:等待当前文件处理完成';
  310. if (isComplete.value) return governTaskFinished.value ? '数据治理完成' : '清洗入库流程已完成';
  311. return `当前正在执行${currentStepLabel.value}`;
  312. });
  313. const completeTitle = computed(() => {
  314. if (governFailed.value) return '数据治理未完成';
  315. return stoppedClean.value ? '已停止清洗' : '清洗导入完成';
  316. });
  317. const completeDesc = computed(() => {
  318. if (governFailed.value) {
  319. return '清洗与入库已完成,但治理阶段失败。可查看任务日志定位原因,或到数据页重新执行治理。';
  320. }
  321. if (stoppedClean.value) {
  322. return '已完成的数据已保留,正在清洗的文件已跑完,其余文件未清洗(也不会自动进入数据治理)。可查看任务日志,稍后重新发起清洗。';
  323. }
  324. return governTaskFinished.value ? '数据治理已完成,治理结果已写入案件数据。' : '清洗与入库流程已执行完毕。';
  325. });
  326. const displaySuccessCount = computed(() => cleanStatsSnapshot.value.success ?? successCount.value);
  327. const displayFailCount = computed(() => cleanStatsSnapshot.value.fail ?? failCount.value);
  328. /** 完成概览里的成功率:成功 /(成功 + 失败),没有数据时显示横杠 */
  329. const successRate = computed(() => {
  330. const total = displaySuccessCount.value + displayFailCount.value;
  331. if (total <= 0) return '—';
  332. return `${Math.round((displaySuccessCount.value / total) * 100)}%`;
  333. });
  334. /** 任务耗时:用日志首尾时间估算(日志按时间倒序,第一条最新、最后一条最早) */
  335. const taskDurationText = computed(() => {
  336. if (taskLog.value.length < 2) return '—';
  337. const toSeconds = (value: string) => {
  338. const [hour, minute, second] = String(value || '')
  339. .split(':')
  340. .map((item) => Number(item));
  341. if (![hour, minute, second].every(Number.isFinite)) return Number.NaN;
  342. return hour * 3600 + minute * 60 + second;
  343. };
  344. const newest = toSeconds(taskLog.value[0]?.time || '');
  345. const oldest = toSeconds(taskLog.value[taskLog.value.length - 1]?.time || '');
  346. if (!Number.isFinite(newest) || !Number.isFinite(oldest)) return '—';
  347. let diff = newest - oldest;
  348. // 跨零点时时间是回绕的,补一天
  349. if (diff < 0) diff += 24 * 3600;
  350. if (diff < 60) return `${Math.max(1, diff)} 秒`;
  351. if (diff < 3600) return `${Math.floor(diff / 60)} 分 ${diff % 60} 秒`;
  352. return `${Math.floor(diff / 3600)} 小时 ${Math.floor((diff % 3600) / 60)} 分`;
  353. });
  354. const getCurrentCaseId = () => userStore.getCaseInfo?.id;
  355. const persistImportProgress = () => {
  356. if (isComplete.value) {
  357. clearImportProgress(getCurrentCaseId());
  358. return;
  359. }
  360. if (!cleanTaskStarted.value) return;
  361. saveImportProgress({
  362. active: true,
  363. caseId: getCurrentCaseId(),
  364. progress: progress.value,
  365. activeStep: activeStep.value,
  366. currentFileName: currentFileName.value,
  367. currentCleanFiles: currentCleanFiles.value,
  368. currentCleanBatchId: currentCleanBatchId.value,
  369. successCount: successCount.value,
  370. failCount: failCount.value,
  371. cleanStatsSnapshot: cleanStatsSnapshot.value,
  372. cleanTaskStarted: cleanTaskStarted.value,
  373. cleanTaskFinished: cleanTaskFinished.value,
  374. calcTaskTriggered: calcTaskTriggered.value,
  375. governTaskStarted: governTaskStarted.value,
  376. governTaskFinished: governTaskFinished.value,
  377. shouldRunGovernAfterClean: shouldRunGovernAfterClean.value,
  378. updatedAt: Date.now(),
  379. });
  380. };
  381. const restoreImportProgress = () => {
  382. const snapshot = getActiveImportProgress(getCurrentCaseId());
  383. if (!snapshot) return false;
  384. progress.value = snapshot.progress;
  385. activeStep.value = snapshot.activeStep;
  386. currentFileName.value = snapshot.currentFileName;
  387. currentCleanFiles.value = snapshot.currentCleanFiles || [];
  388. currentCleanBatchId.value = snapshot.currentCleanBatchId;
  389. successCount.value = snapshot.successCount;
  390. failCount.value = snapshot.failCount;
  391. cleanStatsSnapshot.value = snapshot.cleanStatsSnapshot || {};
  392. cleanTaskStarted.value = snapshot.cleanTaskStarted;
  393. cleanTaskFinished.value = snapshot.cleanTaskFinished;
  394. calcTaskTriggered.value = snapshot.calcTaskTriggered;
  395. governTaskStarted.value = snapshot.governTaskStarted;
  396. governTaskFinished.value = snapshot.governTaskFinished;
  397. shouldRunGovernAfterClean.value = snapshot.shouldRunGovernAfterClean;
  398. // 恢复快照即视为「此刻还活着」:卡 100% 的兜底看门狗从页面打开时刻重新计时
  399. lastTaskActivityAt = Date.now();
  400. return true;
  401. };
  402. watch(
  403. [
  404. progress,
  405. activeStep,
  406. currentFileName,
  407. currentCleanFiles,
  408. currentCleanBatchId,
  409. successCount,
  410. failCount,
  411. cleanStatsSnapshot,
  412. cleanTaskStarted,
  413. cleanTaskFinished,
  414. calcTaskTriggered,
  415. governTaskStarted,
  416. governTaskFinished,
  417. shouldRunGovernAfterClean,
  418. ],
  419. persistImportProgress,
  420. { deep: true },
  421. );
  422. const normalizeText = (value: unknown) => String(value ?? '').trim();
  423. const normalizeBatchId = (value: unknown) => normalizeText(value);
  424. /**
  425. * 后端 SSE 消息 → 日志文本。
  426. *
  427. * <p>直接保留原文(含 {@code [数据清洗]} / {@code [数据治理]} 前缀),不判断级别、不归类。
  428. */
  429. const resolveTaskLogText = (payload: SseDTO): string => {
  430. const raw = normalizeText(payload.message);
  431. if (!raw || raw === '心跳' || raw === '连接成功') return '';
  432. return raw;
  433. };
  434. /**
  435. * 写一条处理日志:后端说什么就记什么,最新在上;新批次的第一条日志会清空上一批次的缓存。
  436. */
  437. const addTaskLog = (text: string) => {
  438. const normalized = normalizeText(text);
  439. if (!normalized) return;
  440. const batchId = currentCleanBatchId.value || refreshCurrentCleanBatchId();
  441. if (taskLogBatchId.value && batchId && batchId !== taskLogBatchId.value) {
  442. taskLog.value = [];
  443. governFailed.value = false;
  444. }
  445. taskLogBatchId.value = batchId || taskLogBatchId.value;
  446. taskLogSeq += 1;
  447. taskLog.value.unshift({
  448. id: `${Date.now()}-${taskLogSeq}`,
  449. time: new Date().toLocaleTimeString('zh-CN', { hour12: false }),
  450. text: normalized,
  451. });
  452. if (taskLog.value.length > 200) {
  453. taskLog.value.length = 200;
  454. }
  455. };
  456. const findBatchId = (items?: FileInfo[] | null): string => {
  457. if (!Array.isArray(items) || !items.length) return '';
  458. for (const item of items) {
  459. const batchId = normalizeBatchId(item?.batchId);
  460. if (batchId) return batchId;
  461. const childBatchId = findBatchId(Array.isArray(item?.children) ? item.children : []);
  462. if (childBatchId) return childBatchId;
  463. }
  464. return '';
  465. };
  466. const refreshCurrentCleanBatchId = () => {
  467. const preFileRaw = sessionStorage.getItem(FILE_INFO_STORAGE_KEY);
  468. if (preFileRaw) {
  469. try {
  470. const preFileInfos = JSON.parse(preFileRaw) as FileInfo[];
  471. const preFileBatchId = findBatchId(preFileInfos);
  472. if (preFileBatchId) {
  473. currentCleanBatchId.value = preFileBatchId;
  474. return currentCleanBatchId.value;
  475. }
  476. } catch (error) {
  477. // Ignore invalid preFile cache and fallback to current task files.
  478. }
  479. }
  480. currentCleanBatchId.value = findBatchId(currentCleanFiles.value);
  481. return currentCleanBatchId.value;
  482. };
  483. const handleViewLog = () => {
  484. refreshCurrentCleanBatchId();
  485. logModalOpen.value = true;
  486. };
  487. /** 完成出口「查看结果」:跳清洗结果统计页(导入文件列表带数据量/成功失败条数) */
  488. const handleViewResult = async () => {
  489. if (!shouldRunGovernAfterClean.value) {
  490. createMessage.warning('数据治理已关闭,本次导入未自动治理,可在数据页手动执行');
  491. }
  492. await navigateToImportResult();
  493. };
  494. const navigateToImportResult = async () => {
  495. sessionStorage.removeItem(IMPORT_FILE_INFO_STORAGE_KEY);
  496. sessionStorage.removeItem(RECLEAN_CONTEXT_STORAGE_KEY);
  497. markAnalysisDataChanged();
  498. // 落到「导入文件」页签:列表带每个文件的数据量与成功/失败条数,即清洗结果统计。
  499. // 页签与完成出口标记经 sessionStorage 一次性传递——目标页被 keep-alive 缓存,
  500. // 激活时机由 onActivated 消费该上下文决定。
  501. // 跳转**不带任何 URL 参数**:「案件数据」是固定页签,带 query 会让 URL 变脏、也容易把页签身份搞乱。
  502. sessionStorage.setItem(CLEAN_RESULT_CONTEXT_KEY, JSON.stringify({ tab: 'files', mode: 'manual' }));
  503. await go({ path: PageEnum.BASE_HOME }, true);
  504. await nextTick();
  505. emitter.emit(CASE_DATA_REFRESH_EVENT);
  506. };
  507. type SseDTO = {
  508. cmd: number;
  509. code: number;
  510. process: number;
  511. message: string;
  512. caseId?: number | string;
  513. seeData?: Recordable;
  514. data?: Recordable;
  515. result?: Recordable;
  516. successCount?: number;
  517. failCount?: number;
  518. successNum?: number;
  519. failNum?: number;
  520. };
  521. const readNumber = (source: Recordable | null | undefined, keys: string[]) => {
  522. if (!source) return undefined;
  523. for (const key of keys) {
  524. const value = source[key];
  525. if (value !== undefined && value !== null && value !== '') {
  526. const numberValue = Number(value);
  527. if (Number.isFinite(numberValue)) return numberValue;
  528. }
  529. }
  530. return undefined;
  531. };
  532. const normalizeCleanResult = (result: Recordable | null | undefined) => {
  533. const nested =
  534. result?.data && typeof result.data === 'object'
  535. ? (result.data as Recordable)
  536. : result?.seeData && typeof result.seeData === 'object'
  537. ? (result.seeData as Recordable)
  538. : result?.result && typeof result.result === 'object'
  539. ? (result.result as Recordable)
  540. : result;
  541. const data = nested || {};
  542. const completedCount = readNumber(data, ['completedCount', 'successCount', 'successNum', 'success']);
  543. const failCount = readNumber(data, ['failCount', 'failNum', 'failedCount', 'fail']);
  544. return {
  545. success: completedCount,
  546. fail: failCount,
  547. process: readNumber(data, ['process', 'progress', 'taskProcess']),
  548. };
  549. };
  550. const normalizeSseProcess = (value: unknown) => {
  551. const numberValue = Number(value);
  552. if (!Number.isFinite(numberValue)) return progress.value;
  553. return Math.min(100, Math.max(0, Math.round(numberValue)));
  554. };
  555. const applyCleanResult = (result: Recordable | null | undefined, applyProcess = true) => {
  556. const normalized = normalizeCleanResult(result);
  557. if (normalized.success !== undefined) {
  558. successCount.value = normalized.success;
  559. cleanStatsSnapshot.value = { ...cleanStatsSnapshot.value, success: normalized.success };
  560. }
  561. if (normalized.fail !== undefined) {
  562. failCount.value = normalized.fail;
  563. cleanStatsSnapshot.value = { ...cleanStatsSnapshot.value, fail: normalized.fail };
  564. }
  565. if (applyProcess && normalized.process !== undefined) {
  566. progress.value = Math.min(100, Math.max(0, normalized.process));
  567. }
  568. };
  569. // const isCleanFinishedResult = (result: Recordable | null | undefined) => {
  570. // const normalized = normalizeCleanResult(result);
  571. // if (normalized.process !== undefined && normalized.process >= 100) return true;
  572. // const cmd = Number(result?.cmd ?? result?.data?.cmd ?? result?.seeData?.cmd ?? result?.result?.cmd);
  573. // if (cmd === 102) return false;
  574. // const data = (result?.data || result?.seeData || result?.result || result || {}) as Recordable;
  575. // const message = String(data?.message || data?.msg || result?.message || result?.msg || '').trim();
  576. // return (
  577. // message.includes('清洗导入完成') ||
  578. // message.includes('清洗完成') ||
  579. // message.includes('清洗结束') ||
  580. // message.includes('入库完成') ||
  581. // message.includes('全部清洗完成') ||
  582. // message.includes('全部入库完成')
  583. // );
  584. // };
  585. const startGovernAfterClean = async () => {
  586. // if (!shouldRunGovernAfterClean.value) {
  587. // await triggerCalcTask();
  588. // return;
  589. // }
  590. activeStep.value = 2;
  591. await triggerCalcTask();
  592. };
  593. const safeEmitImportRefresh = () => {
  594. try {
  595. emitter.emit(CASE_IMPORT_FILE_REFRESH_EVENT);
  596. } catch (error) {
  597. console.error('[clean-progress] import refresh emit failed', error);
  598. }
  599. };
  600. // const handleCleanFinished = async () => {
  601. // if (calcTaskTriggered.value || governTaskStarted.value || governTaskFinished.value) return;
  602. // if (!cleanTaskFinished.value) {
  603. // cleanTaskFinished.value = true;
  604. // }
  605. // await startGovernAfterClean();
  606. // safeEmitImportRefresh();
  607. // };
  608. const normalizeGovernConfFlag = (value?: unknown) =>
  609. String(value ?? '')
  610. .trim()
  611. .toUpperCase();
  612. const getRequestErrorMessage = (error: any, fallback = '操作失败') =>
  613. error?.response?.data?.message || error?.message || fallback;
  614. /** 是否在清洗完成后自动治理:按「同时治理」配置执行 */
  615. const loadGovernSwitch = async () => {
  616. try {
  617. const list = await getGovernConfList();
  618. const hasGovernConf = (Array.isArray(list) ? list : []).find(
  619. (item) =>
  620. String(item?.confType ?? '')
  621. .trim()
  622. .toLowerCase() === 'hasgovern',
  623. );
  624. // `hasGovern` 的实际语义以接口返回为准:N 表示导入不立即治理,Y 表示立即治理。
  625. shouldRunGovernAfterClean.value = normalizeGovernConfFlag(hasGovernConf?.confStr) === 'Y';
  626. } catch (error) {
  627. shouldRunGovernAfterClean.value = true;
  628. createMessage.warning('治理配置读取失败,将按默认流程继续执行数据治理');
  629. }
  630. };
  631. const isGovernCompleteText = (text: string) =>
  632. ['数据治理完成', '治理完成', '治理结束', '治理任务完成'].some((keyword) => text.includes(keyword));
  633. const isGovernCompletePayload = (payload: SseDTO, raw = '') => {
  634. const value = Number(payload.process ?? 0);
  635. const message = `${payload.message || ''}${raw}`;
  636. if (isGovernCompleteText(message)) return true;
  637. if (payload.cmd === 101) return false;
  638. return (governTaskStarted.value || calcTaskTriggered.value || activeStep.value >= 2) && value >= 100;
  639. };
  640. const markGovernComplete = () => {
  641. if (governTaskFinished.value) return;
  642. activeStep.value = 2;
  643. governTaskFinished.value = true;
  644. closeSse();
  645. clearImportProgress(getCurrentCaseId());
  646. safeEmitImportRefresh();
  647. if (!governCompleteNotified.value) {
  648. governCompleteNotified.value = true;
  649. createMessage.success('数据治理完成');
  650. }
  651. };
  652. const triggerCalcTask = async () => {
  653. if (!shouldRunGovernAfterClean.value) {
  654. activeStep.value = 1;
  655. progress.value = 100;
  656. closeSse();
  657. persistImportProgress();
  658. return;
  659. }
  660. if (calcTaskTriggered.value) return;
  661. calcTaskTriggered.value = true;
  662. persistImportProgress();
  663. try {
  664. if (!eventSource) {
  665. connectSse();
  666. }
  667. await calcTask({
  668. // 治理启动接口固定传起始进度值,不能复用清洗完成时返回的 100。
  669. taskProcess: progress.value,
  670. });
  671. governTaskStarted.value = true;
  672. lastTaskActivityAt = Date.now();
  673. persistImportProgress();
  674. if (!eventSource || !sseConnected.value) {
  675. connectSse();
  676. }
  677. createMessage.success('治理任务已启动');
  678. } catch (error: any) {
  679. const message = getRequestErrorMessage(error, '治理任务启动失败');
  680. calcTaskTriggered.value = false;
  681. governTaskStarted.value = false;
  682. governFailed.value = true;
  683. progress.value = 100;
  684. addTaskLog(`[数据治理]${message}`);
  685. closeSse();
  686. createMessage.error(message);
  687. }
  688. };
  689. const updateProgressFromMessage = (rawMessage: string) => {
  690. const normalized = rawMessage.trim();
  691. if (!normalized) return;
  692. let payload: SseDTO | null = null;
  693. try {
  694. payload = JSON.parse(normalized) as SseDTO;
  695. } catch (error) {
  696. payload = null;
  697. }
  698. if (payload) {
  699. // 案件切换后,上一个案件可能还有后台任务在推进度;只处理当前案件(心跳无 caseId,照常放行)
  700. const currentCaseId = getCurrentCaseId();
  701. if (
  702. payload.caseId !== undefined &&
  703. payload.caseId !== null &&
  704. String(payload.caseId) !== String(currentCaseId ?? '')
  705. ) {
  706. return;
  707. }
  708. // 任何任务事件(清洗 101 / 治理 102 / AI 状态 103 / 清洗日志 104)都算「任务在推进」:
  709. // 兜底看门狗据此续期;999 心跳不算,避免 SSE 还连着但任务早已停摆时被无限续期
  710. if (payload.cmd === 101 || payload.cmd === 102 || payload.cmd === 103 || payload.cmd === 104) {
  711. lastTaskActivityAt = Date.now();
  712. }
  713. const value = normalizeSseProcess(payload.process);
  714. // 清洗 / 治理 / 清洗日志(104)原样进任务日志;AI 状态(103)由 AI 卡片单独展示,不重复刷日志。
  715. // 104 只追加日志,不参与进度与终态判定(后端逐 sheet 推「识别/入库」流水账)。
  716. if (payload.cmd === 101 || payload.cmd === 102 || payload.cmd === 104) {
  717. const logText = resolveTaskLogText(payload);
  718. if (logText) addTaskLog(logText);
  719. }
  720. if (payload.cmd === 101) {
  721. const shouldApplyCleanProgress = !calcTaskTriggered.value && activeStep.value < 2;
  722. // 停止收口消息:完成页文案按「已停止」展示
  723. if (String(payload.message || '').includes('[清洗] 已停止')) {
  724. stoppedByUser.value = true;
  725. }
  726. const fileName = String(payload.message || '').trim();
  727. if (fileName) currentFileName.value = fileName;
  728. applyCleanResult(payload as unknown as Recordable, shouldApplyCleanProgress);
  729. if (shouldApplyCleanProgress) {
  730. activeStep.value = 1;
  731. progress.value = value;
  732. }
  733. // if (isCleanFinishedResult(payload as unknown as Recordable)) {
  734. // void handleCleanFinished();
  735. // }
  736. if (value >= 100) {
  737. // 终态文案由后端统一推送(「[清洗] 全部完成:成功 N 行,失败 M 行」),
  738. // 这里不再补一条重复的「清洗入库完成」
  739. cleanTaskFinished.value = true;
  740. }
  741. } else if (payload.cmd === 102) {
  742. activeStep.value = 2;
  743. governTaskStarted.value = true;
  744. const message = String(payload.message || '').trim();
  745. if (/治理失败|治理异常/.test(message)) {
  746. governFailed.value = true;
  747. progress.value = 100;
  748. closeSse();
  749. createMessage.error(message || '数据治理失败,请查看任务日志');
  750. return;
  751. }
  752. progress.value = value;
  753. // shouldRunGovernAfterClean.value = true;
  754. startGovernAfterClean();
  755. // 「开始治理」本身不是完成信号:智能链路会带 process=100 推这条启动消息,
  756. // 不能据此关掉 SSE,否则治理阶段的日志全部收不到。
  757. const isGovernStartLog = /开始数据治理|治理任务已启动|正在准备执行/.test(message);
  758. if (value >= 100 && !isGovernStartLog) {
  759. markGovernComplete();
  760. }
  761. } else if (payload.cmd === 103) {
  762. // AI 清洗批次状态快照(后端 SSE 推送,非轮询):
  763. // 进度环、无法清洗明细、完成判定都由它驱动;终态快照即「清洗入库完成」
  764. const vo = (payload.seeData as Recordable | undefined)?.payload as SmartCleanStatusVO | undefined;
  765. if (vo && vo.stage) {
  766. applyAiStage(vo);
  767. if (aiStageFinished.value && !cleanTaskFinished.value) {
  768. // 终态文案由后端 cmd 101 统一推送,这里只落状态,不重复写日志
  769. cleanTaskFinished.value = true;
  770. }
  771. }
  772. } else {
  773. // activeStep.value = 0;
  774. // progress.value = value;
  775. }
  776. if (payload.message) {
  777. sseMessages.value.unshift(payload.message);
  778. sseMessages.value = sseMessages.value.slice(0, 20);
  779. }
  780. persistImportProgress();
  781. return;
  782. }
  783. // if (isGovernCompleteText(normalized)) {
  784. // sseMessages.value.unshift(normalized);
  785. // sseMessages.value = sseMessages.value.slice(0, 20);
  786. // markGovernComplete();
  787. // return;
  788. // }
  789. // const percentMatch = normalized.match(/(\d{1,3})%/);
  790. // if (percentMatch) {
  791. // const value = Math.min(100, Math.max(0, Number(percentMatch[1])));
  792. // progress.value = value;
  793. // if (value >= 90) {
  794. // activeStep.value = 2;
  795. // } else if (value >= 50) {
  796. // activeStep.value = 1;
  797. // } else {
  798. // activeStep.value = 0;
  799. // }
  800. // return;
  801. // }
  802. // if (normalized.includes('读取')) {
  803. // activeStep.value = 0;
  804. // } else if (normalized.includes('清洗')) {
  805. // activeStep.value = 1;
  806. // } else if (normalized.includes('治理')) {
  807. // activeStep.value = 2;
  808. // }
  809. };
  810. /**
  811. * 建立治理进度 SSE 连接。
  812. *
  813. * ★ 不能用原生 EventSource:它无法自定义请求头,而本项目登录凭据走 `x-token` 头
  814. * (后端 sa-token 配置为「仅 Header」模式),EventSource 必然 401。
  815. * 这里改用 fetch + ReadableStream 手动按 `\n\n` 分帧。
  816. */
  817. const connectSse = () => {
  818. const activeEventSource = getImportProgressEventSource();
  819. if (activeEventSource) {
  820. eventSource = activeEventSource;
  821. return;
  822. }
  823. sseConnected.value = false;
  824. sseError.value = null;
  825. const controller = new AbortController();
  826. // 占位句柄:让共享的「已有连接」判断成立,并支持既有的 .close() 调用
  827. const handle = { close: () => controller.abort() } as unknown as EventSource;
  828. eventSource = handle;
  829. setImportProgressEventSource(handle);
  830. void (async () => {
  831. try {
  832. const token = getToken();
  833. const res = await fetch(getGovernTaskSseUrl(), {
  834. headers: {
  835. Accept: 'text/event-stream',
  836. ...(token ? { 'x-token': token as string } : {}),
  837. },
  838. credentials: 'include',
  839. signal: controller.signal,
  840. });
  841. const contentType = res.headers.get('content-type') || '';
  842. if (!res.ok || !contentType.includes('text/event-stream')) {
  843. // 未登录等场景后端返回的是普通 Result JSON
  844. let msg = 'SSE 连接失败';
  845. try {
  846. const json = await res.json();
  847. msg = json?.message || msg;
  848. } catch {
  849. /* ignore */
  850. }
  851. sseConnected.value = false;
  852. sseError.value = msg;
  853. if (isFused.value && !aiStageFinished.value) {
  854. // 进度全靠 SSE 推送:连接起不来就没有后续事件,给出超时出口而不是傻等
  855. aiStageTimeout.value = true;
  856. }
  857. return;
  858. }
  859. sseConnected.value = true;
  860. sseError.value = null;
  861. const reader = res.body?.getReader();
  862. if (!reader) {
  863. sseError.value = 'SSE 连接中断';
  864. return;
  865. }
  866. const decoder = new TextDecoder();
  867. let buffer = '';
  868. for (;;) {
  869. const { value, done } = await reader.read();
  870. if (done) break;
  871. buffer += decoder.decode(value, { stream: true });
  872. let idx = buffer.indexOf('\n\n');
  873. while (idx >= 0) {
  874. const frame = buffer.slice(0, idx);
  875. buffer = buffer.slice(idx + 2);
  876. const payload = frame
  877. .split('\n')
  878. .filter((line) => line.startsWith('data:'))
  879. .map((line) => line.slice(5).trimStart())
  880. .join('\n');
  881. if (payload) {
  882. updateProgressFromMessage(payload);
  883. }
  884. idx = buffer.indexOf('\n\n');
  885. }
  886. }
  887. } catch (error: any) {
  888. if (error?.name !== 'AbortError') {
  889. sseConnected.value = false;
  890. if (!governTaskFinished.value) {
  891. sseError.value = 'SSE 连接中断';
  892. }
  893. if (isFused.value && !aiStageFinished.value) {
  894. // 流断了就收不到后续的 AI 进度推送:给「改为手动清洗」出口
  895. aiStageTimeout.value = true;
  896. }
  897. }
  898. } finally {
  899. sseConnected.value = false;
  900. if (getImportProgressEventSource() === eventSource) {
  901. setImportProgressEventSource(null);
  902. }
  903. eventSource = null;
  904. }
  905. })();
  906. };
  907. const loadCleanFiles = () => {
  908. const storageKeys = [IMPORT_FILE_INFO_STORAGE_KEY, FILE_INFO_STORAGE_KEY];
  909. for (const key of storageKeys) {
  910. const raw = sessionStorage.getItem(key);
  911. if (!raw) continue;
  912. try {
  913. const parsed = JSON.parse(raw) as FileInfo[];
  914. if (Array.isArray(parsed) && parsed.length) {
  915. return parsed;
  916. }
  917. } catch (error) {
  918. // Ignore invalid session payload and continue reading fallback storage.
  919. }
  920. }
  921. return [];
  922. };
  923. const loadReCleanContext = (): { reClean?: 0 | 1; fileId?: string } | null => {
  924. const raw = sessionStorage.getItem(RECLEAN_CONTEXT_STORAGE_KEY);
  925. if (!raw) return null;
  926. try {
  927. const parsed = JSON.parse(raw) as { reClean?: number; fileId?: string | number };
  928. const reClean = Number(parsed?.reClean) === 1 ? 1 : 0;
  929. const fileId = normalizeText(parsed?.fileId);
  930. if (reClean !== 1 || !fileId) return null;
  931. return { reClean: 1, fileId };
  932. } catch {
  933. return null;
  934. }
  935. };
  936. const pickFirstFileName = (files: FileInfo[]) => {
  937. const first = files[0];
  938. if (!first) return '暂无文件';
  939. return first.fileName || first.sheetName || first.filePath || '暂无文件';
  940. };
  941. const startClean = async () => {
  942. if (cleanTaskStarted.value) return;
  943. stopping.value = false;
  944. stoppedByUser.value = false;
  945. const fileInfos = loadCleanFiles();
  946. if (!fileInfos.length || !fileInfos.some((item) => (item.children || []).length > 0)) {
  947. createMessage.warning('未找到可清洗文件,请先上传并匹配文件');
  948. closeSse();
  949. go(PageEnum.BASE_UPLOAD, true);
  950. return;
  951. }
  952. currentCleanFiles.value = fileInfos;
  953. currentCleanBatchId.value = findBatchId(fileInfos);
  954. currentFileName.value = pickFirstFileName(fileInfos);
  955. addTaskLog(`[数据清洗]开始处理:${currentFileName.value}`);
  956. cleanTaskStarted.value = true;
  957. persistImportProgress();
  958. try {
  959. const reCleanContext = loadReCleanContext();
  960. await doClean(
  961. reCleanContext
  962. ? {
  963. fileInfos,
  964. reClean: 1,
  965. fileId: reCleanContext.fileId,
  966. }
  967. : { fileInfos },
  968. );
  969. // 清洗任务已发起:文件列表已读入 currentCleanFiles、进度快照由 persistImportProgress 维护,
  970. // 因此立即清空「已上传文件缓存」与清洗流程中间缓存,避免后续进入流程时复用上一批文件。
  971. // 放在 doClean 成功之后再清,保证发起失败时缓存仍在、可重新发起。
  972. sessionStorage.removeItem(FILE_INFO_STORAGE_KEY);
  973. sessionStorage.removeItem(IMPORT_FILE_INFO_STORAGE_KEY);
  974. sessionStorage.removeItem(RECLEAN_CONTEXT_STORAGE_KEY);
  975. // applyCleanResult(result);
  976. // if (isCleanFinishedResult(result)) {
  977. // await handleCleanFinished();
  978. // }
  979. createMessage.success('清洗任务已启动');
  980. addTaskLog('[数据清洗]清洗任务已启动');
  981. } catch (error) {
  982. cleanTaskStarted.value = false;
  983. clearImportProgress(getCurrentCaseId());
  984. createMessage.error('清洗任务启动失败');
  985. }
  986. };
  987. // ==================== 融合模式:上传页「智能」= 既有清洗 + AI 清洗 ====================
  988. const route = useRoute();
  989. const AI_STAGE_DONE = ['DONE', 'PARTIAL', 'FAILED', 'STOPPED'];
  990. /** fused=1 且带 batchId 才认融合模式;没有批次号就没法关联进度,宁可退回原行为 */
  991. const isFused = computed(() => normalizeText(route.query?.fused) === '1' && !!normalizeText(route.query?.batchId));
  992. const fusedBatchId = computed(() => normalizeText(route.query?.batchId));
  993. const aiStage = ref<SmartCleanStatusVO | null>(null);
  994. const aiStageTimeout = ref(false);
  995. /** 用户已点「停止清洗」:后端收口前按钮转 loading */
  996. const stopping = ref(false);
  997. /** 本轮被用户停止(决定完成页文案) */
  998. const stoppedByUser = ref(false);
  999. const stoppedClean = computed(() => stoppedByUser.value || aiStage.value?.stage === 'STOPPED');
  1000. /** 交给 AI 判定的表数 = 全部 sheet - 原本就匹配上模板的 sheet */
  1001. const aiSheetTotal = computed(() =>
  1002. Math.max(0, (aiStage.value?.sheetTotal ?? 0) - (aiStage.value?.matchedCount ?? 0)),
  1003. );
  1004. const aiJudgedCount = computed(() => aiStage.value?.aiJudgedCount ?? 0);
  1005. const aiStageFinished = computed(() => AI_STAGE_DONE.includes(aiStage.value?.stage ?? ''));
  1006. /** 清洗结果页的「无法清洗」统计与明细(仅融合模式有 AI 链路) */
  1007. const unableCount = computed(() => (isFused.value ? (aiStage.value?.needReviewCount ?? 0) : 0));
  1008. /**
  1009. * 统一进度:系统清洗(SSE)与 AI 识别两条链路按各自处理的 sheet 数加权合成一个百分比。
  1010. * AI 识别进度 = 已判定数 / 待判定数(判定完的入库/并入清洗随 SSE 推进)。
  1011. * 非融合模式(纯既有清洗)直接用 SSE 进度。
  1012. */
  1013. const overallProgress = computed(() => {
  1014. if (!isFused.value || !aiStage.value) return progress.value;
  1015. // 批次已到终态 = 1/2/3 级全部收尾,进度定格 100%(与 isComplete 的判定保持一致)
  1016. if (aiStageFinished.value) return 100;
  1017. const matched = aiStage.value.matchedCount ?? 0;
  1018. const total = Math.max(1, aiSheetTotal.value + matched);
  1019. const aiWeight = aiSheetTotal.value / total;
  1020. const aiPct = Math.round((aiJudgedCount.value / Math.max(1, aiSheetTotal.value)) * 100);
  1021. return Math.min(100, Math.round(progress.value * (1 - aiWeight) + aiPct * aiWeight));
  1022. });
  1023. /**
  1024. * 清洗阶段完成判定:非融合模式看 SSE 进度;融合模式看 AI 批次终态 —— 后端在
  1025. * 1/2/3 级全部结束后推终态消息(cmd 103,stage=DONE/PARTIAL/FAILED)。纯 AI/4级
  1026. * 批次没有 doClean,SSE 进度不会走到 100%,不能拿 progress 当完成依据。
  1027. */
  1028. const cleanPhaseDone = computed(() => (isFused.value ? aiStageFinished.value : progress.value >= 100));
  1029. /**
  1030. * 「正常完成」判定(不含兜底):
  1031. * 1) 清洗完成 + (治理关闭或治理已完成);
  1032. * 2) 治理已完成且进度环已 100% —— 即便 AI 阶段终态消息(cmd 103)丢了也算完成。
  1033. */
  1034. const baseComplete = computed(
  1035. () =>
  1036. (cleanPhaseDone.value && (!shouldRunGovernAfterClean.value || governTaskFinished.value)) ||
  1037. (governTaskFinished.value && overallProgress.value >= 100),
  1038. );
  1039. /**
  1040. * 最终完成态:兜底成立时不再要求 cleanPhaseDone —— 融合模式的 AI 阶段终态消息(cmd 103)
  1041. * 丢失时,进度环可能已经 100%(cmd 101),但 aiStageFinished 永远为 false,会永久卡住。
  1042. */
  1043. const isComplete = computed(() => governFailed.value || completionFallback.value || baseComplete.value);
  1044. /** 页面说明文案:治理未开启时不出现「治理」,与左侧步骤条保持一致 */
  1045. const pageSubtitle = computed(() => {
  1046. const scope = shouldRunGovernAfterClean.value ? '清洗、入库与治理' : '清洗与入库';
  1047. return isComplete.value
  1048. ? `查看本次${scope}的执行结果,以及完整任务日志。`
  1049. : `实时展示文件${scope}的执行进度,便于快速确认任务运行状态。`;
  1050. });
  1051. /**
  1052. * 完成时提示「另有 N 个表 AI 无法清洗」——只在完成那一刻提醒一次。
  1053. * 完成后<b>不自动跳转</b>(2026-10-11 需求):跳转由完成面板上的「查看结果」按钮触发。
  1054. */
  1055. watch(isComplete, (done) => {
  1056. if (!done) return;
  1057. const unable = isFused.value ? (aiStage.value?.needReviewCount ?? 0) : 0;
  1058. if (unable > 0) {
  1059. createMessage.warning(`另有 ${unable} 个表 AI 无法清洗,详情见处理日志;可用「手动清洗」处理。`);
  1060. }
  1061. });
  1062. /**
  1063. * 融合模式批次终态收口:既有清洗完成时由 SSE 的 100% 触发治理/关会话,但纯 AI/4级
  1064. * 批次没有 doClean、SSE 不推完成消息 —— 批次到终态(cmd 103 推送)时在这里补上与
  1065. * 既有清洗完成相同的出口(治理开关开启则启动治理,否则定格完成并触发自动跳转)。
  1066. * calcTaskTriggered 幂等:混合批次里治理已被触发过时不会重复启动。
  1067. */
  1068. watch(aiStageFinished, (finished) => {
  1069. if (!isFused.value || !finished) return;
  1070. void triggerCalcTask();
  1071. });
  1072. const clearCompletionFallbackTimer = () => {
  1073. if (completionFallbackTimer !== undefined) {
  1074. clearTimeout(completionFallbackTimer);
  1075. completionFallbackTimer = undefined;
  1076. }
  1077. };
  1078. const resetCompletionFallback = () => {
  1079. clearCompletionFallbackTimer();
  1080. completionFallback.value = false;
  1081. lastTaskActivityAt = 0;
  1082. completionFallbackNotified = false;
  1083. };
  1084. /** 进度环已 100%、但「正常完成」条件还不成立 = 卡在收尾阶段,需要看门狗兜底 */
  1085. const completionStalled = computed(() => overallProgress.value >= 100 && !baseComplete.value);
  1086. /**
  1087. * 卡 100% 的兜底看门狗:静默期内只要还有任务事件(cmd 101/102/103)就继续等,
  1088. * 彻底没动静后按完成处理 —— 覆盖治理未启动/启动失败、SSE 断流、AI 终态消息丢失等异常。
  1089. */
  1090. const scheduleCompletionFallback = () => {
  1091. clearCompletionFallbackTimer();
  1092. if (!completionStalled.value) return;
  1093. const waitMs = governTaskStarted.value ? COMPLETION_FALLBACK_GRACE_MS : COMPLETION_FALLBACK_QUICK_MS;
  1094. completionFallbackTimer = setTimeout(() => {
  1095. completionFallbackTimer = undefined;
  1096. if (!completionStalled.value) return;
  1097. // 还在静默期内(可能有事件晚到)或治理刚开始、需要给更长的观察期
  1098. const quietFor = Date.now() - lastTaskActivityAt;
  1099. if (
  1100. quietFor < COMPLETION_FALLBACK_QUICK_MS ||
  1101. (governTaskStarted.value && quietFor < COMPLETION_FALLBACK_GRACE_MS)
  1102. ) {
  1103. scheduleCompletionFallback();
  1104. return;
  1105. }
  1106. completionFallback.value = true;
  1107. addTaskLog('[数据清洗]超过静默期未收到后续进度,已按完成处理(数据治理可能未执行)');
  1108. if (!completionFallbackNotified) {
  1109. completionFallbackNotified = true;
  1110. createMessage.warning('长时间未收到数据治理完成通知,已按清洗完成处理;如需治理可在数据页手动执行');
  1111. }
  1112. }, waitMs);
  1113. };
  1114. watch(
  1115. completionStalled,
  1116. (stalled) => {
  1117. if (!stalled) {
  1118. resetCompletionFallback();
  1119. return;
  1120. }
  1121. scheduleCompletionFallback();
  1122. },
  1123. { immediate: true },
  1124. );
  1125. // 新一轮任务(清洗未启动)时清掉上一轮留下的兜底状态,避免沿用旧的「已完成」判定
  1126. watch(cleanTaskStarted, (started) => {
  1127. if (!started) resetCompletionFallback();
  1128. });
  1129. /** 记录上一次看到的 AI 状态,用于把变化差量写进处理日志(SSE 推送与启动同步共用) */
  1130. const lastAiLogged = ref({ stage: '', judged: -1, reviewKeys: '' });
  1131. /**
  1132. * AI 链路事件并入处理日志:阶段迁移记里程碑,无法清洗的表逐条记文件级日志。
  1133. * 系统清洗与 AI 只是处理方式不同,日志/进度统一在同一张卡里呈现。
  1134. */
  1135. const logAiStageEvents = (res: SmartCleanStatusVO) => {
  1136. const prev = lastAiLogged.value;
  1137. if (res.stage !== prev.stage) {
  1138. if (res.stage === 'CLEANING_EXISTING') {
  1139. addTaskLog('[数据清洗]AI 识别完成,命中模板的表已并入系统清洗');
  1140. } else if (res.stage === 'LOADING_AI') {
  1141. addTaskLog('[数据清洗]AI 新建表入库中');
  1142. } else if (res.stage === 'DONE') {
  1143. addTaskLog(
  1144. `[数据清洗]AI 识别阶段完成:无法清洗 ${res.needReviewCount ?? 0} 个,失败 ${res.failedCount ?? 0} 个`,
  1145. );
  1146. } else if (res.stage === 'PARTIAL') {
  1147. addTaskLog(
  1148. `[数据清洗]AI 识别阶段部分完成:无法清洗 ${res.needReviewCount ?? 0} 个,失败 ${res.failedCount ?? 0} 个`,
  1149. );
  1150. } else if (res.stage === 'FAILED') {
  1151. addTaskLog('[数据清洗]AI 识别阶段异常结束(已匹配模板的文件仍按系统流程清洗)');
  1152. } else if (res.stage === 'STOPPED') {
  1153. addTaskLog('[数据清洗]已停止:已完成的部分保留,其余文件未清洗');
  1154. stoppedByUser.value = true;
  1155. }
  1156. }
  1157. const keys = (res.needReview || [])
  1158. .map((row) => String(row.sheetId))
  1159. .sort()
  1160. .join('|');
  1161. if (keys !== prev.reviewKeys) {
  1162. const prevSet = new Set(prev.reviewKeys ? prev.reviewKeys.split('|') : []);
  1163. for (const row of res.needReview || []) {
  1164. if (!prevSet.has(String(row.sheetId))) {
  1165. addTaskLog(
  1166. `[数据清洗]AI 无法清洗:${row.sheetName || row.fileName || '-'}(${row.reason || '原因见后端日志'})`,
  1167. );
  1168. }
  1169. }
  1170. }
  1171. lastAiLogged.value = { stage: res.stage, judged: res.aiJudgedCount ?? 0, reviewKeys: keys };
  1172. };
  1173. /** 应用一份 AI 批次状态:进度环、处理日志、步骤条统一在这里收口 */
  1174. const applyAiStage = (res: SmartCleanStatusVO) => {
  1175. aiStage.value = res;
  1176. aiStageTimeout.value = false;
  1177. lastTaskActivityAt = Date.now();
  1178. logAiStageEvents(res);
  1179. // AI 判定/入库属于「清洗入库」阶段:有在跑的 AI 任务就把步骤条推进到第 2 步
  1180. if (!aiStageFinished.value && activeStep.value < 1) {
  1181. activeStep.value = 1;
  1182. }
  1183. };
  1184. const logAiStageWarn = (msg: string, error?: any) => {
  1185. console.warn(`[smartClean] ${msg}: ${error?.message ?? error}`);
  1186. };
  1187. /**
  1188. * 打开页面(含刷新恢复)时的一次性状态同步:只调一次状态接口对齐初始值,
  1189. * 后续进度全部由后端 SSE 推送(cmd 103)驱动 —— 不做周期轮询(需求 2026-10-11)。
  1190. */
  1191. const syncAiStageOnce = async () => {
  1192. if (!isFused.value) return;
  1193. try {
  1194. const res = await smartCleanStatus(fusedBatchId.value);
  1195. if (!res) {
  1196. // 后端重启过或批次被清掉:给出出口而不是傻等
  1197. aiStageTimeout.value = true;
  1198. return;
  1199. }
  1200. applyAiStage(res);
  1201. } catch (error: any) {
  1202. logAiStageWarn('AI 阶段状态同步失败', error);
  1203. }
  1204. };
  1205. /**
  1206. * 停止清洗(协作式):
  1207. * 已清洗的数据不回滚;正在清洗的文件跑完;未开始的文件不再清洗;不自动进入数据治理。
  1208. */
  1209. const handleStopClean = () => {
  1210. if (stopping.value) return;
  1211. Modal.confirm({
  1212. title: '停止清洗?',
  1213. content: '已完成的数据保留;正在清洗的文件会继续跑完;其余文件不再清洗,也不会自动进入数据治理。',
  1214. okText: '停止清洗',
  1215. okType: 'danger',
  1216. cancelText: '继续清洗',
  1217. onOk: async () => {
  1218. stopping.value = true;
  1219. try {
  1220. if (isFused.value && fusedBatchId.value) {
  1221. await stopSmartClean(fusedBatchId.value);
  1222. } else {
  1223. await stopClean();
  1224. }
  1225. stoppedByUser.value = true;
  1226. addTaskLog('[清洗] 已请求停止:正在清洗的文件会跑完,其余文件将不再清洗');
  1227. createMessage.success('已请求停止清洗,等待当前文件处理完成');
  1228. } catch (error: any) {
  1229. stopping.value = false;
  1230. createMessage.error(error?.message || '停止清洗失败');
  1231. }
  1232. },
  1233. });
  1234. };
  1235. // 收口后按钮不再 loading(后端推完终态、页面切到完成态)
  1236. watch(isComplete, (done) => {
  1237. if (done) stopping.value = false;
  1238. });
  1239. /** 融合模式下后端已经发过那一次 doClean,这里只把文件与批次读进来供本页展示 */
  1240. const prepareFusedFiles = () => {
  1241. const fileInfos = loadCleanFiles();
  1242. currentCleanFiles.value = fileInfos;
  1243. currentCleanBatchId.value = findBatchId(fileInfos);
  1244. currentFileName.value = pickFirstFileName(fileInfos);
  1245. addTaskLog(`[数据清洗]开始处理:${currentFileName.value}`);
  1246. cleanTaskStarted.value = true;
  1247. persistImportProgress();
  1248. // 与 startClean 成功后一致:这批文件已进入清洗流程,不能再被下次进入时复用
  1249. sessionStorage.removeItem(FILE_INFO_STORAGE_KEY);
  1250. sessionStorage.removeItem(IMPORT_FILE_INFO_STORAGE_KEY);
  1251. sessionStorage.removeItem(RECLEAN_CONTEXT_STORAGE_KEY);
  1252. addTaskLog('[数据清洗]融合清洗已启动(既有清洗 + AI 识别并行)');
  1253. };
  1254. /** 超时出口「改为手动清洗」:不带 focusKey,清洗页按 batchId 从后端重建本批次文件树 */
  1255. const goManualClean = () => {
  1256. const query: Recordable = {};
  1257. if (fusedBatchId.value) {
  1258. query.batchId = fusedBatchId.value;
  1259. query.redirect = encodeURIComponent(route.fullPath);
  1260. }
  1261. go({ path: PageEnum.BASE_CLEANING, query });
  1262. };
  1263. const initializeProgress = async () => {
  1264. // 任务日志只存在本页内存:进入时清空,并清掉旧版本遗留的 localStorage 快照
  1265. taskLog.value = [];
  1266. taskLogBatchId.value = '';
  1267. governFailed.value = false;
  1268. stopping.value = false;
  1269. stoppedByUser.value = false;
  1270. clearLegacyTaskLogStorage();
  1271. if (restoreImportProgress()) {
  1272. eventSource = getImportProgressEventSource();
  1273. if (!eventSource) {
  1274. connectSse();
  1275. await testSse();
  1276. }
  1277. // 刷新恢复:一次性对齐 AI 批次状态,之后全靠 SSE 推送
  1278. void syncAiStageOnce();
  1279. return;
  1280. }
  1281. resetImportProgressRuntimeState();
  1282. await loadGovernSwitch();
  1283. connectSse();
  1284. await testSse();
  1285. if (isFused.value) {
  1286. prepareFusedFiles();
  1287. // 打开页即对齐一次 AI 批次状态(此后全部由 SSE 推送驱动,无轮询)
  1288. void syncAiStageOnce();
  1289. return;
  1290. }
  1291. await startClean();
  1292. };
  1293. onMounted(() => {
  1294. void initializeProgress();
  1295. });
  1296. onBeforeUnmount(() => {
  1297. clearCompletionFallbackTimer();
  1298. // 清洗/治理日志不跨页面保留:退出即清空内存,并清掉旧版本遗留的 localStorage
  1299. taskLog.value = [];
  1300. taskLogBatchId.value = '';
  1301. clearLegacyTaskLogStorage();
  1302. if (isComplete.value) {
  1303. closeSse();
  1304. } else {
  1305. persistImportProgress();
  1306. }
  1307. });
  1308. </script>
  1309. <style lang="less">
  1310. @prefix-cls: ~'jeesite-case-clean-progress';
  1311. .@{prefix-cls}.case-clean-progress {
  1312. // 独立全屏路由(不套 LAYOUT):父级不再是有确定高度的布局内容容器,
  1313. // height: 100% 会退化成 auto(页面塌成内容高度),必须用 100vh 撑满视口。
  1314. min-height: 100vh;
  1315. height: 100vh;
  1316. background: #f0f2f5;
  1317. display: flex;
  1318. flex-direction: column;
  1319. box-sizing: border-box;
  1320. overflow: hidden;
  1321. // 公共顶栏由 AppTopBar 自带高度,内容区在剩余高度里滚动
  1322. .page-body {
  1323. flex: 1 1 auto;
  1324. min-height: 0;
  1325. padding: 16px 24px 20px;
  1326. display: flex;
  1327. flex-direction: column;
  1328. gap: 14px;
  1329. box-sizing: border-box;
  1330. overflow: auto;
  1331. }
  1332. // 页头:与下方进度卡一致的白色卡片
  1333. .page-header {
  1334. flex: 0 0 auto;
  1335. display: flex;
  1336. align-items: center;
  1337. justify-content: space-between;
  1338. gap: 16px;
  1339. padding: 12px 16px;
  1340. border: 1px solid #e2e8f0;
  1341. border-radius: 14px;
  1342. background: #fff;
  1343. box-shadow: 0 1px 2px rgba(15, 23, 42, 0.03);
  1344. box-sizing: border-box;
  1345. }
  1346. /* 顶栏右侧:停止清洗按钮 + SSE 连接状态 */
  1347. .page-header__actions {
  1348. display: flex;
  1349. flex: 0 0 auto;
  1350. align-items: center;
  1351. gap: 10px;
  1352. }
  1353. .page-header__main {
  1354. display: flex;
  1355. align-items: center;
  1356. gap: 12px;
  1357. min-width: 0;
  1358. }
  1359. .page-title-icon {
  1360. display: flex;
  1361. align-items: center;
  1362. justify-content: center;
  1363. flex: none;
  1364. width: 38px;
  1365. height: 38px;
  1366. border-radius: 11px;
  1367. background: #eff6ff;
  1368. color: #2563eb;
  1369. }
  1370. .page-title-wrap {
  1371. min-width: 0;
  1372. overflow: hidden;
  1373. }
  1374. .page-title {
  1375. font-size: 16px;
  1376. line-height: 1.4;
  1377. font-weight: 600;
  1378. color: #0f172a;
  1379. }
  1380. .page-subtitle {
  1381. margin-top: 2px;
  1382. overflow: hidden;
  1383. font-size: 12px;
  1384. line-height: 1.6;
  1385. color: #64748b;
  1386. white-space: nowrap;
  1387. text-overflow: ellipsis;
  1388. }
  1389. // 页头右侧的实时推送状态胶囊(完成态隐藏)
  1390. .sse-pill {
  1391. display: inline-flex;
  1392. align-items: center;
  1393. gap: 8px;
  1394. flex: none;
  1395. height: 32px;
  1396. padding: 0 14px;
  1397. border-radius: 999px;
  1398. background: #fff;
  1399. border: 1px solid #e2e8f0;
  1400. font-size: 12px;
  1401. color: #64748b;
  1402. .sse-dot {
  1403. width: 8px;
  1404. height: 8px;
  1405. border-radius: 50%;
  1406. background: #cbd5e1;
  1407. }
  1408. &.is-on {
  1409. color: #15803d;
  1410. border-color: #bbf7d0;
  1411. background: #f0fdf4;
  1412. .sse-dot {
  1413. background: #22c55e;
  1414. box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.15);
  1415. }
  1416. }
  1417. }
  1418. .progress-layout {
  1419. flex: 1 1 auto;
  1420. min-height: 0;
  1421. display: flex;
  1422. }
  1423. .progress-card {
  1424. display: flex;
  1425. flex-direction: column;
  1426. gap: 8px;
  1427. padding: 20px 24px;
  1428. border: 1px solid #e5e7eb;
  1429. border-radius: 16px;
  1430. background: #fff;
  1431. box-shadow:
  1432. 0 1px 2px rgba(15, 23, 42, 0.04),
  1433. 0 8px 24px rgba(15, 23, 42, 0.05);
  1434. min-height: 0;
  1435. width: 100%;
  1436. }
  1437. // 执行中:左侧任务状态 + 右侧整块日志
  1438. .run-layout {
  1439. flex: 1 1 auto;
  1440. min-height: 0;
  1441. display: grid;
  1442. grid-template-columns: minmax(320px, 380px) minmax(0, 1fr);
  1443. align-items: stretch;
  1444. gap: 16px;
  1445. }
  1446. .run-side {
  1447. display: flex;
  1448. flex-direction: column;
  1449. gap: 18px;
  1450. min-height: 0;
  1451. padding: 18px;
  1452. border: 1px solid #e8eef6;
  1453. border-radius: 14px;
  1454. background: #f8fbff;
  1455. box-sizing: border-box;
  1456. }
  1457. .run-head {
  1458. display: flex;
  1459. align-items: flex-start;
  1460. gap: 10px;
  1461. min-width: 0;
  1462. }
  1463. // 执行中的呼吸圆点
  1464. .run-live {
  1465. position: relative;
  1466. flex: none;
  1467. width: 10px;
  1468. height: 10px;
  1469. margin-top: 6px;
  1470. border-radius: 50%;
  1471. background: #2563eb;
  1472. &::after {
  1473. content: '';
  1474. position: absolute;
  1475. inset: -4px;
  1476. border-radius: 50%;
  1477. border: 2px solid rgba(37, 99, 235, 0.28);
  1478. animation: clean-progress-live-pulse 1.6s ease-out infinite;
  1479. }
  1480. }
  1481. .run-head__text {
  1482. min-width: 0;
  1483. }
  1484. .run-title {
  1485. font-size: 15px;
  1486. font-weight: 600;
  1487. line-height: 1.4;
  1488. color: #0f172a;
  1489. }
  1490. .run-subtitle {
  1491. margin-top: 2px;
  1492. font-size: 12px;
  1493. line-height: 1.6;
  1494. color: #64748b;
  1495. }
  1496. .run-summary {
  1497. display: flex;
  1498. align-items: center;
  1499. gap: 18px;
  1500. }
  1501. .run-ring {
  1502. flex: none;
  1503. .progress-ring,
  1504. .progress-ring svg {
  1505. width: 140px;
  1506. height: 140px;
  1507. }
  1508. .progress-value {
  1509. inset: 18px;
  1510. gap: 3px;
  1511. strong {
  1512. font-size: 30px;
  1513. small {
  1514. font-size: 15px;
  1515. }
  1516. }
  1517. span {
  1518. font-size: 11.5px;
  1519. }
  1520. }
  1521. }
  1522. .run-summary__stats {
  1523. flex: 1 1 auto;
  1524. min-width: 0;
  1525. display: flex;
  1526. flex-direction: column;
  1527. }
  1528. .run-stat-line {
  1529. display: flex;
  1530. align-items: baseline;
  1531. justify-content: space-between;
  1532. gap: 10px;
  1533. padding: 9px 0;
  1534. border-bottom: 1px solid #eef2f7;
  1535. &:last-child {
  1536. border-bottom: 0;
  1537. }
  1538. }
  1539. .run-stat-line__label {
  1540. font-size: 11.5px;
  1541. color: #94a3b8;
  1542. white-space: nowrap;
  1543. }
  1544. .run-stat-line__value {
  1545. font-size: 22px;
  1546. line-height: 1.1;
  1547. font-weight: 700;
  1548. color: #0f172a;
  1549. font-variant-numeric: tabular-nums;
  1550. &.is-success {
  1551. color: #16a34a;
  1552. }
  1553. &.is-fail {
  1554. color: #dc2626;
  1555. }
  1556. }
  1557. .run-steps {
  1558. flex: 1 1 auto;
  1559. min-height: 0;
  1560. display: flex;
  1561. flex-direction: column;
  1562. }
  1563. .run-step {
  1564. flex: 1 1 0;
  1565. min-height: 0;
  1566. display: flex;
  1567. gap: 12px;
  1568. }
  1569. .run-step__rail {
  1570. position: relative;
  1571. display: flex;
  1572. flex-direction: column;
  1573. align-items: center;
  1574. flex: none;
  1575. width: 24px;
  1576. }
  1577. .run-step__dot {
  1578. display: flex;
  1579. align-items: center;
  1580. justify-content: center;
  1581. flex: none;
  1582. width: 24px;
  1583. height: 24px;
  1584. border: 1.5px solid #dbe3ee;
  1585. border-radius: 50%;
  1586. background: #fff;
  1587. color: #94a3b8;
  1588. font-size: 12px;
  1589. font-weight: 600;
  1590. box-sizing: border-box;
  1591. transition:
  1592. color 0.2s ease,
  1593. background-color 0.2s ease,
  1594. border-color 0.2s ease;
  1595. }
  1596. .run-step__line {
  1597. flex: 1;
  1598. width: 2px;
  1599. margin: 4px 0;
  1600. border-radius: 1px;
  1601. background: #e2e8f0;
  1602. }
  1603. .run-step__body {
  1604. position: relative;
  1605. flex: 1 1 auto;
  1606. min-width: 0;
  1607. padding-bottom: 8px;
  1608. > * {
  1609. position: relative;
  1610. z-index: 1;
  1611. }
  1612. }
  1613. .run-step__head {
  1614. display: flex;
  1615. align-items: center;
  1616. gap: 8px;
  1617. min-width: 0;
  1618. }
  1619. .run-step__title {
  1620. font-size: 13.5px;
  1621. font-weight: 600;
  1622. line-height: 24px;
  1623. color: #64748b;
  1624. }
  1625. .run-step__status {
  1626. display: inline-flex;
  1627. align-items: center;
  1628. flex: none;
  1629. height: 18px;
  1630. margin-left: auto;
  1631. padding: 0 7px;
  1632. border-radius: 999px;
  1633. background: #f1f5f9;
  1634. color: #94a3b8;
  1635. font-size: 10.5px;
  1636. font-weight: 600;
  1637. line-height: 18px;
  1638. white-space: nowrap;
  1639. }
  1640. .run-step__status-dot {
  1641. display: inline-block;
  1642. width: 5px;
  1643. height: 5px;
  1644. margin-right: 5px;
  1645. border-radius: 50%;
  1646. background: currentColor;
  1647. animation: run-status-blink 1.2s ease-in-out infinite;
  1648. }
  1649. .run-step__desc {
  1650. margin-top: 1px;
  1651. font-size: 11.5px;
  1652. line-height: 1.5;
  1653. color: #94a3b8;
  1654. }
  1655. .run-step.is-done {
  1656. .run-step__dot {
  1657. border-color: #86efac;
  1658. background: #f0fdf4;
  1659. color: #16a34a;
  1660. }
  1661. .run-step__line {
  1662. background: #86efac;
  1663. }
  1664. .run-step__title {
  1665. color: #334155;
  1666. }
  1667. .run-step__status {
  1668. color: #15803d;
  1669. background: #ecfdf5;
  1670. }
  1671. }
  1672. .run-step.is-active {
  1673. .run-step__body::before {
  1674. content: '';
  1675. position: absolute;
  1676. inset: -8px -10px -8px -6px;
  1677. border-radius: 12px;
  1678. background: rgba(37, 99, 235, 0.06);
  1679. pointer-events: none;
  1680. }
  1681. .run-step__dot {
  1682. border-color: #2563eb;
  1683. background: #2563eb;
  1684. color: #fff;
  1685. animation: run-dot-pulse 1.8s ease-out infinite;
  1686. }
  1687. .run-step__line {
  1688. background: #bfdbfe;
  1689. }
  1690. .run-step__title {
  1691. color: #0f172a;
  1692. }
  1693. .run-step__desc {
  1694. color: #64748b;
  1695. }
  1696. .run-step__status {
  1697. color: #1d4ed8;
  1698. background: #eff6ff;
  1699. box-shadow: 0 0 0 1px rgba(37, 99, 235, 0.12);
  1700. }
  1701. }
  1702. // 沿时间线向下移动的小圆点:实色,不使用渐变
  1703. .run-step__flow {
  1704. position: absolute;
  1705. left: 50%;
  1706. top: 28px;
  1707. width: 6px;
  1708. height: 6px;
  1709. margin-left: -3px;
  1710. border-radius: 50%;
  1711. background: #2563eb;
  1712. box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.14);
  1713. pointer-events: none;
  1714. animation: run-flow-down 1.8s linear infinite;
  1715. }
  1716. .run-log {
  1717. display: flex;
  1718. flex-direction: column;
  1719. flex: 1 1 auto;
  1720. align-self: stretch;
  1721. min-height: 0;
  1722. padding: 14px 16px;
  1723. border: 1px solid #e8eef6;
  1724. border-radius: 14px;
  1725. background: #fbfdff;
  1726. overflow: hidden;
  1727. box-sizing: border-box;
  1728. }
  1729. .run-log.is-govern {
  1730. border-color: #dbeafe;
  1731. background: #f7fbff;
  1732. }
  1733. .progress-ring {
  1734. position: relative;
  1735. flex: none;
  1736. width: 200px;
  1737. height: 200px;
  1738. display: flex;
  1739. align-items: center;
  1740. justify-content: center;
  1741. }
  1742. .progress-ring svg {
  1743. width: 200px;
  1744. height: 200px;
  1745. transform: rotate(-90deg);
  1746. }
  1747. .ring-bg {
  1748. fill: none;
  1749. // 轨道色不能太接近卡片白底(旧值 #eef2f7 在 0% 时几乎看不见「圆环」存在)
  1750. stroke: #e2e8f0;
  1751. stroke-width: 10;
  1752. }
  1753. .ring-value {
  1754. fill: none;
  1755. stroke: #2563eb;
  1756. stroke-width: 10;
  1757. stroke-linecap: round;
  1758. transition:
  1759. stroke-dasharray 0.4s ease,
  1760. stroke-dashoffset 0.4s ease;
  1761. filter: drop-shadow(0 10px 18px rgba(37, 99, 235, 0.18));
  1762. }
  1763. .progress-value {
  1764. position: absolute;
  1765. inset: 26px;
  1766. border-radius: 50%;
  1767. background: #fff;
  1768. display: flex;
  1769. flex-direction: column;
  1770. align-items: center;
  1771. justify-content: center;
  1772. gap: 6px;
  1773. strong {
  1774. font-size: 36px;
  1775. line-height: 1;
  1776. font-weight: 700;
  1777. color: #0f172a;
  1778. font-variant-numeric: tabular-nums;
  1779. small {
  1780. margin-left: 1px;
  1781. font-size: 18px;
  1782. font-weight: 600;
  1783. color: #64748b;
  1784. }
  1785. }
  1786. span {
  1787. font-size: 13px;
  1788. color: #64748b;
  1789. }
  1790. }
  1791. // 完成态日志容器(执行中的日志改用 .run-log)
  1792. .progress-log {
  1793. display: flex;
  1794. flex-direction: column;
  1795. gap: 8px;
  1796. width: min(560px, 100%);
  1797. padding: 18px 20px;
  1798. border-radius: 14px;
  1799. background: #f8fafc;
  1800. border: 1px solid #eef2f7;
  1801. }
  1802. // 完成态:顶部一条概览(结论 / 统计 / 操作),下方任务日志占满剩余高度
  1803. .progress-complete-layout {
  1804. flex: 1 1 auto;
  1805. min-height: 0;
  1806. display: flex;
  1807. flex-direction: column;
  1808. gap: 16px;
  1809. }
  1810. .complete-summary {
  1811. flex: 0 0 auto;
  1812. display: flex;
  1813. align-items: center;
  1814. gap: 20px;
  1815. padding: 16px 20px;
  1816. border: 1px solid #d9f0e3;
  1817. border-radius: 14px;
  1818. background: #f6fcf9;
  1819. &.is-failed {
  1820. border-color: #fecaca;
  1821. background: #fff6f6;
  1822. }
  1823. }
  1824. .complete-icon {
  1825. display: flex;
  1826. align-items: center;
  1827. justify-content: center;
  1828. flex: none;
  1829. width: 58px;
  1830. height: 58px;
  1831. border-radius: 16px;
  1832. background: #16a34a;
  1833. color: #fff;
  1834. font-size: 28px;
  1835. font-weight: 700;
  1836. box-shadow: 0 10px 22px rgba(22, 163, 74, 0.22);
  1837. &.is-failed {
  1838. background: #dc2626;
  1839. box-shadow: 0 10px 22px rgba(220, 38, 38, 0.22);
  1840. }
  1841. }
  1842. .complete-main {
  1843. flex: 1 1 auto;
  1844. min-width: 0;
  1845. }
  1846. .complete-title {
  1847. font-size: 20px;
  1848. font-weight: 600;
  1849. line-height: 1.35;
  1850. color: #0f172a;
  1851. &.is-failed {
  1852. color: #b91c1c;
  1853. }
  1854. }
  1855. .complete-desc {
  1856. margin-top: 3px;
  1857. font-size: 12.5px;
  1858. line-height: 1.6;
  1859. color: #64748b;
  1860. }
  1861. .complete-meta {
  1862. display: flex;
  1863. align-items: center;
  1864. flex-wrap: wrap;
  1865. gap: 8px;
  1866. margin-top: 6px;
  1867. font-size: 11.5px;
  1868. color: #94a3b8;
  1869. }
  1870. .complete-meta__item {
  1871. display: inline-flex;
  1872. align-items: center;
  1873. & + & {
  1874. &::before {
  1875. content: '·';
  1876. margin-right: 8px;
  1877. color: #cbd5e1;
  1878. }
  1879. }
  1880. }
  1881. .complete-stats {
  1882. display: flex;
  1883. align-items: center;
  1884. gap: 20px;
  1885. flex: 0 0 auto;
  1886. padding: 0 4px;
  1887. }
  1888. .complete-stat {
  1889. display: flex;
  1890. flex-direction: column;
  1891. gap: 3px;
  1892. min-width: 66px;
  1893. }
  1894. .complete-stat__value {
  1895. font-size: 24px;
  1896. line-height: 1.1;
  1897. font-weight: 700;
  1898. color: #0f172a;
  1899. font-variant-numeric: tabular-nums;
  1900. &.is-success {
  1901. color: #16a34a;
  1902. }
  1903. &.is-fail {
  1904. color: #dc2626;
  1905. }
  1906. &.is-warn {
  1907. color: #d97706;
  1908. }
  1909. &.is-rate {
  1910. color: #2563eb;
  1911. font-size: 20px;
  1912. }
  1913. }
  1914. .complete-stat__label {
  1915. font-size: 11.5px;
  1916. color: #64748b;
  1917. white-space: nowrap;
  1918. }
  1919. .complete-stat__divider {
  1920. width: 1px;
  1921. height: 30px;
  1922. background: #e2e8f0;
  1923. }
  1924. .complete-actions {
  1925. display: flex;
  1926. align-items: center;
  1927. gap: 10px;
  1928. flex: 0 0 auto;
  1929. }
  1930. .complete-log,
  1931. .complete-result {
  1932. min-width: 108px;
  1933. height: 34px;
  1934. border-radius: 8px;
  1935. }
  1936. // 完成态日志:占满概览以下的全部高度,内部滚动
  1937. .progress-log--complete {
  1938. flex: 1 1 auto;
  1939. width: 100%;
  1940. min-height: 0;
  1941. padding: 14px 16px;
  1942. border-radius: 14px;
  1943. background: #fbfdff;
  1944. border: 1px solid #e8eef6;
  1945. overflow: hidden;
  1946. }
  1947. // 融合模式出口横幅:AI 识别超时时的提示与「改为手动清洗」(在主卡内展示)
  1948. .ai-timeout-banner {
  1949. display: flex;
  1950. align-items: center;
  1951. gap: 12px;
  1952. margin: 0 0 4px;
  1953. padding: 10px 14px;
  1954. border: 1px solid #fde68a;
  1955. border-radius: 10px;
  1956. background: #fffbeb;
  1957. font-size: 13px;
  1958. color: #92400e;
  1959. }
  1960. @keyframes clean-progress-live-pulse {
  1961. 0% {
  1962. transform: scale(0.6);
  1963. opacity: 1;
  1964. }
  1965. 100% {
  1966. transform: scale(1.5);
  1967. opacity: 0;
  1968. }
  1969. }
  1970. @keyframes run-dot-pulse {
  1971. 0% {
  1972. box-shadow: 0 0 0 0 rgba(37, 99, 235, 0.35);
  1973. }
  1974. 70% {
  1975. box-shadow: 0 0 0 9px rgba(37, 99, 235, 0);
  1976. }
  1977. 100% {
  1978. box-shadow: 0 0 0 0 rgba(37, 99, 235, 0);
  1979. }
  1980. }
  1981. @keyframes run-status-blink {
  1982. 0%,
  1983. 100% {
  1984. opacity: 1;
  1985. }
  1986. 50% {
  1987. opacity: 0.25;
  1988. }
  1989. }
  1990. @keyframes run-flow-down {
  1991. 0% {
  1992. top: 28px;
  1993. opacity: 0;
  1994. }
  1995. 10% {
  1996. opacity: 1;
  1997. }
  1998. 85% {
  1999. opacity: 1;
  2000. }
  2001. 100% {
  2002. top: calc(100% - 6px);
  2003. opacity: 0;
  2004. }
  2005. }
  2006. @media (max-width: 1100px) {
  2007. .run-layout {
  2008. grid-template-columns: minmax(280px, 320px) minmax(0, 1fr);
  2009. }
  2010. .complete-summary {
  2011. flex-wrap: wrap;
  2012. }
  2013. .complete-main {
  2014. flex: 1 1 calc(100% - 78px);
  2015. }
  2016. .complete-stats {
  2017. order: 3;
  2018. flex: 1 1 100%;
  2019. padding-top: 4px;
  2020. }
  2021. .complete-actions {
  2022. order: 4;
  2023. flex: 1 1 100%;
  2024. justify-content: flex-end;
  2025. }
  2026. }
  2027. @media (max-width: 900px) {
  2028. .run-layout {
  2029. grid-template-columns: minmax(0, 1fr);
  2030. }
  2031. .run-log {
  2032. min-height: 420px;
  2033. }
  2034. }
  2035. @media (max-width: 768px) {
  2036. .page-header {
  2037. flex-direction: column;
  2038. align-items: flex-start;
  2039. }
  2040. .complete-actions {
  2041. width: 100%;
  2042. flex-direction: column;
  2043. }
  2044. .complete-log,
  2045. .complete-result {
  2046. width: 100%;
  2047. }
  2048. }
  2049. }
  2050. </style>