diff --git a/cms/Addon.php b/cms/Addon.php new file mode 100644 index 00000000..4231bd0f --- /dev/null +++ b/cms/Addon.php @@ -0,0 +1,37 @@ +) { + return request.get(`cms/article`, {params}) +} + +/** + * 获取文章表详情 + * @param id 文章表id + * @returns + */ +export function getArticleInfo(id: number) { + return request.get(`cms/article/${id}`); +} + +/** + * 添加文章表 + * @param params + * @returns + */ +export function addArticle(params: Record) { + return request.post('cms/article', params, {showSuccessMessage: true}) +} + +/** + * 编辑文章表 + * @param params + */ +export function editArticle(params: Record) { + return request.put(`cms/article/${params.id}`, params, {showSuccessMessage: true}) +} + +/** + * 删除文章表 + * @param id + * @returns + */ +export function deleteArticle(id: number) { + return request.delete(`cms/article/${id}`, {showSuccessMessage: true}) +} + +/***************************************************** 文章分类管理 ****************************************************/ + +/** + * 获取文章分类列表 + * @param params + * @returns + */ +export function getArticleCategoryList(params: Record) { + return request.get(`cms/category`, {params}) +} + + +/** + * 获取文章全部分类 + * @param params + * @returns + */ +export function getArticleCategoryAll(params: Record) { + return request.get(`cms/category/all`, params) +} + +/** + * 获取文章分类详情 + * @param category_id + */ +export function getArticleCategoryInfo(category_id: number) { + return request.get(`cms/category/${category_id}`); +} + +/** + * 添加文章分类 + * @param params + * @returns + */ +export function addArticleCategory(params: Record) { + return request.post('cms/category', params, {showSuccessMessage: true}) +} + +/** + * 编辑文章分类 + * @param params + * @returns + */ +export function editArticleCategory(params: Record) { + return request.put(`cms/category/${params.category_id}`, params, {showSuccessMessage: true}) +} + +/** + * 文章分类删除 + * @param category_id + */ +export function deleteArticleCategory(category_id: number) { + return request.delete(`cms/category/${category_id}`, {showSuccessMessage: true}); +} \ No newline at end of file diff --git a/cms/admin/lang/zh-cn/article.category.json b/cms/admin/lang/zh-cn/article.category.json new file mode 100644 index 00000000..886b34a5 --- /dev/null +++ b/cms/admin/lang/zh-cn/article.category.json @@ -0,0 +1,17 @@ +{ + "name": "栏目名称", + "sort": "排序", + "isShow": "是否显示", + "namePlaceholder": "请输入栏目名称", + "sortPlaceholder": "请输入排序", + "isShowPlaceholder": "是否显示", + "addArticleCategory": "添加栏目", + "updateArticleCategory": "编辑栏目", + "articleCategoryDeleteTips": "确定要删除该栏目吗?", + "nameMax": "名称不能超过20个字符", + "sortNumber": "排序号必须是数字", + "sortBetween": "排序号不能超过10000", + "show": "显示", + "hide": "不显示", + "articleNumber": "文章数量" +} \ No newline at end of file diff --git a/cms/admin/lang/zh-cn/article.edit.json b/cms/admin/lang/zh-cn/article.edit.json new file mode 100644 index 00000000..437e8c03 --- /dev/null +++ b/cms/admin/lang/zh-cn/article.edit.json @@ -0,0 +1,36 @@ +{ + "categoryName": "文章栏目", + "title": "文章标题", + "intro": "简介", + "summary": "文章摘要", + "image": "文章图片", + "author": "作者", + "content": "文章内容", + "visit": "实际浏览量", + "visitVirtual": "初始浏览量", + "isShow": "是否显示", + "sort": "排序", + "categoryIdPlaceholder": "请选择文章栏目", + "titlePlaceholder": "请输入文章标题", + "introPlaceholder": "请输入简介", + "summaryPlaceholder": "请输入文章摘要", + "imagePlaceholder": "请上传文章图片", + "authorPlaceholder": "请输入作者", + "contentPlaceholder": "请输入文章内容", + "visitPlaceholder": "请输入实际浏览量", + "visitVirtualPlaceholder": "请输入初始浏览量", + "isShowPlaceholder": "是否显示", + "sortPlaceholder": "请输入排序", + "addArticle": "添加文章", + "updateArticle": "编辑文章", + "titleMax": "文章标题不能超过20个字符", + "introMax": "文章简介不能超过50个字符", + "summaryMax": "文章摘要不能超过50个字符", + "imageMax": "图片路径太长", + "authorMax": "文章作者不能超过20个字符", + "isShowNumber": "是否显示必须是数字", + "isShowBetween": "是否显示只能是0或者1", + "sortNumber": "排序号必须是数字", + "sortBetween": "排序号需要在0-10000之间", + "articleNull": "未读取到文章信息!" +} \ No newline at end of file diff --git a/cms/admin/lang/zh-cn/article.list.json b/cms/admin/lang/zh-cn/article.list.json new file mode 100644 index 00000000..2f4b0761 --- /dev/null +++ b/cms/admin/lang/zh-cn/article.list.json @@ -0,0 +1,21 @@ +{ + "categoryName": "栏目", + "ID": "ID", + "title": "标题", + "intro": "简介", + "summary": "摘要", + "image": "封面", + "author": "作者", + "content": "文章内容", + "visit": "浏览量", + "visitVirtual": "初始浏览量", + "isShow": "是否显示", + "sort": "排序", + "createTime": "创建时间", + "updateTime": "更新时间", + "addArticle": "添加文章", + "updateArticle": "编辑文章", + "titlePlaceholder": "请输入文章标题", + "categoryIdPlaceholder": "请选择文章栏目", + "articleDeleteTips": "确定要删除该文章吗?" +} \ No newline at end of file diff --git a/cms/admin/views/article/category.vue b/cms/admin/views/article/category.vue new file mode 100644 index 00000000..b0561501 --- /dev/null +++ b/cms/admin/views/article/category.vue @@ -0,0 +1,144 @@ + + + + + diff --git a/cms/admin/views/article/components/edit-category.vue b/cms/admin/views/article/components/edit-category.vue new file mode 100644 index 00000000..1545a110 --- /dev/null +++ b/cms/admin/views/article/components/edit-category.vue @@ -0,0 +1,135 @@ + + + + + \ No newline at end of file diff --git a/cms/admin/views/article/edit.vue b/cms/admin/views/article/edit.vue new file mode 100644 index 00000000..826261dd --- /dev/null +++ b/cms/admin/views/article/edit.vue @@ -0,0 +1,176 @@ + + + + + diff --git a/cms/admin/views/article/list.vue b/cms/admin/views/article/list.vue new file mode 100644 index 00000000..ab238cf4 --- /dev/null +++ b/cms/admin/views/article/list.vue @@ -0,0 +1,181 @@ + + + + + diff --git a/cms/admin/views/diy/components/edit-article.vue b/cms/admin/views/diy/components/edit-article.vue new file mode 100644 index 00000000..6d835654 --- /dev/null +++ b/cms/admin/views/diy/components/edit-article.vue @@ -0,0 +1,177 @@ + + + + + + \ No newline at end of file diff --git a/cms/app/adminapi/controller/article/Article.php b/cms/app/adminapi/controller/article/Article.php new file mode 100644 index 00000000..f4669625 --- /dev/null +++ b/cms/app/adminapi/controller/article/Article.php @@ -0,0 +1,108 @@ +request->params([ + [ 'title', '' ], + [ 'category_id', '' ], + [ 'sort', '' ], + [ 'is_show', '' ], + ]); + return success(( new ArticleService() )->getPage($data)); + } + + /** + * 文章详情 + * @param int $id + * @return Response + */ + public function info(int $id) + { + return success(( new ArticleService() )->getInfo($id)); + } + + /** + * 添加文章 + * @return Response + */ + public function add() + { + $data = $this->request->params([ + [ 'title', '' ], + [ 'category_id', '' ], + [ 'intro', '' ], + [ 'summary', '' ], + [ 'image', '' ], + [ 'author', '' ], + [ 'content', '', false ], + [ 'visit_virtual', 0 ], + [ 'is_show', 1 ], + [ 'sort', 0 ], + ]); + $this->validate($data, 'addon\cms\app\validate\article\Article.add'); + $id = ( new ArticleService() )->add($data); + return success('ADD_SUCCESS', [ 'id' => $id ]); + } + + /** + * 文章编辑 + * @param int $id + * @return Response + */ + public function edit(int $id) + { + $data = $this->request->params([ + [ 'title', '' ], + [ 'category_id', '' ], + [ 'intro', '' ], + [ 'summary', '' ], + [ 'image', '' ], + [ 'author', '' ], + [ 'content', '', false ], + [ 'visit_virtual', 0 ], + [ 'is_show', 1 ], + [ 'sort', 0 ], + ]); + $this->validate($data, 'addon\cms\app\validate\article\Article.edit'); + ( new ArticleService() )->edit($id, $data); + return success('EDIT_SUCCESS'); + } + + /** + * 文章删除 + * @param int $id + * @return Response + */ + public function del(int $id) + { + ( new ArticleService() )->del($id); + return success('DELETE_SUCCESS'); + } + +} diff --git a/cms/app/adminapi/controller/article/ArticleCategory.php b/cms/app/adminapi/controller/article/ArticleCategory.php new file mode 100644 index 00000000..00d148f0 --- /dev/null +++ b/cms/app/adminapi/controller/article/ArticleCategory.php @@ -0,0 +1,95 @@ +request->params([ + [ 'name', '' ], + ]); + return success(( new ArticleCategoryService() )->getPage($data)); + } + + /** + * 查询所有分类(文章添加,编辑,索引) + * @return Response + */ + public function all() + { + return success(( new ArticleCategoryService() )->getAll()); + } + + /** + * 文章分类详情 + * @param int $id + * @return Response + */ + public function info(int $id) + { + return success(( new ArticleCategoryService() )->getInfo($id)); + } + + /** + * 添加文章分类 + * @return Response + */ + public function add() + { + $data = $this->request->params([ + [ 'name', '' ], + [ 'is_show', 1 ], + [ 'sort', 0 ], + ]); + $this->validate($data, 'addon\cms\app\validate\article\ArticleCategory.add'); + $id = ( new ArticleCategoryService() )->add($data); + return success('ADD_SUCCESS', [ 'id' => $id ]); + } + + /** + * 文章分类编辑 + * @param int $category_id //分类id + * @return Response + */ + public function edit(int $category_id) + { + $data = $this->request->params([ + [ 'name', '' ], + [ 'is_show', 1 ], + [ 'sort', 0 ], + ]); + $this->validate($data, 'addon\cms\app\validate\article\ArticleCategory.edit'); + ( new ArticleCategoryService() )->edit($category_id, $data); + return success('EDIT_SUCCESS'); + } + + /** + * 文章分类删除 + * @param int $category_id + * @return Response + */ + public function del(int $category_id) + { + ( new ArticleCategoryService() )->del($category_id); + return success('DELETE_SUCCESS'); + } + +} diff --git a/cms/app/adminapi/route/route.php b/cms/app/adminapi/route/route.php new file mode 100644 index 00000000..3cfad854 --- /dev/null +++ b/cms/app/adminapi/route/route.php @@ -0,0 +1,64 @@ +middleware([ + AdminCheckToken::class, + AdminCheckRole::class, + AdminLog::class +]); diff --git a/cms/app/api/controller/article/Article.php b/cms/app/api/controller/article/Article.php new file mode 100644 index 00000000..7b365029 --- /dev/null +++ b/cms/app/api/controller/article/Article.php @@ -0,0 +1,59 @@ +request->params([ + [ 'title', '' ], + [ 'category_id', '' ], + ]); + return success(( new ArticleService() )->getPage($data)); + } + + public function all() + { + $data = $this->request->params([ + [ 'title', '' ], + [ 'category_id', '' ], + [ 'ids', [] ], + [ 'limit', 0 ] + ]); + return success(( new ArticleService() )->getAll($data, $data[ 'limit' ])); + } + + /** + * 文章详情 + * @param int $id + * @return Response + */ + public function info(int $id) + { + return success(( new ArticleService() )->getInfo($id)); + } + +} diff --git a/cms/app/api/controller/article/ArticleCategory.php b/cms/app/api/controller/article/ArticleCategory.php new file mode 100644 index 00000000..a8925795 --- /dev/null +++ b/cms/app/api/controller/article/ArticleCategory.php @@ -0,0 +1,48 @@ +request->params([ + [ 'name', '' ], + ]); + return success(( new ArticleCategoryService() )->getPage($data)); + } + + /** + * 文章分类详情 + * @param int $id + * @return Response + */ + public function info(int $id) + { + return success(( new ArticleCategoryService() )->getInfo($id)); + } + + +} diff --git a/cms/app/api/route/route.php b/cms/app/api/route/route.php new file mode 100644 index 00000000..3c214942 --- /dev/null +++ b/cms/app/api/route/route.php @@ -0,0 +1,44 @@ +middleware(ApiChannel::class) + ->middleware(ApiCheckToken::class, false) //false表示不验证登录 + ->middleware(ApiLog::class); diff --git a/cms/app/dict/diy/components.php b/cms/app/dict/diy/components.php new file mode 100644 index 00000000..450ddb9b --- /dev/null +++ b/cms/app/dict/diy/components.php @@ -0,0 +1,23 @@ + [ + 'title' => get_lang('dict_diy.component_type_basic'), + 'list' => [ + 'Article' => [ + 'title' => '文章', + 'icon' => 'iconfont-iconwenzhang', + 'path' => 'edit-article', + 'support_page' => [], + 'uses' => 0, + 'sort' => 10007, + 'value' => [ + 'sources' => 'initial', + 'count' => 8, + 'articleIds' => [] + ], + ], + ], + ], + +]; \ No newline at end of file diff --git a/cms/app/dict/diy/links.php b/cms/app/dict/diy/links.php new file mode 100644 index 00000000..67e80083 --- /dev/null +++ b/cms/app/dict/diy/links.php @@ -0,0 +1,18 @@ + [ + 'key' => 'cms', + 'addon_title' => get_lang('dict_diy.cms_title'), + 'title' => get_lang('dict_diy.cms_link'), + 'child_list' => [ + [ + 'name' => 'ARTICLE_LIST', + 'title' => get_lang('dict_diy.cms_link_article_list'), + 'url' => '/cms/pages/list', + 'is_share' => 1, + 'action' => '' + ], + ] + ], +]; \ No newline at end of file diff --git a/cms/app/dict/menu/admin.php b/cms/app/dict/menu/admin.php new file mode 100644 index 00000000..bee73cf4 --- /dev/null +++ b/cms/app/dict/menu/admin.php @@ -0,0 +1,4 @@ + '微官网', + 'menu_key' => 'cms', + 'menu_type' => 0, + 'icon' => 'element-Tickets', + 'api_url' => '', + 'router_path' => 'cms', + 'view_path' => '', + 'methods' => '', + 'sort' => 100, + 'status' => 1, + 'is_show' => 1, + 'children' => [ + [ + 'menu_name' => '文章管理', + 'menu_short_name' => '文章', + 'menu_key' => 'cms_article', + 'menu_type' => 0, + 'icon' => 'iconfont-iconwenzhangguanli1', + 'api_url' => '', + 'router_path' => 'article', + 'view_path' => '', + 'methods' => '', + 'sort' => 98, + 'status' => 1, + 'is_show' => 1, + 'children' => [ + [ + 'menu_name' => '文章列表', + 'menu_key' => 'cms_article_list', + 'menu_type' => 1, + 'icon' => 'element-ChatDotSquare', + 'api_url' => 'cms/article', + 'router_path' => 'list', + 'view_path' => 'article/list', + 'methods' => 'get', + 'sort' => 100, + 'status' => 1, + 'is_show' => 1, + ], + [ + 'menu_name' => '文章添加/编辑', + 'menu_key' => 'cms_article_edit', + 'menu_type' => 1, + 'icon' => '', + 'api_url' => 'cms/article', + 'router_path' => 'edit', + 'view_path' => 'article/edit', + 'methods' => 'post', + 'sort' => 90, + 'status' => 1, + 'is_show' => 0, + ], + [ + 'menu_name' => '文章栏目', + 'menu_key' => 'cms_article_category', + 'menu_type' => 1, + 'icon' => 'element-CollectionTag', + 'api_url' => 'article/category', + 'router_path' => 'category', + 'view_path' => 'article/category', + 'methods' => 'get', + 'sort' => 80, + 'status' => 1, + 'is_show' => 1, + ], + ] + ] + ] + ] +]; diff --git a/cms/app/event.php b/cms/app/event.php new file mode 100644 index 00000000..e97c7685 --- /dev/null +++ b/cms/app/event.php @@ -0,0 +1,7 @@ + [ + 'WapIndex' => [ 'addon\cms\app\listener\WapIndexListener' ], + ] +]; \ No newline at end of file diff --git a/cms/app/lang/en/api.php b/cms/app/lang/en/api.php new file mode 100644 index 00000000..92293fcd --- /dev/null +++ b/cms/app/lang/en/api.php @@ -0,0 +1,14 @@ + [ + 'article' => 'article', + 'article_list' => 'article list', + 'article_edit' => 'article edit', + 'article_category' => 'article category', + ], + +]; diff --git a/cms/app/lang/en/validate.php b/cms/app/lang/en/validate.php new file mode 100644 index 00000000..8a318b17 --- /dev/null +++ b/cms/app/lang/en/validate.php @@ -0,0 +1,27 @@ + [ + 'title_require' => 'title is require', + 'title_max' => 'title must not be exceed 20 points', + 'intro_max' => 'intro must not be exceed 50 points', + 'summary_max' => 'summary must not be exceed 50 points', + 'image_max' => 'image is exceed max', + 'author_max' => 'author must not be exceed 20 points', + 'is_show_number' => 'is_show must be a number', + 'is_show_between' => 'is_show must be 0 or 1', + 'sort_number' => 'sort must be a number', + 'sort_between' => 'sort must not be exceed 10000', + 'cate_name_require' => 'cate_name is require', + 'cate_name_max' => 'cate_name must not be exceed 120 points', + ] +]; diff --git a/cms/app/lang/zh-cn/api.php b/cms/app/lang/zh-cn/api.php new file mode 100644 index 00000000..92293fcd --- /dev/null +++ b/cms/app/lang/zh-cn/api.php @@ -0,0 +1,14 @@ + [ + 'cms_title' => '微官网', + 'cms_link' => '微官网链接', + 'cms_link_article_list' => '文章资讯', + ], + 'dict_wap_index' => [ + 'cms' => '微官网', + 'cms_desc' => '文章栏目管理', + ], +]; diff --git a/cms/app/lang/zh-cn/validate.php b/cms/app/lang/zh-cn/validate.php new file mode 100644 index 00000000..1a56efc1 --- /dev/null +++ b/cms/app/lang/zh-cn/validate.php @@ -0,0 +1,30 @@ + [ + 'title_require' => '文章标题必须填写', + 'title_max' => '文章标题不能超过20个字符', + 'intro_max' => '文章简介不能超过50个字符', + 'summary_max' => '文章摘要不能超过50个字符', + 'image_max' => '图片路径太长', + 'author_max' => '文章作者不能超过20个字符', + 'is_show_number' => '是否显示必须是数字', + 'is_show_between' => '是否显示只能是0或者1', + 'sort_number' => '排序号必须是数字', + 'sort_between' => '排序号不能超过10000', + 'cate_name_require' => '栏目名称必须填写', + 'cate_name_max' => '栏目不能超过20个字符', + 'category_id_require' => '文章栏目必须填写', + 'category_id_num' => '文章栏目必须是整数', + 'content_require' => '文章内容必须填写', + ], +]; diff --git a/cms/app/listener/WapIndexListener.php b/cms/app/listener/WapIndexListener.php new file mode 100644 index 00000000..5d84d432 --- /dev/null +++ b/cms/app/listener/WapIndexListener.php @@ -0,0 +1,31 @@ + 'cms', + "title" => get_lang("dict_wap_index.cms"), + 'desc' => get_lang("dict_wap_index.cms_desc"), + "url" => "/cms/pages/list", + 'icon'=>'addon/cms/icon.png' + ], + ]; + } +} \ No newline at end of file diff --git a/cms/app/model/article/CmsArticle.php b/cms/app/model/article/CmsArticle.php new file mode 100644 index 00000000..d825e2fc --- /dev/null +++ b/cms/app/model/article/CmsArticle.php @@ -0,0 +1,139 @@ +hasOne(CmsArticleCategory::class, 'category_id', 'category_id')->joinType('left')->withField('category_id, name')->bind([ 'category_name' => 'name' ]); + } + + /** + * 文章分类搜索器 + * @param $query + * @param $value + * @param $data + */ + public function searchCategoryIdAttr($query, $value, $data) + { + if ($value) { + $query->where('category_id', $value); + } + } + + /** + * 文章标题搜索器 + * @param $query + * @param $value + * @param $data + */ + public function searchTitleAttr($query, $value, $data) + { + if ($value) { + $query->where('title', 'like', '%' . $value . '%'); + } + } + + /** + * 文章标题搜索器 + * @param $query + * @param $value + * @param $data + */ + public function searchIsShowAttr($query, $value, $data) + { + if ($value != '') { + $query->where('is_show', $value); + } + } + + public function searchIdsAttr(Query $query, $value, $data) + { + if (!empty($value)) { + $query->whereIn('id', $data[ 'ids' ]); + } + } + + + /** + * 文章标题搜索器 + * @param $query + * @param $value + * @param $data + */ + public function searchSortAttr($query, $value, $data) + { + if ($value) { + $query->where('sort', $value); + } + } + + public function getArticleUrlAttr($value, $data) + { + + $wap_domain = !empty(env("system.wap_domain")) ? preg_replace('#/$#', '', env("system.wap_domain")) : request()->domain(); + $web_domain = !empty(env("system.web_domain")) ? preg_replace('#/$#', '', env("system.web_domain")) : request()->domain(); + + return [ + 'wap_url' => $wap_domain . "/wap/cms/pages/detail?id={$data['id']}", + 'web_url' => $web_domain . "/web/article/detail?id={$data['id']}" + ]; + } + + public function getImageThumbBigAttr($value, $data) + { + if ($data[ 'image' ] != '') { + return get_thumb_images($data[ 'image' ], FileDict::BIG); + } + } + + public function getImageThumbMidAttr($value, $data) + { + if ($data[ 'image' ] != '') { + return get_thumb_images($data[ 'image' ], FileDict::MID); + } + } + + public function getImageThumbSmallAttr($value, $data) + { + if ($data[ 'image' ] != '') { + return get_thumb_images($data[ 'image' ], FileDict::SMALL); + } + } +} diff --git a/cms/app/model/article/CmsArticleCategory.php b/cms/app/model/article/CmsArticleCategory.php new file mode 100644 index 00000000..07ca27ef --- /dev/null +++ b/cms/app/model/article/CmsArticleCategory.php @@ -0,0 +1,54 @@ +where([ [ 'name', 'like', "%$value%" ] ]); + } + } + + public function getArticleNumAttr($value, $data) + { + return ( new CmsArticle() )->where([ [ 'category_id', '=', $data[ 'category_id' ] ] ])->count(); + } + +} diff --git a/cms/app/service/admin/article/ArticleCategoryService.php b/cms/app/service/admin/article/ArticleCategoryService.php new file mode 100644 index 00000000..904ddb03 --- /dev/null +++ b/cms/app/service/admin/article/ArticleCategoryService.php @@ -0,0 +1,104 @@ +model = new CmsArticleCategory(); + } + + /** + * 获取文章分类列表 + * @param array $where + * @return array + */ + public function getPage(array $where = []) + { + + $field = 'category_id, site_id, name, sort, is_show, create_time, update_time'; + $order = 'create_time desc'; + $search_model = $this->model->where([['site_id', '=', $this->site_id]])->withSearch(['name'], $where)->field($field)->order($order)->append(["article_num"]); + return $this->pageQuery($search_model); + } + + /** + * 查询所有分类(文章添加) + */ + public function getAll() + { + + $field = 'category_id, site_id, name, sort'; + $order = 'sort desc'; + return $this->model->where([['site_id', '=', $this->site_id], ['is_show', '=', 1]])->field($field)->order($order)->select()->toArray(); + } + + /** + * 获取文章分类信息 + * @param int $id + * @return array + */ + public function getInfo(int $id) + { + $field = 'category_id, site_id, name, sort, is_show, create_time, update_time'; + + return $this->model->field($field)->where([['category_id', '=', $id], ['site_id', '=', $this->site_id]])->append(["article_num"])->findOrEmpty()->toArray(); + } + + /** + * 添加文章分类 + * @param array $data + * @return mixed + */ + public function add(array $data) + { + $data['site_id'] = $this->site_id; + $res = $this->model->create($data); + return $res->category_id; + + } + + /** + * 文章分类编辑 + * @param int $id + * @param array $data + * @return true + */ + public function edit(int $id, array $data) + { + $data['update_time'] = time(); + $this->model->where([['category_id', '=', $id], ['site_id', '=', $this->site_id]])->update($data); + return true; + } + + /** + * 删除文章分类 + * @param int $id + * @return bool + */ + public function del(int $id) + { + return $this->model->where([['category_id', '=', $id], ['site_id', '=', $this->site_id]])->delete(); + } + +} diff --git a/cms/app/service/admin/article/ArticleService.php b/cms/app/service/admin/article/ArticleService.php new file mode 100644 index 00000000..5ed65fd1 --- /dev/null +++ b/cms/app/service/admin/article/ArticleService.php @@ -0,0 +1,94 @@ +model = new CmsArticle(); + } + + /** + * 获取文章列表 + * @param array $where + * @return array + */ + public function getPage(array $where = []) + { + $where[] = [ 'site_id', '=', $this->site_id ]; + $field = 'id, category_id, site_id, title, intro, summary, image, author, content, visit, visit_virtual, is_show, sort, create_time, update_time'; + $order = 'create_time desc'; + $search_model = $this->model->where([ [ 'site_id', '=', $this->site_id ] ])->withSearch([ 'title', 'category_id', 'is_show'], $where)->with('articleCategory')->field($field)->order($order)->append(['article_url','image_thumb_small']); + return $this->pageQuery($search_model); + } + + /** + * 获取文章信息 + * @param int $id + * @return array + */ + public function getInfo(int $id) + { + $field = 'id, category_id, site_id, title, intro, summary, image, author, content, visit, visit_virtual, is_show, sort, create_time, update_time'; + + return $this->model->where([ [ 'id', '=', $id ], [ 'site_id', '=', $this->site_id ] ])->with('articleCategory')->field($field)->append(['image_thumb_small'])->findOrEmpty()->toArray(); + } + + /** + * 添加文章 + * @param array $data + * @return mixed + */ + public function add(array $data) + { + $data[ 'site_id' ] = $this->site_id; + $data[ 'create_time' ] = time(); + $res = $this->model->create($data); + return $res->id; + + } + + /** + * 文章编辑 + * @param int $id + * @param array $data + * @return true + */ + public function edit(int $id, array $data) + { + $data[ 'update_time' ] = time(); + $this->model->where([ [ 'id', '=', $id ], [ 'site_id', '=', $this->site_id ] ])->update($data); + return true; + } + + /** + * 删除文章 + * @param int $id + * @return bool + */ + public function del(int $id) + { + return $this->model->where([ [ 'id', '=', $id ], [ 'site_id', '=', $this->site_id ] ])->delete(); + } + +} diff --git a/cms/app/service/api/article/ArticleCategoryService.php b/cms/app/service/api/article/ArticleCategoryService.php new file mode 100644 index 00000000..caa58c48 --- /dev/null +++ b/cms/app/service/api/article/ArticleCategoryService.php @@ -0,0 +1,53 @@ +model = new CmsArticleCategory(); + } + + /** + * 获取文章分类列表 + * @param array $where + * @return array + */ + public function getPage(array $where = []) + { + $field = 'category_id, site_id, name, sort, is_show, create_time, update_time'; + $order = 'create_time desc'; + $search_model = $this->model->where([['site_id', '=', $this->site_id]])->withSearch(['name'], $where)->field($field)->order($order); + return $this->pageQuery($search_model); + } + + /** + * 获取文章分类信息 + * @param int $id + * @return array + */ + public function getInfo(int $id) + { + $field = 'category_id, site_id, name, sort, is_show, create_time, update_time'; + return $this->model->field($field)->where([['category_id', '=', $id], ['site_id', '=', $this->site_id]])->findOrEmpty()->toArray(); + } +} diff --git a/cms/app/service/api/article/ArticleService.php b/cms/app/service/api/article/ArticleService.php new file mode 100644 index 00000000..cef1edab --- /dev/null +++ b/cms/app/service/api/article/ArticleService.php @@ -0,0 +1,76 @@ +model = new CmsArticle(); + } + + /** + * 获取文章列表 + * @param array $where + * @return array + */ + public function getPage(array $where = []) + { + $where[] = [ 'site_id', '=', $this->site_id ]; + $field = 'id, category_id, site_id, title, intro, summary, image, author, content, visit, visit_virtual, is_show, sort, create_time, update_time'; + $order = 'create_time desc'; + $search_model = $this->model->where([ [ 'site_id', '=', $this->site_id ] ])->withSearch([ 'title', 'category_id'], $where)->with('articleCategory')->field($field)->order($order)->append(['image_thumb_mid']); + return $this->pageQuery($search_model); + } + + /** + * 文章列表 + * @param array $where + * @param int $limit + * @return array + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException + */ + public function getAll(array $where = [], int $limit = 0){ + $where[] = [ 'site_id', '=', $this->site_id ]; + $field = 'id, category_id, site_id, title, intro, summary, image, author, content, visit, visit_virtual, is_show, sort, create_time, update_time'; + $order = 'create_time desc'; + return $this->model->where([ [ 'site_id', '=', $this->site_id ] , ['is_show', '=', 1]])->withSearch([ 'title', 'category_id', 'ids' ], $where)->limit($limit)->with('articleCategory')->field($field)->append(['image_thumb_mid'])->order($order)->select()->toArray(); + } + + /** + * 获取文章信息 + * @param int $id + * @return array + */ + public function getInfo(int $id) + { + $field = 'id, category_id, site_id, title, intro, summary, image, author, content, visit, visit_virtual, is_show, sort, create_time, update_time'; + + return $this->model->with('articleCategory')->field($field)->where([ [ 'id', '=', $id ], [ 'site_id', '=', $this->site_id ] ])->append(['image_thumb_big'])->findOrEmpty()->toArray(); + } + +} diff --git a/cms/app/validate/article/Article.php b/cms/app/validate/article/Article.php new file mode 100644 index 00000000..1ebfcfaa --- /dev/null +++ b/cms/app/validate/article/Article.php @@ -0,0 +1,57 @@ + 'require|max:20', + 'intro' => 'max:50', + 'summary' => 'max:50', + 'image' => 'max:100', + 'author' => 'max:20', + 'is_show' => 'number|between:0,1', + 'sort' => 'number|between:0,10000', + 'category_id' => 'number|require', + 'content' => 'require', + ]; + + protected $message = [ + 'title.require' => 'validate_article.title_require', + 'title.max' => 'validate_article.title_max', + 'intro.max' => 'validate_article.intro_max', + 'summary.max' => 'validate_article.summary_max', + 'image.max' => 'validate_article.image_max', + 'author.max' => 'validate_article.author_max', + 'is_show.number' => 'validate_article.is_show_number', + 'is_show.between' => 'validate_article.is_show_between', + 'sort.number' => 'validate_article.sort_number', + 'sort.between' => 'validate_article.sort_between', + 'category_id.require' => 'validate_article.category_id_require', + 'category_id.number' => 'validate_article.category_id_number', + 'content.require' => 'validate_article.content_require', + ]; + + protected $scene = [ + 'add' => ['title', 'intro', 'summary', 'image', 'author', 'is_show', 'sort', 'content', 'category_id'], + 'edit' => ['title', 'intro', 'summary', 'image', 'author', 'is_show', 'sort', 'content', 'category_id'], + ]; +} diff --git a/cms/app/validate/article/ArticleCategory.php b/cms/app/validate/article/ArticleCategory.php new file mode 100644 index 00000000..a0264410 --- /dev/null +++ b/cms/app/validate/article/ArticleCategory.php @@ -0,0 +1,45 @@ + 'require|max:20', + 'is_show' => 'number|between:0,1', + 'sort' => 'number|between:0,10000' + ]; + + protected $message = [ + 'name.require' => 'validate_article.cate_name_require', + 'name.max' => 'validate_article.cate_name_max', + 'is_show.number' => 'validate_article.is_show_number', + 'is_show.between' => 'validate_article.is_show_between', + 'sort.number' => 'validate_article.sort_number', + 'sort.between' => 'validate_article.sort_between', + ]; + + protected $scene = [ + 'add' => ['name', 'is_show', 'sort'], + 'edit' => ['name', 'is_show', 'sort'], + ]; +} diff --git a/cms/info.json b/cms/info.json new file mode 100644 index 00000000..c1ec7974 --- /dev/null +++ b/cms/info.json @@ -0,0 +1,9 @@ +{ + "title": "微官网", + "desc": "文章栏目管理", + "key": "cms", + "version": "1.0.2", + "author": "niucloud", + "type": "app", + "support_app": "" +} diff --git a/cms/package/uni-app-pages.php b/cms/package/uni-app-pages.php new file mode 100644 index 00000000..c42e2130 --- /dev/null +++ b/cms/package/uni-app-pages.php @@ -0,0 +1,19 @@ + <<) { + return request.get('cms/article', params) +} + +/** + * 文章列表 + */ +export function getArticleAll(params: Record) { + return request.get('cms/article/all', params) +} + +/** + * 文章详情 + */ +export function getArticleDetail(id: number) { + return request.get(`cms/article/${id}`) +} + +/** + * 文章分类 + */ +export function getArticleCategory() { + return request.get('cms/category') +} \ No newline at end of file diff --git a/cms/uni-app/components/diy/article/index.vue b/cms/uni-app/components/diy/article/index.vue new file mode 100644 index 00000000..bcbafe1b --- /dev/null +++ b/cms/uni-app/components/diy/article/index.vue @@ -0,0 +1,132 @@ + + + + + \ No newline at end of file diff --git a/cms/uni-app/locale/en.json b/cms/uni-app/locale/en.json new file mode 100644 index 00000000..7a73a41b --- /dev/null +++ b/cms/uni-app/locale/en.json @@ -0,0 +1,2 @@ +{ +} \ No newline at end of file diff --git a/cms/uni-app/locale/zh-Hans.json b/cms/uni-app/locale/zh-Hans.json new file mode 100644 index 00000000..bf3bd620 --- /dev/null +++ b/cms/uni-app/locale/zh-Hans.json @@ -0,0 +1,4 @@ +{ + "pages.list": "资讯中心", + "pages.detail": "文章详情" +} \ No newline at end of file diff --git a/cms/uni-app/locale/zh-Hans/pages.detail.json b/cms/uni-app/locale/zh-Hans/pages.detail.json new file mode 100644 index 00000000..ca6b8c2d --- /dev/null +++ b/cms/uni-app/locale/zh-Hans/pages.detail.json @@ -0,0 +1,5 @@ +{ + "detail": "文章详情", + "abstract": "摘要", + "loadingText": "正在加载" +} diff --git a/cms/uni-app/locale/zh-Hans/pages.list.json b/cms/uni-app/locale/zh-Hans/pages.list.json new file mode 100644 index 00000000..1770d8c5 --- /dev/null +++ b/cms/uni-app/locale/zh-Hans/pages.list.json @@ -0,0 +1,7 @@ +{ + "list": "文章列表", + "noData": "~ 暂无数据 ~", + "all": "全部", + "end": "-- 到底了 --", + "searchPlaceholder": "请输入搜索关键词" +} diff --git a/cms/uni-app/pages/detail.vue b/cms/uni-app/pages/detail.vue new file mode 100644 index 00000000..3a5da5b4 --- /dev/null +++ b/cms/uni-app/pages/detail.vue @@ -0,0 +1,65 @@ + + + + \ No newline at end of file diff --git a/cms/uni-app/pages/list.vue b/cms/uni-app/pages/list.vue new file mode 100644 index 00000000..f36731b3 --- /dev/null +++ b/cms/uni-app/pages/list.vue @@ -0,0 +1,164 @@ + + + + + \ No newline at end of file diff --git a/cms/web/api/article.ts b/cms/web/api/article.ts new file mode 100644 index 00000000..266901f0 --- /dev/null +++ b/cms/web/api/article.ts @@ -0,0 +1,27 @@ +/** + * 文章列表 + */ +export function getArticleList(params: Record) { + return request.get('cms/article', params) +} + +/** + * 文章列表 + */ +export function getArticleAll(params: Record) { + return request.get('cms/article/all', params) +} + +/** + * 文章详情 + */ +export function getArticleDetail(id: number) { + return request.get(`cms/article/${id}`) +} + +/** + * 文章分类 + */ +export function getArticleCategory() { + return request.get('cms/category') +} \ No newline at end of file diff --git a/cms/web/lang/zh-cn/article.detail.json b/cms/web/lang/zh-cn/article.detail.json new file mode 100644 index 00000000..96fc010c --- /dev/null +++ b/cms/web/lang/zh-cn/article.detail.json @@ -0,0 +1,3 @@ +{ + "title": "文章" +} \ No newline at end of file diff --git a/cms/web/lang/zh-cn/article.list.json b/cms/web/lang/zh-cn/article.list.json new file mode 100644 index 00000000..96fc010c --- /dev/null +++ b/cms/web/lang/zh-cn/article.list.json @@ -0,0 +1,3 @@ +{ + "title": "文章" +} \ No newline at end of file diff --git a/cms/web/lang/zh-cn/pages.json b/cms/web/lang/zh-cn/pages.json new file mode 100644 index 00000000..ca3a6263 --- /dev/null +++ b/cms/web/lang/zh-cn/pages.json @@ -0,0 +1,10 @@ +{ + "pages": { + "cms": { + "article": { + "list": "文章", + "detail": "文章" + } + } + } +} \ No newline at end of file diff --git a/cms/web/pages/article/detail.vue b/cms/web/pages/article/detail.vue new file mode 100644 index 00000000..00e47bda --- /dev/null +++ b/cms/web/pages/article/detail.vue @@ -0,0 +1,86 @@ + + + + + diff --git a/cms/web/pages/article/list.vue b/cms/web/pages/article/list.vue new file mode 100644 index 00000000..1b516163 --- /dev/null +++ b/cms/web/pages/article/list.vue @@ -0,0 +1,160 @@ + + + + + diff --git a/cms/web/pages/routes.ts b/cms/web/pages/routes.ts new file mode 100644 index 00000000..760f8b08 --- /dev/null +++ b/cms/web/pages/routes.ts @@ -0,0 +1,10 @@ +export default [ + { + path: "/cms/article/list", + component: () => import('~/cms/pages/article/list.vue') + }, + { + path: "/cms/article/detail", + component: () => import('~/cms/pages/article/detail.vue') + } +] \ No newline at end of file