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;