From 0db4bf5a865d183a83dc991d2ef53f820dca8c77 Mon Sep 17 00:00:00 2001
From: gaoluyang <2820782392@qq.com>
Date: 星期一, 12 十月 2026 10:32:57 +0800
Subject: [PATCH] fix(mdm): 物料管理 导入失败展示修改及同步生产物料问题
---
src/views/basicData/mdm/modules/import-form.vue | 113 ++++++++++++++++++++++++++++++++++++++++++++++++--------
1 files changed, 96 insertions(+), 17 deletions(-)
diff --git a/src/views/basicData/mdm/modules/import-form.vue b/src/views/basicData/mdm/modules/import-form.vue
index 5cc47a2..c868b40 100644
--- a/src/views/basicData/mdm/modules/import-form.vue
+++ b/src/views/basicData/mdm/modules/import-form.vue
@@ -1,18 +1,28 @@
<script lang="ts" setup>
import type { FileType } from 'ant-design-vue/es/upload/interface';
-import { h } from 'vue';
+import { computed, ref } from 'vue';
import { useVbenModal } from '@vben/common-ui';
import { downloadFileFromBlobPart } from '@vben/utils';
-import { Button, message, notification, Upload } from 'ant-design-vue';
+import { Button, message, Upload } from 'ant-design-vue';
import { useVbenForm } from '#/adapter/form';
import { importItem, importItemTemplate } from '#/api/mdm/item';
import { $t } from '#/locales';
import { useImportFormSchema } from '../data';
+
+/** 瀵煎叆缁撴灉锛屽搴斿悗绔� MdmItemImportRespVO */
+interface ImportResult {
+ /** 鏂板鎴愬姛鐨勭墿鏂� */
+ createList?: string[];
+ /** 鏇存柊鎴愬姛鐨勭墿鏂� */
+ updateList?: string[];
+ /** 澶辫触鏄庣粏锛歬ey 涓恒�岀墿鏂欑紪鐮� 鍚嶇О銆嶏紝value 涓哄け璐ュ師鍥� */
+ failureList?: Record<string, string>;
+}
const emit = defineEmits(['success']);
@@ -26,6 +36,17 @@
showDefaultActions: false,
});
+const importResult = ref<ImportResult>({});
+const createCount = computed(() => importResult.value.createList?.length ?? 0);
+const updateCount = computed(() => importResult.value.updateList?.length ?? 0);
+const failureEntries = computed(() =>
+ Object.entries(importResult.value.failureList ?? {}),
+);
+const failureCount = computed(() => failureEntries.value.length);
+
+// 娉ㄦ剰锛氭湰缁勪欢閲岀殑澶氫釜 useVbenModal 鏈夊厛鍚庨『搴忚姹傗�斺��
+// 鐖堕〉闈㈢敤 useVbenModal({ connectedComponent: ImportForm }) 閫氳繃 provide/inject 缁戝畾锛�
+// 鍙湁绗竴涓皟鐢ㄤ細鎺ョ杩欎釜缁戝畾銆傛墍浠ュ鍏ョ獥鍙e繀椤诲0鏄庡湪鏈�鍓嶏紝鍏朵綑寮规锛堝缁撴灉寮规锛夋帓鍦ㄥ悗闈€��
const [Modal, modalApi] = useVbenModal({
async onConfirm() {
const { valid } = await formApi.validate();
@@ -37,29 +58,45 @@
const data = await formApi.getValues();
try {
const response = (await importItem(data.file, data.updateSupport)) as any;
- // 鍏抽棴骞舵彁绀�
- await modalApi.close();
+ const resultData = (response?.data || response || {}) as ImportResult;
+ const hasFailure = Object.keys(resultData.failureList ?? {}).length > 0;
+
emit('success');
- const resultData = response?.data || response || {};
- const failureList = resultData.failureList || {};
-
- if (Object.keys(failureList).length > 0) {
- const errorNodes = Object.entries(failureList).map(([name, reason]) => {
- return h('div', `${name}: ${reason}`);
- });
-
- notification.warning({
- message: '瀵煎叆瀹屾垚锛岄儴鍒嗙墿鏂欏鍏ュけ璐�',
- description: () => h('div', errorNodes),
- duration: null,
- });
+ if (hasFailure) {
+ // 涓嶈兘鍦ㄨ繖閲屽厛鍏冲鍏ョ獥鍙o細鐖堕〉闈㈤厤缃簡 destroyOnClose锛�
+ // 鍏崇獥浼氭妸鏈粍浠舵暣涓噸寤猴紝鍒氭墦寮�鐨勭粨鏋滃脊妗嗕細琚繛甯﹀嵏杞斤紙闂竴涓嬪氨娑堝け锛夈��
+ // 鏀逛负鎶婄粨鏋滃脊妗嗗彔鍦ㄤ笂闈紝绛夊畠鍏抽棴鍚庡啀鍏冲鍏ョ獥鍙o紙瑙佷笅闈� onClosed锛夈��
+ importResult.value = resultData;
+ resultModalApi.open();
} else {
+ importResult.value = {};
message.success($t('ui.actionMessage.operationSuccess'));
+ await modalApi.close();
}
} finally {
modalApi.unlock();
}
+ },
+});
+
+/** 瀵煎叆缁撴灉寮规锛氬け璐ユ槑缁嗗彲鑳藉緢闀匡紝寮规鍐呭浐瀹氶珮搴︽粴鍔紝閬垮厤鍍忛�氱煡鏉¢偅鏍锋拺鍑哄睆骞� */
+const [ResultModal, resultModalApi] = useVbenModal({
+ onOpenChange(isOpen: boolean) {
+ if (isOpen) {
+ resultModalApi.setState({
+ confirmText: '鐭ラ亾浜�',
+ showCancelButton: false,
+ });
+ }
+ },
+ // 蹇呴』鏄惧紡鎻愪緵锛歁odalApi.onConfirm 鏄� this.api.onConfirm?.() 鐨勫彲閫夎皟鐢紝涓嶄紶鍒欑偣鎸夐挳姣棤鍙嶅簲
+ onConfirm() {
+ resultModalApi.close();
+ },
+ // 缁撴灉寮规鍏抽棴鍚庡啀鍏冲鍏ョ獥鍙o紙姝ゆ椂鏈粍浠惰閿�姣佹槸瀹夊叏鐨勶級
+ onClosed() {
+ modalApi.close();
},
});
@@ -102,4 +139,46 @@
</div>
</template>
</Modal>
+
+ <ResultModal title="瀵煎叆缁撴灉" class="w-[760px]">
+ <div class="mx-4">
+ <div class="mb-3 flex flex-wrap gap-x-6 gap-y-1 text-sm">
+ <span>
+ 鏂板锛�<span class="font-medium text-green-600">{{ createCount }}</span>
+ 鏉�
+ </span>
+ <span>
+ 鏇存柊锛�<span class="font-medium text-blue-600">{{ updateCount }}</span>
+ 鏉�
+ </span>
+ <span>
+ 澶辫触锛�<span class="font-medium text-red-600">{{ failureCount }}</span>
+ 鏉�
+ </span>
+ </div>
+
+ <div
+ v-if="failureCount > 0"
+ class="overflow-hidden rounded-md border border-red-100"
+ >
+ <div
+ class="border-b border-red-100 bg-red-50 px-3 py-2 text-sm font-medium text-red-600"
+ >
+ 澶辫触鏄庣粏锛堝叡 {{ failureCount }} 鏉★紝涓嬫柟鍖哄煙鍙粴鍔ㄦ煡鐪嬶級
+ </div>
+ <div class="max-h-[60vh] overflow-y-auto">
+ <div
+ v-for="[itemKey, itemReason] in failureEntries"
+ :key="itemKey"
+ class="flex gap-2 border-b border-gray-100 px-3 py-2 text-sm last:border-b-0"
+ >
+ <span class="w-56 shrink-0 break-all text-gray-700">
+ {{ itemKey }}
+ </span>
+ <span class="break-all text-red-500">{{ itemReason }}</span>
+ </div>
+ </div>
+ </div>
+ </div>
+ </ResultModal>
</template>
--
Gitblit v1.9.3