upload.vue 51 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622
  1. <template>
  2. <div :class="prefixCls" class="case-upload-page">
  3. <!-- 清洗流程公共顶栏:品牌 / 案件 / 模板库 / 下载管理 / 窗口控制 -->
  4. <CaseFlowTopBar />
  5. <div class="page-body">
  6. <div class="page-header">
  7. <div class="page-header__left">
  8. <Tooltip title="返回" placement="bottom" :mouseEnterDelay="0.5">
  9. <button type="button" class="back-btn" aria-label="返回" @click="handleBack">
  10. <LeftOutlined />
  11. </button>
  12. </Tooltip>
  13. <span class="page-header__divider" aria-hidden="true"></span>
  14. <div class="page-title-block">
  15. <div class="page-title">文件上传</div>
  16. <div class="page-subtitle">{{ UPLOAD_FILE_SUMMARY }},其余格式不开放选择。</div>
  17. </div>
  18. </div>
  19. <div class="page-header__actions">
  20. <Button
  21. type="primary"
  22. class="next-btn"
  23. :loading="smartCleaning"
  24. :disabled="!hasCleanableSheet"
  25. @click="handleSmartClean"
  26. >
  27. 智能清洗
  28. </Button>
  29. <Button class="next-btn" :disabled="!hasCleanableSheet" @click="handleManualClean">手动清洗</Button>
  30. </div>
  31. </div>
  32. <div class="upload-layout">
  33. <aside class="left-panel">
  34. <div class="upload-picker">
  35. <div class="upload-mode-switch" role="tablist" aria-label="上传类型切换">
  36. <button
  37. type="button"
  38. :class="['upload-mode-switch__item', { 'is-active': uploadMode === 'single' }]"
  39. :disabled="isUploading"
  40. @click="handleUploadModeChange('single')"
  41. >
  42. 选择文件
  43. </button>
  44. <button
  45. type="button"
  46. :class="['upload-mode-switch__item', { 'is-active': uploadMode === 'folder' }]"
  47. :disabled="isUploading"
  48. @click="handleUploadModeChange('folder')"
  49. >
  50. 选择文件夹
  51. </button>
  52. </div>
  53. </div>
  54. <!-- 隐藏的文件输入:accept 与知识库共用全局格式清单(拖拽不受 accept 限制) -->
  55. <input
  56. ref="fileInputRef"
  57. type="file"
  58. multiple
  59. :accept="UPLOAD_FILE_ACCEPT"
  60. style="display: none"
  61. @change="handleFileInputChange"
  62. />
  63. <input
  64. ref="folderInputRef"
  65. type="file"
  66. webkitdirectory
  67. directory
  68. style="display: none"
  69. @change="handleFolderInputChange"
  70. />
  71. <div
  72. class="upload-dropzone"
  73. :class="{ 'is-dragover': dragOver }"
  74. @dragover.prevent="handleDragOver"
  75. @dragleave="handleDragLeave"
  76. @drop.prevent="handleDrop"
  77. >
  78. <div class="upload-dragger-content">
  79. <div class="upload-dragger-icon">⬆</div>
  80. <div class="upload-dragger-title">
  81. {{ uploadMode === 'single' ? '拖拽文件到这里,或点击选择文件' : '拖拽文件夹到这里,或点击选择文件夹' }}
  82. </div>
  83. <div class="upload-dragger-desc">
  84. {{
  85. uploadMode === 'single'
  86. ? `支持批量选择文件;${UPLOAD_FILE_SUMMARY}`
  87. : '支持选择整个文件夹,文件夹内文件全部上传;不支持的格式仅登记、不保存源文件'
  88. }}
  89. </div>
  90. <Button type="primary" class="upload-action-btn" :disabled="isUploading" @click="handleTriggerFileSelect">
  91. {{ uploadMode === 'single' ? '选择文件' : '选择文件夹' }}
  92. </Button>
  93. </div>
  94. </div>
  95. <!-- 已选文件列表(加入后自动上传,成功即移除) -->
  96. <div v-if="selectedFiles.length" class="upload-file-list">
  97. <div class="upload-file-list__header">
  98. <span>待上传 {{ selectedFiles.length }} 个文件</span>
  99. <Button type="link" size="small" :disabled="isUploading" @click="clearSelectedFiles"> 清空 </Button>
  100. </div>
  101. <div class="upload-file-list__body">
  102. <div
  103. v-for="file in selectedFiles"
  104. :key="file.name + file.size + file.lastModified"
  105. class="upload-file-item"
  106. >
  107. <div class="upload-file-item__info">
  108. <span class="upload-file-item__name">{{ file.name }}</span>
  109. <span class="upload-file-item__size">{{ formatFileSize(file.size) }}</span>
  110. </div>
  111. <div class="upload-file-item__status">
  112. <template v-if="uploadStatuses.get(file) === 'error'">
  113. <span class="upload-file-item__error">✗</span>
  114. </template>
  115. <template v-else-if="uploadStatuses.get(file) === 'uploading'">
  116. <span class="upload-file-item__progress-text">{{ uploadProgressMap.get(file) || 0 }}%</span>
  117. </template>
  118. <template v-else>
  119. <span class="upload-file-item__pending">待上传</span>
  120. </template>
  121. </div>
  122. <button
  123. v-if="!isUploading && (uploadStatuses.get(file) || 'pending') === 'pending'"
  124. type="button"
  125. class="upload-file-item__remove"
  126. aria-label="移除文件"
  127. @click="removeSelectedFile(file)"
  128. >
  129. <CloseOutlined />
  130. </button>
  131. </div>
  132. </div>
  133. <!-- 整体进度 -->
  134. <div v-if="isUploading" class="upload-overall-progress">
  135. <div class="upload-overall-progress__bar">
  136. <div class="upload-overall-progress__fill" :style="{ width: overallProgress + '%' }"></div>
  137. </div>
  138. <span class="upload-overall-progress__text">总进度 {{ overallProgress }}%</span>
  139. </div>
  140. </div>
  141. <div v-else class="upload-file-list upload-file-list--empty">
  142. <div class="upload-empty">暂无待上传文件,选择文件后将自动上传解析</div>
  143. </div>
  144. </aside>
  145. <section class="right-panel">
  146. <div class="panel-header">
  147. <div>
  148. <div class="panel-title">解析结果(实时)</div>
  149. <div class="panel-desc">每完成一份文件解析,结果树会实时追加到下方</div>
  150. </div>
  151. <div class="panel-header__actions">
  152. <Button size="small" :disabled="!expandableCount" @click="toggleExpandAllRows">
  153. {{ allExpanded ? '全部收起' : '全部展开' }}
  154. </Button>
  155. </div>
  156. <div class="panel-stats">已解析 {{ resultTrees.length }} 个文件</div>
  157. </div>
  158. <div class="table-wrapper">
  159. <Table
  160. class="result-tree-table"
  161. :columns="resultTableColumns"
  162. :data-source="tableDataSource"
  163. :loading="tableLoading"
  164. :pagination="false"
  165. row-key="id"
  166. :children-column-name="'children'"
  167. :expanded-row-keys="expandedRowKeys"
  168. size="small"
  169. :scroll="{ x: 840 }"
  170. @expandedRowsChange="onExpandedRowsChange"
  171. />
  172. </div>
  173. </section>
  174. </div>
  175. </div>
  176. </div>
  177. </template>
  178. <script lang="ts" setup name="ViewsDataUpload">
  179. import { computed, h, onMounted, ref } from 'vue';
  180. import { onBeforeRouteLeave } from 'vue-router';
  181. import { CloseOutlined, LeftOutlined } from '@ant-design/icons-vue';
  182. import { Button, Modal, Table, Tooltip, type TableColumnsType } from 'ant-design-vue';
  183. import { useDesign } from '@/core/hooks/web/useDesign';
  184. import { useGo, useQuery } from '@/core/hooks/web/usePage';
  185. import { PageEnum } from '@/core/enums/pageEnum';
  186. import { useMessage } from '@/core/hooks/web/useMessage';
  187. import { UPLOAD_FILE_ACCEPT, UPLOAD_FILE_SUFFIXES, UPLOAD_FILE_SUMMARY } from '@/core/constants/fileFormats';
  188. import { useEmitter } from '@/core/store/modules/case';
  189. import { clearUploadBatch, deletedFileList, preFileUpload, smartClean } from '@/case/api/govern/governApi';
  190. import { FileStatusEnum } from '@/case/types/enum';
  191. import CaseFlowTopBar from './components/CaseFlowTopBar.vue';
  192. import { resetImportProgressSession } from './importProgressSession';
  193. import type { FileInfo } from '@/types/api';
  194. const { prefixCls } = useDesign('case-upload');
  195. const go = useGo();
  196. const pageQuery = useQuery();
  197. const emitter = useEmitter();
  198. const { createMessage } = useMessage();
  199. const FILE_INFO_STORAGE_KEY = 'case_clean_file_infos';
  200. const IMPORT_FILE_INFO_STORAGE_KEY = 'case_clean_import_file_infos';
  201. const RECLEAN_CONTEXT_STORAGE_KEY = 'case_clean_reclean_context';
  202. const CASE_DATA_REFRESH_EVENT = 'case-data:refresh';
  203. type UploadMode = 'single' | 'folder';
  204. /** 进入上传页即生成批次 id,本页所有文件统一使用该批次(Long 型,上限约 1.7e18,安全) */
  205. const createUploadBatchId = () => Date.now() * 1000000 + Math.floor(Math.random() * 1000000);
  206. const uploadBatchId = ref(createUploadBatchId());
  207. const modeFromQuery = computed<UploadMode>(() => (pageQuery.value?.mode === 'folder' ? 'folder' : 'single'));
  208. const uploadMode = ref<UploadMode>(modeFromQuery.value);
  209. // 文件选择与上传状态(以 File 对象为键,上传成功移除文件时状态映射不会错乱)
  210. const fileInputRef = ref<HTMLInputElement | null>(null);
  211. const folderInputRef = ref<HTMLInputElement | null>(null);
  212. const selectedFiles = ref<File[]>([]);
  213. const uploadProgressMap = ref<Map<File, number>>(new Map());
  214. const uploadStatuses = ref<Map<File, 'pending' | 'uploading' | 'done' | 'error'>>(new Map());
  215. const isUploading = ref(false);
  216. const overallProgress = ref(0);
  217. const dragOver = ref(false);
  218. // 解析结果(右侧 treetable 数据源,实时追加)
  219. const resultTrees = ref<FileInfo[]>([]);
  220. const allFileInfos = ref<Recordable[]>([]);
  221. const tableLoading = ref(false);
  222. // 受控展开:默认全部展开,新解析的文件根节点自动展开
  223. // (键类型与 ant-design-vue Table 的 expandedRowKeys 保持一致:string | number)
  224. const expandedRowKeys = ref<(string | number)[]>([]);
  225. const expandableCount = computed(() => resultTrees.value.filter((root) => (root.children || []).length > 0).length);
  226. const allExpanded = computed(
  227. () => expandableCount.value > 0 && expandedRowKeys.value.length >= expandableCount.value,
  228. );
  229. const collectExpandableKeys = () =>
  230. resultTrees.value.filter((root) => (root.children || []).length > 0).map((root) => String(root.id ?? ''));
  231. const expandAllRows = () => {
  232. expandedRowKeys.value = collectExpandableKeys();
  233. };
  234. const toggleExpandAllRows = () => {
  235. expandedRowKeys.value = allExpanded.value ? [] : collectExpandableKeys();
  236. };
  237. // 用户手动展开/收起时同步受控 keys
  238. const onExpandedRowsChange = (keys: (string | number)[]) => {
  239. expandedRowKeys.value = keys;
  240. };
  241. // 表格数据源:递归剥离空 children。
  242. // 后端 FileInfo.children 恒为空数组(非 undefined),ant-design-vue 树形模式下
  243. // 只要 record.children 为真值就渲染展开图标,空数组也算,必须逐层剥掉
  244. const stripEmptyChildren = (node: Recordable): Recordable => {
  245. const children = node.children || [];
  246. if (!children.length) {
  247. return { ...node, children: undefined };
  248. }
  249. return { ...node, children: children.map(stripEmptyChildren) };
  250. };
  251. const tableDataSource = computed(() => resultTrees.value.map(stripEmptyChildren));
  252. // 离开放行标记:点「下一步」或已确认清理后的程序化跳转置为 true
  253. const allowedToLeave = ref(false);
  254. // 放弃标记:确认离开后中断上传循环,避免组件卸载后继续写结果
  255. const isAbandoned = ref(false);
  256. const batchIdReady = computed(() => !!uploadBatchId.value);
  257. const hasActivity = computed(
  258. () => isUploading.value || selectedFiles.value.length > 0 || resultTrees.value.length > 0,
  259. );
  260. /**
  261. * 是否存在可清洗的工作表(「智能」与「手动清洗」的可用条件)。
  262. *
  263. * 不能沿用 `resultTrees.length` —— 「无法读取」的失败节点(txt / md / doc / docx / pdf)
  264. * 也会进 resultTrees,但它没有 children(没有解析出任何 sheet)。
  265. * 若只按长度判断,用户传一个 docx 后「手动清洗」按钮会亮起,点进去却是一个空的手动清洗页。
  266. */
  267. const hasCleanableSheet = computed(() => resultTrees.value.some((root) => (root.children || []).length > 0));
  268. /** 「智能」是异步发起:请求本身要等后端建批次,按钮要给出进行中反馈 */
  269. const smartCleaning = ref(false);
  270. const formatFileSize = (bytes?: number | null) => {
  271. if (bytes == null || bytes === 0) return '0 B';
  272. const k = 1024;
  273. const sizes = ['B', 'KB', 'MB', 'GB'];
  274. const i = Math.floor(Math.log(bytes) / Math.log(k));
  275. return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i];
  276. };
  277. const handleDragOver = () => {
  278. dragOver.value = true;
  279. };
  280. const handleDragLeave = () => {
  281. dragOver.value = false;
  282. };
  283. const traverseDirectory = async (entry: FileSystemDirectoryEntry): Promise<File[]> => {
  284. const files: File[] = [];
  285. const reader = entry.createReader();
  286. const getEntries = (): Promise<FileSystemEntry[]> => new Promise((resolve) => reader.readEntries(resolve));
  287. let entries = await getEntries();
  288. while (entries.length) {
  289. for (const e of entries) {
  290. if (e.isFile) {
  291. const file = await new Promise<File>((resolve) => (e as FileSystemFileEntry).file(resolve));
  292. files.push(file);
  293. } else if (e.isDirectory) {
  294. files.push(...(await traverseDirectory(e as FileSystemDirectoryEntry)));
  295. }
  296. }
  297. entries = await getEntries();
  298. }
  299. return files;
  300. };
  301. /**
  302. * 递归收集拖拽内容。
  303. *
  304. * @return hasDirectory 表示拖拽内容里包含文件夹 —— 文件夹按「全部上传」处理,不做格式过滤
  305. */
  306. const collectFilesFromDataTransfer = async (
  307. items: DataTransferItemList,
  308. ): Promise<{ files: File[]; hasDirectory: boolean }> => {
  309. const files: File[] = [];
  310. let hasDirectory = false;
  311. for (let i = 0; i < items.length; i++) {
  312. const item = items[i];
  313. const entry = item.webkitGetAsEntry?.();
  314. if (!entry) {
  315. const file = item.getAsFile();
  316. if (file) files.push(file);
  317. continue;
  318. }
  319. if (entry.isFile) {
  320. const file = await new Promise<File>((resolve) => (entry as FileSystemFileEntry).file(resolve));
  321. files.push(file);
  322. } else if (entry.isDirectory) {
  323. hasDirectory = true;
  324. files.push(...(await traverseDirectory(entry as FileSystemDirectoryEntry)));
  325. }
  326. }
  327. return { files, hasDirectory };
  328. };
  329. /**
  330. * 加入待上传列表并自动开始上传。
  331. *
  332. * @param filterFormat true = 只保留全局支持格式(选择文件 / 拖拽单个文件);
  333. * false = 不过滤、全部上传(选择文件夹 / 拖拽文件夹)——
  334. * 不支持的格式由后端只登记一条记录并说明原因,不保存源文件
  335. */
  336. const addFiles = (files: File[], filterFormat = true) => {
  337. if (!files.length || isAbandoned.value) return;
  338. let accepted = files;
  339. if (filterFormat) {
  340. accepted = files.filter((file) => {
  341. const suffix = (file.name.split('.').pop() || '').toLowerCase();
  342. return UPLOAD_FILE_SUFFIXES.includes(suffix);
  343. });
  344. const skipped = files.length - accepted.length;
  345. if (skipped > 0) {
  346. createMessage.warning(`${skipped} 个文件格式不在支持清单内,已跳过`);
  347. }
  348. }
  349. if (!accepted.length) return;
  350. selectedFiles.value = [...selectedFiles.value, ...accepted];
  351. void startUpload();
  352. };
  353. const handleDrop = async (event: DragEvent) => {
  354. dragOver.value = false;
  355. if (!event.dataTransfer) return;
  356. const { files, hasDirectory } = await collectFilesFromDataTransfer(event.dataTransfer.items);
  357. // 拖文件夹 = 文件夹上传:全部上传,不按格式过滤
  358. addFiles(files, !hasDirectory);
  359. };
  360. const handleFileInputChange = (event: Event) => {
  361. const target = event.target as HTMLInputElement;
  362. if (!target.files?.length) return;
  363. addFiles(Array.from(target.files));
  364. target.value = '';
  365. };
  366. const handleFolderInputChange = (event: Event) => {
  367. const target = event.target as HTMLInputElement;
  368. if (!target.files?.length) return;
  369. const files = Array.from(target.files).filter((f) => f.webkitRelativePath);
  370. // 文件夹内全部上传:不支持的格式由后端登记记录并说明原因
  371. addFiles(files, false);
  372. target.value = '';
  373. };
  374. const handleTriggerFileSelect = () => {
  375. if (uploadMode.value === 'folder') {
  376. folderInputRef.value?.click();
  377. } else {
  378. fileInputRef.value?.click();
  379. }
  380. };
  381. const handleUploadModeChange = (mode: UploadMode) => {
  382. if (uploadMode.value === mode || isUploading.value) return;
  383. uploadMode.value = mode;
  384. clearSelectedFiles();
  385. };
  386. const clearSelectedFiles = () => {
  387. selectedFiles.value = [];
  388. uploadProgressMap.value = new Map();
  389. uploadStatuses.value = new Map();
  390. overallProgress.value = 0;
  391. };
  392. /** 移除单个待上传文件(上传解析中不允许移除) */
  393. const removeSelectedFile = (target: File) => {
  394. if (isUploading.value) return;
  395. const index = selectedFiles.value.indexOf(target);
  396. if (index === -1) return;
  397. // 仅允许移除待上传文件
  398. if ((uploadStatuses.value.get(target) || 'pending') !== 'pending') {
  399. return;
  400. }
  401. selectedFiles.value.splice(index, 1);
  402. uploadProgressMap.value.delete(target);
  403. uploadStatuses.value.delete(target);
  404. if (!selectedFiles.value.length) {
  405. overallProgress.value = 0;
  406. }
  407. };
  408. const persistFileInfos = (infos: Recordable[]) => {
  409. sessionStorage.setItem(FILE_INFO_STORAGE_KEY, JSON.stringify(infos));
  410. };
  411. /**
  412. * 从 storage 恢复已解析结果(从清洗页返回时右侧表格还原)
  413. * 同时把批次号恢复为原批次,保证后续上传/删除/清理与原批次数据一致
  414. */
  415. const restoreParsedResults = () => {
  416. try {
  417. const raw = sessionStorage.getItem(FILE_INFO_STORAGE_KEY);
  418. if (!raw) return;
  419. const parsed = JSON.parse(raw);
  420. if (!Array.isArray(parsed) || !parsed.length) return;
  421. allFileInfos.value = parsed;
  422. resultTrees.value = parsed;
  423. // 恢复后默认全部展开
  424. expandAllRows();
  425. const storedBatchId = parsed[0]?.batchId;
  426. if (storedBatchId !== null && storedBatchId !== undefined && String(storedBatchId).trim() !== '') {
  427. uploadBatchId.value = storedBatchId as number;
  428. }
  429. } catch {
  430. // 无效缓存忽略,保持新批次
  431. }
  432. };
  433. onMounted(() => {
  434. restoreParsedResults();
  435. });
  436. const isOwnBatchStorage = () => {
  437. const raw = sessionStorage.getItem(FILE_INFO_STORAGE_KEY);
  438. if (!raw) return true;
  439. try {
  440. const parsed = JSON.parse(raw);
  441. if (!Array.isArray(parsed) || !parsed.length) return true;
  442. return parsed.every((item) => String(item?.batchId ?? '') === String(uploadBatchId.value));
  443. } catch {
  444. return true;
  445. }
  446. };
  447. const clearStoredFileInfos = () => {
  448. if (isOwnBatchStorage()) {
  449. sessionStorage.removeItem(FILE_INFO_STORAGE_KEY);
  450. }
  451. };
  452. /**
  453. * 离开上传页时清空本流程的 sessionStorage 缓存,避免上一批已上传文件被后续流程复用:
  454. * - case_clean_file_infos 已上传文件的解析结果(右侧表格数据源)
  455. * - case_clean_import_file_infos 手动清洗页提交给清洗进度页的导入文件列表
  456. * - case_clean_reclean_context 重新清洗上下文(reClean=1 + fileId)
  457. * - case_clean_import_progress 清洗进度快照,连同运行时状态与 SSE 连接一起重置
  458. */
  459. const clearCleanFlowSessionCache = () => {
  460. clearStoredFileInfos();
  461. sessionStorage.removeItem(IMPORT_FILE_INFO_STORAGE_KEY);
  462. sessionStorage.removeItem(RECLEAN_CONTEXT_STORAGE_KEY);
  463. resetImportProgressSession();
  464. };
  465. /**
  466. * 自动上传队列:选择文件后自动触发,按序消费列表中的待上传文件;
  467. * 上传解析成功即从列表移除,失败保留(标记错误,可手动移除)。
  468. */
  469. const startUpload = async () => {
  470. if (isUploading.value || !batchIdReady.value) return;
  471. const currentBatchId = uploadBatchId.value;
  472. isUploading.value = true;
  473. isAbandoned.value = false;
  474. tableLoading.value = true;
  475. try {
  476. while (true) {
  477. if (isAbandoned.value) break;
  478. // 取当前第一个待上传文件
  479. const index = selectedFiles.value.findIndex((f) => (uploadStatuses.value.get(f) || 'pending') === 'pending');
  480. if (index === -1) break;
  481. const file = selectedFiles.value[index];
  482. uploadStatuses.value.set(file, 'uploading');
  483. const onProgress = (percent: number) => {
  484. uploadProgressMap.value.set(file, percent);
  485. // 总进度:全量待处理文件按(pending=0 / uploading=进度 / error=100)取平均
  486. const list = selectedFiles.value;
  487. const total = list.length || 1;
  488. const sum = list.reduce((acc, f) => {
  489. const st = uploadStatuses.value.get(f);
  490. if (st === 'uploading') return acc + (uploadProgressMap.value.get(f) || 0);
  491. if (st === 'error') return acc + 100;
  492. return acc;
  493. }, 0);
  494. overallProgress.value = Math.round(sum / total);
  495. };
  496. try {
  497. // defHttp.uploadFile 返回原始 AxiosResponse,业务数据在 res.data.data;
  498. // 非 200 的业务错误(如 MD5 重复)在 res.data.message 里,交给 catch 统一提示
  499. const res = await preFileUpload(file, onProgress, { batchId: currentBatchId });
  500. if (isAbandoned.value) break;
  501. // errorMessageMode=none 时网络异常会被响应拦截器 resolve 成空值,这里兜底
  502. if (!res?.data) {
  503. throw new Error('网络异常或服务不可用');
  504. }
  505. if (Number(res.data.code) !== 200) {
  506. throw new Error(res.data.message || '上传失败');
  507. }
  508. const fileNode: FileInfo | null = res?.data?.data ?? null;
  509. if (fileNode) {
  510. // 右侧 treetable 直接渲染树(文件根 → sheet 子节点)
  511. resultTrees.value = [...resultTrees.value, fileNode];
  512. // 新文件根自动展开(受控展开,默认全部展开)
  513. if ((fileNode.children || []).length > 0) {
  514. expandedRowKeys.value = [...expandedRowKeys.value, String(fileNode.id ?? '')];
  515. }
  516. // 持久化给 match/清洗流程的数据按后端返回的树结构存储(文件根 + children sheet)
  517. allFileInfos.value = [...allFileInfos.value, fileNode];
  518. persistFileInfos(allFileInfos.value);
  519. }
  520. // 上传成功:从列表移除该文件
  521. uploadProgressMap.value.delete(file);
  522. uploadStatuses.value.delete(file);
  523. const idx = selectedFiles.value.indexOf(file);
  524. if (idx !== -1) {
  525. selectedFiles.value.splice(idx, 1);
  526. }
  527. onProgress(100);
  528. } catch (error: any) {
  529. // 失败保留在列表,标记错误供用户查看/移除
  530. uploadStatuses.value.set(file, 'error');
  531. uploadProgressMap.value.set(file, 100);
  532. createMessage.error(`「${file.name}」上传失败:${error?.message || '未知错误'}`);
  533. }
  534. }
  535. overallProgress.value = 100;
  536. // 只有解析出工作表(children)的才算真正解析成功;「未解析」的节点也占一个 resultTrees 名额,
  537. // 若直接按长度提示「成功解析 N 个文件」,对用户就是假消息。
  538. const parsedCount = resultTrees.value.filter((root) => (root.children || []).length > 0).length;
  539. const unreadable = resultTrees.value.filter((root) => !(root.children || []).length);
  540. const unreadableCount = unreadable.length;
  541. // 保留了原件的(文档/图片/音视频)可以下载、可以在对话中 @ 引用;
  542. // 不在支持清单里的只登记一条记录、不保存源文件(文件夹上传会走到这一类)
  543. const retainedCount = unreadable.filter((root) => !!root.filePath).length;
  544. const registeredOnlyCount = unreadableCount - retainedCount;
  545. const detail = [
  546. retainedCount ? `${retainedCount} 个已保留原件,可在对话中 @ 引用` : '',
  547. registeredOnlyCount ? `${registeredOnlyCount} 个格式不支持,仅登记、未保存源文件` : '',
  548. ]
  549. .filter(Boolean)
  550. .join(';');
  551. const unreadableHint = detail ? `(其中 ${detail})` : '';
  552. if (!isAbandoned.value && parsedCount) {
  553. createMessage.success(
  554. unreadableCount
  555. ? `成功解析 ${parsedCount} 个文件;另有 ${unreadableCount} 个文件未解析${unreadableHint},已在右侧列表标出`
  556. : `成功解析 ${parsedCount} 个文件,可在右侧查看结果`,
  557. );
  558. } else if (!isAbandoned.value && unreadableCount) {
  559. createMessage.warning(`${unreadableCount} 个文件未解析${unreadableHint},见右侧列表`);
  560. } else if (!isAbandoned.value && !selectedFiles.value.length) {
  561. createMessage.warning('未识别到可处理文件,请检查文件格式是否正确');
  562. }
  563. } catch (error) {
  564. createMessage.error('上传解析过程中发生错误');
  565. } finally {
  566. isUploading.value = false;
  567. tableLoading.value = false;
  568. }
  569. };
  570. /** 文件/工作表状态 → 中文标签(与 importList、cleaning 页保持一致) */
  571. const fileStatusLabelMap = Object.entries(FileStatusEnum).reduce<Record<string, string>>((map, [key, label]) => {
  572. map[key] = label;
  573. return map;
  574. }, {});
  575. /** 读取/处理成功,可进入匹配、清洗流程的状态 */
  576. const SUCCESS_FILE_STATUSES = new Set<string>([
  577. 'FILE_READ_COMPLETE',
  578. 'SHEET_TEMPLATE_MATCHED_SUCCESS',
  579. 'FILE_CLEAN_COMPLETE',
  580. 'FILE_GOVERN_COMPLETE',
  581. ]);
  582. /** 明确失败的状态(加密文件等中性状态不算失败) */
  583. const FAIL_FILE_STATUSES = new Set<string>([
  584. 'FILE_READ_FAIL',
  585. 'FILE_UNSUPPORTED_FAIL',
  586. 'SHEET_READ_FAIL',
  587. 'SHEET_TEMPLATE_MATCHED_FAIL',
  588. ]);
  589. const isSuccessStatus = (status?: string | null) => {
  590. const normalized = String(status || '').trim();
  591. return !!normalized && SUCCESS_FILE_STATUSES.has(normalized);
  592. };
  593. const mapStatus = (status?: string) => {
  594. const normalized = String(status || '').trim();
  595. if (!normalized) return { success: false, fail: false, label: '待处理' };
  596. return {
  597. success: SUCCESS_FILE_STATUSES.has(normalized),
  598. fail: FAIL_FILE_STATUSES.has(normalized),
  599. label: fileStatusLabelMap[normalized] || normalized,
  600. };
  601. };
  602. const isRootNode = (record: Recordable) => !record.pid || Number(record.pid) === 0;
  603. const resultTableColumns: TableColumnsType<Recordable> = [
  604. {
  605. title: '名称',
  606. key: 'name',
  607. width: 360,
  608. ellipsis: true,
  609. customRender: ({ record }: any) => {
  610. const root = isRootNode(record);
  611. const name = root ? record.fileName || '未命名文件' : record.sheetName || record.tableName || '未命名工作表';
  612. const extra = root && record.fileType ? ` · ${record.fileType}` : '';
  613. return h('span', { class: ['cell-name', { 'is-child': !root }] }, [name + extra]);
  614. },
  615. },
  616. {
  617. title: '大小',
  618. key: 'fileSize',
  619. width: 110,
  620. customRender: ({ record }: any) => (isRootNode(record) ? formatFileSize(record.fileSize) : '—'),
  621. },
  622. {
  623. title: '数据量',
  624. key: 'dataNum',
  625. width: 90,
  626. customRender: ({ record }: any) => record.dataNum ?? '—',
  627. },
  628. {
  629. title: '状态',
  630. key: 'status',
  631. width: 130,
  632. customRender: ({ record }: any) => {
  633. const mapped = mapStatus(record.fileStatus);
  634. const cls = mapped.success ? 'is-success' : mapped.fail ? 'is-fail' : 'is-other';
  635. // 未解析的文件悬停可看原因:保留原件的说可下载/可 @ 引用,未落盘的说仅登记
  636. return h('span', { class: ['status-tag', cls], title: record.unsupportedReason || undefined }, [mapped.label]);
  637. },
  638. },
  639. {
  640. title: '操作',
  641. key: 'action',
  642. width: 150,
  643. customRender: ({ record }: any) => {
  644. // 文件根行:删除整个文件(级联全部工作表)
  645. if (isRootNode(record)) {
  646. return h('div', { class: 'cell-actions' }, [
  647. h(
  648. Button,
  649. {
  650. type: 'link',
  651. size: 'small',
  652. class: 'action-link is-danger',
  653. disabled: isUploading.value,
  654. onClick: () => handleRowDelete(record),
  655. },
  656. () => '删除',
  657. ),
  658. ]);
  659. }
  660. // 工作表行:手动清洗 + 删除
  661. return h('div', { class: 'cell-actions' }, [
  662. h(
  663. Button,
  664. {
  665. type: 'link',
  666. size: 'small',
  667. class: 'action-link',
  668. disabled: isUploading.value,
  669. onClick: () => handleRowManualClean(record),
  670. },
  671. () => '手动清洗',
  672. ),
  673. h(
  674. Button,
  675. {
  676. type: 'link',
  677. size: 'small',
  678. class: 'action-link is-danger',
  679. disabled: isUploading.value,
  680. onClick: () => handleRowDelete(record),
  681. },
  682. () => '删除',
  683. ),
  684. ]);
  685. },
  686. },
  687. ];
  688. const cleanupAndLeave = async () => {
  689. isAbandoned.value = true;
  690. allowedToLeave.value = true;
  691. try {
  692. await clearUploadBatch({ batchId: uploadBatchId.value });
  693. } catch (error: any) {
  694. createMessage.warning(error?.message || '清理本批次数据失败,可稍后在导入文件管理中删除');
  695. } finally {
  696. clearCleanFlowSessionCache();
  697. await go(PageEnum.BASE_HOME, true);
  698. emitter.emit(CASE_DATA_REFRESH_EVENT);
  699. }
  700. };
  701. const handleBack = () => {
  702. if (!hasActivity.value) {
  703. allowedToLeave.value = true;
  704. // 返回案件数据:清空已上传文件与清洗流程缓存,避免下次进入上传页还原上一批文件
  705. clearCleanFlowSessionCache();
  706. go(PageEnum.BASE_HOME, true);
  707. emitter.emit(CASE_DATA_REFRESH_EVENT);
  708. return;
  709. }
  710. Modal.confirm({
  711. title: isUploading.value ? '上传解析进行中' : '存在未处理文件',
  712. content: isUploading.value
  713. ? '当前仍有文件在上传解析,离开将中断本次上传,并清理本批次已上传文件与解析结果,是否继续?'
  714. : '离开将清理本批次已上传文件与解析结果(未进入清洗流程),是否继续?',
  715. okText: '离开并清理',
  716. cancelText: '留在本页',
  717. onOk: cleanupAndLeave,
  718. });
  719. };
  720. /**
  721. * 智能清洗:一次请求跑完「既有模板清洗 + 未匹配文件的 AI 清洗」,跳到进度页看两路结果。
  722. *
  723. * 可用条件是 hasCleanableSheet 而不是 hasSuccessResult:模板匹配失败的那批文件正是 AI 要接的活,
  724. * 按「有成功文件」判断等于在最需要这个按钮的场景里把它锁死。
  725. *
  726. * 接口立即返回 batchId(后台异步跑),所以要把 fileInfos 先写进 sessionStorage:
  727. * 进度页读它来展示文件与批次。发起失败时留在本页、不清缓存,用户可重试或转手动清洗。
  728. */
  729. const handleSmartClean = async () => {
  730. if (!hasCleanableSheet.value || smartCleaning.value) return;
  731. smartCleaning.value = true;
  732. try {
  733. const fileInfos = allFileInfos.value as unknown as FileInfo[];
  734. persistFileInfos(allFileInfos.value);
  735. const res = await smartClean({ fileInfos, reClean: 0 });
  736. if (!res?.batchId) {
  737. throw new Error('后端未返回批次号');
  738. }
  739. allowedToLeave.value = true;
  740. resetImportProgressSession();
  741. go({
  742. path: PageEnum.BASE_CLEAN_PROGRESS,
  743. query: { fused: '1', batchId: String(res.batchId) },
  744. });
  745. } catch (error: any) {
  746. createMessage.error(error?.message || '智能清洗发起失败,可改用手动清洗');
  747. } finally {
  748. smartCleaning.value = false;
  749. }
  750. };
  751. /** 手动清洗:进入手动清洗页逐个处理(含模板匹配失败的表) */
  752. const handleManualClean = () => {
  753. if (!hasCleanableSheet.value) return;
  754. allowedToLeave.value = true;
  755. go({ path: PageEnum.BASE_CLEANING });
  756. };
  757. /** 行级手动清洗:定位到指定工作表进入手动清洗页 */
  758. const handleRowManualClean = (record: Recordable) => {
  759. const focusKey = String(record.id ?? '').trim();
  760. if (!focusKey) {
  761. createMessage.warning('未获取到工作表ID,暂时无法手动清洗');
  762. return;
  763. }
  764. allowedToLeave.value = true;
  765. go({ path: PageEnum.BASE_CLEANING, query: { focusKey } });
  766. };
  767. /** 本地移除整个文件节点并同步 sessionStorage */
  768. const removeFileNodeSync = (rootId: string) => {
  769. resultTrees.value = resultTrees.value.filter((item) => String(item.id ?? '') !== rootId);
  770. allFileInfos.value = allFileInfos.value.filter((item) => String(item.id ?? '') !== rootId);
  771. // 同步移除已删除文件根的展开状态
  772. expandedRowKeys.value = expandedRowKeys.value.filter((key) => String(key) !== rootId);
  773. persistFileInfos(allFileInfos.value);
  774. };
  775. /** 本地移除单个工作表节点并同步 sessionStorage */
  776. const removeSheetNodeSync = (rootId: string, sheetId: string) => {
  777. const stripSheet = (item: Recordable) =>
  778. String(item.id ?? '') === rootId
  779. ? {
  780. ...item,
  781. children: (item.children || []).filter((child) => String(child.id ?? '') !== sheetId),
  782. }
  783. : item;
  784. resultTrees.value = resultTrees.value.map(stripSheet);
  785. allFileInfos.value = allFileInfos.value.map(stripSheet);
  786. persistFileInfos(allFileInfos.value);
  787. };
  788. /** 行级删除:文件根行删除整个文件(级联全部工作表),工作表行删除单个工作表(仅剩此表时连同文件根) */
  789. const handleRowDelete = (record: Recordable) => {
  790. // 文件根行:整文件删除
  791. if (isRootNode(record)) {
  792. const fileRootId = String(record.id ?? '').trim();
  793. const fileName = record.fileName || '未命名文件';
  794. if (!fileRootId) {
  795. createMessage.warning('未获取到文件ID,暂时无法删除');
  796. return;
  797. }
  798. Modal.confirm({
  799. title: '删除确认',
  800. content: `确定删除文件「${fileName}」及其全部工作表吗?`,
  801. okText: '删除',
  802. okType: 'primary',
  803. okButtonProps: { danger: true },
  804. cancelText: '取消',
  805. onOk: async () => {
  806. try {
  807. // 后端按 id 级联删除(id 匹配 + pid 匹配),传根 id 即删整文件
  808. await deletedFileList({ ids: [fileRootId] });
  809. removeFileNodeSync(fileRootId);
  810. createMessage.success('删除成功');
  811. } catch (error: any) {
  812. createMessage.error(error?.message || '删除失败');
  813. }
  814. },
  815. });
  816. return;
  817. }
  818. // 工作表行:单表删除(该文件仅剩此表时连同文件根一起删除)
  819. const rootId = String(record.pid ?? '').trim();
  820. const root = resultTrees.value.find((item) => String(item.id ?? '') === rootId);
  821. const siblings = root?.children || [];
  822. const isLastSheet = siblings.length <= 1;
  823. const sheetId = String(record.id ?? '').trim();
  824. const sheetName = record.sheetName || '未命名工作表';
  825. const fileName = root?.fileName || '未命名文件';
  826. Modal.confirm({
  827. title: '删除确认',
  828. content: isLastSheet
  829. ? `「${fileName}」仅剩此工作表,删除后将移除整个文件,是否继续?`
  830. : `确定删除工作表「${sheetName}」吗?`,
  831. okText: '删除',
  832. okType: 'primary',
  833. okButtonProps: { danger: true },
  834. cancelText: '取消',
  835. onOk: async () => {
  836. try {
  837. // 后端按 id 级联删除(id 匹配 + pid 匹配):仅剩此表时传根 id 删整文件,否则传 sheet id 删单表
  838. const deleteIds = isLastSheet && root ? [String(root.id ?? '')] : [sheetId];
  839. const validIds = deleteIds.filter(Boolean);
  840. if (!validIds.length) {
  841. createMessage.warning('未获取到ID,暂时无法删除');
  842. return;
  843. }
  844. await deletedFileList({ ids: validIds });
  845. if (isLastSheet) {
  846. removeFileNodeSync(rootId);
  847. } else {
  848. removeSheetNodeSync(rootId, sheetId);
  849. }
  850. createMessage.success('删除成功');
  851. } catch (error: any) {
  852. createMessage.error(error?.message || '删除失败');
  853. }
  854. },
  855. });
  856. };
  857. // 兜底浏览器返回 / 标签页关闭等非按钮离开
  858. onBeforeRouteLeave((to, _from, next) => {
  859. if (allowedToLeave.value || !hasActivity.value) {
  860. // 进入清洗流程(清洗页 / 清洗进度页)时保留缓存,供下游页面读取;
  861. // 其余离开上传页的场景(返回案件数据、切菜单等)一律清空已上传文件与清洗流程缓存
  862. const toPath = String(to?.path ?? '');
  863. if (toPath !== PageEnum.BASE_CLEANING && toPath !== PageEnum.BASE_CLEAN_PROGRESS) {
  864. clearCleanFlowSessionCache();
  865. }
  866. next();
  867. return;
  868. }
  869. Modal.confirm({
  870. title: isUploading.value ? '上传解析进行中' : '存在未处理文件',
  871. content: '离开将清理本批次已上传文件与解析结果(未进入清洗流程),是否继续?',
  872. okText: '离开并清理',
  873. cancelText: '留在本页',
  874. onOk: cleanupAndLeave,
  875. });
  876. next(false);
  877. });
  878. </script>
  879. <style lang="less">
  880. @prefix-cls: ~'jeesite-case-upload';
  881. .@{prefix-cls}.case-upload-page {
  882. width: 100%;
  883. height: 100vh;
  884. background: #f0f2f5;
  885. display: flex;
  886. flex-direction: column;
  887. box-sizing: border-box;
  888. overflow: hidden;
  889. // 公共顶栏由 AppTopBar 自带高度,内容区在剩余高度里滚动
  890. .page-body {
  891. flex: 1 1 auto;
  892. min-height: 0;
  893. padding: 8px 12px;
  894. display: flex;
  895. flex-direction: column;
  896. gap: 8px;
  897. box-sizing: border-box;
  898. overflow: hidden;
  899. }
  900. .page-header {
  901. flex-shrink: 0;
  902. display: flex;
  903. align-items: center;
  904. justify-content: space-between;
  905. gap: 16px;
  906. padding: 10px 14px;
  907. border: 1px solid #e2e8f0;
  908. border-radius: 10px;
  909. background: #fff;
  910. box-shadow: 0 1px 2px rgba(15, 23, 42, 0.03);
  911. }
  912. .page-header__left {
  913. display: flex;
  914. align-items: center;
  915. gap: 12px;
  916. min-width: 0;
  917. }
  918. .page-header__divider {
  919. flex: 0 0 auto;
  920. width: 1px;
  921. height: 22px;
  922. background: #e2e8f0;
  923. }
  924. .back-btn {
  925. display: inline-flex;
  926. align-items: center;
  927. justify-content: center;
  928. flex: 0 0 auto;
  929. width: 32px;
  930. height: 32px;
  931. padding: 0;
  932. border: 1px solid #e2e8f0;
  933. border-radius: 8px;
  934. background: #f8fafc;
  935. color: #475569;
  936. font-size: 14px;
  937. line-height: 1;
  938. cursor: pointer;
  939. transition:
  940. color 0.2s ease,
  941. border-color 0.2s ease,
  942. background-color 0.2s ease;
  943. &:hover,
  944. &:focus,
  945. &:focus-visible {
  946. color: #2563eb;
  947. border-color: #bfdbfe;
  948. background: #eff6ff;
  949. outline: none;
  950. }
  951. }
  952. .page-title-block {
  953. min-width: 0;
  954. overflow: hidden;
  955. }
  956. .page-title {
  957. font-size: 16px;
  958. line-height: 1.4;
  959. font-weight: 600;
  960. color: #111827;
  961. }
  962. .page-subtitle {
  963. margin-top: 1px;
  964. overflow: hidden;
  965. font-size: 12px;
  966. line-height: 1.6;
  967. color: #64748b;
  968. white-space: nowrap;
  969. text-overflow: ellipsis;
  970. }
  971. .page-header__actions {
  972. display: flex;
  973. align-items: center;
  974. gap: 8px;
  975. flex-shrink: 0;
  976. }
  977. .next-btn {
  978. height: 32px;
  979. padding: 0 16px;
  980. border-radius: 8px;
  981. font-weight: 500;
  982. }
  983. .upload-layout {
  984. flex: 1 1 auto;
  985. min-height: 0;
  986. display: flex;
  987. gap: 8px;
  988. align-items: stretch;
  989. }
  990. .left-panel,
  991. .right-panel {
  992. border: 1px solid #e2e8f0;
  993. border-radius: 10px;
  994. background: #fff;
  995. overflow: hidden;
  996. }
  997. .left-panel {
  998. flex: 0 0 460px;
  999. display: flex;
  1000. flex-direction: column;
  1001. gap: 10px;
  1002. padding: 12px;
  1003. box-sizing: border-box;
  1004. overflow-y: auto;
  1005. }
  1006. .right-panel {
  1007. flex: 1 1 auto;
  1008. min-width: 0;
  1009. display: flex;
  1010. flex-direction: column;
  1011. }
  1012. .panel-header {
  1013. flex-shrink: 0;
  1014. display: flex;
  1015. align-items: center;
  1016. justify-content: space-between;
  1017. gap: 12px;
  1018. padding: 10px 14px 8px;
  1019. border-bottom: 1px solid #eef2f7;
  1020. }
  1021. .panel-title {
  1022. position: relative;
  1023. padding-left: 11px;
  1024. font-size: 15px;
  1025. font-weight: 600;
  1026. line-height: 22px;
  1027. color: #111827;
  1028. // 与「持续连续(连续研判)」页的卡片标题一致:左侧 3px 蓝色竖条
  1029. &::before {
  1030. content: '';
  1031. position: absolute;
  1032. top: 4px;
  1033. bottom: 4px;
  1034. left: 0;
  1035. width: 3px;
  1036. border-radius: 2px;
  1037. background: #2a50ec;
  1038. }
  1039. }
  1040. .panel-desc {
  1041. margin-top: 2px;
  1042. font-size: 12px;
  1043. color: #6b7280;
  1044. line-height: 1.5;
  1045. }
  1046. .panel-header__actions {
  1047. display: flex;
  1048. align-items: center;
  1049. gap: 8px;
  1050. margin-left: auto;
  1051. }
  1052. .panel-stats {
  1053. font-size: 12px;
  1054. color: #64748b;
  1055. white-space: nowrap;
  1056. }
  1057. .table-wrapper {
  1058. flex: 1 1 auto;
  1059. min-height: 0;
  1060. padding: 2px 10px 10px;
  1061. overflow: auto;
  1062. }
  1063. .result-tree-table {
  1064. .ant-table-thead > tr > th {
  1065. padding: 6px 8px;
  1066. font-size: 12px;
  1067. font-weight: 600;
  1068. color: #6b7280;
  1069. background: #fafbfc;
  1070. border-bottom: 1px solid #eef2f7;
  1071. }
  1072. .ant-table-tbody > tr > td {
  1073. padding: 6px 8px;
  1074. font-size: 13px;
  1075. border-bottom: 1px solid #f6f8fa;
  1076. }
  1077. .ant-table-tbody > tr:hover > td {
  1078. background: #f8fafc;
  1079. }
  1080. .ant-table-row-expand-icon {
  1081. margin-right: 6px;
  1082. border-radius: 3px;
  1083. }
  1084. /* 无子集的行:隐藏展开占位图标(样式块非 scoped,直接用普通选择器) */
  1085. .ant-table-row-expand-icon-spaced {
  1086. display: none;
  1087. }
  1088. }
  1089. .cell-name {
  1090. color: #1e293b;
  1091. font-size: 13px;
  1092. &.is-child {
  1093. color: #475569;
  1094. }
  1095. }
  1096. .cell-actions {
  1097. display: inline-flex;
  1098. align-items: center;
  1099. gap: 2px;
  1100. .action-link {
  1101. padding: 0 4px;
  1102. height: 24px;
  1103. font-size: 12px;
  1104. color: #2563eb;
  1105. &:hover {
  1106. color: #1d4ed8;
  1107. }
  1108. &.is-danger {
  1109. color: #dc2626;
  1110. &:hover {
  1111. color: #b91c1c;
  1112. }
  1113. }
  1114. }
  1115. }
  1116. .status-tag {
  1117. display: inline-flex;
  1118. align-items: center;
  1119. padding: 2px 10px;
  1120. border-radius: 999px;
  1121. font-size: 12px;
  1122. font-weight: 600;
  1123. white-space: nowrap;
  1124. &.is-success {
  1125. background: #ecfdf3;
  1126. color: #15803d;
  1127. }
  1128. &.is-fail {
  1129. background: #fef2f2;
  1130. color: #dc2626;
  1131. }
  1132. &.is-other {
  1133. background: #f1f5f9;
  1134. color: #64748b;
  1135. }
  1136. }
  1137. .upload-picker {
  1138. flex: 0 0 auto;
  1139. display: flex;
  1140. justify-content: center;
  1141. }
  1142. .upload-mode-switch {
  1143. display: inline-flex;
  1144. align-items: center;
  1145. gap: 4px;
  1146. width: fit-content;
  1147. padding: 3px;
  1148. border-radius: 8px;
  1149. background: #f1f5f9;
  1150. border: 1px solid #e2e8f0;
  1151. }
  1152. .upload-mode-switch__item {
  1153. min-width: 92px;
  1154. height: 28px;
  1155. padding: 0 12px;
  1156. border: none;
  1157. border-radius: 6px;
  1158. background: transparent;
  1159. color: #64748b;
  1160. font-size: 12px;
  1161. font-weight: 600;
  1162. cursor: pointer;
  1163. transition:
  1164. background-color 0.2s ease,
  1165. color 0.2s ease;
  1166. &.is-active {
  1167. background: #2563eb;
  1168. color: #fff;
  1169. }
  1170. &:disabled {
  1171. cursor: not-allowed;
  1172. opacity: 0.6;
  1173. }
  1174. }
  1175. .upload-dropzone {
  1176. flex: 0 0 auto;
  1177. min-height: 96px;
  1178. border-radius: 8px;
  1179. /* 2px 虚线:1px 虚线在顶部处于小数像素位置(y≈179.578)时,
  1180. Chrome 会把整段顶部边框舍弃不渲染,表现为顶部边框消失 */
  1181. border: 2px dashed #cbd5e1;
  1182. background: #fafbfc;
  1183. transition: all 0.2s ease;
  1184. cursor: pointer;
  1185. &:hover,
  1186. &.is-dragover {
  1187. border-color: #3b82f6;
  1188. }
  1189. }
  1190. .upload-dragger-content {
  1191. display: flex;
  1192. flex-direction: column;
  1193. align-items: center;
  1194. justify-content: center;
  1195. gap: 4px;
  1196. padding: 12px 0;
  1197. color: #475569;
  1198. }
  1199. .upload-dragger-icon {
  1200. width: 28px;
  1201. height: 28px;
  1202. border-radius: 8px;
  1203. background: rgba(59, 130, 246, 0.1);
  1204. color: #2563eb;
  1205. display: flex;
  1206. align-items: center;
  1207. justify-content: center;
  1208. font-size: 14px;
  1209. }
  1210. .upload-dragger-title {
  1211. font-size: 13px;
  1212. font-weight: 600;
  1213. color: #334155;
  1214. }
  1215. .upload-dragger-desc {
  1216. font-size: 12px;
  1217. color: #64748b;
  1218. max-width: 420px;
  1219. text-align: center;
  1220. }
  1221. .upload-action-btn {
  1222. margin-top: 2px;
  1223. height: 26px;
  1224. padding: 0 14px;
  1225. border-radius: 6px;
  1226. }
  1227. .upload-file-list {
  1228. flex: 1 1 auto;
  1229. min-height: 0;
  1230. display: flex;
  1231. flex-direction: column;
  1232. border: 1px solid #e2e8f0;
  1233. border-radius: 12px;
  1234. background: #ffffff;
  1235. overflow: hidden;
  1236. &__header {
  1237. flex-shrink: 0;
  1238. display: flex;
  1239. align-items: center;
  1240. justify-content: space-between;
  1241. padding: 8px 12px;
  1242. background: #f8fafc;
  1243. border-bottom: 1px solid #e2e8f0;
  1244. font-size: 13px;
  1245. color: #475569;
  1246. font-weight: 500;
  1247. }
  1248. &__body {
  1249. flex: 1 1 auto;
  1250. min-height: 0;
  1251. overflow-y: auto;
  1252. padding: 4px 0;
  1253. }
  1254. &--empty {
  1255. flex: 1 1 auto;
  1256. border-style: dashed;
  1257. background: #fafafa;
  1258. }
  1259. }
  1260. .upload-empty {
  1261. margin: auto;
  1262. padding: 24px 12px;
  1263. color: #9ca3af;
  1264. font-size: 13px;
  1265. text-align: center;
  1266. }
  1267. .upload-file-item {
  1268. display: flex;
  1269. align-items: center;
  1270. justify-content: space-between;
  1271. padding: 6px 12px;
  1272. gap: 12px;
  1273. transition: background 0.15s ease;
  1274. &:hover {
  1275. background: #f8fafc;
  1276. }
  1277. &__info {
  1278. display: flex;
  1279. align-items: center;
  1280. gap: 10px;
  1281. min-width: 0;
  1282. flex: 1;
  1283. }
  1284. &__name {
  1285. font-size: 13px;
  1286. color: #1e293b;
  1287. white-space: nowrap;
  1288. overflow: hidden;
  1289. text-overflow: ellipsis;
  1290. max-width: 300px;
  1291. }
  1292. &__size {
  1293. font-size: 12px;
  1294. color: #94a3b8;
  1295. flex-shrink: 0;
  1296. }
  1297. &__status {
  1298. flex-shrink: 0;
  1299. font-size: 12px;
  1300. min-width: 48px;
  1301. text-align: right;
  1302. }
  1303. &__remove {
  1304. flex-shrink: 0;
  1305. display: inline-flex;
  1306. align-items: center;
  1307. justify-content: center;
  1308. width: 22px;
  1309. height: 22px;
  1310. padding: 0;
  1311. border: none;
  1312. border-radius: 6px;
  1313. background: transparent;
  1314. color: #9ca3af;
  1315. font-size: 11px;
  1316. cursor: pointer;
  1317. transition:
  1318. background-color 0.15s ease,
  1319. color 0.15s ease;
  1320. &:hover {
  1321. background: #fef2f2;
  1322. color: #dc2626;
  1323. }
  1324. }
  1325. &__error {
  1326. color: #dc2626;
  1327. font-weight: 600;
  1328. }
  1329. &__progress-text {
  1330. color: #2563eb;
  1331. font-weight: 500;
  1332. }
  1333. &__pending {
  1334. color: #94a3b8;
  1335. }
  1336. }
  1337. .upload-overall-progress {
  1338. flex-shrink: 0;
  1339. display: flex;
  1340. align-items: center;
  1341. gap: 10px;
  1342. padding: 8px 12px;
  1343. border-top: 1px solid #e2e8f0;
  1344. &__bar {
  1345. flex: 1;
  1346. height: 5px;
  1347. border-radius: 3px;
  1348. background: #e2e8f0;
  1349. overflow: hidden;
  1350. }
  1351. &__fill {
  1352. height: 100%;
  1353. border-radius: 3px;
  1354. background: #2563eb;
  1355. transition: width 0.3s ease;
  1356. }
  1357. &__text {
  1358. font-size: 12px;
  1359. color: #475569;
  1360. font-weight: 500;
  1361. white-space: nowrap;
  1362. }
  1363. }
  1364. @media (max-width: 1080px) {
  1365. .upload-layout {
  1366. flex-direction: column;
  1367. }
  1368. .left-panel {
  1369. flex: 0 0 auto;
  1370. width: auto;
  1371. }
  1372. }
  1373. }
  1374. html[data-theme='dark'] {
  1375. .@{prefix-cls}.case-upload-page {
  1376. background: #0f172a;
  1377. .page-header {
  1378. border-color: #1f2937;
  1379. background: #111827;
  1380. box-shadow: none;
  1381. }
  1382. .page-header__divider {
  1383. background: #1f2937;
  1384. }
  1385. .back-btn {
  1386. border-color: #334155;
  1387. background: #0f172a;
  1388. color: #cbd5e1;
  1389. &:hover,
  1390. &:focus,
  1391. &:focus-visible {
  1392. border-color: #3b82f6;
  1393. background: #1e293b;
  1394. color: #93c5fd;
  1395. }
  1396. }
  1397. .page-title,
  1398. .panel-title,
  1399. .upload-dragger-title,
  1400. .upload-file-item__name,
  1401. .cell-name {
  1402. color: #e5e7eb;
  1403. }
  1404. .page-subtitle,
  1405. .panel-desc,
  1406. .panel-stats,
  1407. .upload-dragger-desc,
  1408. .upload-file-item__size,
  1409. .upload-file-item__pending {
  1410. color: #9ca3af;
  1411. }
  1412. .left-panel,
  1413. .right-panel,
  1414. .upload-file-list {
  1415. background: #111827;
  1416. border-color: #1f2937;
  1417. }
  1418. .panel-header,
  1419. .upload-file-list__header,
  1420. .upload-overall-progress {
  1421. border-color: #1f2937;
  1422. }
  1423. .upload-file-list__header {
  1424. background: #0f172a;
  1425. color: #cbd5e1;
  1426. }
  1427. .upload-file-item:hover {
  1428. background: #1f2937;
  1429. }
  1430. .upload-dropzone {
  1431. border-color: #334155;
  1432. background: #0f172a;
  1433. }
  1434. .upload-mode-switch {
  1435. background: #1e293b;
  1436. border-color: #334155;
  1437. }
  1438. .upload-mode-switch__item {
  1439. color: #94a3b8;
  1440. }
  1441. .upload-overall-progress__bar {
  1442. background: #1f2937;
  1443. }
  1444. .status-tag.is-other {
  1445. background: #1e293b;
  1446. color: #94a3b8;
  1447. }
  1448. .cell-name.is-child {
  1449. color: #cbd5e1;
  1450. }
  1451. .result-tree-table {
  1452. :deep(.ant-table-thead > tr > th) {
  1453. background: #0f172a;
  1454. color: #94a3b8;
  1455. border-bottom-color: #1f2937;
  1456. }
  1457. :deep(.ant-table-tbody > tr > td) {
  1458. border-bottom-color: #111827;
  1459. }
  1460. :deep(.ant-table-tbody > tr:hover > td) {
  1461. background: #1f2937;
  1462. }
  1463. }
  1464. }
  1465. }
  1466. </style>