match.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605
  1. <template>
  2. <div :class="prefixCls" class="case-match-page">
  3. <div class="page-header">
  4. <div class="page-title-wrap">
  5. <Button type="link" class="back-btn" @click="handleBack">
  6. <template #icon><LeftOutlined /></template>
  7. 返回
  8. </Button>
  9. <div>
  10. <div class="page-title">数据匹配结果</div>
  11. <div class="page-subtitle">按匹配状态查看文件识别结果,确认无误后继续执行清洗导入。</div>
  12. </div>
  13. </div>
  14. <Button type="primary" class="page-action" @click="handleCleanImport">清洗并导入</Button>
  15. </div>
  16. <div class="filter-bar">
  17. <div class="filter-item">
  18. <span class="filter-label">匹配状态:</span>
  19. <Select v-model:value="status" class="filter-select" :options="statusOptions" />
  20. </div>
  21. <div class="filter-summary"
  22. >共 {{ totalCount }} 个工作表,成功 {{ successList.length }} 个,失败 {{ failList.length }} 个</div
  23. >
  24. </div>
  25. <div class="stats-grid">
  26. <div class="stat-card">
  27. <div class="stat-label">全部文件</div>
  28. <div class="stat-value">{{ totalCount }}</div>
  29. </div>
  30. <div class="stat-card success">
  31. <div class="stat-label">匹配成功</div>
  32. <div class="stat-value">{{ successList.length }}</div>
  33. </div>
  34. <div class="stat-card error">
  35. <div class="stat-label">匹配失败</div>
  36. <div class="stat-value">{{ failList.length }}</div>
  37. </div>
  38. </div>
  39. <div class="sections-scroll">
  40. <div v-for="section in visibleSections" :key="section.key" class="section-card">
  41. <div class="panel-header">
  42. <div>
  43. <div class="panel-title">{{ section.title }} ({{ section.items.length }})</div>
  44. <div class="panel-desc">{{ section.desc }}</div>
  45. </div>
  46. </div>
  47. <div v-if="section.items.length" class="match-list">
  48. <div
  49. v-for="item in section.items"
  50. :key="item.key"
  51. class="match-row"
  52. :class="{ 'is-active': activeMatchKey === item.key }"
  53. @click="handleSelectItem(item)"
  54. >
  55. <span class="match-name">{{ item.name }}</span>
  56. <span class="match-status" :class="{ error: !item.success }">{{ item.status }}</span>
  57. <div class="match-actions">
  58. <Button type="link" class="action-link" @click.stop="handleManualClean(item)">手动清洗</Button>
  59. <Button type="link" class="action-link danger" @click.stop="handleDeleteItem(item)">删除</Button>
  60. </div>
  61. </div>
  62. </div>
  63. <div v-else class="empty-state">当前筛选条件下暂无数据。</div>
  64. </div>
  65. <div v-if="!visibleSections.length" class="empty-state">当前筛选条件下暂无匹配结果。</div>
  66. </div>
  67. </div>
  68. </template>
  69. <script lang="ts" setup name="ViewsDataMatch">
  70. import { computed, nextTick, onMounted, ref } from 'vue';
  71. import { LeftOutlined } from '@ant-design/icons-vue';
  72. import { Button, Select } from 'ant-design-vue';
  73. import { useGo, useQuery } from '@jeesite/core/hooks/web/usePage';
  74. import { PageEnum } from '@jeesite/core/enums/pageEnum';
  75. import { useDesign } from '@jeesite/core/hooks/web/useDesign';
  76. import { useMessage } from '@jeesite/core/hooks/web/useMessage';
  77. import { useEmitter } from '@jeesite/core/store/modules/case';
  78. import { cancelClean } from '@jeesite/case/api/govern/governApi';
  79. import { resetImportProgressSession } from './importProgressSession';
  80. const { prefixCls } = useDesign('case-match');
  81. const go = useGo();
  82. const pageQuery = useQuery();
  83. const emitter = useEmitter();
  84. const { createMessage } = useMessage();
  85. const CASE_DATA_REFRESH_EVENT = 'case-data:refresh';
  86. type MatchStatus = 'all' | 'success' | 'fail';
  87. const status = ref<MatchStatus>('all');
  88. const FILE_INFO_STORAGE_KEY = 'case_clean_file_infos';
  89. const MATCH_KEY_FIELD = '__matchKey';
  90. const statusOptions = [
  91. { label: '全部', value: 'all' },
  92. { label: '匹配成功', value: 'success' },
  93. { label: '匹配失败', value: 'fail' },
  94. ];
  95. type MatchItem = {
  96. key: string;
  97. focusKey: string;
  98. name: string;
  99. status: string;
  100. success: boolean;
  101. };
  102. const matchFileInfos = ref<Recordable[]>([]);
  103. const activeMatchKey = ref('');
  104. const normalizeMatchParentId = (value?: string | number | null) => {
  105. const normalized = String(value ?? '').trim();
  106. return !normalized || normalized === '0' ? '' : normalized;
  107. };
  108. const isMatchFileRootItem = (item?: Recordable | null) => !!item && !normalizeMatchParentId(item.pid);
  109. const buildMatchItem = (item: Recordable): MatchItem => {
  110. const name = item.sheetName || item.fileName || '未命名文件';
  111. const mapped = mapStatus(item.fileStatus);
  112. const matchKey = String(item[MATCH_KEY_FIELD]);
  113. return {
  114. key: matchKey,
  115. focusKey: matchKey,
  116. name,
  117. status: mapped.label,
  118. success: mapped.success,
  119. };
  120. };
  121. const matchItems = computed(() =>
  122. matchFileInfos.value.filter((item) => !isMatchFileRootItem(item)).map(buildMatchItem),
  123. );
  124. const totalCount = computed(() => matchItems.value.length);
  125. const successList = computed(() => matchItems.value.filter((item) => item.success));
  126. const failList = computed(() => matchItems.value.filter((item) => !item.success));
  127. const visibleSections = computed(() => {
  128. const sections = [
  129. {
  130. key: 'success',
  131. title: '匹配成功',
  132. desc: '已成功识别模板和数据结构,可直接进入清洗导入流程。',
  133. items: successList.value,
  134. },
  135. {
  136. key: 'fail',
  137. title: '未匹配成功',
  138. desc: '建议先检查文件格式或执行手动清洗后再重新导入。',
  139. items: failList.value,
  140. },
  141. ];
  142. if (status.value === 'success') {
  143. return sections.filter((item) => item.key === 'success');
  144. }
  145. if (status.value === 'fail') {
  146. return sections.filter((item) => item.key === 'fail');
  147. }
  148. return sections;
  149. });
  150. const resolveBatchId = () => {
  151. const matchedItem = matchFileInfos.value.find((item) => item?.batchId);
  152. const batchId = String(matchedItem?.batchId ?? '').trim();
  153. return batchId || undefined;
  154. };
  155. const handleBack = async () => {
  156. const batchId = resolveBatchId();
  157. if (batchId) {
  158. try {
  159. await cancelClean({ batchId });
  160. } catch (error) {
  161. createMessage.warning('取消清洗失败,已返回案件数据页面');
  162. }
  163. }
  164. await go(PageEnum.BASE_HOME, true);
  165. await nextTick();
  166. emitter.emit(CASE_DATA_REFRESH_EVENT);
  167. };
  168. const mapStatus = (status?: string) => {
  169. if (!status) return { success: false, label: '待处理' };
  170. if (status.includes('SUCCESS') || status.includes('COMPLETE')) return { success: true, label: '匹配成功' };
  171. if (status.includes('FAIL')) return { success: false, label: '匹配错误' };
  172. if (status.includes('PASSWORD')) return { success: false, label: '密码未识别' };
  173. if (status.includes('FORMAT')) return { success: false, label: '格式不正确' };
  174. if (status.includes('EMPTY')) return { success: false, label: '内容为空' };
  175. return { success: false, label: status };
  176. };
  177. const normalizeMatchNodeId = (value?: string | number | null) => String(value ?? '').trim();
  178. const getMatchNodeFallbackKey = (item: Recordable) =>
  179. [
  180. item.filePath || item.fileName || 'file',
  181. item.sheetName || 'root',
  182. item.tableName || '',
  183. item.lineNo ?? '',
  184. item.createDateTime || '',
  185. ].join('__');
  186. const getMatchNodeKey = (item: Recordable, index: number) =>
  187. normalizeMatchNodeId(item.id) || normalizeMatchNodeId(getMatchNodeFallbackKey(item)) || String(index);
  188. const normalizeQueryText = (value?: string | string[] | null) =>
  189. Array.isArray(value) ? String(value[0] ?? '').trim() : String(value ?? '').trim();
  190. const restoreMatchStatusFromQuery = () => {
  191. const nextStatus = normalizeQueryText(pageQuery.value?.status);
  192. if (['all', 'success', 'fail'].includes(nextStatus)) {
  193. status.value = nextStatus as MatchStatus;
  194. }
  195. };
  196. const restoreActiveMatchKeyFromQuery = () => {
  197. const nextFocusKey = normalizeQueryText(pageQuery.value?.focusKey);
  198. if (!nextFocusKey) return;
  199. const matchedItem = matchItems.value.find((item) => item.key === nextFocusKey || item.focusKey === nextFocusKey);
  200. if (matchedItem) {
  201. activeMatchKey.value = matchedItem.key;
  202. }
  203. };
  204. const loadMatchItems = () => {
  205. const raw = sessionStorage.getItem(FILE_INFO_STORAGE_KEY);
  206. if (!raw) {
  207. matchFileInfos.value = [];
  208. return;
  209. }
  210. try {
  211. const parsed = JSON.parse(raw) as Recordable[];
  212. if (!Array.isArray(parsed)) {
  213. matchFileInfos.value = [];
  214. return;
  215. }
  216. const fileInfos = parsed.map((item, index) => ({
  217. ...item,
  218. [MATCH_KEY_FIELD]: item[MATCH_KEY_FIELD] || getMatchNodeKey(item, index),
  219. }));
  220. matchFileInfos.value = fileInfos;
  221. } catch (error) {
  222. matchFileInfos.value = [];
  223. }
  224. };
  225. const handleSelectItem = (item: MatchItem) => {
  226. activeMatchKey.value = item.key;
  227. };
  228. const handleManualClean = (item: MatchItem) => {
  229. handleSelectItem(item);
  230. if (!matchFileInfos.value.length) {
  231. createMessage.warning('未找到可清洗文件,请先上传并匹配文件');
  232. return;
  233. }
  234. sessionStorage.setItem(FILE_INFO_STORAGE_KEY, JSON.stringify(matchFileInfos.value));
  235. go({
  236. path: PageEnum.BASE_CLEANING,
  237. query: {
  238. focusKey: item.focusKey,
  239. from: 'match',
  240. matchStatus: status.value,
  241. },
  242. });
  243. };
  244. const handleDeleteItem = (item: MatchItem) => {
  245. handleSelectItem(item);
  246. const targetInfo = matchFileInfos.value.find((fileInfo) => String(fileInfo[MATCH_KEY_FIELD]) === item.key);
  247. const targetParentId = normalizeMatchParentId(targetInfo?.pid);
  248. const nextFileInfos = matchFileInfos.value.filter((fileInfo) => String(fileInfo[MATCH_KEY_FIELD]) !== item.key);
  249. if (targetParentId) {
  250. const hasSiblingSheet = nextFileInfos.some((fileInfo) => normalizeMatchParentId(fileInfo.pid) === targetParentId);
  251. if (!hasSiblingSheet) {
  252. matchFileInfos.value = nextFileInfos.filter((fileInfo) => String(fileInfo.id ?? '').trim() !== targetParentId);
  253. } else {
  254. matchFileInfos.value = nextFileInfos;
  255. }
  256. } else {
  257. matchFileInfos.value = nextFileInfos;
  258. }
  259. sessionStorage.setItem(FILE_INFO_STORAGE_KEY, JSON.stringify(matchFileInfos.value));
  260. if (activeMatchKey.value === item.key) {
  261. const nextActiveItem = matchItems.value.find((matchItem) => matchItem.key !== item.key);
  262. activeMatchKey.value = nextActiveItem?.key || '';
  263. }
  264. createMessage.success('删除成功');
  265. };
  266. const handleCleanImport = () => {
  267. if (!matchItems.value.length) {
  268. createMessage.warning('未找到可清洗文件,请先上传并匹配文件');
  269. return;
  270. }
  271. resetImportProgressSession();
  272. go(PageEnum.BASE_CLEAN_PROGRESS);
  273. };
  274. onMounted(() => {
  275. restoreMatchStatusFromQuery();
  276. loadMatchItems();
  277. restoreActiveMatchKeyFromQuery();
  278. });
  279. </script>
  280. <style lang="less">
  281. @prefix-cls: ~'jeesite-case-match';
  282. .@{prefix-cls}.case-match-page {
  283. min-height: 100%;
  284. height: 100%;
  285. padding: 12px 16px 24px;
  286. background: #fff;
  287. display: flex;
  288. flex-direction: column;
  289. gap: 12px;
  290. box-sizing: border-box;
  291. overflow: auto;
  292. .page-header {
  293. display: flex;
  294. align-items: center;
  295. justify-content: space-between;
  296. gap: 16px;
  297. }
  298. .page-title-wrap {
  299. display: flex;
  300. align-items: flex-start;
  301. gap: 12px;
  302. min-width: 0;
  303. }
  304. .back-btn {
  305. display: inline-flex;
  306. align-items: center;
  307. gap: 4px;
  308. padding: 0 6px 0 0;
  309. height: 36px;
  310. border-radius: 8px;
  311. color: #2563eb;
  312. font-size: 16px;
  313. font-weight: 600;
  314. line-height: 1;
  315. flex-shrink: 0;
  316. :deep(.ant-btn-icon) {
  317. font-size: 18px;
  318. }
  319. &:hover {
  320. color: #1d4ed8;
  321. }
  322. }
  323. .page-title {
  324. font-size: 18px;
  325. line-height: 1.4;
  326. font-weight: 600;
  327. color: #111827;
  328. }
  329. .page-subtitle {
  330. margin-top: 4px;
  331. font-size: 13px;
  332. line-height: 1.6;
  333. color: #6b7280;
  334. }
  335. .page-action {
  336. height: 36px;
  337. padding: 0 18px;
  338. border-radius: 8px;
  339. flex-shrink: 0;
  340. }
  341. .filter-bar {
  342. display: flex;
  343. align-items: center;
  344. gap: 12px;
  345. flex-wrap: wrap;
  346. padding: 12px 16px;
  347. border: 1px solid #e5e7eb;
  348. border-radius: 12px;
  349. background: #fafafa;
  350. box-shadow: 0 8px 24px rgba(15, 23, 42, 0.04);
  351. }
  352. .filter-item {
  353. display: flex;
  354. align-items: center;
  355. gap: 8px;
  356. }
  357. .filter-label {
  358. color: #4b5563;
  359. font-size: 13px;
  360. white-space: nowrap;
  361. }
  362. .filter-select {
  363. width: 160px;
  364. }
  365. .filter-summary {
  366. margin-left: auto;
  367. color: #6b7280;
  368. font-size: 12px;
  369. white-space: nowrap;
  370. }
  371. .stats-grid {
  372. display: grid;
  373. grid-template-columns: repeat(3, minmax(0, 1fr));
  374. gap: 12px;
  375. }
  376. .stat-card {
  377. padding: 16px 18px;
  378. border: 1px solid #e5e7eb;
  379. border-radius: 12px;
  380. background: #fff;
  381. box-shadow: 0 8px 24px rgba(15, 23, 42, 0.04);
  382. }
  383. .stat-label {
  384. color: #6b7280;
  385. font-size: 13px;
  386. }
  387. .stat-value {
  388. margin-top: 8px;
  389. font-size: 28px;
  390. line-height: 1;
  391. font-weight: 600;
  392. color: #111827;
  393. }
  394. .stat-card.success .stat-value {
  395. color: #15803d;
  396. }
  397. .stat-card.error .stat-value {
  398. color: #dc2626;
  399. }
  400. .section-card {
  401. flex: 0 0 auto;
  402. border: 1px solid #e5e7eb;
  403. border-radius: 12px;
  404. background: #fff;
  405. box-shadow: 0 8px 24px rgba(15, 23, 42, 0.04);
  406. overflow: hidden;
  407. }
  408. .sections-scroll {
  409. min-height: 0;
  410. flex: 1 1 auto;
  411. display: flex;
  412. flex-direction: column;
  413. gap: 12px;
  414. overflow-y: auto;
  415. padding-right: 4px;
  416. padding-bottom: 2px;
  417. }
  418. .panel-header {
  419. display: flex;
  420. align-items: center;
  421. justify-content: space-between;
  422. gap: 12px;
  423. padding: 16px 18px 12px;
  424. border-bottom: 1px solid #eef2f7;
  425. }
  426. .panel-title {
  427. font-size: 15px;
  428. font-weight: 600;
  429. color: #111827;
  430. }
  431. .panel-desc {
  432. margin-top: 4px;
  433. font-size: 12px;
  434. color: #6b7280;
  435. line-height: 1.6;
  436. }
  437. .match-list {
  438. display: flex;
  439. flex-direction: column;
  440. padding: 12px 18px 18px;
  441. }
  442. .match-row {
  443. display: grid;
  444. grid-template-columns: minmax(0, 1fr) 140px 180px;
  445. align-items: center;
  446. gap: 12px;
  447. position: relative;
  448. margin: 0 -10px;
  449. min-height: 52px;
  450. padding: 10px 10px;
  451. border-radius: 10px;
  452. border-bottom: 1px solid #eef2f7;
  453. cursor: pointer;
  454. transition:
  455. background-color 0.2s ease,
  456. box-shadow 0.2s ease;
  457. &:last-child {
  458. border-bottom: none;
  459. }
  460. &:hover {
  461. background: #f8fbff;
  462. }
  463. &.is-active {
  464. background: #eef4ff;
  465. box-shadow:
  466. inset 3px 0 0 #3651d9,
  467. inset 0 0 0 1px rgba(54, 81, 217, 0.12);
  468. .match-name {
  469. color: #1d4ed8;
  470. font-weight: 600;
  471. }
  472. }
  473. }
  474. .match-name {
  475. color: #111827;
  476. font-size: 13px;
  477. line-height: 1.6;
  478. }
  479. .match-status {
  480. display: inline-flex;
  481. align-items: center;
  482. justify-content: center;
  483. width: fit-content;
  484. min-width: 88px;
  485. padding: 4px 10px;
  486. border-radius: 999px;
  487. background: #ecfdf3;
  488. color: #15803d;
  489. font-size: 12px;
  490. font-weight: 600;
  491. }
  492. .match-status.error {
  493. background: #fef2f2;
  494. color: #dc2626;
  495. }
  496. .match-actions {
  497. display: flex;
  498. justify-content: flex-end;
  499. gap: 8px;
  500. }
  501. .action-link {
  502. padding: 0;
  503. height: auto;
  504. }
  505. .action-link.danger {
  506. color: #ef4444;
  507. }
  508. .empty-state {
  509. padding: 28px 18px;
  510. border: 1px dashed #d1d5db;
  511. border-radius: 12px;
  512. background: #fafafa;
  513. color: #9ca3af;
  514. text-align: center;
  515. font-size: 13px;
  516. }
  517. @media (max-width: 960px) {
  518. .page-header {
  519. flex-direction: column;
  520. align-items: flex-start;
  521. }
  522. .filter-summary {
  523. margin-left: 0;
  524. }
  525. .stats-grid {
  526. grid-template-columns: 1fr;
  527. }
  528. .match-row {
  529. grid-template-columns: 1fr;
  530. }
  531. .match-actions {
  532. justify-content: flex-start;
  533. }
  534. }
  535. }
  536. </style>