From 18c174490b5778a652c10a3b57509ff61e743dd4 Mon Sep 17 00:00:00 2001
From: xiaoyi <908147524@qq.com>
Date: 星期五, 06 十一月 2026 15:32:30 +0800
Subject: [PATCH] 完善设备监测、安全管理及采购业务页面
---
src/components/wm-doc-import/index.vue | 31 +++++++++++++++++--------------
1 files changed, 17 insertions(+), 14 deletions(-)
diff --git a/src/components/wm-doc-import/index.vue b/src/components/wm-doc-import/index.vue
index 057aa3b..aa2f1fb 100644
--- a/src/components/wm-doc-import/index.vue
+++ b/src/components/wm-doc-import/index.vue
@@ -3,6 +3,7 @@
import { useVbenModal } from '@vben/common-ui';
import { downloadFileFromBlobPart } from '@vben/utils';
+import { shallowRef } from 'vue';
import { Button, message, Upload } from 'ant-design-vue';
@@ -10,21 +11,16 @@
defineOptions({ name: 'WmDocImportForm' });
-const props = withDefaults(
- defineProps<{
+interface ImportOptions {
/** 涓嬭浇妯℃澘鎺ュ彛 */
templateApi: () => Promise<Blob | BlobPart | any>;
/** 瀵煎叆鎺ュ彛 */
importApi: (file: File) => Promise<any>;
/** 鍗曟嵁鍚嶇О锛岀敤浜庢彁绀轰笌鏂囦欢鍚� */
subject: string;
- /** 涓婁紶妗嗘爣绛� */
- fileLabel?: string;
- }>(),
- {
- fileLabel: 'Excel 鏁版嵁',
- },
-);
+}
+
+const options = shallowRef<ImportOptions>();
const emit = defineEmits(['success']);
@@ -48,6 +44,11 @@
});
const [Modal, modalApi] = useVbenModal({
+ onOpenChange(isOpen) {
+ if (isOpen) {
+ options.value = modalApi.getData<ImportOptions>();
+ }
+ },
async onConfirm() {
const { valid } = await formApi.validate();
if (!valid) {
@@ -56,7 +57,7 @@
modalApi.lock();
const data = await formApi.getValues();
try {
- const result = (await props.importApi(data.file as File)) as any;
+ const result = (await options.value!.importApi(data.file as File)) as any;
const createCodes: string[] = result?.createCodes ?? [];
const failureCodes: Record<string, string> = result?.failureCodes ?? {};
const failCount = Object.keys(failureCodes).length;
@@ -69,7 +70,7 @@
// 缁撴灉鎻愮ず锛氭垚鍔�/澶辫触鍒嗗埆姹囨�伙紝澶辫触鏄庣粏鏈�澶氬睍绀� 5 鏉�
const lines: string[] = [];
if (createCodes.length > 0) {
- lines.push(`鎴愬姛瀵煎叆 ${createCodes.length} 寮�${props.subject}`);
+ lines.push(`鎴愬姛瀵煎叆 ${createCodes.length} 寮�${options.value!.subject}`);
}
if (failCount > 0) {
const detail = Object.entries(failureCodes)
@@ -91,6 +92,8 @@
} else {
message.warning(lines.join('锛�'));
}
+ } catch {
+ // 璇锋眰灞傚凡鎻愮ず閿欒锛屼繚鐣欏脊绐椾緵鐢ㄦ埛璋冩暣鏂囦欢鍚庨噸璇曘��
} finally {
modalApi.unlock();
}
@@ -105,16 +108,16 @@
/** 涓嬭浇妯$増 */
async function handleDownload() {
- const data = await props.templateApi();
+ const data = await options.value!.templateApi();
downloadFileFromBlobPart({
- fileName: `${props.subject}瀵煎叆妯℃澘.xls`,
+ fileName: `${options.value!.subject}瀵煎叆妯℃澘.xls`,
source: data,
});
}
</script>
<template>
- <Modal :title="`瀵煎叆${subject}`" class="w-2/5">
+ <Modal :title="`瀵煎叆${options?.subject ?? ''}`" class="w-2/5">
<Form class="mx-4">
<template #file>
<div class="w-full">
--
Gitblit v1.9.3