diff --git a/extend/catcher/CatchAdmin.php b/extend/catcher/CatchAdmin.php index a6ba36b..e43751f 100644 --- a/extend/catcher/CatchAdmin.php +++ b/extend/catcher/CatchAdmin.php @@ -22,6 +22,20 @@ class CatchAdmin return app()->getRootPath() . self::$root . DIRECTORY_SEPARATOR; } + /** + * 设置 root + * + * @time 2021年03月28日 + * @param $root + * @return CatchAdmin + */ + public static function setRoot($root): CatchAdmin + { + self::$root = $root; + + return new self(); + } + /** * 创建目录 * diff --git a/extend/catcher/library/form/Form.php b/extend/catcher/library/form/Form.php index 7b681f1..a3181b9 100644 --- a/extend/catcher/library/form/Form.php +++ b/extend/catcher/library/form/Form.php @@ -58,7 +58,6 @@ abstract class Form use UploadFactoryTrait; use ValidateFactoryTrait; use GroupFactoryTrait; - use FormOptions; use FormValidates; protected $primaryKeyField = 'id'; @@ -121,9 +120,13 @@ abstract class Form */ protected function getFields(): array { - return array_merge($this->fields(), [ - self::hidden($this->primaryKeyField, 0) - ]); + if ($this->primaryKeyField) { + return array_merge($this->fields(), [ + self::hidden($this->primaryKeyField, 0) + ]); + } + + return $this->fields(); } /** @@ -135,10 +138,6 @@ abstract class Form */ public function rule(array $rules): array { - if ($this->primaryKeyField) { - array_push($rules, self::hidden($this->primaryKeyField, 0)); - } - try{ return Elm::createForm('', $rules)->formRule(); } catch (FormBuilderException $e) { @@ -251,4 +250,15 @@ abstract class Form ->data(['none' => '']) ->headers(self::authorization()); } + + /** + * options + * + * @time 2021年03月24日 + * @return FormOptions + */ + public static function options(): FormOptions + { + return new FormOptions(); + } } diff --git a/extend/catcher/library/form/FormOptions.php b/extend/catcher/library/form/FormOptions.php index acc74e0..9a5239d 100644 --- a/extend/catcher/library/form/FormOptions.php +++ b/extend/catcher/library/form/FormOptions.php @@ -14,29 +14,36 @@ namespace catcher\library\form; -trait FormOptions +class FormOptions { + protected $options = []; + /** - * 是/否的选项 + * 增加 option * - * @time 2021年03月06日 - * @param array $label - * @param array $value - * @return array[] + * @time 2021年03月24日 + * @param $label + * @param $value + * @return $this */ - protected function yesOrNo(array $label = [], array $value = []): array + public function add($label, $value): FormOptions { - if (!count($label)) { - $label = ['是', '否']; - } - - if (!count($value)) { - $value = [1, 2]; - } - - return [ - ['value' => $value[0], 'label' => $label[0]], - ['value' => $value[1], 'label' => $label[1]], + $this->options[] = [ + 'value' => $value, + 'label' => $label, ]; + + return $this; + } + + /** + * 获取 + * + * @time 2021年03月24日 + * @return array + */ + public function render() + { + return $this->options; } } diff --git a/extend/catcher/library/form/FormValidates.php b/extend/catcher/library/form/FormValidates.php index 9f086f9..860b2db 100644 --- a/extend/catcher/library/form/FormValidates.php +++ b/extend/catcher/library/form/FormValidates.php @@ -3,6 +3,18 @@ namespace catcher\library\form; trait FormValidates { + /** + * 正则验证 + * + * @time 2021年03月06日 + * @param string $pattern + * @return \FormBuilder\UI\Elm\Validate + */ + public static function validatePattern(string $pattern): \FormBuilder\UI\Elm\Validate + { + return self::validateStr()->pattern($pattern); + } + /** * 纯数字验证 *