Эх сурвалжийг харах

解决自定义布局渲染报错问题

lph 1 жил өмнө
parent
commit
c6a7160d05

+ 17 - 3
zkqy-ui/src/views/tablelist/commonTable/listInfo.vue

@@ -959,7 +959,8 @@ export default {
                 this.transformDataFormat(res.data);
                 this.transformDataFormat(res.data);
                 if (this.isLayout) {
                 if (this.isLayout) {
                   //自定义布局
                   //自定义布局
-                  this.layoutData = res.data;
+                  console.log(JSON.parse(JSON.stringify(res.data)));
+                  this.layoutData = JSON.parse(JSON.stringify(res.data));
                 }
                 }
 
 
                 // this.tableName = res.data.mainForm.showTemplate.dfTableName;
                 // this.tableName = res.data.mainForm.showTemplate.dfTableName;
@@ -969,6 +970,7 @@ export default {
               }
               }
               // console.log(this.formList);
               // console.log(this.formList);
               this.open = true;
               this.open = true;
+
               if (btnData.btnFormType == "dragFormGroup") {
               if (btnData.btnFormType == "dragFormGroup") {
                 this.times--;
                 this.times--;
                 if (this.times) {
                 if (this.times) {
@@ -981,6 +983,13 @@ export default {
                   });
                   });
                 }
                 }
               }
               }
+              this.$nextTick(() => {
+                // 手动触发布局组件的数据处理函数
+                console.log(111, JSON.parse(JSON.stringify(res.data)));
+                this.$refs.formGroupLayoutRef?.initLayoutData(
+                  JSON.parse(JSON.stringify(res.data))
+                );
+              });
 
 
               // this.$nextTick(() => {
               // this.$nextTick(() => {
               //   this.open = false;
               //   this.open = false;
@@ -1138,7 +1147,10 @@ export default {
         for (const key of Object.keys(showValue)) {
         for (const key of Object.keys(showValue)) {
           if (key != "remark") {
           if (key != "remark") {
             showValue[toUnderline(key)] = showValue[key];
             showValue[toUnderline(key)] = showValue[key];
-            delete showValue[key];
+            // delete showValue[key];
+            if (toUnderline(key) != key) {
+              delete showValue[key];
+            }
           }
           }
         }
         }
         mainForm.showTemplate.resultMap = [showValue];
         mainForm.showTemplate.resultMap = [showValue];
@@ -1189,7 +1201,9 @@ export default {
               for (const key of Object.keys(item.showValue[0].resultMap)) {
               for (const key of Object.keys(item.showValue[0].resultMap)) {
                 item.showValue[0].resultMap[toUnderline(key)] =
                 item.showValue[0].resultMap[toUnderline(key)] =
                   item.showValue[0].resultMap[key];
                   item.showValue[0].resultMap[key];
-                delete item.showValue[0].resultMap[key];
+                if (toUnderline(key) != key) {
+                  delete item.showValue[0].resultMap[key];
+                }
               }
               }
 
 
               item.showTemplate.resultMap = [item.showValue[0].resultMap];
               item.showTemplate.resultMap = [item.showValue[0].resultMap];

+ 19 - 12
zkqy-ui/src/views/tablelist/components/FormGroupLayout/LayoutIndex.vue

@@ -12,6 +12,7 @@
 <script>
 <script>
 import { camelCase, toUnderline } from "@/utils";
 import { camelCase, toUnderline } from "@/utils";
 import LayoutItem from "./LayoutItem.vue";
 import LayoutItem from "./LayoutItem.vue";
+import { cloneDeep } from "lodash";
 export default {
 export default {
   name: "LayoutIndex",
   name: "LayoutIndex",
   props: ["layoutData"],
   props: ["layoutData"],
@@ -27,7 +28,7 @@ export default {
     myLayoutData: {
     myLayoutData: {
       handler(newVal, oldVal) {
       handler(newVal, oldVal) {
         if (newVal) {
         if (newVal) {
-          this.initLayoutData(newVal);
+          // this.initLayoutData(newVal);
         }
         }
       },
       },
       deep: true,
       deep: true,
@@ -41,9 +42,9 @@ export default {
   },
   },
   methods: {
   methods: {
     initLayoutData(formData) {
     initLayoutData(formData) {
+      console.log(JSON.parse(JSON.stringify(formData)));
       let { layoutJson, mainForm, subFormList } = formData;
       let { layoutJson, mainForm, subFormList } = formData;
       this.layoutJson = JSON.parse(layoutJson);
       this.layoutJson = JSON.parse(layoutJson);
-      console.log(formData);
       this.transformDataFormat(formData);
       this.transformDataFormat(formData);
       this.formArray = this.disableHandler(this.formList);
       this.formArray = this.disableHandler(this.formList);
       this.setFormInfo(this.layoutJson.list);
       this.setFormInfo(this.layoutJson.list);
@@ -63,10 +64,13 @@ export default {
       }
       }
 
 
       if (showValue) {
       if (showValue) {
+        console.log("main showValue", showValue);
         for (const key of Object.keys(showValue)) {
         for (const key of Object.keys(showValue)) {
           if (key != "remark") {
           if (key != "remark") {
             showValue[toUnderline(key)] = showValue[key];
             showValue[toUnderline(key)] = showValue[key];
-            delete showValue[key];
+            if (toUnderline(key) != key) {
+              delete showValue[key];
+            }
           }
           }
         }
         }
         mainForm.showTemplate.resultMap = [showValue];
         mainForm.showTemplate.resultMap = [showValue];
@@ -88,19 +92,19 @@ export default {
       });
       });
       if (subFormList && subFormList.length > 0) {
       if (subFormList && subFormList.length > 0) {
         subFormList.forEach((item) => {
         subFormList.forEach((item) => {
-          let showValue = null;
+          console.log(JSON.parse(JSON.stringify(item)));
+          let subShowValue = null;
           if (item.showValue) {
           if (item.showValue) {
-            showValue = item.showValue[0];
+            subShowValue = item.showValue[0];
           }
           }
           let defaultValue = {};
           let defaultValue = {};
-          if (showValue) {
+          if (subShowValue) {
             if (item.showTemplate.spare == "2") {
             if (item.showTemplate.spare == "2") {
               //动态表格表单
               //动态表格表单
               let batch = {},
               let batch = {},
                 tableName = item.formItem?.split(".")?.[0];
                 tableName = item.formItem?.split(".")?.[0];
               batch[tableName] = item.showValue.map((item) => item.resultMap);
               batch[tableName] = item.showValue.map((item) => item.resultMap);
               defaultValue = JSON.parse(JSON.stringify(batch));
               defaultValue = JSON.parse(JSON.stringify(batch));
-              console.log(JSON.parse(JSON.stringify(batch)));
               // 所有字段驼峰转下划线
               // 所有字段驼峰转下划线
               batch[tableName].forEach((i) => {
               batch[tableName].forEach((i) => {
                 for (const key of Object.keys(i)) {
                 for (const key of Object.keys(i)) {
@@ -116,13 +120,16 @@ export default {
                 },
                 },
               ];
               ];
             } else {
             } else {
-              for (const key of Object.keys(item.showValue[0].resultMap)) {
-                item.showValue[0].resultMap[toUnderline(key)] =
-                  item.showValue[0].resultMap[key];
-                delete item.showValue[0].resultMap[key];
+              console.log("showValue", subShowValue.resultMap);
+              for (const key of Object.keys(subShowValue.resultMap)) {
+                subShowValue.resultMap[toUnderline(key)] =
+                  subShowValue.resultMap[key];
+                if (toUnderline(key) != key) {
+                  delete subShowValue.resultMap[key];
+                }
               }
               }
 
 
-              item.showTemplate.resultMap = [item.showValue[0].resultMap];
+              item.showTemplate.resultMap = [subShowValue.resultMap];
             }
             }
           }
           }
           this.formList.push({
           this.formList.push({

+ 1 - 0
zkqy-ui/src/views/tablelist/components/FormGroupLayout/LayoutItem.vue

@@ -57,6 +57,7 @@
       <k-form-build
       <k-form-build
         ref="formBuild"
         ref="formBuild"
         :value="record.dfVueTemplate"
         :value="record.dfVueTemplate"
+        :defaultValue="record.defaultValue || {}"
       ></k-form-build>
       ></k-form-build>
     </template>
     </template>
   </div>
   </div>