Browse Source

升级 form-create 版本,支持 group 组件

xaboy 6 years ago
parent
commit
ba937d9228

+ 3 - 1
src/Factory/Elm.php

@@ -25,6 +25,7 @@ use FormBuilder\UI\Elm\Traits\ColorPickerFactoryTrait;
 use FormBuilder\UI\Elm\Traits\DatePickerFactoryTrait;
 use FormBuilder\UI\Elm\Traits\FrameFactoryTrait;
 use FormBuilder\UI\Elm\Traits\FormStyleFactoryTrait;
+use FormBuilder\UI\Elm\Traits\GroupFactoryTrait;
 use FormBuilder\UI\Elm\Traits\HiddenFactoryTrait;
 use FormBuilder\UI\Elm\Traits\InputFactoryTrait;
 use FormBuilder\UI\Elm\Traits\InputNumberFactoryTrait;
@@ -58,6 +59,7 @@ abstract class Elm extends Base
     use TreeFactoryTrait;
     use UploadFactoryTrait;
     use ValidateFactoryTrait;
+    use GroupFactoryTrait;
 
     /**
      * 获取选择类组件 option 类
@@ -134,7 +136,7 @@ abstract class Elm extends Base
      * @param array $children
      * @return \FormBuilder\Driver\CustomComponent
      */
-    public static function group($children = [])
+    public static function item($children = [])
     {
         return self::createComponent('el-row')->children($children);
     }

+ 3 - 1
src/Factory/Iview.php

@@ -25,6 +25,7 @@ use FormBuilder\UI\Iview\Traits\ColorPickerFactoryTrait;
 use FormBuilder\UI\Iview\Traits\DatePickerFactoryTrait;
 use FormBuilder\UI\Iview\Traits\FrameFactoryTrait;
 use FormBuilder\UI\Iview\Traits\FormStyleFactoryTrait;
+use FormBuilder\UI\Iview\Traits\GroupFactoryTrait;
 use FormBuilder\UI\Iview\Traits\HiddenFactoryTrait;
 use FormBuilder\UI\Iview\Traits\InputFactoryTrait;
 use FormBuilder\UI\Iview\Traits\InputNumberFactoryTrait;
@@ -58,6 +59,7 @@ abstract class Iview extends Base
     use TreeFactoryTrait;
     use UploadFactoryTrait;
     use ValidateFactoryTrait;
+    use GroupFactoryTrait;
 
     /**
      * 获取选择类组件 option 类
@@ -149,7 +151,7 @@ abstract class Iview extends Base
      * @param array $children
      * @return \FormBuilder\Driver\CustomComponent
      */
-    public static function group($children = [])
+    public static function item($children = [])
     {
         return self::createComponent('row')->children($children);
     }

+ 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.6/dist/form-create.min.js"></script>',
+            '<script src="https://unpkg.com/@form-create/element-ui@1.0.7/dist/form-create.min.js"></script>',
         ]);
 
         $form->setDependScript($dependScript);

+ 1 - 0
src/UI/Elm/Components/Frame.php

@@ -31,6 +31,7 @@ use FormBuilder\Factory\Elm;
  * @method $this modal(array $modalProps) 弹出框props
  * @method $this handleIcon(bool $bool) 操作按钮的图标, 设置为false将不显示, 设置为true为默认的预览图标, 类型为file时默认为false, image类型默认为true
  * @method $this allowRemove(bool $bool) 是否可删除, 设置为false是不显示删除按钮
+ * @method $this disabled(bool $bool) 是否禁用
  *
  *
  */

+ 77 - 0
src/UI/Elm/Components/Group.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\UI\Elm\Components;
+
+
+use FormBuilder\Contract\ValidateInterface;
+use FormBuilder\Driver\CustomComponent;
+use FormBuilder\Driver\FormComponent;
+use FormBuilder\Factory\Elm;
+use FormBuilder\Util;
+
+/**
+ * 数组组件
+ *
+ * Class Group
+ * @method $this min(int $min) 最少几项
+ * @method $this max(int $max) 最多几项
+ * @method $this disabled(bool $bool) 是否禁用
+ */
+class Group extends FormComponent
+{
+    protected $defaultValue = [];
+
+    protected static $propsRule = [
+        'min' => 'string',
+        'max' => 'string',
+        'disabled' => 'int',
+    ];
+
+    /**
+     * @param array|CustomComponent $rule
+     * @return $this
+     */
+    public function rule($rule)
+    {
+        $this->props['rule'] = $this->tidyRule([$rule])[0];
+        return $this;
+    }
+
+    /**
+     * @param array $rules
+     * @return array
+     */
+    protected function tidyRule(array $rules)
+    {
+        foreach ($rules as $k => $rule) {
+            if (Util::isComponent($rule)) {
+                $rules[$k] = $rule->build();
+            }
+        }
+        return $rules;
+    }
+
+    public function rules(array $rules)
+    {
+        $this->props['rules'] = $this->tidyRule($rules);
+        return $this;
+    }
+
+    /**
+     * @return ValidateInterface
+     */
+    public function createValidate()
+    {
+        return Elm::validateArr();
+    }
+}

+ 33 - 0
src/UI/Elm/Traits/GroupFactoryTrait.php

@@ -0,0 +1,33 @@
+<?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\UI\Elm\Traits;
+
+
+use FormBuilder\UI\Elm\Components\Group;
+
+trait GroupFactoryTrait
+{
+
+    /**
+     * 数组组件
+     *
+     * @param string $field
+     * @param string $title
+     * @param array $value
+     * @return Group
+     */
+    public static function group($field, $title, $value = [])
+    {
+        return new Group($field, $title, $value);
+    }
+}

+ 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.6/dist/form-create.min.js"></script>',
+                '<script src="https://unpkg.com/@form-create/iview@1.0.7/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.6/dist/form-create.min.js"></script>',
+                '<script src="https://unpkg.com/@form-create/iview4@1.0.7/dist/form-create.min.js"></script>',
             ]);
         }
 

+ 1 - 1
src/UI/Iview/Components/Frame.php

@@ -31,7 +31,7 @@ use FormBuilder\Factory\Iview;
  * @method $this modal(array $modalProps) 弹出框props
  * @method $this handleIcon(bool $bool) 操作按钮的图标, 设置为false将不显示, 设置为true为默认的预览图标, 类型为file时默认为false, image类型默认为true
  * @method $this allowRemove(bool $bool) 是否可删除, 设置为false是不显示删除按钮
- *
+ * @method $this disabled(bool $bool) 是否禁用
  *
  */
 class Frame extends FormComponent

+ 77 - 0
src/UI/Iview/Components/Group.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\UI\Iview\Components;
+
+
+use FormBuilder\Contract\ValidateInterface;
+use FormBuilder\Driver\CustomComponent;
+use FormBuilder\Driver\FormComponent;
+use FormBuilder\Factory\Iview;
+use FormBuilder\Util;
+
+/**
+ * 数组组件
+ *
+ * Class Group
+ * @method $this min(int $min) 最少几项
+ * @method $this max(int $max) 最多几项
+ * @method $this disabled(bool $bool) 是否禁用
+ */
+class Group extends FormComponent
+{
+    protected $defaultValue = [];
+
+    protected static $propsRule = [
+        'min' => 'string',
+        'max' => 'string',
+        'disabled' => 'int',
+    ];
+
+    /**
+     * @param array|CustomComponent $rule
+     * @return $this
+     */
+    public function rule($rule)
+    {
+        $this->props['rule'] = $this->tidyRule([$rule])[0];
+        return $this;
+    }
+
+    /**
+     * @param array $rules
+     * @return array
+     */
+    protected function tidyRule(array $rules)
+    {
+        foreach ($rules as $k => $rule) {
+            if (Util::isComponent($rule)) {
+                $rules[$k] = $rule->build();
+            }
+        }
+        return $rules;
+    }
+
+    public function rules(array $rules)
+    {
+        $this->props['rules'] = $this->tidyRule($rules);
+        return $this;
+    }
+
+    /**
+     * @return ValidateInterface
+     */
+    public function createValidate()
+    {
+        return Iview::validateArr();
+    }
+}

+ 33 - 0
src/UI/Iview/Traits/GroupFactoryTrait.php

@@ -0,0 +1,33 @@
+<?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\UI\Iview\Traits;
+
+
+use FormBuilder\UI\Iview\Components\Group;
+
+trait GroupFactoryTrait
+{
+
+    /**
+     * 数组组件
+     *
+     * @param string $field
+     * @param string $title
+     * @param array $value
+     * @return Group
+     */
+    public static function group($field, $title, $value = [])
+    {
+        return new Group($field, $title, $value);
+    }
+}