Browse Source

升级 form-create 版本,支持 control

xaboy 5 years ago
parent
commit
df490d4549

+ 4 - 1
src/Driver/CustomComponent.php

@@ -17,6 +17,7 @@ use FormBuilder\Contract\CustomComponentInterface;
 use FormBuilder\Rule\BaseRule;
 use FormBuilder\Rule\CallPropsRule;
 use FormBuilder\Rule\ChildrenRule;
+use FormBuilder\Rule\ControlRule;
 use FormBuilder\Rule\EmitRule;
 use FormBuilder\Rule\PropsRule;
 use FormBuilder\Rule\ValidateRule;
@@ -33,6 +34,7 @@ class CustomComponent implements CustomComponentInterface, \JsonSerializable, \A
     use PropsRule;
     use ValidateRule;
     use CallPropsRule;
+    use ControlRule;
 
     protected static $propsRule = [];
 
@@ -74,7 +76,8 @@ class CustomComponent implements CustomComponentInterface, \JsonSerializable, \A
             $this->parseEmitRule(),
             $this->parsePropsRule(),
             $this->parseValidateRule(),
-            $this->parseChildrenRule()
+            $this->parseChildrenRule(),
+            $this->parseControlRule()
         );
     }
 

+ 1 - 6
src/Rule/ChildrenRule.php

@@ -81,11 +81,6 @@ trait ChildrenRule
         return $this->children;
     }
 
-    protected function parseChildren($child)
-    {
-        return Util::isComponent($child) ? $child->build() : $child;
-    }
-
     /**
      * @return array
      */
@@ -94,7 +89,7 @@ trait ChildrenRule
         if (!count($this->children)) return [];
         $children = [];
         foreach ($this->children as $child) {
-            $children[] = $this->parseChildren($child);
+            $children[] = Util::isComponent($child) ? $child->build() : $child;
         }
 
         return compact('children');

+ 77 - 0
src/Rule/ControlRule.php

@@ -0,0 +1,77 @@
+<?php
+/**
+ * PHP表单生成器
+ *
+ * @package  FormBuilder
+ * @author   xaboy <xaboy2005@qq.com>
+ * @version  2.0
+ * @license  MIT
+ * @link     https://github.com/xaboy/form-builder
+ * @document http://php.form-create.com
+ */
+
+namespace FormBuilder\Rule;
+
+
+use FormBuilder\Util;
+
+trait ControlRule
+{
+    /**
+     * 根据组件的值显示不同的组件
+     *
+     * @var
+     */
+    protected $control = [];
+
+
+    /**
+     * @param array $control
+     * @return $this
+     */
+    public function control(array $control)
+    {
+        $this->control = $control;
+        return $this;
+    }
+
+    /**
+     * @param string|int|float $value
+     * @param array $rule
+     * @return $this
+     */
+    public function appendControl($value, array $rule)
+    {
+        $this->control[] = compact('value', 'rule');
+        return $this;
+    }
+
+    /**
+     * @param array $controls
+     * @return $this
+     */
+    public function appendControls(array $controls)
+    {
+        $this->control = array_merge($this->control, $controls);
+        return $this;
+    }
+
+    public function getControl()
+    {
+        return $this->control;
+    }
+
+    /**
+     * @return array
+     */
+    public function parseControlRule()
+    {
+        if (!count($this->control)) return [];
+        $control = [];
+        foreach ($this->control as $child) {
+            $control[] = Util::isComponent($child) ? $child->build() : $child;
+        }
+
+        return compact('control');
+    }
+}

+ 1 - 1
src/UI/Elm/Bootstrap.php

@@ -25,7 +25,7 @@ class Bootstrap implements BootstrapInterface
         array_splice($dependScript, 2, 0, [
             '<link href="https://unpkg.com/element-ui@2.12.0/lib/theme-chalk/index.css" rel="stylesheet">',
             '<script src="https://unpkg.com/element-ui@2.12.0/lib/index.js"></script>',
-            '<script src="https://unpkg.com/@form-create/element-ui@1.0.7/dist/form-create.min.js"></script>',
+            '<script src="https://unpkg.com/@form-create/element-ui@1.0.9/dist/form-create.min.js"></script>',
         ]);
 
         $form->setDependScript($dependScript);

+ 11 - 0
src/UI/Elm/Style/FormStyle.php

@@ -65,6 +65,17 @@ class FormStyle implements StyleInterface
     }
 
     /**
+     * 设置表单 class
+     * @param $class
+     * @return $this
+     */
+    public function className($class)
+    {
+        $this->props['className'] = $class;
+        return $this;
+    }
+
+    /**
      * @return object
      */
     public function getStyle()

+ 2 - 2
src/UI/Iview/Bootstrap.php

@@ -37,13 +37,13 @@ class Bootstrap implements BootstrapInterface
             array_splice($dependScript, 2, 0, [
                 '<link href="https://unpkg.com/iview@3.4.2/dist/styles/iview.css" rel="stylesheet">',
                 '<script src="https://unpkg.com/iview@3.4.2/dist/iview.min.js"></script>',
-                '<script src="https://unpkg.com/@form-create/iview@1.0.7/dist/form-create.min.js"></script>',
+                '<script src="https://unpkg.com/@form-create/iview@1.0.9/dist/form-create.min.js"></script>',
             ]);
         } else {
             array_splice($dependScript, 2, 0, [
                 '<link href="https://unpkg.com/view-design@4.0.2/dist/styles/iview.css" rel="stylesheet">',
                 '<script src="https://unpkg.com/view-design@4.0.2/dist/iview.min.js"></script>',
-                '<script src="https://unpkg.com/@form-create/iview4@1.0.7/dist/form-create.min.js"></script>',
+                '<script src="https://unpkg.com/@form-create/iview4@1.0.9/dist/form-create.min.js"></script>',
             ]);
         }
 

+ 11 - 0
src/UI/Iview/Style/FormStyle.php

@@ -48,6 +48,17 @@ class FormStyle implements StyleInterface
     }
 
     /**
+     * 设置表单 class
+     * @param $class
+     * @return $this
+     */
+    public function className($class)
+    {
+        $this->rule['className'] = $class;
+        return $this;
+    }
+
+    /**
      * 表单域标签的位置,可选值为 left、right、top
      *
      * @param string $position