upload.vue 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690
  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 || desktopFolderReading"
  25. @click="handleSmartClean"
  26. >
  27. 智能清洗
  28. </Button>
  29. <Button class="next-btn" :disabled="!hasCleanableSheet || desktopFolderReading" @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 || desktopFolderReading"
  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 || desktopFolderReading"
  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. : desktopFolderPicker
  88. ? '支持一次选择多个文件夹;文件夹内文件全部上传;不支持的格式仅登记、不保存源文件'
  89. : '浏览器一次只能选择一个文件夹,可连续选择多次;也可一次拖入多个文件夹;不支持的格式仅登记、不保存源文件'
  90. }}
  91. </div>
  92. <Button
  93. type="primary"
  94. class="upload-action-btn"
  95. :loading="uploadMode === 'folder' && desktopFolderReading"
  96. @click="handleTriggerFileSelect"
  97. >
  98. {{ uploadMode === 'single' ? '选择文件' : '选择文件夹' }}
  99. </Button>
  100. </div>
  101. </div>
  102. <!-- 已选文件列表(加入后自动上传,成功即移除) -->
  103. <div v-if="selectedFiles.length" class="upload-file-list">
  104. <div class="upload-file-list__header">
  105. <span>待上传 {{ selectedFiles.length }} 个文件</span>
  106. <Button type="link" size="small" :disabled="isUploading || desktopFolderReading" @click="clearSelectedFiles"> 清空 </Button>
  107. </div>
  108. <div class="upload-file-list__body">
  109. <div
  110. v-for="file in selectedFiles"
  111. :key="file.name + file.size + file.lastModified"
  112. class="upload-file-item"
  113. >
  114. <div class="upload-file-item__info">
  115. <span class="upload-file-item__name">{{ file.name }}</span>
  116. <span class="upload-file-item__size">{{ formatFileSize(file.size) }}</span>
  117. </div>
  118. <div class="upload-file-item__status">
  119. <template v-if="uploadStatuses.get(file) === 'error'">
  120. <span class="upload-file-item__error">✗</span>
  121. </template>
  122. <template v-else-if="uploadStatuses.get(file) === 'uploading'">
  123. <span class="upload-file-item__progress-text">{{ uploadProgressMap.get(file) || 0 }}%</span>
  124. </template>
  125. <template v-else>
  126. <span class="upload-file-item__pending">待上传</span>
  127. </template>
  128. </div>
  129. <button
  130. v-if="!isUploading && (uploadStatuses.get(file) || 'pending') === 'pending'"
  131. type="button"
  132. class="upload-file-item__remove"
  133. aria-label="移除文件"
  134. @click="removeSelectedFile(file)"
  135. >
  136. <CloseOutlined />
  137. </button>
  138. </div>
  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 { isDesktopDialogAvailable, pickDirectories } from '@/core/utils/desktop/pathPicker';
  192. import CaseFlowTopBar from './components/CaseFlowTopBar.vue';
  193. import { resetImportProgressSession } from './importProgressSession';
  194. import type { FileInfo } from '@/types/api';
  195. const { prefixCls } = useDesign('case-upload');
  196. const go = useGo();
  197. const pageQuery = useQuery();
  198. const emitter = useEmitter();
  199. const { createMessage } = useMessage();
  200. const FILE_INFO_STORAGE_KEY = 'case_clean_file_infos';
  201. const IMPORT_FILE_INFO_STORAGE_KEY = 'case_clean_import_file_infos';
  202. const RECLEAN_CONTEXT_STORAGE_KEY = 'case_clean_reclean_context';
  203. const CASE_DATA_REFRESH_EVENT = 'case-data:refresh';
  204. type UploadMode = 'single' | 'folder';
  205. /** 进入上传页即生成批次 id,本页所有文件统一使用该批次(Long 型,上限约 1.7e18,安全) */
  206. const createUploadBatchId = () => Date.now() * 1000000 + Math.floor(Math.random() * 1000000);
  207. const uploadBatchId = ref(createUploadBatchId());
  208. const modeFromQuery = computed<UploadMode>(() => (pageQuery.value?.mode === 'folder' ? 'folder' : 'single'));
  209. const uploadMode = ref<UploadMode>(modeFromQuery.value);
  210. // 文件选择与上传状态(以 File 对象为键,上传成功移除文件时状态映射不会错乱)
  211. const fileInputRef = ref<HTMLInputElement | null>(null);
  212. const folderInputRef = ref<HTMLInputElement | null>(null);
  213. const selectedFiles = ref<File[]>([]);
  214. const uploadProgressMap = ref<Map<File, number>>(new Map());
  215. const uploadStatuses = ref<Map<File, 'pending' | 'uploading' | 'done' | 'error'>>(new Map());
  216. const isUploading = ref(false);
  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. /** 是否运行在 Electron:桌面端用系统对话框一次选多个文件夹 */
  375. const desktopFolderPicker = isDesktopDialogAvailable();
  376. const desktopFolderReading = ref(false);
  377. const resolveDesktopNodeModules = (): { fs: any; path: any } | null => {
  378. const nodeRequire = (window as unknown as { require?: (id: string) => any }).require;
  379. if (typeof nodeRequire !== 'function') return null;
  380. try {
  381. return { fs: nodeRequire('fs'), path: nodeRequire('path') };
  382. } catch {
  383. return null;
  384. }
  385. };
  386. /** 等单个文件上传结束(成功移除或失败保留),避免一次性把所有文件读进内存 */
  387. const waitForUploadSettled = (file: File) =>
  388. new Promise<void>((resolve) => {
  389. const startedAt = Date.now();
  390. const timer = setInterval(() => {
  391. const settled =
  392. !selectedFiles.value.includes(file) ||
  393. uploadStatuses.value.get(file) === 'error' ||
  394. Date.now() - startedAt > 10 * 60 * 1000;
  395. if (settled) {
  396. clearInterval(timer);
  397. resolve();
  398. }
  399. }, 150);
  400. });
  401. /** 递归遍历目录;文件逐个读取、上传,控制内存占用 */
  402. const walkDesktopDirectory = async (
  403. fs: any,
  404. path: any,
  405. dir: string,
  406. onFile: (fullPath: string, fileName: string) => Promise<void>,
  407. ) => {
  408. const entries = await fs.promises.readdir(dir, { withFileTypes: true });
  409. for (const entry of entries) {
  410. const fullPath = path.join(dir, entry.name);
  411. if (entry.isDirectory()) {
  412. await walkDesktopDirectory(fs, path, fullPath, onFile);
  413. } else if (entry.isFile()) {
  414. await onFile(fullPath, String(entry.name));
  415. }
  416. }
  417. };
  418. const handleDesktopFolderSelect = async () => {
  419. if (desktopFolderReading.value) return;
  420. if (!batchIdReady.value) {
  421. createMessage.warning('上传批次尚未就绪,请稍后重试');
  422. return;
  423. }
  424. const dirs = await pickDirectories().catch((error) => {
  425. console.error('打开多文件夹选择框失败', error);
  426. createMessage.error('多文件夹选择不可用,请重启桌面客户端后重试');
  427. return [] as string[];
  428. });
  429. if (!dirs.length) return;
  430. const nodeModules = resolveDesktopNodeModules();
  431. if (!nodeModules) {
  432. createMessage.error('当前环境无法读取本机文件夹,请重新启动桌面客户端');
  433. return;
  434. }
  435. desktopFolderReading.value = true;
  436. let added = 0;
  437. let failed = 0;
  438. try {
  439. for (const dir of dirs) {
  440. try {
  441. await walkDesktopDirectory(nodeModules.fs, nodeModules.path, dir, async (fullPath, fileName) => {
  442. if (isAbandoned.value) return;
  443. try {
  444. const stat = await nodeModules.fs.promises.stat(fullPath);
  445. const buffer = await nodeModules.fs.promises.readFile(fullPath);
  446. const file = new File([buffer as unknown as BlobPart], fileName, { lastModified: stat.mtimeMs });
  447. addFiles([file], false);
  448. added += 1;
  449. await waitForUploadSettled(file);
  450. } catch (error) {
  451. failed += 1;
  452. console.error('读取本机文件失败', fullPath, error);
  453. }
  454. });
  455. } catch (error) {
  456. failed += 1;
  457. console.error('读取本机文件夹失败', dir, error);
  458. }
  459. }
  460. } finally {
  461. desktopFolderReading.value = false;
  462. }
  463. if (!added) {
  464. createMessage.warning('所选文件夹中没有可上传文件');
  465. } else if (failed) {
  466. createMessage.warning(`已加入 ${added} 个文件,${failed} 个文件读取失败`);
  467. }
  468. };
  469. const handleTriggerFileSelect = async () => {
  470. if (uploadMode.value === 'folder') {
  471. if (desktopFolderPicker) {
  472. await handleDesktopFolderSelect();
  473. return;
  474. }
  475. folderInputRef.value?.click();
  476. } else {
  477. fileInputRef.value?.click();
  478. }
  479. };
  480. const handleUploadModeChange = (mode: UploadMode) => {
  481. if (uploadMode.value === mode || isUploading.value || desktopFolderReading.value) return;
  482. uploadMode.value = mode;
  483. clearSelectedFiles();
  484. };
  485. const clearSelectedFiles = () => {
  486. selectedFiles.value = [];
  487. uploadProgressMap.value = new Map();
  488. uploadStatuses.value = new Map();
  489. };
  490. /** 移除单个待上传文件(上传解析中不允许移除) */
  491. const removeSelectedFile = (target: File) => {
  492. if (isUploading.value) return;
  493. const index = selectedFiles.value.indexOf(target);
  494. if (index === -1) return;
  495. // 仅允许移除待上传文件
  496. if ((uploadStatuses.value.get(target) || 'pending') !== 'pending') {
  497. return;
  498. }
  499. selectedFiles.value.splice(index, 1);
  500. uploadProgressMap.value.delete(target);
  501. uploadStatuses.value.delete(target);
  502. };
  503. const persistFileInfos = (infos: Recordable[]) => {
  504. sessionStorage.setItem(FILE_INFO_STORAGE_KEY, JSON.stringify(infos));
  505. };
  506. /**
  507. * 从 storage 恢复已解析结果(从清洗页返回时右侧表格还原)
  508. * 同时把批次号恢复为原批次,保证后续上传/删除/清理与原批次数据一致
  509. */
  510. const restoreParsedResults = () => {
  511. try {
  512. const raw = sessionStorage.getItem(FILE_INFO_STORAGE_KEY);
  513. if (!raw) return;
  514. const parsed = JSON.parse(raw);
  515. if (!Array.isArray(parsed) || !parsed.length) return;
  516. allFileInfos.value = parsed;
  517. resultTrees.value = parsed;
  518. // 恢复后默认全部展开
  519. expandAllRows();
  520. const storedBatchId = parsed[0]?.batchId;
  521. if (storedBatchId !== null && storedBatchId !== undefined && String(storedBatchId).trim() !== '') {
  522. uploadBatchId.value = storedBatchId as number;
  523. }
  524. } catch {
  525. // 无效缓存忽略,保持新批次
  526. }
  527. };
  528. onMounted(() => {
  529. restoreParsedResults();
  530. });
  531. const isOwnBatchStorage = () => {
  532. const raw = sessionStorage.getItem(FILE_INFO_STORAGE_KEY);
  533. if (!raw) return true;
  534. try {
  535. const parsed = JSON.parse(raw);
  536. if (!Array.isArray(parsed) || !parsed.length) return true;
  537. return parsed.every((item) => String(item?.batchId ?? '') === String(uploadBatchId.value));
  538. } catch {
  539. return true;
  540. }
  541. };
  542. const clearStoredFileInfos = () => {
  543. if (isOwnBatchStorage()) {
  544. sessionStorage.removeItem(FILE_INFO_STORAGE_KEY);
  545. }
  546. };
  547. /**
  548. * 离开上传页时清空本流程的 sessionStorage 缓存,避免上一批已上传文件被后续流程复用:
  549. * - case_clean_file_infos 已上传文件的解析结果(右侧表格数据源)
  550. * - case_clean_import_file_infos 手动清洗页提交给清洗进度页的导入文件列表
  551. * - case_clean_reclean_context 重新清洗上下文(reClean=1 + fileId)
  552. * - case_clean_import_progress 清洗进度快照,连同运行时状态与 SSE 连接一起重置
  553. */
  554. const clearCleanFlowSessionCache = () => {
  555. clearStoredFileInfos();
  556. sessionStorage.removeItem(IMPORT_FILE_INFO_STORAGE_KEY);
  557. sessionStorage.removeItem(RECLEAN_CONTEXT_STORAGE_KEY);
  558. resetImportProgressSession();
  559. };
  560. /**
  561. * 自动上传队列:选择文件后自动触发,按序消费列表中的待上传文件;
  562. * 上传解析成功或后端返回错误都从列表移除,避免失败文件继续堆积。
  563. */
  564. const startUpload = async () => {
  565. if (isUploading.value || !batchIdReady.value) return;
  566. const currentBatchId = uploadBatchId.value;
  567. let failedCount = 0;
  568. isUploading.value = true;
  569. isAbandoned.value = false;
  570. tableLoading.value = true;
  571. try {
  572. while (true) {
  573. if (isAbandoned.value) break;
  574. // 取当前第一个待上传文件
  575. const index = selectedFiles.value.findIndex((f) => (uploadStatuses.value.get(f) || 'pending') === 'pending');
  576. if (index === -1) break;
  577. const file = selectedFiles.value[index];
  578. uploadStatuses.value.set(file, 'uploading');
  579. const onProgress = (percent: number) => {
  580. uploadProgressMap.value.set(file, percent);
  581. };
  582. try {
  583. // defHttp.uploadFile 返回原始 AxiosResponse,业务数据在 res.data.data;
  584. // 非 200 的业务错误(如 MD5 重复)在 res.data.message 里,交给 catch 统一提示
  585. const res = await preFileUpload(file, onProgress, { batchId: currentBatchId });
  586. if (isAbandoned.value) break;
  587. // errorMessageMode=none 时网络异常会被响应拦截器 resolve 成空值,这里兜底
  588. if (!res?.data) {
  589. throw new Error('网络异常或服务不可用');
  590. }
  591. if (Number(res.data.code) !== 200) {
  592. throw new Error(res.data.message || '上传失败');
  593. }
  594. const fileNode: FileInfo | null = res?.data?.data ?? null;
  595. if (fileNode) {
  596. // 右侧 treetable 直接渲染树(文件根 → sheet 子节点)
  597. resultTrees.value = [...resultTrees.value, fileNode];
  598. // 新文件根自动展开(受控展开,默认全部展开)
  599. if ((fileNode.children || []).length > 0) {
  600. expandedRowKeys.value = [...expandedRowKeys.value, String(fileNode.id ?? '')];
  601. }
  602. // 持久化给 match/清洗流程的数据按后端返回的树结构存储(文件根 + children sheet)
  603. allFileInfos.value = [...allFileInfos.value, fileNode];
  604. persistFileInfos(allFileInfos.value);
  605. }
  606. // 上传成功:从列表移除该文件
  607. uploadProgressMap.value.delete(file);
  608. uploadStatuses.value.delete(file);
  609. const idx = selectedFiles.value.indexOf(file);
  610. if (idx !== -1) {
  611. selectedFiles.value.splice(idx, 1);
  612. }
  613. onProgress(100);
  614. } catch (error: any) {
  615. // 后端已返回错误即视为本次上传处理结束:从待上传列表移除,避免失败文件继续堆积
  616. uploadProgressMap.value.delete(file);
  617. uploadStatuses.value.delete(file);
  618. const failedIdx = selectedFiles.value.indexOf(file);
  619. if (failedIdx !== -1) {
  620. selectedFiles.value.splice(failedIdx, 1);
  621. }
  622. createMessage.error(`「${file.name}」上传失败:${error?.message || '未知错误'}`);
  623. failedCount += 1;
  624. }
  625. }
  626. // 只有解析出工作表(children)的才算真正解析成功;「未解析」的节点也占一个 resultTrees 名额,
  627. // 若直接按长度提示「成功解析 N 个文件」,对用户就是假消息。
  628. const parsedCount = resultTrees.value.filter((root) => (root.children || []).length > 0).length;
  629. const unreadable = resultTrees.value.filter((root) => !(root.children || []).length);
  630. const unreadableCount = unreadable.length;
  631. // 保留了原件的(文档/图片/音视频)可以下载、可以在对话中 @ 引用;
  632. // 不在支持清单里的只登记一条记录、不保存源文件(文件夹上传会走到这一类)
  633. const retainedCount = unreadable.filter((root) => !!root.filePath).length;
  634. const registeredOnlyCount = unreadableCount - retainedCount;
  635. const detail = [
  636. retainedCount ? `${retainedCount} 个已保留原件,可在对话中 @ 引用` : '',
  637. registeredOnlyCount ? `${registeredOnlyCount} 个格式不支持,仅登记、未保存源文件` : '',
  638. ]
  639. .filter(Boolean)
  640. .join(';');
  641. const unreadableHint = detail ? `(其中 ${detail})` : '';
  642. if (!isAbandoned.value && parsedCount) {
  643. createMessage.success(
  644. unreadableCount
  645. ? `成功解析 ${parsedCount} 个文件;另有 ${unreadableCount} 个文件未解析${unreadableHint},已在右侧列表标出`
  646. : `成功解析 ${parsedCount} 个文件,可在右侧查看结果`,
  647. );
  648. } else if (!isAbandoned.value && unreadableCount) {
  649. createMessage.warning(`${unreadableCount} 个文件未解析${unreadableHint},见右侧列表`);
  650. } else if (!isAbandoned.value && !failedCount && !selectedFiles.value.length) {
  651. createMessage.warning('未识别到可处理文件,请检查文件格式是否正确');
  652. }
  653. } catch (error) {
  654. createMessage.error('上传解析过程中发生错误');
  655. } finally {
  656. isUploading.value = false;
  657. tableLoading.value = false;
  658. // 上传过程中允许继续选择文件夹:若队列刚好在追加前结束,这里把新加入的待上传文件接上
  659. if (
  660. !isAbandoned.value &&
  661. selectedFiles.value.some((file) => (uploadStatuses.value.get(file) || 'pending') === 'pending')
  662. ) {
  663. void startUpload();
  664. }
  665. }
  666. };
  667. /** 文件/工作表状态 → 中文标签(与 importList、cleaning 页保持一致) */
  668. const fileStatusLabelMap = Object.entries(FileStatusEnum).reduce<Record<string, string>>((map, [key, label]) => {
  669. map[key] = label;
  670. return map;
  671. }, {});
  672. /** 读取/处理成功,可进入匹配、清洗流程的状态 */
  673. const SUCCESS_FILE_STATUSES = new Set<string>([
  674. 'FILE_READ_COMPLETE',
  675. 'SHEET_TEMPLATE_MATCHED_SUCCESS',
  676. 'FILE_CLEAN_COMPLETE',
  677. 'FILE_GOVERN_COMPLETE',
  678. ]);
  679. /** 明确失败的状态(加密文件等中性状态不算失败) */
  680. const FAIL_FILE_STATUSES = new Set<string>([
  681. 'FILE_READ_FAIL',
  682. 'FILE_UNSUPPORTED_FAIL',
  683. 'SHEET_READ_FAIL',
  684. 'SHEET_TEMPLATE_MATCHED_FAIL',
  685. ]);
  686. const isSuccessStatus = (status?: string | null) => {
  687. const normalized = String(status || '').trim();
  688. return !!normalized && SUCCESS_FILE_STATUSES.has(normalized);
  689. };
  690. const mapStatus = (status?: string) => {
  691. const normalized = String(status || '').trim();
  692. if (!normalized) return { success: false, fail: false, label: '待处理' };
  693. return {
  694. success: SUCCESS_FILE_STATUSES.has(normalized),
  695. fail: FAIL_FILE_STATUSES.has(normalized),
  696. label: fileStatusLabelMap[normalized] || normalized,
  697. };
  698. };
  699. const isRootNode = (record: Recordable) => !record.pid || Number(record.pid) === 0;
  700. const resultTableColumns: TableColumnsType<Recordable> = [
  701. {
  702. title: '名称',
  703. key: 'name',
  704. width: 360,
  705. ellipsis: true,
  706. customRender: ({ record }: any) => {
  707. const root = isRootNode(record);
  708. const name = root ? record.fileName || '未命名文件' : record.sheetName || record.tableName || '未命名工作表';
  709. const extra = root && record.fileType ? ` · ${record.fileType}` : '';
  710. return h('span', { class: ['cell-name', { 'is-child': !root }] }, [name + extra]);
  711. },
  712. },
  713. {
  714. title: '大小',
  715. key: 'fileSize',
  716. width: 110,
  717. customRender: ({ record }: any) => (isRootNode(record) ? formatFileSize(record.fileSize) : '—'),
  718. },
  719. {
  720. title: '数据量',
  721. key: 'dataNum',
  722. width: 90,
  723. customRender: ({ record }: any) => record.dataNum ?? '—',
  724. },
  725. {
  726. title: '状态',
  727. key: 'status',
  728. width: 130,
  729. customRender: ({ record }: any) => {
  730. const mapped = mapStatus(record.fileStatus);
  731. const cls = mapped.success ? 'is-success' : mapped.fail ? 'is-fail' : 'is-other';
  732. // 未解析的文件悬停可看原因:保留原件的说可下载/可 @ 引用,未落盘的说仅登记
  733. return h('span', { class: ['status-tag', cls], title: record.unsupportedReason || undefined }, [mapped.label]);
  734. },
  735. },
  736. {
  737. title: '操作',
  738. key: 'action',
  739. width: 150,
  740. customRender: ({ record }: any) => {
  741. // 文件根行:删除整个文件(级联全部工作表)
  742. if (isRootNode(record)) {
  743. return h('div', { class: 'cell-actions' }, [
  744. h(
  745. Button,
  746. {
  747. type: 'link',
  748. size: 'small',
  749. class: 'action-link is-danger',
  750. disabled: isUploading.value,
  751. onClick: () => handleRowDelete(record),
  752. },
  753. () => '删除',
  754. ),
  755. ]);
  756. }
  757. // 工作表行:手动清洗 + 删除
  758. return h('div', { class: 'cell-actions' }, [
  759. h(
  760. Button,
  761. {
  762. type: 'link',
  763. size: 'small',
  764. class: 'action-link',
  765. disabled: isUploading.value,
  766. onClick: () => handleRowManualClean(record),
  767. },
  768. () => '手动清洗',
  769. ),
  770. h(
  771. Button,
  772. {
  773. type: 'link',
  774. size: 'small',
  775. class: 'action-link is-danger',
  776. disabled: isUploading.value,
  777. onClick: () => handleRowDelete(record),
  778. },
  779. () => '删除',
  780. ),
  781. ]);
  782. },
  783. },
  784. ];
  785. const cleanupAndLeave = async () => {
  786. isAbandoned.value = true;
  787. allowedToLeave.value = true;
  788. try {
  789. await clearUploadBatch({ batchId: uploadBatchId.value });
  790. } catch (error: any) {
  791. createMessage.warning(error?.message || '清理本批次数据失败,可稍后在导入文件管理中删除');
  792. } finally {
  793. clearCleanFlowSessionCache();
  794. await go(PageEnum.BASE_HOME, true);
  795. emitter.emit(CASE_DATA_REFRESH_EVENT);
  796. }
  797. };
  798. const handleBack = () => {
  799. if (!hasActivity.value) {
  800. allowedToLeave.value = true;
  801. // 返回案件数据:清空已上传文件与清洗流程缓存,避免下次进入上传页还原上一批文件
  802. clearCleanFlowSessionCache();
  803. go(PageEnum.BASE_HOME, true);
  804. emitter.emit(CASE_DATA_REFRESH_EVENT);
  805. return;
  806. }
  807. Modal.confirm({
  808. title: isUploading.value ? '上传解析进行中' : '存在未处理文件',
  809. content: isUploading.value
  810. ? '当前仍有文件在上传解析,离开将中断本次上传,并清理本批次已上传文件与解析结果,是否继续?'
  811. : '离开将清理本批次已上传文件与解析结果(未进入清洗流程),是否继续?',
  812. okText: '离开并清理',
  813. cancelText: '留在本页',
  814. onOk: cleanupAndLeave,
  815. });
  816. };
  817. /**
  818. * 智能清洗:一次请求跑完「既有模板清洗 + 未匹配文件的 AI 清洗」,跳到进度页看两路结果。
  819. *
  820. * 可用条件是 hasCleanableSheet 而不是 hasSuccessResult:模板匹配失败的那批文件正是 AI 要接的活,
  821. * 按「有成功文件」判断等于在最需要这个按钮的场景里把它锁死。
  822. *
  823. * 接口立即返回 batchId(后台异步跑),所以要把 fileInfos 先写进 sessionStorage:
  824. * 进度页读它来展示文件与批次。发起失败时留在本页、不清缓存,用户可重试或转手动清洗。
  825. */
  826. const handleSmartClean = async () => {
  827. if (!hasCleanableSheet.value || smartCleaning.value) return;
  828. smartCleaning.value = true;
  829. try {
  830. const fileInfos = allFileInfos.value as unknown as FileInfo[];
  831. persistFileInfos(allFileInfos.value);
  832. const res = await smartClean({ fileInfos, reClean: 0 });
  833. if (!res?.batchId) {
  834. throw new Error('后端未返回批次号');
  835. }
  836. allowedToLeave.value = true;
  837. resetImportProgressSession();
  838. go({
  839. path: PageEnum.BASE_CLEAN_PROGRESS,
  840. query: { fused: '1', batchId: String(res.batchId) },
  841. });
  842. } catch (error: any) {
  843. createMessage.error(error?.message || '智能清洗发起失败,可改用手动清洗');
  844. } finally {
  845. smartCleaning.value = false;
  846. }
  847. };
  848. /** 手动清洗:进入手动清洗页逐个处理(含模板匹配失败的表) */
  849. const handleManualClean = () => {
  850. if (!hasCleanableSheet.value) return;
  851. allowedToLeave.value = true;
  852. go({ path: PageEnum.BASE_CLEANING });
  853. };
  854. /** 行级手动清洗:定位到指定工作表进入手动清洗页 */
  855. const handleRowManualClean = (record: Recordable) => {
  856. const focusKey = String(record.id ?? '').trim();
  857. if (!focusKey) {
  858. createMessage.warning('未获取到工作表ID,暂时无法手动清洗');
  859. return;
  860. }
  861. allowedToLeave.value = true;
  862. go({ path: PageEnum.BASE_CLEANING, query: { focusKey } });
  863. };
  864. /** 本地移除整个文件节点并同步 sessionStorage */
  865. const removeFileNodeSync = (rootId: string) => {
  866. resultTrees.value = resultTrees.value.filter((item) => String(item.id ?? '') !== rootId);
  867. allFileInfos.value = allFileInfos.value.filter((item) => String(item.id ?? '') !== rootId);
  868. // 同步移除已删除文件根的展开状态
  869. expandedRowKeys.value = expandedRowKeys.value.filter((key) => String(key) !== rootId);
  870. persistFileInfos(allFileInfos.value);
  871. };
  872. /** 本地移除单个工作表节点并同步 sessionStorage */
  873. const removeSheetNodeSync = (rootId: string, sheetId: string) => {
  874. const stripSheet = (item: Recordable) =>
  875. String(item.id ?? '') === rootId
  876. ? {
  877. ...item,
  878. children: (item.children || []).filter((child) => String(child.id ?? '') !== sheetId),
  879. }
  880. : item;
  881. resultTrees.value = resultTrees.value.map(stripSheet);
  882. allFileInfos.value = allFileInfos.value.map(stripSheet);
  883. persistFileInfos(allFileInfos.value);
  884. };
  885. /** 行级删除:文件根行删除整个文件(级联全部工作表),工作表行删除单个工作表(仅剩此表时连同文件根) */
  886. const handleRowDelete = (record: Recordable) => {
  887. // 文件根行:整文件删除
  888. if (isRootNode(record)) {
  889. const fileRootId = String(record.id ?? '').trim();
  890. const fileName = record.fileName || '未命名文件';
  891. if (!fileRootId) {
  892. createMessage.warning('未获取到文件ID,暂时无法删除');
  893. return;
  894. }
  895. Modal.confirm({
  896. title: '删除确认',
  897. content: `确定删除文件「${fileName}」及其全部工作表吗?`,
  898. okText: '删除',
  899. okType: 'primary',
  900. okButtonProps: { danger: true },
  901. cancelText: '取消',
  902. onOk: async () => {
  903. try {
  904. // 后端按 id 级联删除(id 匹配 + pid 匹配),传根 id 即删整文件
  905. await deletedFileList({ ids: [fileRootId] });
  906. removeFileNodeSync(fileRootId);
  907. createMessage.success('删除成功');
  908. } catch (error: any) {
  909. createMessage.error(error?.message || '删除失败');
  910. }
  911. },
  912. });
  913. return;
  914. }
  915. // 工作表行:单表删除(该文件仅剩此表时连同文件根一起删除)
  916. const rootId = String(record.pid ?? '').trim();
  917. const root = resultTrees.value.find((item) => String(item.id ?? '') === rootId);
  918. const siblings = root?.children || [];
  919. const isLastSheet = siblings.length <= 1;
  920. const sheetId = String(record.id ?? '').trim();
  921. const sheetName = record.sheetName || '未命名工作表';
  922. const fileName = root?.fileName || '未命名文件';
  923. Modal.confirm({
  924. title: '删除确认',
  925. content: isLastSheet
  926. ? `「${fileName}」仅剩此工作表,删除后将移除整个文件,是否继续?`
  927. : `确定删除工作表「${sheetName}」吗?`,
  928. okText: '删除',
  929. okType: 'primary',
  930. okButtonProps: { danger: true },
  931. cancelText: '取消',
  932. onOk: async () => {
  933. try {
  934. // 后端按 id 级联删除(id 匹配 + pid 匹配):仅剩此表时传根 id 删整文件,否则传 sheet id 删单表
  935. const deleteIds = isLastSheet && root ? [String(root.id ?? '')] : [sheetId];
  936. const validIds = deleteIds.filter(Boolean);
  937. if (!validIds.length) {
  938. createMessage.warning('未获取到ID,暂时无法删除');
  939. return;
  940. }
  941. await deletedFileList({ ids: validIds });
  942. if (isLastSheet) {
  943. removeFileNodeSync(rootId);
  944. } else {
  945. removeSheetNodeSync(rootId, sheetId);
  946. }
  947. createMessage.success('删除成功');
  948. } catch (error: any) {
  949. createMessage.error(error?.message || '删除失败');
  950. }
  951. },
  952. });
  953. };
  954. // 兜底浏览器返回 / 标签页关闭等非按钮离开
  955. onBeforeRouteLeave((to, _from, next) => {
  956. if (allowedToLeave.value || !hasActivity.value) {
  957. // 进入清洗流程(清洗页 / 清洗进度页)时保留缓存,供下游页面读取;
  958. // 其余离开上传页的场景(返回案件数据、切菜单等)一律清空已上传文件与清洗流程缓存
  959. const toPath = String(to?.path ?? '');
  960. if (toPath !== PageEnum.BASE_CLEANING && toPath !== PageEnum.BASE_CLEAN_PROGRESS) {
  961. clearCleanFlowSessionCache();
  962. }
  963. next();
  964. return;
  965. }
  966. Modal.confirm({
  967. title: isUploading.value ? '上传解析进行中' : '存在未处理文件',
  968. content: '离开将清理本批次已上传文件与解析结果(未进入清洗流程),是否继续?',
  969. okText: '离开并清理',
  970. cancelText: '留在本页',
  971. onOk: cleanupAndLeave,
  972. });
  973. next(false);
  974. });
  975. </script>
  976. <style lang="less">
  977. @prefix-cls: ~'jeesite-case-upload';
  978. .@{prefix-cls}.case-upload-page {
  979. width: 100%;
  980. height: 100vh;
  981. background: #f0f2f5;
  982. display: flex;
  983. flex-direction: column;
  984. box-sizing: border-box;
  985. overflow: hidden;
  986. // 公共顶栏由 AppTopBar 自带高度,内容区在剩余高度里滚动
  987. .page-body {
  988. flex: 1 1 auto;
  989. min-height: 0;
  990. padding: 8px 12px;
  991. display: flex;
  992. flex-direction: column;
  993. gap: 8px;
  994. box-sizing: border-box;
  995. overflow: hidden;
  996. }
  997. .page-header {
  998. flex-shrink: 0;
  999. display: flex;
  1000. align-items: center;
  1001. justify-content: space-between;
  1002. gap: 16px;
  1003. padding: 10px 14px;
  1004. border: 1px solid #e2e8f0;
  1005. border-radius: 10px;
  1006. background: #fff;
  1007. box-shadow: 0 1px 2px rgba(15, 23, 42, 0.03);
  1008. }
  1009. .page-header__left {
  1010. display: flex;
  1011. align-items: center;
  1012. gap: 12px;
  1013. min-width: 0;
  1014. }
  1015. .page-header__divider {
  1016. flex: 0 0 auto;
  1017. width: 1px;
  1018. height: 22px;
  1019. background: #e2e8f0;
  1020. }
  1021. .back-btn {
  1022. display: inline-flex;
  1023. align-items: center;
  1024. justify-content: center;
  1025. flex: 0 0 auto;
  1026. width: 32px;
  1027. height: 32px;
  1028. padding: 0;
  1029. border: 1px solid #e2e8f0;
  1030. border-radius: 8px;
  1031. background: #f8fafc;
  1032. color: #475569;
  1033. font-size: 14px;
  1034. line-height: 1;
  1035. cursor: pointer;
  1036. transition:
  1037. color 0.2s ease,
  1038. border-color 0.2s ease,
  1039. background-color 0.2s ease;
  1040. &:hover,
  1041. &:focus,
  1042. &:focus-visible {
  1043. color: #2563eb;
  1044. border-color: #bfdbfe;
  1045. background: #eff6ff;
  1046. outline: none;
  1047. }
  1048. }
  1049. .page-title-block {
  1050. min-width: 0;
  1051. overflow: hidden;
  1052. }
  1053. .page-title {
  1054. font-size: 16px;
  1055. line-height: 1.4;
  1056. font-weight: 600;
  1057. color: #111827;
  1058. }
  1059. .page-subtitle {
  1060. margin-top: 1px;
  1061. overflow: hidden;
  1062. font-size: 12px;
  1063. line-height: 1.6;
  1064. color: #64748b;
  1065. white-space: nowrap;
  1066. text-overflow: ellipsis;
  1067. }
  1068. .page-header__actions {
  1069. display: flex;
  1070. align-items: center;
  1071. gap: 8px;
  1072. flex-shrink: 0;
  1073. }
  1074. .next-btn {
  1075. height: 32px;
  1076. padding: 0 16px;
  1077. border-radius: 8px;
  1078. font-weight: 500;
  1079. }
  1080. .upload-layout {
  1081. flex: 1 1 auto;
  1082. min-height: 0;
  1083. display: flex;
  1084. gap: 8px;
  1085. align-items: stretch;
  1086. }
  1087. .left-panel,
  1088. .right-panel {
  1089. border: 1px solid #e2e8f0;
  1090. border-radius: 10px;
  1091. background: #fff;
  1092. overflow: hidden;
  1093. }
  1094. .left-panel {
  1095. flex: 0 0 460px;
  1096. display: flex;
  1097. flex-direction: column;
  1098. gap: 10px;
  1099. padding: 12px;
  1100. box-sizing: border-box;
  1101. overflow-y: auto;
  1102. }
  1103. .right-panel {
  1104. flex: 1 1 auto;
  1105. min-width: 0;
  1106. display: flex;
  1107. flex-direction: column;
  1108. }
  1109. .panel-header {
  1110. flex-shrink: 0;
  1111. display: flex;
  1112. align-items: center;
  1113. justify-content: space-between;
  1114. gap: 12px;
  1115. padding: 10px 14px 8px;
  1116. border-bottom: 1px solid #eef2f7;
  1117. }
  1118. .panel-title {
  1119. position: relative;
  1120. padding-left: 11px;
  1121. font-size: 15px;
  1122. font-weight: 600;
  1123. line-height: 22px;
  1124. color: #111827;
  1125. // 与「持续连续(连续研判)」页的卡片标题一致:左侧 3px 蓝色竖条
  1126. &::before {
  1127. content: '';
  1128. position: absolute;
  1129. top: 4px;
  1130. bottom: 4px;
  1131. left: 0;
  1132. width: 3px;
  1133. border-radius: 2px;
  1134. background: #2a50ec;
  1135. }
  1136. }
  1137. .panel-desc {
  1138. margin-top: 2px;
  1139. font-size: 12px;
  1140. color: #6b7280;
  1141. line-height: 1.5;
  1142. }
  1143. .panel-header__actions {
  1144. display: flex;
  1145. align-items: center;
  1146. gap: 8px;
  1147. margin-left: auto;
  1148. }
  1149. .panel-stats {
  1150. font-size: 12px;
  1151. color: #64748b;
  1152. white-space: nowrap;
  1153. }
  1154. .table-wrapper {
  1155. flex: 1 1 auto;
  1156. min-height: 0;
  1157. padding: 2px 10px 10px;
  1158. overflow: auto;
  1159. }
  1160. .result-tree-table {
  1161. .ant-table-thead > tr > th {
  1162. padding: 6px 8px;
  1163. font-size: 12px;
  1164. font-weight: 600;
  1165. color: #6b7280;
  1166. background: #fafbfc;
  1167. border-bottom: 1px solid #eef2f7;
  1168. }
  1169. .ant-table-tbody > tr > td {
  1170. padding: 6px 8px;
  1171. font-size: 13px;
  1172. border-bottom: 1px solid #f6f8fa;
  1173. }
  1174. .ant-table-tbody > tr:hover > td {
  1175. background: #f8fafc;
  1176. }
  1177. .ant-table-row-expand-icon {
  1178. margin-right: 6px;
  1179. border-radius: 3px;
  1180. }
  1181. /* 无子集的行:隐藏展开占位图标(样式块非 scoped,直接用普通选择器) */
  1182. .ant-table-row-expand-icon-spaced {
  1183. display: none;
  1184. }
  1185. }
  1186. .cell-name {
  1187. color: #1e293b;
  1188. font-size: 13px;
  1189. &.is-child {
  1190. color: #475569;
  1191. }
  1192. }
  1193. .cell-actions {
  1194. display: inline-flex;
  1195. align-items: center;
  1196. gap: 2px;
  1197. .action-link {
  1198. padding: 0 4px;
  1199. height: 24px;
  1200. font-size: 12px;
  1201. color: #2563eb;
  1202. &:hover {
  1203. color: #1d4ed8;
  1204. }
  1205. &.is-danger {
  1206. color: #dc2626;
  1207. &:hover {
  1208. color: #b91c1c;
  1209. }
  1210. }
  1211. }
  1212. }
  1213. .status-tag {
  1214. display: inline-flex;
  1215. align-items: center;
  1216. padding: 2px 10px;
  1217. border-radius: 999px;
  1218. font-size: 12px;
  1219. font-weight: 600;
  1220. white-space: nowrap;
  1221. &.is-success {
  1222. background: #ecfdf3;
  1223. color: #15803d;
  1224. }
  1225. &.is-fail {
  1226. background: #fef2f2;
  1227. color: #dc2626;
  1228. }
  1229. &.is-other {
  1230. background: #f1f5f9;
  1231. color: #64748b;
  1232. }
  1233. }
  1234. .upload-picker {
  1235. flex: 0 0 auto;
  1236. display: flex;
  1237. justify-content: center;
  1238. }
  1239. .upload-mode-switch {
  1240. display: inline-flex;
  1241. align-items: center;
  1242. gap: 4px;
  1243. width: fit-content;
  1244. padding: 3px;
  1245. border-radius: 8px;
  1246. background: #f1f5f9;
  1247. border: 1px solid #e2e8f0;
  1248. }
  1249. .upload-mode-switch__item {
  1250. min-width: 92px;
  1251. height: 28px;
  1252. padding: 0 12px;
  1253. border: none;
  1254. border-radius: 6px;
  1255. background: transparent;
  1256. color: #64748b;
  1257. font-size: 12px;
  1258. font-weight: 600;
  1259. cursor: pointer;
  1260. transition:
  1261. background-color 0.2s ease,
  1262. color 0.2s ease;
  1263. &.is-active {
  1264. background: #2563eb;
  1265. color: #fff;
  1266. }
  1267. &:disabled {
  1268. cursor: not-allowed;
  1269. opacity: 0.6;
  1270. }
  1271. }
  1272. .upload-dropzone {
  1273. flex: 0 0 auto;
  1274. min-height: 96px;
  1275. border-radius: 8px;
  1276. /* 2px 虚线:1px 虚线在顶部处于小数像素位置(y≈179.578)时,
  1277. Chrome 会把整段顶部边框舍弃不渲染,表现为顶部边框消失 */
  1278. border: 2px dashed #cbd5e1;
  1279. background: #fafbfc;
  1280. transition: all 0.2s ease;
  1281. cursor: pointer;
  1282. &:hover,
  1283. &.is-dragover {
  1284. border-color: #3b82f6;
  1285. }
  1286. }
  1287. .upload-dragger-content {
  1288. display: flex;
  1289. flex-direction: column;
  1290. align-items: center;
  1291. justify-content: center;
  1292. gap: 4px;
  1293. padding: 12px 0;
  1294. color: #475569;
  1295. }
  1296. .upload-dragger-icon {
  1297. width: 28px;
  1298. height: 28px;
  1299. border-radius: 8px;
  1300. background: rgba(59, 130, 246, 0.1);
  1301. color: #2563eb;
  1302. display: flex;
  1303. align-items: center;
  1304. justify-content: center;
  1305. font-size: 14px;
  1306. }
  1307. .upload-dragger-title {
  1308. font-size: 13px;
  1309. font-weight: 600;
  1310. color: #334155;
  1311. }
  1312. .upload-dragger-desc {
  1313. font-size: 12px;
  1314. color: #64748b;
  1315. max-width: 420px;
  1316. text-align: center;
  1317. }
  1318. .upload-action-btn {
  1319. margin-top: 2px;
  1320. height: 26px;
  1321. padding: 0 14px;
  1322. border-radius: 6px;
  1323. }
  1324. .upload-file-list {
  1325. flex: 1 1 auto;
  1326. min-height: 0;
  1327. display: flex;
  1328. flex-direction: column;
  1329. border: 1px solid #e2e8f0;
  1330. border-radius: 12px;
  1331. background: #ffffff;
  1332. overflow: hidden;
  1333. &__header {
  1334. flex-shrink: 0;
  1335. display: flex;
  1336. align-items: center;
  1337. justify-content: space-between;
  1338. padding: 8px 12px;
  1339. background: #f8fafc;
  1340. border-bottom: 1px solid #e2e8f0;
  1341. font-size: 13px;
  1342. color: #475569;
  1343. font-weight: 500;
  1344. }
  1345. &__body {
  1346. flex: 1 1 auto;
  1347. min-height: 0;
  1348. overflow-y: auto;
  1349. padding: 4px 0;
  1350. }
  1351. &--empty {
  1352. flex: 1 1 auto;
  1353. border-style: dashed;
  1354. background: #fafafa;
  1355. }
  1356. }
  1357. .upload-empty {
  1358. margin: auto;
  1359. padding: 24px 12px;
  1360. color: #9ca3af;
  1361. font-size: 13px;
  1362. text-align: center;
  1363. }
  1364. .upload-file-item {
  1365. display: flex;
  1366. align-items: center;
  1367. justify-content: space-between;
  1368. padding: 6px 12px;
  1369. gap: 12px;
  1370. transition: background 0.15s ease;
  1371. &:hover {
  1372. background: #f8fafc;
  1373. }
  1374. &__info {
  1375. display: flex;
  1376. align-items: center;
  1377. gap: 10px;
  1378. min-width: 0;
  1379. flex: 1;
  1380. }
  1381. &__name {
  1382. font-size: 13px;
  1383. color: #1e293b;
  1384. white-space: nowrap;
  1385. overflow: hidden;
  1386. text-overflow: ellipsis;
  1387. max-width: 300px;
  1388. }
  1389. &__size {
  1390. font-size: 12px;
  1391. color: #94a3b8;
  1392. flex-shrink: 0;
  1393. }
  1394. &__status {
  1395. flex-shrink: 0;
  1396. font-size: 12px;
  1397. min-width: 48px;
  1398. text-align: right;
  1399. }
  1400. &__remove {
  1401. flex-shrink: 0;
  1402. display: inline-flex;
  1403. align-items: center;
  1404. justify-content: center;
  1405. width: 22px;
  1406. height: 22px;
  1407. padding: 0;
  1408. border: none;
  1409. border-radius: 6px;
  1410. background: transparent;
  1411. color: #9ca3af;
  1412. font-size: 11px;
  1413. cursor: pointer;
  1414. transition:
  1415. background-color 0.15s ease,
  1416. color 0.15s ease;
  1417. &:hover {
  1418. background: #fef2f2;
  1419. color: #dc2626;
  1420. }
  1421. }
  1422. &__error {
  1423. color: #dc2626;
  1424. font-weight: 600;
  1425. }
  1426. &__progress-text {
  1427. color: #2563eb;
  1428. font-weight: 500;
  1429. }
  1430. &__pending {
  1431. color: #94a3b8;
  1432. }
  1433. }
  1434. @media (max-width: 1080px) {
  1435. .upload-layout {
  1436. flex-direction: column;
  1437. }
  1438. .left-panel {
  1439. flex: 0 0 auto;
  1440. width: auto;
  1441. }
  1442. }
  1443. }
  1444. html[data-theme='dark'] {
  1445. .@{prefix-cls}.case-upload-page {
  1446. background: #0f172a;
  1447. .page-header {
  1448. border-color: #1f2937;
  1449. background: #111827;
  1450. box-shadow: none;
  1451. }
  1452. .page-header__divider {
  1453. background: #1f2937;
  1454. }
  1455. .back-btn {
  1456. border-color: #334155;
  1457. background: #0f172a;
  1458. color: #cbd5e1;
  1459. &:hover,
  1460. &:focus,
  1461. &:focus-visible {
  1462. border-color: #3b82f6;
  1463. background: #1e293b;
  1464. color: #93c5fd;
  1465. }
  1466. }
  1467. .page-title,
  1468. .panel-title,
  1469. .upload-dragger-title,
  1470. .upload-file-item__name,
  1471. .cell-name {
  1472. color: #e5e7eb;
  1473. }
  1474. .page-subtitle,
  1475. .panel-desc,
  1476. .panel-stats,
  1477. .upload-dragger-desc,
  1478. .upload-file-item__size,
  1479. .upload-file-item__pending {
  1480. color: #9ca3af;
  1481. }
  1482. .left-panel,
  1483. .right-panel,
  1484. .upload-file-list {
  1485. background: #111827;
  1486. border-color: #1f2937;
  1487. }
  1488. .panel-header,
  1489. .upload-file-list__header {
  1490. border-color: #1f2937;
  1491. }
  1492. .upload-file-list__header {
  1493. background: #0f172a;
  1494. color: #cbd5e1;
  1495. }
  1496. .upload-file-item:hover {
  1497. background: #1f2937;
  1498. }
  1499. .upload-dropzone {
  1500. border-color: #334155;
  1501. background: #0f172a;
  1502. }
  1503. .upload-mode-switch {
  1504. background: #1e293b;
  1505. border-color: #334155;
  1506. }
  1507. .upload-mode-switch__item {
  1508. color: #94a3b8;
  1509. }
  1510. .status-tag.is-other {
  1511. background: #1e293b;
  1512. color: #94a3b8;
  1513. }
  1514. .cell-name.is-child {
  1515. color: #cbd5e1;
  1516. }
  1517. .result-tree-table {
  1518. :deep(.ant-table-thead > tr > th) {
  1519. background: #0f172a;
  1520. color: #94a3b8;
  1521. border-bottom-color: #1f2937;
  1522. }
  1523. :deep(.ant-table-tbody > tr > td) {
  1524. border-bottom-color: #111827;
  1525. }
  1526. :deep(.ant-table-tbody > tr:hover > td) {
  1527. background: #1f2937;
  1528. }
  1529. }
  1530. }
  1531. }
  1532. </style>