From 766a01e766a3e3f6fb37b6d1ed270dcb27f885da Mon Sep 17 00:00:00 2001 From: JaguarJack Date: Sat, 6 Mar 2021 20:05:20 +0800 Subject: [PATCH] =?UTF-8?q?update:=E6=9B=B4=E6=96=B0=E5=BF=AB=E6=8D=B7?= =?UTF-8?q?=E6=90=9C=E7=B4=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- catch/cms/controller/Form.php | 1 + catch/cms/form/Form.php | 161 +++++++++++++++++++++++++++++++++ catch/cms/form/FormFactory.php | 11 +++ extend/catcher/CatchQuery.php | 9 +- 4 files changed, 181 insertions(+), 1 deletion(-) create mode 100644 catch/cms/controller/Form.php create mode 100644 catch/cms/form/Form.php create mode 100644 catch/cms/form/FormFactory.php diff --git a/catch/cms/controller/Form.php b/catch/cms/controller/Form.php new file mode 100644 index 0000000..b3d9bbc --- /dev/null +++ b/catch/cms/controller/Form.php @@ -0,0 +1 @@ +rule($this->fields()); + } + + /** + * form rule + * + * @time 2021年03月06日 + * @param array $rules + * @return array + */ + public function rule(array $rules): array + { + try { + return Elm::createForm('', $rules)->formRule(); + } catch (FormBuilderException $e) { + throw new FailedException('Form Created Failed: ' .$e->getMessage()); + } + } + + + /** + * 上传图片地址 + * + * @time 2021年03月03日 + * @return string + */ + protected function uploadImageUrl(): string + { + return env('app.domain') . '/cms/upload/image'; + } + + + /** + * 上传图片地址 + * + * @time 2021年03月03日 + * @return string + */ + protected function uploadFileUrl(): string + { + return env('app.domain') . '/cms/upload/file'; + } + + + protected function authorization(): array + { + return [ + 'authorization' => 'Bearer ' . request()->user()->remember_token, + ]; + } + + /** + * 上传图片 + * + * @time 2021年03月03日 + * @param $title + * @param string $value + * @return \FormBuilder\UI\Elm\Components\Upload + */ + public function image(string $title, string $value = ''): Upload + { + return self::uploadImage('image', $title, $this->uploadImageUrl(), $value) + ->uploadName('image') + ->data(['none' => '']) + ->headers($this->authorization()); + } + + /** + * 多图 + * + * @time 2021年03月03日 + * @param $title + * @param array $value + * @return \FormBuilder\UI\Elm\Components\Upload + */ + public function images(string $title, array $value = []): Upload + { + return self::uploadImages('image', $title, $this->uploadImageUrl(), $value) + ->uploadName('image') + ->data(['none' => '']) + ->headers($this->authorization()); + } +} diff --git a/catch/cms/form/FormFactory.php b/catch/cms/form/FormFactory.php new file mode 100644 index 0000000..389940e --- /dev/null +++ b/catch/cms/form/FormFactory.php @@ -0,0 +1,11 @@ +whereRightLike($field, $value); } } + // = 值搜索 - $this->where($field, $value); + if ($value || is_numeric($value)) { + $this->where($field, $value); + } } } @@ -296,6 +299,10 @@ class CatchQuery extends Query $this->order($this->getTable() . '.sort', $order); } + if (in_array('weight', array_keys($this->getFields()))) { + $this->order($this->getTable() . '.weight', $order); + } + $this->order($this->getTable() . '.' . $this->getPk(), $order); return $this;