Bladeren bron

fix: 使用工厂函数创建表单对象以避免引用共享污染,并在关闭对话框时重置 fileObj

xieyong 2 weken geleden
bovenliggende
commit
b29224545d

+ 7 - 4
src/views/saleManage/contact/components/certificateManagement/components/add-dialog.vue

@@ -149,7 +149,8 @@
 
   // import { listOrganizations } from '@/api/system/organization';
   import { holderTypeOptions } from '@/enum/dict.js';
-  const defaultForm = {
+  // 用工厂函数返回新对象,避免模块级常量 + 浅拷贝导致的引用共享污染(特别是 fileObj 数组)
+  const createDefaultForm = () => ({
     code: '',
     holder: '',
     holderId: '',
@@ -159,7 +160,7 @@
     holderType: '4',
 
     status: 1
-  };
+  });
   export default {
     components: {
       // fileMain,
@@ -215,7 +216,7 @@
           // ],
           fileObj: [{ required: true, trigger: 'input', message: ' ' }]
         },
-        form: { ...defaultForm },
+        form: createDefaultForm(),
         title: '新增',
         holderTypeOptions,
         companyData: [] //公司分类
@@ -250,6 +251,8 @@
         } else {
           this.title = '新增';
           console.log(holderData, 'holderData~~~');
+          // 防御性重置:每次新增前清掉 fileObj,避免上一家公司残留(即便 A 没关闭 dialog 直接切 B 也不会带过去)
+          this.form.fileObj = [];
           this.form.holderType = holderData?.holderType || '';
           if (holderData.holderId) {
             this.form.holder = holderData.holder;
@@ -281,7 +284,7 @@
 
       close() {
         this.dialogVisible = false;
-        this.form = { ...defaultForm, fileObj: [] };
+        this.form = createDefaultForm();
         this.$refs.productTableRef.initData();
       },