升级form_buider 1.2.7

This commit is contained in:
sugar1569 2018-12-24 15:15:30 +08:00
parent cbc9236d76
commit f5e792dbe0
52 changed files with 664 additions and 306 deletions

26
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "3dd0118e5d08ef728cb0c2f4f7de15a5", "content-hash": "ae2e50326d8e83fd299c3350bb0f87d1",
"packages": [ "packages": [
{ {
"name": "doctrine/cache", "name": "doctrine/cache",
@ -1078,16 +1078,16 @@
}, },
{ {
"name": "tp5er/tp5-databackup", "name": "tp5er/tp5-databackup",
"version": "dev-master", "version": "1.0.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/tp5er/tp5-databackup.git", "url": "https://github.com/tp5er/tp5-databackup.git",
"reference": "101477abe810fb91bad5c1304a93c5f461db6dc8" "reference": "10abd4383cf78844e1c22584fd823ef1d18e75dc"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/tp5er/tp5-databackup/zipball/101477abe810fb91bad5c1304a93c5f461db6dc8", "url": "https://api.github.com/repos/tp5er/tp5-databackup/zipball/10abd4383cf78844e1c22584fd823ef1d18e75dc",
"reference": "101477abe810fb91bad5c1304a93c5f461db6dc8", "reference": "10abd4383cf78844e1c22584fd823ef1d18e75dc",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -1110,20 +1110,20 @@
} }
], ],
"description": "Implement the database backup restore", "description": "Implement the database backup restore",
"time": "2018-04-07T11:20:53+00:00" "time": "2017-12-29T05:36:58+00:00"
}, },
{ {
"name": "xaboy/form-builder", "name": "xaboy/form-builder",
"version": "1.2.5", "version": "1.2.7",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/xaboy/form-builder.git", "url": "https://github.com/xaboy/form-builder.git",
"reference": "73cb5be3d9f57680f64d01ab424c4ac5c462f1b8" "reference": "43d5c0a8f1f1f0fc1f6430b827fbe2b7b0d5b5cf"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/xaboy/form-builder/zipball/73cb5be3d9f57680f64d01ab424c4ac5c462f1b8", "url": "https://api.github.com/repos/xaboy/form-builder/zipball/43d5c0a8f1f1f0fc1f6430b827fbe2b7b0d5b5cf",
"reference": "73cb5be3d9f57680f64d01ab424c4ac5c462f1b8", "reference": "43d5c0a8f1f1f0fc1f6430b827fbe2b7b0d5b5cf",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -1148,15 +1148,13 @@
], ],
"description": "PHP表单生成器快速生成现代化的form表单。包含复选框、单选框、输入框、下拉选择框等元素以及,省市区三级联动,时间选择,日期选择,颜色选择,文件/图片上传等功能。", "description": "PHP表单生成器快速生成现代化的form表单。包含复选框、单选框、输入框、下拉选择框等元素以及,省市区三级联动,时间选择,日期选择,颜色选择,文件/图片上传等功能。",
"homepage": "https://github.com/xaboy/form-builder", "homepage": "https://github.com/xaboy/form-builder",
"time": "2018-11-13T12:44:31+00:00" "time": "2018-12-12T12:20:38+00:00"
} }
], ],
"packages-dev": [], "packages-dev": [],
"aliases": [], "aliases": [],
"minimum-stability": "stable", "minimum-stability": "stable",
"stability-flags": { "stability-flags": [],
"tp5er/tp5-databackup": 20
},
"prefer-stable": false, "prefer-stable": false,
"prefer-lowest": false, "prefer-lowest": false,
"platform": { "platform": {

View File

@ -1111,23 +1111,23 @@
}, },
{ {
"name": "tp5er/tp5-databackup", "name": "tp5er/tp5-databackup",
"version": "dev-master", "version": "1.0.0",
"version_normalized": "9999999-dev", "version_normalized": "1.0.0.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/tp5er/tp5-databackup.git", "url": "https://github.com/tp5er/tp5-databackup.git",
"reference": "101477abe810fb91bad5c1304a93c5f461db6dc8" "reference": "10abd4383cf78844e1c22584fd823ef1d18e75dc"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/tp5er/tp5-databackup/zipball/101477abe810fb91bad5c1304a93c5f461db6dc8", "url": "https://api.github.com/repos/tp5er/tp5-databackup/zipball/10abd4383cf78844e1c22584fd823ef1d18e75dc",
"reference": "101477abe810fb91bad5c1304a93c5f461db6dc8", "reference": "10abd4383cf78844e1c22584fd823ef1d18e75dc",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
"php": ">=5.4.0" "php": ">=5.4.0"
}, },
"time": "2018-04-07T11:20:53+00:00", "time": "2017-12-29T05:36:58+00:00",
"type": "library", "type": "library",
"installation-source": "source", "installation-source": "source",
"autoload": { "autoload": {
@ -1149,24 +1149,24 @@
}, },
{ {
"name": "xaboy/form-builder", "name": "xaboy/form-builder",
"version": "1.2.5", "version": "1.2.7",
"version_normalized": "1.2.5.0", "version_normalized": "1.2.7.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/xaboy/form-builder.git", "url": "https://github.com/xaboy/form-builder.git",
"reference": "73cb5be3d9f57680f64d01ab424c4ac5c462f1b8" "reference": "43d5c0a8f1f1f0fc1f6430b827fbe2b7b0d5b5cf"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/xaboy/form-builder/zipball/73cb5be3d9f57680f64d01ab424c4ac5c462f1b8", "url": "https://api.github.com/repos/xaboy/form-builder/zipball/43d5c0a8f1f1f0fc1f6430b827fbe2b7b0d5b5cf",
"reference": "73cb5be3d9f57680f64d01ab424c4ac5c462f1b8", "reference": "43d5c0a8f1f1f0fc1f6430b827fbe2b7b0d5b5cf",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
"ext-json": "*", "ext-json": "*",
"php": ">=5.4.0" "php": ">=5.4.0"
}, },
"time": "2018-11-13T12:44:31+00:00", "time": "2018-12-12T12:20:38+00:00",
"type": "library", "type": "library",
"installation-source": "dist", "installation-source": "dist",
"autoload": { "autoload": {

View File

@ -21,12 +21,21 @@
PHP表单生成器快速生成现代化的form表单。包含复选框、单选框、输入框、下拉选择框等元素以及省市区三级联动、时间选择、日期选择、颜色选择、树型、文件/图片上传等功能。 PHP表单生成器快速生成现代化的form表单。包含复选框、单选框、输入框、下拉选择框等元素以及省市区三级联动、时间选择、日期选择、颜色选择、树型、文件/图片上传等功能。
</p> </p>
> 1.2.4 版本支持简单字段验证 > 1.2.4 版本支持字段验证
#### 如果对您有帮助,您可以点右上角 "Star" 支持一下 谢谢! #### 如果对您有帮助,您可以点右上角 "Star" 支持一下 谢谢!
#### 本项目还在不断开发完善中,如有建议或问题请[在这里提出](https://github.com/xaboy/form-builder/issues/new) #### 本项目还在不断开发完善中,如有建议或问题请[在这里提出](https://github.com/xaboy/form-builder/issues/new)
## 更新说明
#### 1.2.7 (2018-12-12)
- 完善时间选择组件,日期选择组件验证规则
- 新增 fields 类型验证规则
- 新增 使用 view 方法生成时,表单只能被创建一次
- 修复一些小问题
## 安装 ## 安装
`composer require xaboy/form-builder` `composer require xaboy/form-builder`

View File

@ -11,6 +11,7 @@ use FormBuilder\components\Cascader;
use FormBuilder\components\FormStyle; use FormBuilder\components\FormStyle;
use FormBuilder\components\Hidden; use FormBuilder\components\Hidden;
use FormBuilder\components\Row; use FormBuilder\components\Row;
use FormBuilder\exception\FormBuilderException;
use FormBuilder\traits\form\FormCascaderTrait; use FormBuilder\traits\form\FormCascaderTrait;
use FormBuilder\traits\form\FormCheckBoxTrait; use FormBuilder\traits\form\FormCheckBoxTrait;
use FormBuilder\traits\form\FormColorPickerTrait; use FormBuilder\traits\form\FormColorPickerTrait;
@ -33,6 +34,7 @@ use FormBuilder\traits\form\FormValidateTrait;
/** /**
* Class Form * Class Form
*
* @package FormBuilder * @package FormBuilder
*/ */
class Form class Form
@ -59,12 +61,14 @@ class Form
/** /**
* 三级联动 加载省市数据 * 三级联动 加载省市数据
*
* @var bool * @var bool
*/ */
protected $loadCityData = false; protected $loadCityData = false;
/** /**
* 三级联动 加载省市区数据 * 三级联动 加载省市区数据
*
* @var bool * @var bool
*/ */
protected $loadCityAreaData = false; protected $loadCityAreaData = false;
@ -96,18 +100,21 @@ class Form
/** /**
* 加载 jquery * 加载 jquery
*
* @var bool * @var bool
*/ */
protected $linkJq = true; protected $linkJq = true;
/** /**
* 加载 vue * 加载 vue
*
* @var bool * @var bool
*/ */
protected $linkVue = true; protected $linkVue = true;
/** /**
* 加载 iview * 加载 iview
*
* @var bool * @var bool
*/ */
protected $linkIview = true; protected $linkIview = true;
@ -119,24 +126,28 @@ class Form
/** /**
* 网页标题 * 网页标题
*
* @var string * @var string
*/ */
protected $title = 'formBuilder'; protected $title = 'formBuilder';
/** /**
* 提交地址 * 提交地址
*
* @var string * @var string
*/ */
protected $action = ''; protected $action = '';
/** /**
* 表单id * 表单id
*
* @var string * @var string
*/ */
protected $id = ''; protected $id = '';
/** /**
* 提交方式 * 提交方式
*
* @var string * @var string
*/ */
protected $method = 'post'; protected $method = 'post';
@ -147,6 +158,7 @@ class Form
/** /**
* 表单配置 * 表单配置
*
* @var array|mixed * @var array|mixed
*/ */
protected $config = [ protected $config = [
@ -162,6 +174,7 @@ class Form
/** /**
* Form constructor. * Form constructor.
*
* @param string $action 提交地址 * @param string $action 提交地址
* @param array $components 组件 * @param array $components 组件
*/ */
@ -171,6 +184,11 @@ class Form
$this->action = $action; $this->action = $action;
} }
public static function json()
{
return new Json();
}
/** /**
* @param bool $linkJq * @param bool $linkJq
*/ */
@ -254,6 +272,7 @@ class Form
/** /**
* 表单提交后成功执行的js地址 * 表单提交后成功执行的js地址
* formCreate.formSuccess(formData,$f) * formCreate.formSuccess(formData,$f)
*
* @param string $successScript * @param string $successScript
* @return $this * @return $this
*/ */
@ -292,6 +311,7 @@ class Form
/** /**
* 提交地址 * 提交地址
*
* @param string $action * @param string $action
* @return $this * @return $this
*/ */
@ -323,6 +343,7 @@ class Form
/** /**
* 提交方式 * 提交方式
*
* @param string $method * @param string $method
* @return $this * @return $this
*/ */
@ -334,6 +355,7 @@ class Form
/** /**
* 标题 * 标题
*
* @return string * @return string
*/ */
public function getTitle() public function getTitle()
@ -354,6 +376,7 @@ class Form
/** /**
* 追加组件 * 追加组件
*
* @param FormComponentDriver $component * @param FormComponentDriver $component
* @return $this * @return $this
*/ */
@ -369,6 +392,7 @@ class Form
/** /**
* 开头插入组件 * 开头插入组件
*
* @param FormComponentDriver $component * @param FormComponentDriver $component
* @return $this * @return $this
*/ */
@ -384,6 +408,7 @@ class Form
/** /**
* 是否需要引入省市区数据 * 是否需要引入省市区数据
*
* @param FormComponentDriver $component * @param FormComponentDriver $component
*/ */
protected function checkLoadData(FormComponentDriver $component) protected function checkLoadData(FormComponentDriver $component)
@ -402,15 +427,23 @@ class Form
/** /**
* 获得表单规则 * 获得表单规则
*
* @return array * @return array
* @throws FormBuilderException
*/ */
public function getRules() public function getRules()
{ {
$rules = []; $rules = [];
$fields = [];
foreach ($this->fields as $field) { foreach ($this->fields as $field) {
$component = $this->components[$field]; $component = $this->components[$field];
if (!($component instanceof FormComponentDriver)) if (!($component instanceof FormComponentDriver))
continue; continue;
$field = $component->getField();
if (in_array($field, $fields))
throw new FormBuilderException($field . '字段已重复,请保证组件 field 无重复');
$fields[] = $field;
$rule = $component->build(); $rule = $component->build();
if (!$component instanceof Hidden) if (!$component instanceof Hidden)
$rule['validate'] = array_merge(isset($rule['validate']) ? $rule['validate'] : [], $component->validate()->build()); $rule['validate'] = array_merge(isset($rule['validate']) ? $rule['validate'] : [], $component->validate()->build());
@ -422,6 +455,7 @@ class Form
/** /**
* 获取表单视图 * 获取表单视图
*
* @return string * @return string
*/ */
public function view() public function view()
@ -435,6 +469,7 @@ class Form
/** /**
* 获取表单生成器所需全部js * 获取表单生成器所需全部js
*
* @return array * @return array
*/ */
public function script() public function script()
@ -444,6 +479,7 @@ class Form
/** /**
* 获取生成表单的js代码 * 获取生成表单的js代码
*
* @return string * @return string
*/ */
public function formScript() public function formScript()
@ -458,6 +494,7 @@ class Form
/** /**
* 获取表单生成器所需js * 获取表单生成器所需js
*
* @return array * @return array
*/ */
public function getScript() public function getScript()
@ -483,6 +520,7 @@ class Form
/** /**
* 是否隐藏提交按钮(默认显示) * 是否隐藏提交按钮(默认显示)
*
* @param bool $isShow * @param bool $isShow
* @return Form * @return Form
*/ */
@ -495,6 +533,7 @@ class Form
/** /**
* 是否隐藏重置按钮(默认隐藏) * 是否隐藏重置按钮(默认隐藏)
*
* @param bool $isShow * @param bool $isShow
* @return Form * @return Form
*/ */
@ -523,12 +562,13 @@ class Form
/** /**
* 生成表单快捷方法 * 生成表单快捷方法
*
* @param string $action * @param string $action
* @param array $components * @param array $components
* @return Form * @return Form
*/ */
public static function create($action, array $components = []) public static function create($action, array $components = [])
{ {
return new static($action, $components); return new self($action, $components);
} }
} }

View File

@ -8,6 +8,8 @@
namespace FormBuilder; namespace FormBuilder;
use FormBuilder\exception\FormBuilderException;
class Helper class Helper
{ {
public static function toType($var, $type = 'string') public static function toType($var, $type = 'string')
@ -42,6 +44,7 @@ class Helper
return "unknown type"; return "unknown type";
} }
public static function verifyType($var, $verify, $title = '') public static function verifyType($var, $verify, $title = '')
{ {
if (!is_array($verify)) $verify = [$verify]; if (!is_array($verify)) $verify = [$verify];
@ -51,7 +54,7 @@ class Helper
} }
$type = self::getVarType($var); $type = self::getVarType($var);
if (!in_array($type, $verify)) if (!in_array($type, $verify))
throw new \Exception($title . '类型需为' . implode(',', $verify)); throw new FormBuilderException($title . '类型需为' . implode(',', $verify));
} }
public static function getDate($date) public static function getDate($date)

View File

@ -17,22 +17,22 @@ class Json
public static function succ($msg, $data = []) public static function succ($msg, $data = [])
{ {
return static::result(200, $msg, $data); return self::result(200, $msg, $data);
} }
public static function fail($msg, $data = []) public static function fail($msg, $data = [])
{ {
return static::result(400, $msg, $data); return self::result(400, $msg, $data);
} }
public static function uploadSucc($filePath, $msg = '上传成功', $data = []) public static function uploadSucc($filePath, $msg = '上传成功', $data = [])
{ {
$data['filePath'] = $filePath; $data['filePath'] = $filePath;
return static::succ($msg, $data); return self::succ($msg, $data);
} }
public static function uploadFail($msg = '上传失败', $data = []) public static function uploadFail($msg = '上传失败', $data = [])
{ {
return static::fail($msg, $data); return self::fail($msg, $data);
} }
} }

View File

@ -14,6 +14,7 @@ use FormBuilder\Helper;
/** /**
* 多级联动组件 * 多级联动组件
* Class Cascader * Class Cascader
*
* @package FormBuilder\components * @package FormBuilder\components
* @method $this type(String $type) 数据类型, 支持 city_area(省市区三级联动), city (省市二级联动), other (自定义) * @method $this type(String $type) 数据类型, 支持 city_area(省市区三级联动), city (省市二级联动), other (自定义)
* @method $this disabled(Boolean $bool) 是否禁用选择器 * @method $this disabled(Boolean $bool) 是否禁用选择器
@ -70,9 +71,6 @@ class Cascader extends FormComponentDriver
'notFoundText' => 'string', 'notFoundText' => 'string',
]; ];
/**
*
*/
protected function init() protected function init()
{ {
$this->placeholder($this->getPlaceHolder()); $this->placeholder($this->getPlaceHolder());
@ -96,6 +94,7 @@ class Cascader extends FormComponentDriver
* "value":"东城区", "label":"东城区" * "value":"东城区", "label":"东城区"
* }] * }]
* } * }
*
* @param array $data * @param array $data
* @return $this * @return $this
*/ */
@ -118,6 +117,7 @@ class Cascader extends FormComponentDriver
/** /**
* 获取组件类型 * 获取组件类型
*
* @return mixed * @return mixed
*/ */
public function getType() public function getType()
@ -128,7 +128,7 @@ class Cascader extends FormComponentDriver
/** /**
* @return Validate * @return Validate
*/ */
protected function getValidateHandler() public function getValidateHandler()
{ {
return Validate::arr(); return Validate::arr();
} }

View File

@ -15,6 +15,7 @@ use FormBuilder\traits\component\ComponentOptionsTrait;
/** /**
* 复选框组件 * 复选框组件
* Class Checkbox * Class Checkbox
*
* @package FormBuilder\components * @package FormBuilder\components
* @method $this size(String $size) 多选框组的尺寸,可选值为 large、small、default 或者不设置 * @method $this size(String $size) 多选框组的尺寸,可选值为 large、small、default 或者不设置
*/ */
@ -56,7 +57,7 @@ class Checkbox extends FormComponentDriver
return $this; return $this;
} }
protected function getValidateHandler() public function getValidateHandler()
{ {
return Validate::arr(); return Validate::arr();
} }

View File

@ -14,6 +14,7 @@ use FormBuilder\traits\component\CallPropsTrait;
/** /**
* col栅格规则 * col栅格规则
* Class Col * Class Col
*
* @package FormBuilder\components * @package FormBuilder\components
* @method $this span(Number $span) 栅格的占位格数可选值为0~24的整数,为 0 相当于display:none * @method $this span(Number $span) 栅格的占位格数可选值为0~24的整数,为 0 相当于display:none
* @method $this order(Number $order) 栅格的顺序在flex布局模式下有效 * @method $this order(Number $order) 栅格的顺序在flex布局模式下有效
@ -60,6 +61,7 @@ class Col implements FormComponentInterFace
/** /**
* Col constructor. * Col constructor.
*
* @param int $span * @param int $span
*/ */
public function __construct($span = 24) public function __construct($span = 24)

View File

@ -14,6 +14,7 @@ use FormBuilder\Helper;
/** /**
* 颜色选择器组件 * 颜色选择器组件
* Class ColorPicker * Class ColorPicker
*
* @package FormBuilder\components * @package FormBuilder\components
* @method $this disabled(Boolean $bool) 是否禁用 * @method $this disabled(Boolean $bool) 是否禁用
* @method $this alpha(Boolean $bool) 是否支持透明度选择, 默认为false * @method $this alpha(Boolean $bool) 是否支持透明度选择, 默认为false
@ -50,6 +51,7 @@ class ColorPicker extends FormComponentDriver
/** /**
* 自定义颜色预设 * 自定义颜色预设
*
* @param $colors * @param $colors
* @return $this * @return $this
*/ */

View File

@ -14,6 +14,7 @@ use FormBuilder\Helper;
/** /**
* 日期选择器组件 * 日期选择器组件
* Class DatePicker * Class DatePicker
*
* @package FormBuilder\components * @package FormBuilder\components
* @method $this type(String $type) 显示类型,可选值为 date、daterange、datetime、datetimerange、year、month * @method $this type(String $type) 显示类型,可选值为 date、daterange、datetime、datetimerange、year、month
* @method $this format(String $format) 展示的日期格式, 默认为yyyy-MM-dd HH:mm:ss * @method $this format(String $format) 展示的日期格式, 默认为yyyy-MM-dd HH:mm:ss
@ -67,7 +68,8 @@ class DatePicker extends FormComponentDriver
*/ */
protected $props = [ protected $props = [
'type' => self::TYPE_DATE, 'type' => self::TYPE_DATE,
'editable' => false 'editable' => false,
'multiple' => false
]; ];
/** /**
@ -86,7 +88,7 @@ class DatePicker extends FormComponentDriver
'editable' => 'boolean', 'editable' => 'boolean',
'transfer' => 'boolean', 'transfer' => 'boolean',
'splitPanels' => 'boolean', 'splitPanels' => 'boolean',
'showWeekNumbers' => 'boolean', 'showWeekNumbers' => 'boolean'
]; ];
/** /**
@ -97,6 +99,22 @@ class DatePicker extends FormComponentDriver
$this->placeholder($this->getPlaceHolder()); $this->placeholder($this->getPlaceHolder());
} }
/**
* 开启后, 可以选择多个日期, 仅在 date 下可用, 默认为false
*
* @param bool $bool
* @return $this
*/
public function multiple($bool = true)
{
if ($this->props['type'] == 'date')
$this->props['multiple'] = (bool)$bool;
else
$this->props['multiple'] = false;
return $this;
}
/** /**
* @param $value * @param $value
* @return $this * @return $this
@ -116,12 +134,25 @@ class DatePicker extends FormComponentDriver
public function getValidateHandler() public function getValidateHandler()
{ {
if(in_array($this->props['type'],['datetimerange','daterange'])) if (in_array($this->props['type'], ['datetimerange', 'daterange']) || $this->props['multiple'])
return Validate::arr(); return Validate::arr();
else else
return Validate::date(); return Validate::date();
} }
public function required($message = null)
{
$message = $message ?: $this->getPlaceHolder();
if (in_array($this->props['type'], ['datetimerange', 'daterange'])) {
$this->validate()->fields([
'0' => ['required' => true, 'type' => 'date', 'message' => $message],
'1' => ['required' => true, 'type' => 'date', 'message' => $message]
], true, $message);
return $this;
} else
return parent::required($message);
}
/** /**
* @return array * @return array
*/ */

View File

@ -14,6 +14,7 @@ use FormBuilder\traits\component\CallPropsTrait;
/** /**
* form表单样式 * form表单样式
* Class FormStyle * Class FormStyle
*
* @package FormBuilder\components * @package FormBuilder\components
* @method $this inline(Boolean $bool) 是否开启行内表单模式 * @method $this inline(Boolean $bool) 是否开启行内表单模式
* @method $this labelPosition(String $labelPosition) 表单域标签的位置,可选值为 left、right、top * @method $this labelPosition(String $labelPosition) 表单域标签的位置,可选值为 left、right、top
@ -41,6 +42,7 @@ class FormStyle implements FormComponentInterFace
/** /**
* FormStyle constructor. * FormStyle constructor.
*
* @param bool $inline * @param bool $inline
* @param string $labelPosition * @param string $labelPosition
* @param int $labelWidth * @param int $labelWidth
@ -55,6 +57,7 @@ class FormStyle implements FormComponentInterFace
/** /**
* 原生的 autocomplete 属性,可选值为 true = off false = on * 原生的 autocomplete 属性,可选值为 true = off false = on
*
* @param bool $bool * @param bool $bool
* @return $this * @return $this
*/ */

View File

@ -14,6 +14,7 @@ use FormBuilder\Helper;
/** /**
* 框架组件 * 框架组件
* Class Frame * Class Frame
*
* @package FormBuilder\components * @package FormBuilder\components
* @method $this type(String $type) frame类型, 有input, file, image, 默认为input * @method $this type(String $type) frame类型, 有input, file, image, 默认为input
* @method $this src(String $src) iframe地址 * @method $this src(String $src) iframe地址
@ -90,7 +91,7 @@ class Frame extends FormComponentDriver
$this->frameTitle($this->getPlaceHolder()); $this->frameTitle($this->getPlaceHolder());
} }
protected function getValidateHandler() public function getValidateHandler()
{ {
return Validate::arr(); return Validate::arr();
} }

View File

@ -13,6 +13,7 @@ use FormBuilder\FormComponentDriver;
/** /**
* hidden组件 * hidden组件
* Class Hidden * Class Hidden
*
* @package FormBuilder\components * @package FormBuilder\components
*/ */
class Hidden extends FormComponentDriver class Hidden extends FormComponentDriver
@ -25,6 +26,7 @@ class Hidden extends FormComponentDriver
/** /**
* Hidden constructor. * Hidden constructor.
*
* @param String $field * @param String $field
* @param String $value * @param String $value
*/ */

View File

@ -14,6 +14,7 @@ use FormBuilder\Helper;
/** /**
* Input组件,支持类型text、password、textarea、url、email、date * Input组件,支持类型text、password、textarea、url、email、date
* Class Input * Class Input
*
* @package FormBuilder\components * @package FormBuilder\components
* @method $this type(String $type) 输入框类型,可选值为 text、password、textarea、url、email、date; * @method $this type(String $type) 输入框类型,可选值为 text、password、textarea、url、email、date;
* @method $this size(String $size) 输入框尺寸可选值为large、small、default或者不设置; * @method $this size(String $size) 输入框尺寸可选值为large、small、default或者不设置;
@ -102,7 +103,7 @@ class Input extends FormComponentDriver
return parent::getPlaceHolder($pre); return parent::getPlaceHolder($pre);
} }
protected function getValidateHandler() public function getValidateHandler()
{ {
return Validate::str(Validate::TRIGGER_BLUR); return Validate::str(Validate::TRIGGER_BLUR);
} }
@ -110,6 +111,7 @@ class Input extends FormComponentDriver
/** /**
* 自适应内容高度,仅在 textarea 类型下有效 * 自适应内容高度,仅在 textarea 类型下有效
*
* @param Bool|Number $minRows * @param Bool|Number $minRows
* @param null|Number $maxRows * @param null|Number $maxRows
* @return $this * @return $this
@ -123,6 +125,7 @@ class Input extends FormComponentDriver
/** /**
* 生成表单规则 * 生成表单规则
*
* @return array * @return array
*/ */
public function build() public function build()

View File

@ -13,6 +13,7 @@ use FormBuilder\FormComponentDriver;
/** /**
* 数字输入框组件 * 数字输入框组件
* Class InputNumber * Class InputNumber
*
* @package FormBuilder\components * @package FormBuilder\components
* @method $this max(float $max) 最大值 * @method $this max(float $max) 最大值
* @method $this min(float $min) 最小值 * @method $this min(float $min) 最小值
@ -59,7 +60,7 @@ class InputNumber extends FormComponentDriver
return parent::getPlaceHolder($pre); return parent::getPlaceHolder($pre);
} }
protected function getValidateHandler() public function getValidateHandler()
{ {
return Validate::num(Validate::TRIGGER_BLUR); return Validate::num(Validate::TRIGGER_BLUR);
} }

View File

@ -13,6 +13,7 @@ use FormBuilder\Helper;
/** /**
* Class Option * Class Option
*
* @package FormBuilder\components * @package FormBuilder\components
*/ */
class Option implements FormComponentInterFace class Option implements FormComponentInterFace
@ -25,9 +26,11 @@ class Option implements FormComponentInterFace
/** /**
* Option constructor. * Option constructor.
*
* @param $value * @param $value
* @param string $label * @param string $label
* @param bool $disabled * @param bool $disabled
* @throws \FormBuilder\exception\FormBuilderException
*/ */
public function __construct($value, $label = '', $disabled = false) public function __construct($value, $label = '', $disabled = false)
{ {
@ -40,6 +43,7 @@ class Option implements FormComponentInterFace
/** /**
* @param $value * @param $value
* @param $label * @param $label
* @throws \FormBuilder\exception\FormBuilderException
*/ */
public static function verify($value, $label) public static function verify($value, $label)
{ {

View File

@ -15,6 +15,7 @@ use FormBuilder\traits\component\ComponentOptionsTrait;
/** /**
* 单选框组件 * 单选框组件
* Class Radio * Class Radio
*
* @package FormBuilder\components * @package FormBuilder\components
* @method $this size(String $size) 单选框的尺寸,可选值为 large、small、default 或者不设置 * @method $this size(String $size) 单选框的尺寸,可选值为 large、small、default 或者不设置
* @method $this vertical(Boolean $bool) 是否垂直排列,按钮样式下无效 * @method $this vertical(Boolean $bool) 是否垂直排列,按钮样式下无效
@ -38,6 +39,7 @@ class Radio extends FormComponentDriver
/** /**
* 使用按钮样式 * 使用按钮样式
*
* @return $this * @return $this
*/ */
public function button() public function button()
@ -46,7 +48,7 @@ class Radio extends FormComponentDriver
return $this; return $this;
} }
protected function getValidateHandler() public function getValidateHandler()
{ {
return Validate::str(); return Validate::str();
} }

View File

@ -13,6 +13,7 @@ use FormBuilder\FormComponentDriver;
/** /**
* 评分组件 * 评分组件
* Class Rate * Class Rate
*
* @package FormBuilder\components * @package FormBuilder\components
* @method $this count(int $star) star 总数, 默认为 5 * @method $this count(int $star) star 总数, 默认为 5
* @method $this allowHalf(Boolean $bool) 是否允许半选, 默认为 false * @method $this allowHalf(Boolean $bool) 是否允许半选, 默认为 false
@ -39,7 +40,7 @@ class Rate extends FormComponentDriver
'clearable' => 'boolean', 'clearable' => 'boolean',
]; ];
protected function getValidateHandler() public function getValidateHandler()
{ {
return Validate::num(); return Validate::num();
} }

View File

@ -14,6 +14,7 @@ use FormBuilder\traits\component\CallPropsTrait;
/** /**
* row栅格规则 * row栅格规则
* Class Row * Class Row
*
* @package FormBuilder\components * @package FormBuilder\components
* @method $this gutter(Number $gutter) 栅格间距,单位 px左右平分 * @method $this gutter(Number $gutter) 栅格间距,单位 px左右平分
* @method $this type(String $type) 栅格的顺序在flex布局模式下有效 * @method $this type(String $type) 栅格的顺序在flex布局模式下有效
@ -43,6 +44,7 @@ class Row implements FormComponentInterFace
/** /**
* Row constructor. * Row constructor.
*
* @param int $gutter * @param int $gutter
* @param string $type * @param string $type
* @param string $align * @param string $align

View File

@ -15,6 +15,7 @@ use FormBuilder\traits\component\ComponentOptionsTrait;
/** /**
* 选择器组件 * 选择器组件
* Class Select * Class Select
*
* @package FormBuilder\components * @package FormBuilder\components
* @method $this multiple(Boolean $bool) 是否支持多选, 默认为false * @method $this multiple(Boolean $bool) 是否支持多选, 默认为false
* @method $this disabled(Boolean $bool) 是否禁用, 默认为false * @method $this disabled(Boolean $bool) 是否禁用, 默认为false
@ -63,9 +64,6 @@ class Select extends FormComponentDriver
'notFoundText' => 'string', 'notFoundText' => 'string',
]; ];
/**
*
*/
protected function init() protected function init()
{ {
$this->placeholder($this->getPlaceHolder()); $this->placeholder($this->getPlaceHolder());
@ -89,7 +87,7 @@ class Select extends FormComponentDriver
} }
protected function getValidateHandler() public function getValidateHandler()
{ {
if ($this->props['multiple'] == true) if ($this->props['multiple'] == true)
return Validate::arr(); return Validate::arr();

View File

@ -14,6 +14,7 @@ use FormBuilder\Helper;
/** /**
* 滑块组件 * 滑块组件
* Class Slider * Class Slider
*
* @package FormBuilder\components * @package FormBuilder\components
* @method $this min(float $min) 最小值, 默认 0 * @method $this min(float $min) 最小值, 默认 0
* @method $this max(float $max) 最大值, 默认 100 * @method $this max(float $max) 最大值, 默认 100
@ -65,7 +66,7 @@ class Slider extends FormComponentDriver
return $this; return $this;
} }
protected function getValidateHandler() public function getValidateHandler()
{ {
if ($this->props['range'] == true) if ($this->props['range'] == true)
return Validate::arr(); return Validate::arr();

View File

@ -12,6 +12,7 @@ use FormBuilder\FormComponentDriver;
/** /**
* 开关组件 * 开关组件
* Class Switches * Class Switches
*
* @package FormBuilder\components * @package FormBuilder\components
* @method $this size(String $size) 开关的尺寸可选值为large、small、default或者不写。建议开关如果使用了2个汉字的文字使用 large。 * @method $this size(String $size) 开关的尺寸可选值为large、small、default或者不写。建议开关如果使用了2个汉字的文字使用 large。
* @method $this disabled(Boolean $bool) 禁用开关, 默认为false * @method $this disabled(Boolean $bool) 禁用开关, 默认为false
@ -50,6 +51,7 @@ class Switches extends FormComponentDriver
/** /**
* 自定义显示打开时的内容 * 自定义显示打开时的内容
*
* @param $open * @param $open
* @return $this * @return $this
*/ */
@ -61,6 +63,7 @@ class Switches extends FormComponentDriver
/** /**
* 自定义显示关闭时的内容 * 自定义显示关闭时的内容
*
* @param $close * @param $close
* @return $this * @return $this
*/ */
@ -70,7 +73,7 @@ class Switches extends FormComponentDriver
return $this; return $this;
} }
protected function getValidateHandler() public function getValidateHandler()
{ {
return Validate::str(); return Validate::str();
} }

View File

@ -14,6 +14,7 @@ use FormBuilder\Helper;
/** /**
* 时间选择器组件 * 时间选择器组件
* Class TimePicker * Class TimePicker
*
* @package FormBuilder\components * @package FormBuilder\components
* @method $this type(String $type) 显示类型,可选值为 time、timerange * @method $this type(String $type) 显示类型,可选值为 time、timerange
* @method $this format(String $format) 展示的时间格式, 默认为HH:mm:ss * @method $this format(String $format) 展示的时间格式, 默认为HH:mm:ss
@ -81,6 +82,7 @@ class TimePicker extends FormComponentDriver
/** /**
* 下拉列表的时间间隔,数组的三项分别对应小时、分钟、秒。 * 下拉列表的时间间隔,数组的三项分别对应小时、分钟、秒。
* 例如设置为 [1, 15] 分钟会显示00、15、30、45。 * 例如设置为 [1, 15] 分钟会显示00、15、30、45。
*
* @param $h * @param $h
* @param int $i * @param int $i
* @param int $s * @param int $s
@ -109,7 +111,7 @@ class TimePicker extends FormComponentDriver
return $this; return $this;
} }
protected function getValidateHandler() public function getValidateHandler()
{ {
if ($this->props['type'] == 'timerange') if ($this->props['type'] == 'timerange')
return Validate::arr(); return Validate::arr();
@ -117,6 +119,20 @@ class TimePicker extends FormComponentDriver
return Validate::str(); return Validate::str();
} }
public function required($message = null)
{
$message = $message ?: $this->getPlaceHolder();
if ($this->props['type'] == 'timerange') {
$this->validate()->fields([
'0' => ['required' => true, 'message' => $message],
'1' => ['required' => true, 'message' => $message]
], true, $message);
return $this;
} else
return parent::required($message);
}
/** /**
* @return array * @return array
*/ */

View File

@ -13,6 +13,7 @@ use FormBuilder\FormComponentDriver;
/** /**
* 树型组件 * 树型组件
* Class Tree * Class Tree
*
* @package FormBuilder\components * @package FormBuilder\components
* @method $this type(String $type) 类型,可选值为 checked、selected * @method $this type(String $type) 类型,可选值为 checked、selected
* @method $this multiple(Boolean $bool) 是否支持多选, `type=selected`并且`multiple=false`, 默认为false, 值为String或Number类型其他情况为Array类型 * @method $this multiple(Boolean $bool) 是否支持多选, `type=selected`并且`multiple=false`, 默认为false, 值为String或Number类型其他情况为Array类型
@ -96,7 +97,7 @@ class Tree extends FormComponentDriver
return $this; return $this;
} }
protected function getValidateHandler() public function getValidateHandler()
{ {
if ($this->props['multiple']) if ($this->props['multiple'])
return Validate::arr(); return Validate::arr();

View File

@ -13,6 +13,7 @@ use FormBuilder\traits\component\CallPropsTrait;
/** /**
* Class TreeData * Class TreeData
*
* @package FormBuilder\components * @package FormBuilder\components
* @method $this id(String $id) Id, 必须唯一 * @method $this id(String $id) Id, 必须唯一
* @method $this title(String $title) 标题 * @method $this title(String $title) 标题
@ -51,6 +52,7 @@ class TreeData implements FormComponentInterFace
/** /**
* TreeData constructor. * TreeData constructor.
*
* @param $id * @param $id
* @param $title * @param $title
* @param array $children * @param array $children

View File

@ -14,6 +14,7 @@ use FormBuilder\Helper;
/** /**
* 上传组件 * 上传组件
* Class Upload * Class Upload
*
* @package FormBuilder\components * @package FormBuilder\components
* @method $this uploadType(String $uploadType) 上传文件类型,可选值为 image图片上传file文件上传 * @method $this uploadType(String $uploadType) 上传文件类型,可选值为 image图片上传file文件上传
* @method $this action(String $action) 上传的地址 * @method $this action(String $action) 上传的地址
@ -79,6 +80,7 @@ class Upload extends FormComponentDriver
/** /**
* 设置上传的请求头部 * 设置上传的请求头部
*
* @param array $headers * @param array $headers
* @return $this * @return $this
*/ */
@ -92,6 +94,7 @@ class Upload extends FormComponentDriver
* 支持的文件类型,与 accept 不同的是, * 支持的文件类型,与 accept 不同的是,
* format 是识别文件的后缀名accept input 标签原生的 accept 属性, * format 是识别文件的后缀名accept input 标签原生的 accept 属性,
* 会在选择文件时过滤,可以两者结合使用 * 会在选择文件时过滤,可以两者结合使用
*
* @param array $headers * @param array $headers
* @return $this * @return $this
*/ */
@ -103,6 +106,7 @@ class Upload extends FormComponentDriver
/** /**
* 上传时附带的额外参数 * 上传时附带的额外参数
*
* @param array $headers * @param array $headers
* @return $this * @return $this
*/ */
@ -112,7 +116,7 @@ class Upload extends FormComponentDriver
return $this; return $this;
} }
protected function getPlaceHolder($pre = '请上传') public function getPlaceHolder($pre = '请上传')
{ {
return parent::getPlaceHolder($pre); return parent::getPlaceHolder($pre);
} }
@ -129,9 +133,6 @@ class Upload extends FormComponentDriver
protected function getValidateHandler() protected function getValidateHandler()
{ {
if($this->props['maxLength'] == 1)
return Validate::str();
else
return Validate::arr(); return Validate::arr();
} }

View File

@ -39,35 +39,50 @@ class Validate implements FormComponentInterFace
public static function str($trigger = self::TRIGGER_CHANGE) public static function str($trigger = self::TRIGGER_CHANGE)
{ {
return new static(self::TYPE_STRING,$trigger); return new self(self::TYPE_STRING, $trigger);
} }
public static function arr($trigger = self::TRIGGER_CHANGE) public static function arr($trigger = self::TRIGGER_CHANGE)
{ {
return new static(self::TYPE_ARRAY,$trigger); return new self(self::TYPE_ARRAY, $trigger);
} }
public static function num($trigger = self::TRIGGER_CHANGE) public static function num($trigger = self::TRIGGER_CHANGE)
{ {
return new static(self::TYPE_NUMBER,$trigger); return new self(self::TYPE_NUMBER, $trigger);
} }
public static function date($trigger = self::TRIGGER_CHANGE) public static function date($trigger = self::TRIGGER_CHANGE)
{ {
return new static(self::TYPE_DATE,$trigger); return new self(self::TYPE_DATE, $trigger);
} }
protected function set($validate, $message = null) public function set($validate, $message = null)
{ {
$this->validate[] = $validate + [ $this->validate[] = $validate + [
'trigger' => $this->trigger, 'trigger' => $this->trigger,
'type' => $this->type, 'type' => $this->type,
'message' => $message 'message' => $message
]; ];
return $this;
}
public function fields(array $fields, $required = null, $message = null)
{
$data = [];
if (!is_null($required))
$data['required'] = $required;
if (is_null($message))
$data['message'] = $message;
$data['fields'] = (object)$fields;
return $this->set($data);
} }
/** /**
* 必须为链接 * 必须为链接
*
* @param string|null $message * @param string|null $message
* @return $this * @return $this
*/ */
@ -81,6 +96,7 @@ class Validate implements FormComponentInterFace
/** /**
* 必须为邮箱 * 必须为邮箱
*
* @param string|null $message * @param string|null $message
* @return $this * @return $this
*/ */
@ -94,6 +110,7 @@ class Validate implements FormComponentInterFace
/** /**
* 必填 * 必填
*
* @param string|null $message * @param string|null $message
* @return $this * @return $this
*/ */
@ -107,6 +124,7 @@ class Validate implements FormComponentInterFace
/** /**
* 长度或值必须在这个范围内 * 长度或值必须在这个范围内
*
* @param int $min * @param int $min
* @param int $max * @param int $max
* @param string|null $message * @param string|null $message
@ -123,6 +141,7 @@ class Validate implements FormComponentInterFace
/** /**
* 长度或值必须大于这个值 * 长度或值必须大于这个值
*
* @param int $min * @param int $min
* @param string|null $message * @param string|null $message
* @return $this * @return $this
@ -137,6 +156,7 @@ class Validate implements FormComponentInterFace
/** /**
* 长度或值必须小于这个值 * 长度或值必须小于这个值
*
* @param int $max * @param int $max
* @param string|null $message * @param string|null $message
* @return $this * @return $this
@ -151,6 +171,7 @@ class Validate implements FormComponentInterFace
/** /**
* 长度或值必须等于这个值 * 长度或值必须等于这个值
*
* @param int $length * @param int $length
* @param string|null $message * @param string|null $message
* @return $this * @return $this
@ -158,13 +179,14 @@ class Validate implements FormComponentInterFace
public function length($length, $message = null) public function length($length, $message = null)
{ {
$this->set([ $this->set([
'length' => (int)$length 'len' => (int)$length
], $message); ], $message);
return $this; return $this;
} }
/** /**
* 值必须在 list * 值必须在 list
*
* @param array $list * @param array $list
* @param string|null $message * @param string|null $message
* @return $this * @return $this

View File

@ -0,0 +1,20 @@
<?php
/**
* Created by PhpStorm.
* User: xaboy
* Date: 2018/12/12
* Time: 19:48
*/
namespace FormBuilder\exception;
use Throwable;
class FormBuilderException extends \Exception
{
public function __construct($message = "", $code = 0, Throwable $previous = null)
{
parent::__construct($message, $code, $previous);
}
}

View File

@ -10,6 +10,7 @@ namespace FormBuilder\interfaces;
/** /**
* Interface FormComponentInterFace * Interface FormComponentInterFace
*
* @package FormBuilder\interfaces * @package FormBuilder\interfaces
*/ */
interface FormComponentInterFace interface FormComponentInterFace
@ -17,6 +18,7 @@ interface FormComponentInterFace
/** /**
* 获取组件的生成规则 * 获取组件的生成规则
*
* @return array * @return array
*/ */
public function build(); public function build();

View File

@ -8,20 +8,23 @@
namespace FormBuilder\traits\component; namespace FormBuilder\traits\component;
use FormBuilder\exception\FormBuilderException;
use FormBuilder\Helper; use FormBuilder\Helper;
/** /**
* Class CallPropsTrait * Class CallPropsTrait
*
* @package FormBuilder\traits\component * @package FormBuilder\traits\component
*/ */
trait CallPropsTrait trait CallPropsTrait
{ {
/** /**
* 设置组件属性 * 设置组件属性
*
* @param $name * @param $name
* @param $arguments * @param $arguments
* @return $this * @return $this
* @throws \Exception * @throws FormBuilderException
*/ */
public function __call($name, $arguments) public function __call($name, $arguments)
{ {
@ -41,7 +44,7 @@ trait CallPropsTrait
} }
return $this; return $this;
} else { } else {
throw new \Exception($name . '方法不存在'); throw new FormBuilderException($name . '方法不存在');
} }
} }
} }

View File

@ -12,6 +12,7 @@ use FormBuilder\components\Option;
/** /**
* Class ComponentOptionsTrait * Class ComponentOptionsTrait
*
* @package FormBuilder\traits\component * @package FormBuilder\traits\component
*/ */
trait ComponentOptionsTrait trait ComponentOptionsTrait
@ -23,10 +24,12 @@ trait ComponentOptionsTrait
/** /**
* 设置的选项 * 设置的选项
*
* @param $value * @param $value
* @param $label * @param $label
* @param bool $disabled * @param bool $disabled
* @return $this * @return $this
* @throws \FormBuilder\exception\FormBuilderException
*/ */
public function option($value, $label, $disabled = false) public function option($value, $label, $disabled = false)
{ {
@ -37,9 +40,11 @@ trait ComponentOptionsTrait
/** /**
* 批量设置的选项 * 批量设置的选项
*
* @param array $options * @param array $options
* @param bool $disabled * @param bool $disabled
* @return $this * @return $this
* @throws \FormBuilder\exception\FormBuilderException
*/ */
public function options(array $options, $disabled = false) public function options(array $options, $disabled = false)
{ {
@ -59,6 +64,7 @@ trait ComponentOptionsTrait
/** /**
* 批量设置选项 支持匿名函数 * 批量设置选项 支持匿名函数
*
* @param $options * @param $options
* @param bool $disabled * @param bool $disabled
* @return $this * @return $this

View File

@ -12,12 +12,14 @@ use FormBuilder\components\Cascader;
/** /**
* Class FormCascaderTrait * Class FormCascaderTrait
*
* @package FormBuilder\traits\form * @package FormBuilder\traits\form
*/ */
trait FormCascaderTrait trait FormCascaderTrait
{ {
/** /**
* 多级联动组件 * 多级联动组件
*
* @param $field * @param $field
* @param $title * @param $title
* @param array $value * @param array $value
@ -34,6 +36,7 @@ trait FormCascaderTrait
/** /**
* 省市二级联动 * 省市二级联动
*
* @param $field * @param $field
* @param $title * @param $title
* @param array|string $province * @param array|string $province
@ -55,6 +58,7 @@ trait FormCascaderTrait
/** /**
* 省市区三级联动 * 省市区三级联动
*
* @param $field * @param $field
* @param $title * @param $title
* @param array|string $province * @param array|string $province

View File

@ -11,11 +11,14 @@ use FormBuilder\components\Checkbox;
/** /**
* Class FormCheckBoxTrait * Class FormCheckBoxTrait
*
* @package FormBuilder\traits\form * @package FormBuilder\traits\form
*/ */
trait FormCheckBoxTrait trait FormCheckBoxTrait
{ {
/** /**
* 多选框组件
*
* @param $field * @param $field
* @param $title * @param $title
* @param array $value * @param array $value

View File

@ -12,11 +12,14 @@ use FormBuilder\components\ColorPicker;
/** /**
* Class FormColorPickerTrait * Class FormColorPickerTrait
*
* @package FormBuilder\traits\form * @package FormBuilder\traits\form
*/ */
trait FormColorPickerTrait trait FormColorPickerTrait
{ {
/** /**
* 颜色选择组件
*
* @param $field * @param $field
* @param $title * @param $title
* @param string $value * @param string $value

View File

@ -12,11 +12,14 @@ use FormBuilder\components\DatePicker;
/** /**
* Class FormDatePickerTrait * Class FormDatePickerTrait
*
* @package FormBuilder\traits\form * @package FormBuilder\traits\form
*/ */
trait FormDatePickerTrait trait FormDatePickerTrait
{ {
/** /**
* 日期组件
*
* @param $field * @param $field
* @param $title * @param $title
* @param string $value * @param string $value
@ -31,6 +34,8 @@ trait FormDatePickerTrait
} }
/** /**
* 单选日期
*
* @param $field * @param $field
* @param $title * @param $title
* @param string $value * @param string $value
@ -42,6 +47,22 @@ trait FormDatePickerTrait
} }
/** /**
* 多选日期
*
* @param $field
* @param $title
* @param array $value
* @return DatePicker
*/
public static function dateMultiple($field, $title, array $value)
{
$date = self::datePicker($field, $title, $value, DatePicker::TYPE_DATE);
return $date->multiple();
}
/**
* 日期区间选择
*
* @param $field * @param $field
* @param $title * @param $title
* @param string $startDate * @param string $startDate
@ -54,6 +75,8 @@ trait FormDatePickerTrait
} }
/** /**
* 单选日期时间
*
* @param $field * @param $field
* @param $title * @param $title
* @param string $value * @param string $value
@ -65,6 +88,8 @@ trait FormDatePickerTrait
} }
/** /**
* 日期时间区间选择
*
* @param $field * @param $field
* @param $title * @param $title
* @param string $startDate * @param string $startDate
@ -77,6 +102,8 @@ trait FormDatePickerTrait
} }
/** /**
* 选择年
*
* @param $field * @param $field
* @param $title * @param $title
* @param string $value * @param string $value
@ -88,6 +115,8 @@ trait FormDatePickerTrait
} }
/** /**
* 选择月
*
* @param $field * @param $field
* @param $title * @param $title
* @param string $value * @param string $value

View File

@ -12,11 +12,14 @@ use FormBuilder\components\Frame;
/** /**
* Class FormFrameTrait * Class FormFrameTrait
*
* @package FormBuilder\traits\form * @package FormBuilder\traits\form
*/ */
trait FormFrameTrait trait FormFrameTrait
{ {
/** /**
* 框架组件
*
* @param $field * @param $field
* @param $title * @param $title
* @param $src * @param $src
@ -33,6 +36,9 @@ trait FormFrameTrait
} }
/** /**
* 使用input 类型显示,多选
* value为Array类型
*
* @param $field * @param $field
* @param $title * @param $title
* @param $src * @param $src
@ -45,6 +51,9 @@ trait FormFrameTrait
} }
/** /**
* 使用文件类型显示,多选
* value为Array类型
*
* @param $field * @param $field
* @param $title * @param $title
* @param $src * @param $src
@ -57,6 +66,9 @@ trait FormFrameTrait
} }
/** /**
* 使用文件类型显示,多选
* value为Array类型
*
* @param $field * @param $field
* @param $title * @param $title
* @param $src * @param $src
@ -69,6 +81,9 @@ trait FormFrameTrait
} }
/** /**
* 使用input 类型显示,单选
* value为String类型
*
* @param $field * @param $field
* @param $title * @param $title
* @param $src * @param $src
@ -81,6 +96,9 @@ trait FormFrameTrait
} }
/** /**
* 使用文件类型显示,单选
* value为String类型
*
* @param $field * @param $field
* @param $title * @param $title
* @param $src * @param $src
@ -93,6 +111,9 @@ trait FormFrameTrait
} }
/** /**
* 使用文件类型显示,单选
* value为String类型
*
* @param $field * @param $field
* @param $title * @param $title
* @param $src * @param $src

View File

@ -12,11 +12,14 @@ use FormBuilder\components\Hidden;
/** /**
* Class FormHiddenTrait * Class FormHiddenTrait
*
* @package FormBuilder\traits\form * @package FormBuilder\traits\form
*/ */
trait FormHiddenTrait trait FormHiddenTrait
{ {
/** /**
* 隐藏组件
*
* @param $field * @param $field
* @param $value * @param $value
* @return Hidden * @return Hidden

View File

@ -12,12 +12,15 @@ use FormBuilder\components\InputNumber;
/** /**
* Class FormInputNumberTrait * Class FormInputNumberTrait
*
* @package FormBuilder\traits\form * @package FormBuilder\traits\form
*/ */
trait FormInputNumberTrait trait FormInputNumberTrait
{ {
/** /**
* 数字输入框组件
*
* @param $field * @param $field
* @param $title * @param $title
* @param null $value * @param null $value

View File

@ -12,12 +12,14 @@ use FormBuilder\components\Input;
/** /**
* Class FormInputTrait * Class FormInputTrait
*
* @package FormBuilder\traits\form * @package FormBuilder\traits\form
*/ */
trait FormInputTrait trait FormInputTrait
{ {
/** /**
* 获取input组件 * input输入框组件
*
* @param $field * @param $field
* @param $title * @param $title
* @param string $value * @param string $value
@ -32,6 +34,8 @@ trait FormInputTrait
} }
/** /**
* text 类型输入框
*
* @param $field * @param $field
* @param $title * @param $title
* @param string $value * @param string $value
@ -43,6 +47,8 @@ trait FormInputTrait
} }
/** /**
* password 类型输入框
*
* @param $field * @param $field
* @param $title * @param $title
* @param string $value * @param string $value
@ -54,6 +60,8 @@ trait FormInputTrait
} }
/** /**
* textarea 类型输入框
*
* @param $field * @param $field
* @param $title * @param $title
* @param string $value * @param string $value
@ -65,6 +73,8 @@ trait FormInputTrait
} }
/** /**
* url 类型输入框
*
* @param $field * @param $field
* @param $title * @param $title
* @param string $value * @param string $value
@ -76,6 +86,8 @@ trait FormInputTrait
} }
/** /**
* email 类型输入框
*
* @param $field * @param $field
* @param $title * @param $title
* @param string $value * @param string $value
@ -87,6 +99,8 @@ trait FormInputTrait
} }
/** /**
* date 类型输入框
*
* @param $field * @param $field
* @param $title * @param $title
* @param string $value * @param string $value

View File

@ -12,15 +12,19 @@ use FormBuilder\components\Option;
/** /**
* Class FormOptionTrait * Class FormOptionTrait
*
* @package FormBuilder\traits\form * @package FormBuilder\traits\form
*/ */
trait FormOptionTrait trait FormOptionTrait
{ {
/** /**
* 获取选择类组件 option
*
* @param $value * @param $value
* @param string $label * @param string $label
* @param bool $disabled * @param bool $disabled
* @return Option * @return Option
* @throws \FormBuilder\exception\FormBuilderException
*/ */
public static function option($value, $label = '', $disabled = false) public static function option($value, $label = '', $disabled = false)
{ {

View File

@ -12,11 +12,14 @@ use FormBuilder\components\Radio;
/** /**
* Class FormRadioTrait * Class FormRadioTrait
*
* @package FormBuilder\traits\form * @package FormBuilder\traits\form
*/ */
trait FormRadioTrait trait FormRadioTrait
{ {
/** /**
* 单选框组件
*
* @param $field * @param $field
* @param $title * @param $title
* @param string $value * @param string $value

View File

@ -12,17 +12,20 @@ use FormBuilder\components\Rate;
/** /**
* Class FormRateTrait * Class FormRateTrait
*
* @package FormBuilder\traits\form * @package FormBuilder\traits\form
*/ */
trait FormRateTrait trait FormRateTrait
{ {
/** /**
* 评分选择组件
*
* @param $field * @param $field
* @param $title * @param $title
* @param number $value * @param float $value
* @return Rate * @return Rate
*/ */
public static function rate($field, $title, $value = 0) public static function rate($field, $title, $value = 0.0)
{ {
return new Rate($field, $title, (float)$value); return new Rate($field, $title, (float)$value);
} }

View File

@ -12,11 +12,14 @@ use FormBuilder\components\Select;
/** /**
* Class FormSelectTrait * Class FormSelectTrait
*
* @package FormBuilder\traits\form * @package FormBuilder\traits\form
*/ */
trait FormSelectTrait trait FormSelectTrait
{ {
/** /**
* 下拉选择组件
*
* @param $field * @param $field
* @param $title * @param $title
* @param string $value * @param string $value
@ -31,6 +34,8 @@ trait FormSelectTrait
} }
/** /**
* 多选
*
* @param $field * @param $field
* @param $title * @param $title
* @param array $value * @param array $value
@ -42,6 +47,8 @@ trait FormSelectTrait
} }
/** /**
* 单选
*
* @param $field * @param $field
* @param $title * @param $title
* @param string $value * @param string $value

View File

@ -12,11 +12,14 @@ use FormBuilder\components\Slider;
/** /**
* Class FormSliderTrait * Class FormSliderTrait
*
* @package FormBuilder\traits\form * @package FormBuilder\traits\form
*/ */
trait FormSliderTrait trait FormSliderTrait
{ {
/** /**
* 滑块组件
*
* @param $field * @param $field
* @param $title * @param $title
* @param int $value * @param int $value
@ -28,6 +31,8 @@ trait FormSliderTrait
} }
/** /**
* 区间选择
*
* @param $field * @param $field
* @param $title * @param $title
* @param int $start * @param int $start

View File

@ -14,12 +14,15 @@ use FormBuilder\components\Row;
/** /**
* Class FormStyleTrait * Class FormStyleTrait
*
* @package FormBuilder\traits\form * @package FormBuilder\traits\form
*/ */
trait FormStyleTrait trait FormStyleTrait
{ {
/** /**
* 组件布局规则类
*
* @param int $span * @param int $span
* @return Col * @return Col
*/ */
@ -29,6 +32,8 @@ trait FormStyleTrait
} }
/** /**
* 表格布局规则类
*
* @param int $gutter * @param int $gutter
* @param string $type * @param string $type
* @param string $align * @param string $align
@ -42,6 +47,8 @@ trait FormStyleTrait
} }
/** /**
* 表格样式类
*
* @param bool $inline * @param bool $inline
* @param string $labelPosition * @param string $labelPosition
* @param int $labelWidth * @param int $labelWidth

View File

@ -12,11 +12,14 @@ use FormBuilder\components\Switches;
/** /**
* Class FormSwitchesTrait * Class FormSwitchesTrait
*
* @package FormBuilder\traits\form * @package FormBuilder\traits\form
*/ */
trait FormSwitchesTrait trait FormSwitchesTrait
{ {
/** /**
* 开关组件
*
* @param $field * @param $field
* @param $title * @param $title
* @param string $value * @param string $value

View File

@ -12,14 +12,17 @@ use FormBuilder\components\TimePicker;
/** /**
* Class FormTimePickerTrait * Class FormTimePickerTrait
*
* @package FormBuilder\traits\form * @package FormBuilder\traits\form
*/ */
trait FormTimePickerTrait trait FormTimePickerTrait
{ {
/** /**
* 时间选择组件
*
* @param $field * @param $field
* @param $title * @param $title
* @param string $value * @param string|int $value
* @param string $type * @param string $type
* @return TimePicker * @return TimePicker
*/ */
@ -29,9 +32,11 @@ trait FormTimePickerTrait
} }
/** /**
* 事件选择
*
* @param $field * @param $field
* @param $title * @param $title
* @param string $value * @param string|int $value
* @return TimePicker * @return TimePicker
*/ */
public static function time($field, $title, $value = '') public static function time($field, $title, $value = '')
@ -40,10 +45,12 @@ trait FormTimePickerTrait
} }
/** /**
* 时间区间选择
*
* @param $field * @param $field
* @param $title * @param $title
* @param string $startTime * @param string|int $startTime
* @param string $endTime * @param string|int $endTime
* @return TimePicker * @return TimePicker
*/ */
public static function timeRange($field, $title, $startTime = '', $endTime = '') public static function timeRange($field, $title, $startTime = '', $endTime = '')

View File

@ -13,11 +13,14 @@ use FormBuilder\components\TreeData;
/** /**
* Class FormTreeTrait * Class FormTreeTrait
*
* @package FormBuilder\traits\form * @package FormBuilder\traits\form
*/ */
trait FormTreeTrait trait FormTreeTrait
{ {
/** /**
* 树形组件
*
* @param $field * @param $field
* @param $title * @param $title
* @param array $value * @param array $value
@ -30,6 +33,8 @@ trait FormTreeTrait
} }
/** /**
* 获取选中的值
*
* @param $field * @param $field
* @param $title * @param $title
* @param array $value * @param array $value
@ -41,6 +46,8 @@ trait FormTreeTrait
} }
/** /**
* 获取勾选的值
*
* @param $field * @param $field
* @param $title * @param $title
* @param array $value * @param array $value
@ -52,6 +59,8 @@ trait FormTreeTrait
} }
/** /**
* 树形组件数据 date
*
* @param $id * @param $id
* @param $title * @param $title
* @param array $children * @param array $children

View File

@ -12,11 +12,14 @@ use FormBuilder\components\Upload;
/** /**
* Class FormUploadTrait * Class FormUploadTrait
*
* @package FormBuilder\traits\form * @package FormBuilder\traits\form
*/ */
trait FormUploadTrait trait FormUploadTrait
{ {
/** /**
* 上传组件
*
* @param $field * @param $field
* @param $title * @param $title
* @param $action * @param $action
@ -32,6 +35,9 @@ trait FormUploadTrait
} }
/** /**
* 图片上传
* value Array类型
*
* @param $field * @param $field
* @param $title * @param $title
* @param $action * @param $action
@ -47,6 +53,9 @@ trait FormUploadTrait
} }
/** /**
* 文件上传
* value Array类型
*
* @param $field * @param $field
* @param $title * @param $title
* @param $action * @param $action
@ -59,6 +68,9 @@ trait FormUploadTrait
} }
/** /**
* 图片上传
* value String类型
*
* @param $field * @param $field
* @param $title * @param $title
* @param $action * @param $action
@ -73,6 +85,9 @@ trait FormUploadTrait
} }
/** /**
* 文件上传
* value String类型
*
* @param $field * @param $field
* @param $title * @param $title
* @param $action * @param $action

View File

@ -12,36 +12,71 @@ use FormBuilder\components\Validate;
trait FormValidateTrait trait FormValidateTrait
{ {
/**
* string 类型验证器
*
* @return Validate
*/
public static function validateStr() public static function validateStr()
{ {
return Validate::str(); return Validate::str();
} }
/**
* input 组件验证器
*
* @return Validate
*/
public static function validateInput() public static function validateInput()
{ {
return Validate::str(Validate::TRIGGER_BLUR); return Validate::str(Validate::TRIGGER_BLUR);
} }
/**
* array 类型验证器
*
* @return Validate
*/
public static function validateArr() public static function validateArr()
{ {
return Validate::arr(); return Validate::arr();
} }
/**
* number 类型验证器
*
* @return Validate
*/
public static function validateNum() public static function validateNum()
{ {
return Validate::num(); return Validate::num();
} }
/**
* inputNumber 组件验证器
*
* @return Validate
*/
public static function validateNumInput() public static function validateNumInput()
{ {
return Validate::num(Validate::TRIGGER_BLUR); return Validate::num(Validate::TRIGGER_BLUR);
} }
/**
* date 类型验证器
*
* @return Validate
*/
public static function validateDate() public static function validateDate()
{ {
return Validate::date(); return Validate::date();
} }
/**
* frame 组件验证器
*
* @return Validate
*/
public static function validateFrame() public static function validateFrame()
{ {
return self::ValidateArr(); return self::ValidateArr();

View File

@ -10,10 +10,12 @@
}); });
return rule; return rule;
}, vm = new Vue,name = 'formBuilderExec<?= !$form->getId() ? '' : '_'.$form->getId() ?>'; }, vm = new Vue,name = 'formBuilderExec<?= !$form->getId() ? '' : '_'.$form->getId() ?>';
var _b = false;
window[name] = function create(el, callback) { window[name] = function create(el, callback) {
if(_b) return ;
_b = true;
if (!el) el = document.body; if (!el) el = document.body;
$f = formCreate.create(getRule(), { var $f = formCreate.create(getRule(), {
el: el, el: el,
form:<?=json_encode($form->getConfig('form'))?>, form:<?=json_encode($form->getConfig('form'))?>,
row:<?=json_encode($form->getConfig('row'))?>, row:<?=json_encode($form->getConfig('row'))?>,
@ -48,12 +50,10 @@
success: function (res) { success: function (res) {
if (res.code == 200) { if (res.code == 200) {
vm.$Message.success(res.msg); vm.$Message.success(res.msg);
$f.submitStatus({loading: false});
formCreate.formSuccess && formCreate.formSuccess(res, $f, formData);
callback && callback(0, res, $f, formData); callback && callback(0, res, $f, formData);
//TODO 表单提交成功! //TODO 表单提交成功!
} else { } else {
vm.$Message.error(res.msg); vm.$Message.error(res.msg || '表单提交失败');
$f.btn.finish(); $f.btn.finish();
callback && callback(1, res, $f, formData); callback && callback(1, res, $f, formData);
//TODO 表单提交失败 //TODO 表单提交失败