diff --git a/extend/catcher/CatchForm.php b/extend/catcher/CatchForm.php index ee6747a..c8f0fae 100644 --- a/extend/catcher/CatchForm.php +++ b/extend/catcher/CatchForm.php @@ -6,12 +6,14 @@ namespace catcher; * @package catcher * * - * @method CatchForm text($column, $label = '') - * @method CatchForm image($column, $label = '') - * @method CatchForm radio($column, $label = '') - * @method CatchForm select($column, $label = '') - * @method CatchForm textarea($column, $label = '') - * @method CatchForm password($column, $label = '') + * @method CatchForm text($column, $label = '', $required = false) + * @method CatchForm image($column, $label = '', $required = false) + * @method CatchForm radio($column, $label = '', $required = false) + * @method CatchForm select($column, $label = '', $required = false) + * @method CatchForm textarea($column, $label = '', $required = false) + * @method CatchForm password($column, $label = '', $required = false) + * @method CatchForm hidden($column, $label = '', $required = false) + * @method CatchForm dom($column, $label = '', $required = false) * */ class CatchForm @@ -30,35 +32,65 @@ class CatchForm protected $btn; - public function action($acton) + /** + * + * @time 2019年12月10日 + * @param $acton + * @return CatchForm + */ + public function action($acton): CatchForm { $this->action = $acton; return $this; } - public function method($method) + /** + * + * @time 2019年12月10日 + * @param $method + * @return CatchForm + */ + public function method($method): CatchForm { $this->method = $method; return $this; } - public function formId($formId) + /** + * + * @time 2019年12月10日 + * @param $formId + * @return CatchForm + */ + public function formId($formId): CatchForm { $this->formId = $formId; return $this; } - public function enctype($enctype ="multipart/form-data") + /** + * + * @time 2019年12月10日 + * @param string $enctype + * @return CatchForm + */ + public function enctype($enctype ="multipart/form-data"): CatchForm { $this->enctype = $enctype; return $this; } - public function id($id) + /** + * + * @time 2019年12月10日 + * @param $id + * @return CatchForm + */ + public function id($id): CatchForm { $this->fields[$this->name] = array_merge($this->fields[$this->name], [ 'id' => sprintf('id="%s"', $id), @@ -66,8 +98,15 @@ class CatchForm return $this; } - - public function class($class='', $labelClass = '', $inlineClass = '') + /** + * + * @time 2019年12月10日 + * @param string $class + * @param string $labelClass + * @param string $inlineClass + * @return CatchForm + */ + public function class($class='', $labelClass = '', $inlineClass = ''): CatchForm { $this->fields[$this->name] = array_merge($this->fields[$this->name], [ 'class' => $class, @@ -78,7 +117,13 @@ class CatchForm return $this; } - public function options(array $options) + /** + * + * @time 2019年12月10日 + * @param array $options + * @return CatchForm + */ + public function options(array $options): CatchForm { $this->fields[$this->name] = array_merge($this->fields[$this->name], [ 'options' => $options, @@ -87,7 +132,13 @@ class CatchForm return $this; } - public function default($value) + /** + * + * @time 2019年12月10日 + * @param $value + * @return CatchForm + */ + public function default($value): CatchForm { $this->fields[$this->name] = array_merge($this->fields[$this->name], [ 'default' => $value, @@ -96,8 +147,12 @@ class CatchForm return $this; } - - public function disabled() + /** + * + * @time 2019年12月10日 + * @return CatchForm + */ + public function disabled(): CatchForm { $this->fields[$this->name] = array_merge($this->fields[$this->name], [ 'disabled' => '', @@ -106,7 +161,14 @@ class CatchForm return $this; } - public function placeholder($content) + + /** + * + * @time 2019年12月10日 + * @param $content + * @return CatchForm + */ + public function placeholder($content): CatchForm { $this->fields[$this->name] = array_merge($this->fields[$this->name], [ 'placeholder' => 'placeholder='.$content, @@ -115,7 +177,12 @@ class CatchForm return $this; } - public function readonly() + /** + * + * @time 2019年12月10日 + * @return CatchForm + */ + public function readonly(): CatchForm { $this->fields[$this->name] = array_merge($this->fields[$this->name], [ 'readonly' => 'readonly', @@ -124,24 +191,35 @@ class CatchForm return $this; } - - public function render() + /** + * + * @time 2019年12月10日 + * @return string + */ + public function render(): string { $form = sprintf('
', $this->formId, $this->formId); foreach ($this->fields as $field) { - $form .= sprintf($this->baseField(), + $form .= in_array($field['type'], ['hidden']) ? + $this->{$field['type'].'Field'}($field) + : sprintf($this->baseField(), $field['labelClass'] ?? '', $field['label'], $field['inlineClass'] ?? '', - $this->{$field['type'].'Field'}($field)) ; - + $this->{$field['type'].'Field'}($field)); } return $form . $this->btn. '
'; } - public function append($append) + /** + * + * @time 2019年12月10日 + * @param $append + * @return CatchForm + */ + public function append($append): CatchForm { $this->fields[$this->name] = array_merge($this->fields[$this->name], [ 'append' => $append, @@ -150,23 +228,36 @@ class CatchForm return $this; } + /** + * + * @time 2019年12月10日 + * @param $method + * @param $arguments + * @return $this + */ public function __call($method, $arguments) { // TODO: Implement __call() method. $this->name = $arguments[0] ?? ''; $label = $arguments[1] ?? ''; + $required = $arguments[2] ?? false; $this->fields[$this->name] = [ 'name' => $this->name, 'type' => $method, - 'label' => $label, + 'label' => $required ? '* '.$label : $label, 'inline' => false, ]; return $this; } - protected function inline() + /** + * + * @time 2019年12月10日 + * @return CatchForm + */ + protected function inline(): CatchForm { $this->fields[] = array_merge($this->fields, [ 'inline' => true, @@ -175,7 +266,12 @@ class CatchForm return $this; } - private function baseField() + /** + * + * @time 2019年12月10日 + * @return string + */ + private function baseField(): string { return '
@@ -192,9 +288,9 @@ class CatchForm * @time 2019年12月06日 * @param $filter * @param string $position - * @return string + * @return CatchForm */ - public function formBtn($filter, $position = 'text-right') + public function formBtn($filter, $position = 'text-right'): CatchForm { $this->btn = sprintf('
@@ -204,7 +300,14 @@ class CatchForm return $this; } - public function verify($rule, $equalTo = []) + /** + * + * @time 2019年12月10日 + * @param $rule + * @param array $equalTo + * @return CatchForm + */ + public function verify($rule, $equalTo = []): CatchForm { if (empty($equalTo)) { $this->fields[$this->name] = array_merge($this->fields[$this->name], [ @@ -222,6 +325,12 @@ class CatchForm return $this; } + /** + * + * @time 2019年12月10日 + * @param $field + * @return string + */ private function textField($field) { return @@ -238,6 +347,12 @@ class CatchForm } + /** + * + * @time 2019年12月10日 + * @param $field + * @return string + */ private function selectField($field) { $select = sprintf(''; } + /** + * + * @time 2019年12月10日 + * @param $field + * @return string + */ private function passwordField($field) { return sprintf('', @@ -261,11 +382,50 @@ class CatchForm ); } - private function radioField() - {} + private function radioField($field) + { + $radio = ''; + foreach ($field['options'] as $option) { + $radio .= sprintf('', + $field['name'], $option['value'], $option['title'], $option['value'] == $field['default'] ? 'checked' : '' + ); + } - private function textareaField() - {} + return $radio; + } + + /** + * + * @time 2019年12月09日 + * @param $field + * @return string + */ + private function textareaField($field): string + { + return sprintf('', + $field['name'], + $field['placeholder'] ?? '', + $field['default'] ?? '' + ); + } + + private function domField($field) + { + return $field['name']; + } + + /** + * + * @time 2019年12月10日 + * @param $field + * @return string + */ + private function hiddenField($field): string + { + return sprintf('', + $field['name'], $field['default'] + ); + } private function imageField() {} diff --git a/extend/catcher/Tree.php b/extend/catcher/Tree.php index b3d9bbc..d75936e 100644 --- a/extend/catcher/Tree.php +++ b/extend/catcher/Tree.php @@ -1 +1,22 @@ $item) { + if ($item[$pidField] == $pid) { + $child = self::done($items, $item['id'], $pidField); + $item[$children] = count($child) ? $child : []; + $tree[] = $item; + } + } + + return $tree; + } + + +} diff --git a/extend/catcher/base/CatchController.php b/extend/catcher/base/CatchController.php index 5b252f3..68bdf17 100644 --- a/extend/catcher/base/CatchController.php +++ b/extend/catcher/base/CatchController.php @@ -4,7 +4,7 @@ namespace catcher\base; use catcher\CatchAdmin; use think\facade\View; -abstract class BaseController +abstract class CatchController { /** * diff --git a/extend/catcher/base/CatchModel.php b/extend/catcher/base/CatchModel.php index 0098352..5b5485a 100644 --- a/extend/catcher/base/CatchModel.php +++ b/extend/catcher/base/CatchModel.php @@ -5,7 +5,7 @@ use catcher\traits\db\BaseOptionsTrait; use catcher\traits\db\TransTrait; use think\model\concern\SoftDelete; -abstract class BaseModel extends \think\Model +abstract class CatchModel extends \think\Model { use SoftDelete; use TransTrait; diff --git a/extend/catcher/base/CatchRequest.php b/extend/catcher/base/CatchRequest.php index 1dbab18..622fac1 100644 --- a/extend/catcher/base/CatchRequest.php +++ b/extend/catcher/base/CatchRequest.php @@ -5,7 +5,7 @@ use app\Request; use catcher\exceptions\ValidateFailedException; use think\Validate; -abstract class BaseRequest extends Request +abstract class CatchRequest extends Request { /** * Request constructor. diff --git a/extend/catcher/base/CatchValidate.php b/extend/catcher/base/CatchValidate.php index d4f3465..ede44a4 100644 --- a/extend/catcher/base/CatchValidate.php +++ b/extend/catcher/base/CatchValidate.php @@ -4,7 +4,7 @@ namespace catcher\base; use catcher\validates\Sometimes; use think\Validate; -abstract class BaseValidate extends Validate +abstract class CatchValidate extends Validate { public function __construct() { diff --git a/extend/catcher/exceptions/FailedException.php b/extend/catcher/exceptions/FailedException.php index b3d9bbc..6fed81b 100644 --- a/extend/catcher/exceptions/FailedException.php +++ b/extend/catcher/exceptions/FailedException.php @@ -1 +1,7 @@ $value) { - if (in_array($field, $this->field)) { - $this->{$field} = $value; - } - } - - if ($this->save()) { + if ($this->allowField($this->field)->save($data)) { return $this->{$this->getPk()}; } @@ -34,15 +28,9 @@ trait BaseOptionsTrait */ public function updateBy($id, $data) { - $model = $this->findBy($id); - foreach ($data as $field => $value) { - if (in_array($field, $this->field)) { - $model->{$field} = $value; - } - } - if ($model->save()) { - return $model->id; + if (static::update($data, [$this->getPk() => $id], $this->field)) { + return true; } return false;