update cms
This commit is contained in:
parent
d97b5f62ee
commit
9252c3d537
@ -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';
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
@ -13,8 +13,12 @@
|
||||
|
||||
namespace catchAdmin\cms\model;
|
||||
|
||||
use catchAdmin\cms\model\search\UsersSearch;
|
||||
|
||||
class Users extends BaseModel
|
||||
{
|
||||
use UsersSearch;
|
||||
|
||||
// 表名
|
||||
public $name = 'cms_users';
|
||||
// 数据库字段映射
|
||||
|
15
catch/cms/model/search/ArticlesSearch.php
Normal file
15
catch/cms/model/search/ArticlesSearch.php
Normal file
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
namespace catchAdmin\cms\model\search;
|
||||
|
||||
trait ArticlesSearch
|
||||
{
|
||||
public function searchCategoryAttr($query, $value)
|
||||
{
|
||||
return $query->whereLike($this->aliasField('name', 'cms_category'), $value);
|
||||
}
|
||||
|
||||
public function searchTitleAttr($query, $value)
|
||||
{
|
||||
return $query->whereLike($this->aliasField('title'), $value);
|
||||
}
|
||||
}
|
44
catch/cms/model/search/CommentsSearch.php
Normal file
44
catch/cms/model/search/CommentsSearch.php
Normal file
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
namespace catchAdmin\cms\model\search;
|
||||
|
||||
trait CommentsSearch
|
||||
{
|
||||
/**
|
||||
* 文章 title 搜索
|
||||
*
|
||||
* @time 2021年05月26日
|
||||
* @param $query
|
||||
* @param $value
|
||||
* @return mixed
|
||||
*/
|
||||
public function searchTitleAttr($query, $value)
|
||||
{
|
||||
return $query->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);
|
||||
}
|
||||
}
|
25
catch/cms/model/search/UsersSearch.php
Normal file
25
catch/cms/model/search/UsersSearch.php
Normal file
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
namespace catchAdmin\cms\model\search;
|
||||
|
||||
trait UsersSearch
|
||||
{
|
||||
public function searchUsernameAttr($query, $value)
|
||||
{
|
||||
return $query->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);
|
||||
}
|
||||
}
|
@ -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([
|
||||
|
52
catch/cms/tables/Comments.php
Normal file
52
catch/cms/tables/Comments.php
Normal file
@ -0,0 +1,52 @@
|
||||
<?php
|
||||
namespace catchAdmin\cms\tables;
|
||||
|
||||
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 Comments extends CatchTable
|
||||
{
|
||||
public function table()
|
||||
{
|
||||
// TODO: Implement table() method.
|
||||
return $this->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');
|
||||
}
|
||||
}
|
59
catch/cms/tables/Users.php
Normal file
59
catch/cms/tables/Users.php
Normal file
@ -0,0 +1,59 @@
|
||||
<?php
|
||||
namespace catchAdmin\cms\tables;
|
||||
|
||||
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 Users extends CatchTable
|
||||
{
|
||||
public function table()
|
||||
{
|
||||
// TODO: Implement table() method.
|
||||
return $this->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');
|
||||
}
|
||||
|
||||
}
|
15
catch/cms/tables/forms/Comments.php
Normal file
15
catch/cms/tables/forms/Comments.php
Normal file
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
namespace catchAdmin\cms\tables\forms;
|
||||
|
||||
use catcher\library\form\Form;
|
||||
|
||||
class Comments extends Form
|
||||
{
|
||||
public function fields(): array
|
||||
{
|
||||
// TODO: Implement fields() method.
|
||||
return [
|
||||
|
||||
];
|
||||
}
|
||||
}
|
34
catch/cms/tables/forms/Users.php
Normal file
34
catch/cms/tables/forms/Users.php
Normal file
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
namespace catchAdmin\cms\tables\forms;
|
||||
|
||||
use catcher\library\form\Form;
|
||||
|
||||
class Users extends Form
|
||||
{
|
||||
public function fields(): array
|
||||
{
|
||||
// TODO: Implement fields() method.
|
||||
return [
|
||||
self::input('username', '用户名')->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()
|
||||
)
|
||||
];
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user