|
|
@@ -9,6 +9,7 @@ namespace FormBuilder;
|
|
|
|
|
|
use FormBuilder\components\Cascader;
|
|
|
use FormBuilder\components\FormStyle;
|
|
|
+use FormBuilder\components\Hidden;
|
|
|
use FormBuilder\components\Row;
|
|
|
use FormBuilder\traits\form\FormCascaderTrait;
|
|
|
use FormBuilder\traits\form\FormCheckBoxTrait;
|
|
|
@@ -28,6 +29,7 @@ use FormBuilder\traits\form\FormTimePickerTrait;
|
|
|
use FormBuilder\traits\form\FormTreeTrait;
|
|
|
use FormBuilder\traits\form\FormUploadTrait;
|
|
|
use FormBuilder\traits\form\FormOptionTrait;
|
|
|
+use FormBuilder\traits\form\FormValidateTrait;
|
|
|
|
|
|
/**
|
|
|
* Class Form
|
|
|
@@ -52,7 +54,8 @@ class Form
|
|
|
FormTimePickerTrait,
|
|
|
FormTreeTrait,
|
|
|
FormStyleTrait,
|
|
|
- FormOptionTrait;
|
|
|
+ FormOptionTrait,
|
|
|
+ FormValidateTrait;
|
|
|
|
|
|
/**
|
|
|
* 三级联动 加载省市数据
|
|
|
@@ -85,12 +88,30 @@ class Form
|
|
|
//iview 版本 2.14.3
|
|
|
'iview-css' => '<link href="https://cdn.jsdelivr.net/npm/iview@2.14.3/dist/styles/iview.css" rel="stylesheet">',
|
|
|
'iview' => '<script src="https://cdn.jsdelivr.net/npm/iview@2.14.3/dist/iview.min.js"></script>',
|
|
|
- //form-create 版本 1.3.3
|
|
|
- 'form-create' => '<script src="https://cdn.jsdelivr.net/npm/form-create@1.4.0/dist/form-create.min.js"></script>',
|
|
|
+ //form-create 版本 1.4.5
|
|
|
+ 'form-create' => '<script src="https://cdn.jsdelivr.net/npm/form-create@1.4.5/dist/form-create.min.js"></script>',
|
|
|
'city-data' => '<script src="https://cdn.jsdelivr.net/npm/form-create/district/province_city.js"></script>',
|
|
|
'city-area-data' => '<script src="https://cdn.jsdelivr.net/npm/form-create/district/province_city_area.js"></script>'
|
|
|
];
|
|
|
|
|
|
+ /**
|
|
|
+ * 加载 jquery
|
|
|
+ * @var bool
|
|
|
+ */
|
|
|
+ protected $linkJq = true;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 加载 vue
|
|
|
+ * @var bool
|
|
|
+ */
|
|
|
+ protected $linkVue = true;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 加载 iview
|
|
|
+ * @var bool
|
|
|
+ */
|
|
|
+ protected $linkIview = true;
|
|
|
+
|
|
|
/**
|
|
|
* @var string
|
|
|
*/
|
|
|
@@ -120,6 +141,10 @@ class Form
|
|
|
*/
|
|
|
protected $method = 'post';
|
|
|
|
|
|
+ protected $resetBtn = false;
|
|
|
+
|
|
|
+ protected $submitBtn = true;
|
|
|
+
|
|
|
/**
|
|
|
* 表单配置
|
|
|
* @var array|mixed
|
|
|
@@ -146,6 +171,30 @@ class Form
|
|
|
$this->action = $action;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * @param bool $linkJq
|
|
|
+ */
|
|
|
+ public function setLinkJq($linkJq)
|
|
|
+ {
|
|
|
+ $this->linkJq = (bool)$linkJq;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param bool $linkVue
|
|
|
+ */
|
|
|
+ public function setLinkVue($linkVue)
|
|
|
+ {
|
|
|
+ $this->linkVue = (bool)$linkVue;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param bool $linkIview
|
|
|
+ */
|
|
|
+ public function setLinkIview($linkIview)
|
|
|
+ {
|
|
|
+ $this->linkIview = (bool)$linkIview;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* @return bool
|
|
|
*/
|
|
|
@@ -334,6 +383,7 @@ class Form
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 是否需要引入省市区数据
|
|
|
* @param FormComponentDriver $component
|
|
|
*/
|
|
|
protected function checkLoadData(FormComponentDriver $component)
|
|
|
@@ -361,7 +411,10 @@ class Form
|
|
|
$component = $this->components[$field];
|
|
|
if (!($component instanceof FormComponentDriver))
|
|
|
continue;
|
|
|
- $rules[] = $component->build();
|
|
|
+ $rule = $component->build();
|
|
|
+ if(!$component instanceof Hidden)
|
|
|
+ $rule['validate'] = array_merge(isset($rule['validate']) ? $rule['validate'] : [],$component->validate()->build());
|
|
|
+ $rules[] = $rule;
|
|
|
}
|
|
|
return $rules;
|
|
|
}
|
|
|
@@ -397,7 +450,6 @@ class Form
|
|
|
{
|
|
|
ob_start();
|
|
|
$form = $this;
|
|
|
- $rule = $this->getRules();
|
|
|
require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'view' . DIRECTORY_SEPARATOR . 'formScript.php';
|
|
|
$script = ob_get_clean();
|
|
|
return $script;
|
|
|
@@ -412,17 +464,61 @@ class Form
|
|
|
{
|
|
|
$_script = $this->script;
|
|
|
$script = [
|
|
|
- $_script['iview-css'],
|
|
|
- $_script['jq'],
|
|
|
- $_script['vue'],
|
|
|
- $_script['iview'],
|
|
|
$_script['form-create']
|
|
|
];
|
|
|
if ($this->loadCityAreaData == true)
|
|
|
$script[] = $_script['city-area-data'];
|
|
|
if ($this->loadCityData == true)
|
|
|
$script[] = $_script['city-data'];
|
|
|
- return $script;
|
|
|
+ if($this->linkJq)
|
|
|
+ $script[] = $_script['jq'];
|
|
|
+ if($this->linkIview){
|
|
|
+ $script[] = $_script['iview'];
|
|
|
+ $script[] = $_script['iview-css'];
|
|
|
+ }
|
|
|
+ if($this->linkVue)
|
|
|
+ $script[] = $_script['vue'];
|
|
|
+ return array_reverse($script);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 是否隐藏提交按钮(默认显示)
|
|
|
+ * @param bool $isShow
|
|
|
+ * @return Form
|
|
|
+ */
|
|
|
+ public function hiddenSubmitBtn($isShow = false)
|
|
|
+ {
|
|
|
+ $this->submitBtn = !(bool)$isShow;
|
|
|
+
|
|
|
+ return $this;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 是否隐藏重置按钮(默认隐藏)
|
|
|
+ * @param bool $isShow
|
|
|
+ * @return Form
|
|
|
+ */
|
|
|
+ public function hiddenResetBtn($isShow = false)
|
|
|
+ {
|
|
|
+ $this->resetBtn = !(bool)$isShow;
|
|
|
+
|
|
|
+ return $this;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @return bool
|
|
|
+ */
|
|
|
+ public function isResetBtn()
|
|
|
+ {
|
|
|
+ return $this->resetBtn;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @return bool
|
|
|
+ */
|
|
|
+ public function isSubmitBtn()
|
|
|
+ {
|
|
|
+ return $this->submitBtn;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -433,6 +529,6 @@ class Form
|
|
|
*/
|
|
|
public static function create($action, array $components = [])
|
|
|
{
|
|
|
- return new self($action, $components);
|
|
|
+ return new static($action, $components);
|
|
|
}
|
|
|
}
|