Browse Source

form表单优化,laben回显

cz 2 years ago
parent
commit
49b40a5282
1 changed files with 23 additions and 13 deletions
  1. 23 13
      src/components/testForm/index.vue

+ 23 - 13
src/components/testForm/index.vue

@@ -470,8 +470,9 @@ const selectDataEcho = (item, val) => {
 };
 
 let btnConfigCopy = {};
+let callNum = ref(0);
+// 循环 label值回显
 const formDataShowLabel = () => {
-  // 选择框值回显
   for (let i = 0; i < formConfig.value.length; i++) {
     const element = formConfig.value[i];
     if (element.type === "picker" && element.itemType !== "datePicker") {
@@ -481,9 +482,13 @@ const formDataShowLabel = () => {
           formData.value[element.prop]
         );
       } else {
-        setTimeout(() => {
-          return formDataShowLabel();
-        }, 200);
+        if (callNum.value <= 3) {
+          setTimeout(() => {
+            callNum.value++;
+            return formDataShowLabel();
+          }, 1500);
+        }
+        return;
       }
     } else if (element.type === "cascader" && element.itemType === "common") {
       if (element.data && element.data.length > 0) {
@@ -492,9 +497,13 @@ const formDataShowLabel = () => {
           formData.value[element.prop]
         );
       } else {
-        setTimeout(() => {
-          return formDataShowLabel();
-        }, 200);
+        if (callNum.value <= 3) {
+          setTimeout(() => {
+            callNum.value++;
+            return formDataShowLabel();
+          }, 1500);
+        }
+        return;
       }
     }
   }
@@ -516,9 +525,13 @@ const formDataShowLabel = () => {
                 formData.value[btnConfigCopy.prop][i][listEle.prop]
               );
           } else {
-            setTimeout(() => {
-              return formDataShowLabel();
-            }, 200);
+            if (callNum.value <= 3) {
+              setTimeout(() => {
+                callNum.value++;
+                return formDataShowLabel();
+              }, 1500);
+            }
+            return;
           }
         } else {
           continue;
@@ -812,9 +825,6 @@ watch(
   }
 );
 
-defineExpose({
-  formDataInit,
-});
 // onMounted(() => {});
 </script>