From 9252c3d537790facbc752a034186f6695416e62e Mon Sep 17 00:00:00 2001 From: JaguarJack Date: Wed, 26 May 2021 18:37:00 +0800 Subject: [PATCH] update cms --- catch/cms/model/Articles.php | 3 +- catch/cms/model/Comments.php | 13 +++++ catch/cms/model/Users.php | 4 ++ catch/cms/model/search/ArticlesSearch.php | 15 ++++++ catch/cms/model/search/CommentsSearch.php | 44 +++++++++++++++++ catch/cms/model/search/UsersSearch.php | 25 ++++++++++ catch/cms/tables/Articles.php | 5 ++ catch/cms/tables/Comments.php | 52 ++++++++++++++++++++ catch/cms/tables/Users.php | 59 +++++++++++++++++++++++ catch/cms/tables/forms/Comments.php | 15 ++++++ catch/cms/tables/forms/Users.php | 34 +++++++++++++ 11 files changed, 268 insertions(+), 1 deletion(-) create mode 100644 catch/cms/model/search/ArticlesSearch.php create mode 100644 catch/cms/model/search/CommentsSearch.php create mode 100644 catch/cms/model/search/UsersSearch.php create mode 100644 catch/cms/tables/Comments.php create mode 100644 catch/cms/tables/Users.php create mode 100644 catch/cms/tables/forms/Comments.php create mode 100644 catch/cms/tables/forms/Users.php diff --git a/catch/cms/model/Articles.php b/catch/cms/model/Articles.php index 5e0f63d..3196195 100644 --- a/catch/cms/model/Articles.php +++ b/catch/cms/model/Articles.php @@ -14,6 +14,7 @@ namespace catchAdmin\cms\model; use catchAdmin\cms\model\events\ArticlesEvent; +use catchAdmin\cms\model\search\ArticlesSearch; /** * Class Articles @@ -47,7 +48,7 @@ use catchAdmin\cms\model\events\ArticlesEvent; */ class Articles extends BaseModel { - use ArticlesEvent; + use ArticlesEvent, ArticlesSearch; // 表名 public $name = 'cms_articles'; diff --git a/catch/cms/model/Comments.php b/catch/cms/model/Comments.php index a4482a3..661e662 100644 --- a/catch/cms/model/Comments.php +++ b/catch/cms/model/Comments.php @@ -13,8 +13,11 @@ namespace catchAdmin\cms\model; +use catchAdmin\cms\model\search\CommentsSearch; + class Comments extends BaseModel { + use CommentsSearch; // 表名 public $name = 'cms_comments'; // 数据库字段映射 @@ -43,4 +46,14 @@ class Comments extends BaseModel // 软删除 'deleted_at', ); + + public function getList() + { + return $this->catchJoin(Articles::class, 'id', 'article_id', ['title']) + ->catchJoin(Users::class, 'id', 'user_id', ['username']) + ->field($this->aliasField('*')) + ->catchSearch() + ->catchOrder() + ->paginate(); + } } \ No newline at end of file diff --git a/catch/cms/model/Users.php b/catch/cms/model/Users.php index 6649245..ad03fc1 100644 --- a/catch/cms/model/Users.php +++ b/catch/cms/model/Users.php @@ -13,8 +13,12 @@ namespace catchAdmin\cms\model; +use catchAdmin\cms\model\search\UsersSearch; + class Users extends BaseModel { + use UsersSearch; + // 表名 public $name = 'cms_users'; // 数据库字段映射 diff --git a/catch/cms/model/search/ArticlesSearch.php b/catch/cms/model/search/ArticlesSearch.php new file mode 100644 index 0000000..fbdc2ef --- /dev/null +++ b/catch/cms/model/search/ArticlesSearch.php @@ -0,0 +1,15 @@ +whereLike($this->aliasField('name', 'cms_category'), $value); + } + + public function searchTitleAttr($query, $value) + { + return $query->whereLike($this->aliasField('title'), $value); + } +} \ No newline at end of file diff --git a/catch/cms/model/search/CommentsSearch.php b/catch/cms/model/search/CommentsSearch.php new file mode 100644 index 0000000..0ac14bc --- /dev/null +++ b/catch/cms/model/search/CommentsSearch.php @@ -0,0 +1,44 @@ +whereLike($this->aliasField('title', 'cms_articles'), $value); + } + + /** + * 评论人昵称 + * + * @time 2021年05月26日 + * @param $query + * @param $value + * @return mixed + */ + public function searchUsernameAttr($query, $value) + { + return $query->whereLike($this->aliasField('username', 'cms_users'), $value); + } + + /** + * 状态搜索 + * + * @time 2021年05月26日 + * @param $query + * @param $value + * @return mixed + */ + public function searchStatusAttr($query, $value) + { + return $query->where($this->aliasField('status'), $value); + } +} \ No newline at end of file diff --git a/catch/cms/model/search/UsersSearch.php b/catch/cms/model/search/UsersSearch.php new file mode 100644 index 0000000..f49db9f --- /dev/null +++ b/catch/cms/model/search/UsersSearch.php @@ -0,0 +1,25 @@ +whereLike($this->aliasField('name'), $value); + } + + public function searchEmailAttr($query, $value) + { + return $query->whereLike($this->aliasField('email'), $value); + } + + public function searchMobileAttr($query, $value) + { + return $query->whereLike($this->aliasField('mobile'), $value); + } + + public function searchStatusAttr($query, $value) + { + return $query->where($this->aliasField('status'), $value); + } +} \ No newline at end of file diff --git a/catch/cms/tables/Articles.php b/catch/cms/tables/Articles.php index 33e078a..7a06994 100644 --- a/catch/cms/tables/Articles.php +++ b/catch/cms/tables/Articles.php @@ -5,6 +5,7 @@ use catcher\CatchTable; use catchAdmin\cms\tables\forms\Factory; use catcher\library\table\Actions; use catcher\library\table\HeaderItem; +use catcher\library\table\Search; class Articles extends CatchTable { @@ -36,6 +37,10 @@ class Articles extends CatchTable Actions::delete() ]) ]) + ->withSearch([ + Search::input('category', '栏目名称')->clearable(true), + Search::input('title', '文章标题')->clearable(true), + ]) ->withBind() ->withApiRoute('cms/articles') ->withActions([ diff --git a/catch/cms/tables/Comments.php b/catch/cms/tables/Comments.php new file mode 100644 index 0000000..c4b371e --- /dev/null +++ b/catch/cms/tables/Comments.php @@ -0,0 +1,52 @@ +getTable('comments') + ->header([ + HeaderItem::label('编号')->prop('id')->width(50), + + HeaderItem::label('文章标题')->prop('title'), + + HeaderItem::label('评论')->prop('content'), + + HeaderItem::label('用户昵称')->prop('username'), + + HeaderItem::label('ip')->prop('ip'), + + HeaderItem::label('状态')->prop('status')->withSwitchComponent(), + + HeaderItem::label('创建时间')->prop('created_at'), + + HeaderItem::label('操作')->actions([ + Actions::delete(), + ]) + ]) + ->withSearch([ + Search::input('title', '文章标题')->clearable(true), + + Search::input('username', '用户名称')->clearable(true), + + Search::label('状态')->status('请选择状态')->clearable(true), + ]) + ->withBind() + ->withApiRoute('/cms/comments') + ->render(); + } + + protected function form() + { + // TODO: Implement form() method. + return Factory::create('comments'); + } +} \ No newline at end of file diff --git a/catch/cms/tables/Users.php b/catch/cms/tables/Users.php new file mode 100644 index 0000000..a4647eb --- /dev/null +++ b/catch/cms/tables/Users.php @@ -0,0 +1,59 @@ +getTable('users') + ->header([ + HeaderItem::label('编号')->prop('id')->width(50), + + HeaderItem::label('用户名')->prop('username'), + + HeaderItem::label('头像')->prop('avatar')->withPreviewComponent(), + + HeaderItem::label('邮箱')->prop('email'), + + HeaderItem::label('手机号')->prop('mobile'), + + HeaderItem::label('状态')->prop('status')->withSwitchComponent(), + + HeaderItem::label('创建时间')->prop('created_at'), + + HeaderItem::label('操作')->actions([ + Actions::update(), + Actions::delete() + ]) + ]) + ->withActions([ + Actions::create() + ]) + ->withSearch([ + Search::input('username', '用户名')->clearable(true), + + Search::input('email', '邮箱')->clearable(true), + + Search::input('mobile', '手机号')->clearable(true), + + Search::label('状态')->status()->clearable(true), + ]) + ->withBind() + ->withApiRoute('/cms/users') + ->render(); + } + + protected function form() + { + // TODO: Implement form() method. + return Factory::create('users'); + } + +} \ No newline at end of file diff --git a/catch/cms/tables/forms/Comments.php b/catch/cms/tables/forms/Comments.php new file mode 100644 index 0000000..1f1d9de --- /dev/null +++ b/catch/cms/tables/forms/Comments.php @@ -0,0 +1,15 @@ +required()->clearable(true), + + self::image('头像', 'avatar'), + + self::email('email', '邮箱')->required()->clearable(true), + + self::input('password', '密码')->required()->appendValidates([ + self::validatePassword() + ])->clearable(true), + + self::input('mobile', '手机号')->appendValidates([ + self::validateMobile() + ])->clearable(true), + + + self::radio('status', '状态', \catchAdmin\cms\model\Users::ENABLE) + ->options( + self::options()->add('启用', \catchAdmin\cms\model\Users::ENABLE) + ->add('禁用', \catchAdmin\cms\model\Users::DISABLE)->render() + ) + ]; + } +} \ No newline at end of file