From 3ee139949840b4ba3caa320312a564e3cfbbfdd1 Mon Sep 17 00:00:00 2001
From: xiaoyi <908147524@qq.com>
Date: 星期一, 26 十月 2026 18:05:02 +0800
Subject: [PATCH] fix 上传

---
 src/components/import-modal/import-modal.vue |  147 +++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 141 insertions(+), 6 deletions(-)

diff --git a/src/components/import-modal/import-modal.vue b/src/components/import-modal/import-modal.vue
index 743e63e..357cc5c 100644
--- a/src/components/import-modal/import-modal.vue
+++ b/src/components/import-modal/import-modal.vue
@@ -1,15 +1,37 @@
 <script lang="ts" setup>
 import type { FileType } from 'ant-design-vue/es/upload/interface';
 
-import { ref } from 'vue';
+import { h, ref } from 'vue';
 
 import { useVbenModal } from '@vben/common-ui';
 import { downloadFileFromBlobPart } from '@vben/utils';
 
-import { Button, message, Upload } from 'ant-design-vue';
+import { Button, message, Modal as AntModal, Upload } from 'ant-design-vue';
 
 import { useVbenForm, z } from '#/adapter/form';
 import { $t } from '#/locales';
+
+/**
+ * 瀵煎叆鎺ュ彛杩斿洖缁撴瀯銆�
+ *
+ * 鍚庣鍚勬ā鍧楃殑瀵煎叆杩斿洖鍊间笉缁熶竴锛岃繖閲屽彧鎻忚堪銆屽彲灞曠ず鐨勫鍏ョ粨鏋溿�嶇殑鍏叡閮ㄥ垎锛�
+ * 鎴愬姛鐨勬潯鏁般�佸け璐ョ殑闆嗗悎銆佽璺宠繃鐨勮銆傝瘑鍒笉鍑虹殑杩斿洖鍊兼寜銆屽叏閮ㄦ垚鍔熴�嶅鐞嗐��
+ */
+export interface ImportResultLike {
+  /** 鎴愬姛瀵煎叆鐨勫崟鍙�/鍚嶇О鍒楄〃 */
+  createPurchaseRequestNos?: string[];
+  /** 澶辫触闆嗗悎锛歬ey 涓哄崟鍙锋垨琛屽彿锛寁alue 涓哄師鍥� */
+  failurePurchaseRequestNos?: Record<string, string>;
+  /** 琚烦杩囩殑琛岋細key 涓� Excel 琛屽彿锛寁alue 涓哄師鍥� */
+  skippedRows?: Record<string, string>;
+  /** Excel 涓疄闄呮湁鏁版嵁鐨勮鏁� */
+  totalRows?: number;
+  /** 鎴愬姛瀵煎叆鐨勮鏁� */
+  successRows?: number;
+  /** 鍏跺畠妯″潡鐨勯�氱敤瀛楁锛氬け璐ュ垪琛� */
+  failureList?: Record<string, string> | string[];
+  [key: string]: unknown;
+}
 
 export interface ImportModalProps {
   /** 寮圭獥鏍囬锛屽銆屽鍏ョ敤鎴枫�� */
@@ -60,6 +82,72 @@
   showDefaultActions: false,
 });
 
+/**
+ * 浠庡鍏ユ帴鍙g殑杩斿洖鍊奸噷鎻愬彇鍙睍绀虹殑缁撴灉銆�
+ *
+ * 鍏抽敭鐐癸細涓嶈兘鍙湅鎺ュ彛鏈夋病鏈夋姤閿欏氨鎻愮ず銆屾搷浣滄垚鍔熴�嶁�斺�斿悗绔彲鑳借烦杩囦簡閮ㄥ垎琛岋紝
+ * 杩欎簺琛屼笉浼氭姏寮傚父锛屽繀椤绘妸璺宠繃/澶辫触鐨勬暟閲忓拰琛屽彿鏄庣‘鍛婅瘔鐢ㄦ埛锛屽惁鍒欐暟鎹棤澹颁涪澶便��
+ */
+function summarizeImportResult(raw: unknown) {
+  const result = (raw ?? {}) as ImportResultLike;
+
+  // 鎴愬姛鏉℃暟锛氫紭鍏堢敤鍚庣缁欑殑鎴愬姛琛屾暟锛屽叾娆$敤鎴愬姛鍗曞彿鏁扮粍闀垮害
+  const successNos = Array.isArray(result.createPurchaseRequestNos)
+    ? result.createPurchaseRequestNos
+    : [];
+  const successRows =
+    typeof result.successRows === 'number' ? result.successRows : successNos.length;
+
+  const failureEntries = toEntries(result.failurePurchaseRequestNos ?? result.failureList);
+  const skippedEntries = toEntries(result.skippedRows);
+
+  const totalRows = typeof result.totalRows === 'number' ? result.totalRows : undefined;
+
+  return {
+    successRows,
+    failureEntries,
+    skippedEntries,
+    totalRows,
+    hasIssue: failureEntries.length > 0 || skippedEntries.length > 0,
+  };
+}
+
+/** 鎶� Record / string[] / undefined 缁熶竴鎴� [label, reason][] */
+function toEntries(input: unknown): Array<[string, string]> {
+  if (!input) {
+    return [];
+  }
+  if (Array.isArray(input)) {
+    return input.map((item) => [String(item), '']);
+  }
+  if (typeof input === 'object') {
+    return Object.entries(input as Record<string, string>).map(([k, v]) => [
+      k,
+      String(v ?? ''),
+    ]);
+  }
+  return [];
+}
+
+/** 鎶婄粨鏋滄嫾鎴愮敤鎴疯兘鐪嬫噦鐨勪竴娈佃瘽 */
+function buildResultMessage(summary: ReturnType<typeof summarizeImportResult>) {
+  const parts: string[] = [];
+  if (summary.successRows > 0) {
+    parts.push(`鎴愬姛 ${summary.successRows} 鏉);
+  }
+  if (summary.skippedEntries.length > 0) {
+    parts.push(`璺宠繃 ${summary.skippedEntries.length} 鏉);
+  }
+  if (summary.failureEntries.length > 0) {
+    parts.push(`澶辫触 ${summary.failureEntries.length} 鏉);
+  }
+  if (parts.length === 0) {
+    return '瀵煎叆瀹屾垚锛屼絾娌℃湁瀵煎叆浠讳綍鏁版嵁';
+  }
+  const total = summary.totalRows === undefined ? '' : `锛堣〃鏍煎叡 ${summary.totalRows} 琛岋級`;
+  return `瀵煎叆瀹屾垚锛�${parts.join('锛�')}${total}`;
+}
+
 const [Modal, modalApi] = useVbenModal({
   async onOpenChange(isOpen: boolean) {
     if (isOpen) {
@@ -76,16 +164,63 @@
     // 鎻愪氦琛ㄥ崟
     const data = await formApi.getValues();
     try {
-      await config.value.importFn(data.file, data.updateSupport);
-      // 鍏抽棴骞舵彁绀�
+      // 缁熶竴鍏滃簳锛氬悗绔悇妯″潡鍘嗗彶瀹炵幇瀵� updateSupport 鐨勬潵婧愪笉涓�鑷达紙鏈夌殑浠� query 璇汇��
+      // 鏈夌殑浠庤〃鍗曡锛夛紝婕忎紶浼氳 @NotNull 鎷︿笅骞跺脊鍑虹敤鎴锋牴鏈湅涓嶅埌瀵瑰簲瀛楁鐨�
+      // "鏄惁鏀寔鏇存柊涓嶈兘涓虹┖"銆傝繖閲屽己鍒舵樉寮忎紶甯冨皵鍊硷紝閬垮厤浠讳綍椤甸潰鍥犳湭鍒濆鍖栬俯鍧戙��
+      const updateSupport = data.updateSupport === true;
+      const raw = await config.value.importFn(data.file, updateSupport);
+      const summary = summarizeImportResult(raw);
+      const text = buildResultMessage(summary);
+
+      if (summary.hasIssue) {
+        // 鏈夎烦杩囨垨澶辫触鐨勮锛氫繚鎸佸脊绐楁墦寮�锛屾妸鏄庣粏灞曠ず缁欑敤鎴凤紝閬垮厤鏁版嵁鏃犲0涓㈠け
+        message.warning({
+          content: text,
+          duration: 8,
+        });
+        showDetail(summary);
+        emit('success');
+        return;
+      }
+
       await modalApi.close();
       emit('success');
-      message.success($t('ui.actionMessage.operationSuccess'));
+      message.success(text);
     } finally {
       modalApi.unlock();
     }
   },
 });
+
+/** 鐢� Modal.info 灞曠ず璺宠繃/澶辫触鏄庣粏锛屾瘮 toast 鏇磋�愯 */
+function showDetail(summary: ReturnType<typeof summarizeImportResult>) {
+  const sections: Array<{ title: string; rows: Array<[string, string]> }> = [];
+  if (summary.skippedEntries.length > 0) {
+    sections.push({ title: '琚烦杩囩殑琛岋紙鏈鍏ワ級', rows: summary.skippedEntries });
+  }
+  if (summary.failureEntries.length > 0) {
+    sections.push({ title: '瀵煎叆澶辫触', rows: summary.failureEntries });
+  }
+  AntModal.info({
+    title: '瀵煎叆缁撴灉鏄庣粏',
+    width: 560,
+    content: h(
+      'div',
+      { style: 'max-height: 360px; overflow-y: auto;' },
+      sections.map((section) =>
+        h('div', { style: 'margin-bottom: 12px;' }, [
+          h('div', { style: 'font-weight: 600; margin-bottom: 4px;' }, section.title),
+          ...section.rows.map(([label, reason]) =>
+            h('div', { style: 'font-size: 13px; line-height: 20px;' }, [
+              h('span', { style: 'color: #cf1322;' }, `${label}`),
+              h('span', {}, `锛�${reason || '鏈鏄庡師鍥�'}`),
+            ]),
+          ),
+        ]),
+      ),
+    ),
+  });
+}
 
 /** 涓婁紶鍓� */
 function beforeUpload(file: FileType) {
@@ -121,4 +256,4 @@
       </div>
     </template>
   </Modal>
-</template>
+</template>
\ No newline at end of file

--
Gitblit v1.9.3