| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341 |
- <?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\Contract\ColComponentInterface;
- trait BaseRule
- {
- /**
- * 组件类型
- *
- * @var string
- */
- protected $type;
- /**
- * 组件字段名
- *
- * @var string
- */
- protected $field;
- /**
- * 字段昵称
- *
- * @var string
- */
- protected $title;
- /**
- * 组件名称
- *
- * @var string
- */
- protected $name;
- /**
- * 组件的提示信息
- *
- * @var string
- */
- protected $info;
- /**
- * 组件 class
- *
- * @var string
- */
- protected $className;
- /**
- * 是否原样生成组件,不嵌套的FormItem中
- *
- * @var bool
- */
- protected $native;
- /**
- * 事件注入时的自定义数据
- *
- * @var mixed
- */
- protected $inject;
- /**
- * 组件布局规则
- *
- * @var ColComponentInterface|array
- */
- protected $col;
- /**
- * 组件的值
- *
- * @var mixed
- */
- protected $value = '';
- /**
- * 组件显示状态
- *
- * @var bool
- */
- protected $hidden;
- /**
- * 组件显示状态
- *
- * @var bool
- */
- protected $visibility;
- /**
- * @var array
- */
- protected $effect;
- /**
- * 组件显示状态
- *
- * @param bool $hidden
- * @return $this
- */
- public function hiddenStatus($hidden = true)
- {
- $this->hidden = !!$hidden;
- return $this;
- }
- /**
- * 组件显示状态
- *
- * @param bool $visibility
- * @return $this
- */
- public function visibilityStatus($visibility = true)
- {
- $this->visibility = !!$visibility;
- return $this;
- }
- /**
- * @param string $type
- * @return $this
- */
- protected function setRuleType($type)
- {
- $this->type = (string)$type;
- return $this;
- }
- /**
- * @param string $field
- * @return $this
- */
- public function field($field)
- {
- $this->field = (string)$field;
- return $this;
- }
- /**
- * @param string $title
- * @return $this
- */
- public function title($title)
- {
- $this->title = (string)$title;
- return $this;
- }
- /**
- * @param string $name
- * @return $this
- */
- public function name($name)
- {
- $this->name = (string)$name;
- return $this;
- }
- /**
- * @param string $className
- * @return $this
- */
- public function className($className)
- {
- $this->className = (string)$className;
- return $this;
- }
- /**
- * @param bool $native
- * @return $this
- */
- public function native($native)
- {
- $this->native = !!$native;
- return $this;
- }
- /**
- * @param mixed $inject
- * @return $this
- */
- public function inject($inject)
- {
- $this->inject = $inject;
- return $this;
- }
- /**
- * @param string $info
- * @return $this
- */
- public function info($info)
- {
- $this->info = $info;
- return $this;
- }
- /**
- * @param array|int|ColComponentInterface $col
- * @return $this
- */
- public function col($col)
- {
- if (is_integer($col)) $col = ['span' => $col];
- $this->col = $col;
- return $this;
- }
- public function effect(array $effect)
- {
- $this->effect = $effect;
- return $this;
- }
- /**
- * @param mixed $value
- * @return $this
- */
- public function value($value)
- {
- if (is_null($value)) $value = '';
- $this->value = $value;
- return $this;
- }
- public function getHiddenStatus()
- {
- return $this->hidden;
- }
- public function getVisibilityStatus()
- {
- return $this->visibility;
- }
- public function getField()
- {
- return $this->field;
- }
- public function getTitle()
- {
- return $this->title;
- }
- public function getName()
- {
- return $this->name;
- }
- public function getClassName()
- {
- return $this->className;
- }
- public function getInfo()
- {
- return $this->info;
- }
- public function getNative()
- {
- return $this->native;
- }
- public function getInject()
- {
- return $this->inject;
- }
- public function getCol()
- {
- return $this->col;
- }
- public function getEffect()
- {
- return $this->effect;
- }
- public function getValue()
- {
- return $this->value;
- }
- protected function parseCol($col)
- {
- return $col instanceof ColComponentInterface ? $col->getCol() : $col;
- }
- protected function parseBaseRule()
- {
- $rule = [
- 'type' => $this->type
- ];
- if (!is_null($this->field))
- $rule['field'] = $this->field;
- if (!is_null($this->value))
- $rule['value'] = $this->value;
- if (!is_null($this->title))
- $rule['title'] = $this->title;
- if (!is_null($this->className))
- $rule['className'] = $this->className;
- if (!is_null($this->name))
- $rule['name'] = $this->name;
- if (!is_null($this->native))
- $rule['native'] = $this->native;
- if (!is_null($this->info))
- $rule['info'] = $this->info;
- if (!is_null($this->effect))
- $rule['effect'] = $this->effect;
- if (!is_null($this->inject))
- $rule['inject'] = $this->inject;
- if (!is_null($this->hidden))
- $rule['hidden'] = $this->hidden;
- if (!is_null($this->visibility))
- $rule['visibility'] = $this->visibility;
- if (!is_null($this->col))
- $rule['col'] = $this->parseCol($this->col);
- return $rule;
- }
- }
|