浏览代码

control 功能完善

xaboy 5 年之前
父节点
当前提交
e6c29380ff
共有 2 个文件被更改,包括 28 次插入4 次删除
  1. 24 3
      src/Form.php
  2. 4 1
      src/Rule/ControlRule.php

+ 24 - 3
src/Form.php

@@ -309,9 +309,19 @@ class Form
     {
     {
         if (Util::isComponent($rule)) {
         if (Util::isComponent($rule)) {
             $rule = $rule->build();
             $rule = $rule->build();
-        } else if (isset($rule['children']) && is_array($rule['children'])) {
-            foreach ($rule['children'] as $i => $child) {
-                $rule['children'][$i] = $this->parseFormComponent($child);
+        } else {
+            if (isset($rule['children']) && is_array($rule['children'])) {
+                foreach ($rule['children'] as $i => $child) {
+                    $rule['children'][$i] = $this->parseFormComponent($child);
+                }
+            }
+            if (isset($rule['control'])) {
+                foreach ($rule['control'] as $i => $child) {
+                    foreach ($child['rule'] as $k => $rule) {
+                        $child['rule'][$k] = Util::isComponent($rule) ? $rule->build() : $rule;
+                    }
+                    $rule['control'][$i] = $child;
+                }
             }
             }
         }
         }
         return $rule;
         return $rule;
@@ -338,6 +348,11 @@ class Form
                 if (isset($item['children']) && is_array($item['children']) && count($item['children'])) {
                 if (isset($item['children']) && is_array($item['children']) && count($item['children'])) {
                     $item['children'] = $this->deepSetFormData($formData, $item['children']);
                     $item['children'] = $this->deepSetFormData($formData, $item['children']);
                 }
                 }
+                if (isset($item['control']) && count($item['control'])) {
+                    foreach ($item['control'] as $_k => $_rule) {
+                        $item['control'][$_k]['rule'] = $this->deepSetFormData($formData, $_rule['rule']);
+                    }
+                }
             }
             }
             $rule[$k] = $item;
             $rule[$k] = $item;
         }
         }
@@ -465,6 +480,12 @@ class Form
             if (isset($rule['children']) && count($rule['children']))
             if (isset($rule['children']) && count($rule['children']))
                 $fields = $this->checkFieldUnique($rule['children'], $fields);
                 $fields = $this->checkFieldUnique($rule['children'], $fields);
 
 
+            if (isset($rule['control'])) {
+                foreach ($rule['control'] as $control) {
+                    $fields = $this->checkFieldUnique($control['rule'], $fields);
+                }
+            }
+
             if (is_null($field) || $field === '')
             if (is_null($field) || $field === '')
                 continue;
                 continue;
             else if (isset($fields[$field]))
             else if (isset($fields[$field]))

+ 4 - 1
src/Rule/ControlRule.php

@@ -69,7 +69,10 @@ trait ControlRule
         if (!count($this->control)) return [];
         if (!count($this->control)) return [];
         $control = [];
         $control = [];
         foreach ($this->control as $child) {
         foreach ($this->control as $child) {
-            $control[] = Util::isComponent($child) ? $child->build() : $child;
+            foreach ($child['rule'] as $k => $rule) {
+                $child['rule'][$k] = Util::isComponent($rule) ? $rule->build() : $rule;
+            }
+            $control[] = $child;
         }
         }
 
 
         return compact('control');
         return compact('control');