From 33d5242e60cd62a78c2b2a3fd8b1e7c0791a321b Mon Sep 17 00:00:00 2001 From: jsasg <735273025@qq.com> Date: Sat, 12 Apr 2025 14:34:07 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=87=E7=AB=A0=E7=9B=B8=E5=85=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/index/controller/Article.php | 50 ++++++++++++++++++ app/index/model/ArticleCategoryModel.php | 25 +++++++++ app/index/model/ArticleModel.php | 6 +-- app/index/model/SysBannerItemModel.php | 12 +++++ app/index/route/route.php | 2 +- app/index/view/article/index.html | 67 ++++++++---------------- public/static/index/css/category.css | 43 ++++----------- 7 files changed, 123 insertions(+), 82 deletions(-) diff --git a/app/index/controller/Article.php b/app/index/controller/Article.php index e080e8db..6d7d85b7 100644 --- a/app/index/controller/Article.php +++ b/app/index/controller/Article.php @@ -3,6 +3,10 @@ declare (strict_types = 1); namespace app\index\controller; +use app\admin\controller\v1\BannerItem; +use app\index\model\ArticleCategoryModel; +use app\index\model\ArticleModel; +use app\index\model\SysBannerItemModel; use think\facade\View; class Article extends Common @@ -12,6 +16,52 @@ class Article extends Common */ public function index() { + // 获取上级分类 + $param = request()->param([ + 'pid', + 'cid', + 'page/d' => 1, + 'size/d' => 12, + ]); + + // 获取banner焦点图 + $banner = SysBannerItemModel::hasWhere('banner', [ + 'language_id' => $this->lang_id, + 'unique_label' => 'BANNER_67f9fc71e27db' + ]) + ->type('image') + ->visible(['id', 'title', 'image', 'link']) + ->find(); + View::assign('banner', $banner); + + // 获取分类列表 + $categorys = ArticleCategoryModel::field([ + 'id', + 'pid', + 'name' + ]) + ->language($this->lang_id) + ->parent($param['pid']??null) + ->isShow(true) + ->order(['sort' => 'asc', 'id' => 'desc']) + ->select(); + View::assign('categorys', $categorys); + + // 获取文章列表 + if (!$categorys->isEmpty()) { + $articles = ArticleModel::field([ + 'id', + 'title', + 'desc', + 'image' + ]) + ->category($param['cid']??$categorys[0]['id']) + ->paginate([ + 'list_rows' => $param['size'], + 'page' => $param['page'], + ]); + } + View::assign('articles', $articles??[]); return View::fetch('index'); } diff --git a/app/index/model/ArticleCategoryModel.php b/app/index/model/ArticleCategoryModel.php index 0f9d4da4..195494da 100644 --- a/app/index/model/ArticleCategoryModel.php +++ b/app/index/model/ArticleCategoryModel.php @@ -16,4 +16,29 @@ class ArticleCategoryModel extends ArticleCategoryBaseModel use SoftDelete; // 软删除字段 protected $deleteTime = 'deleted_at'; + + // 关联文章 + public function article() + { + return $this->hasMany(ArticleModel::class, 'category_id', 'id'); + } + + // 所属语言范围查询 + public function scopeLanguage($query, $language) + { + $query->where('language_id', '=', $language); + } + + // 所属上级分类范围查询 + public function scopeParent($query, $parent) + { + if (is_null($parent)) return; + $query->where('pid', '=', $parent); + } + + // 是否显示状态范围查询 + public function scopeIsShow($query, bool $is_show) + { + $query->where('is_show', '=', (int)$is_show); + } } diff --git a/app/index/model/ArticleModel.php b/app/index/model/ArticleModel.php index 4d6937aa..8903d51f 100644 --- a/app/index/model/ArticleModel.php +++ b/app/index/model/ArticleModel.php @@ -29,9 +29,9 @@ class ArticleModel extends ArticleBaseModel return $query->where('recommend', '=', (int)$stat); } - // 启用状态范围查询 - public function scopeEnabled($query, bool $stat = true) + // 文章分类范围查询 + public function scopeCategory($query, $category) { - return $query->where('enabled', '=', (int)$stat); + return $query->where('category_id', '=', $category); } } diff --git a/app/index/model/SysBannerItemModel.php b/app/index/model/SysBannerItemModel.php index 860da226..2948d528 100644 --- a/app/index/model/SysBannerItemModel.php +++ b/app/index/model/SysBannerItemModel.php @@ -17,6 +17,18 @@ class SysBannerItemModel extends SysBannerItemBaseModel // 软删除字段 protected $deleteTime = 'deleted_at'; + // 关联分类 + public function banner() + { + return $this->hasOne(SysBannerModel::class, 'id', 'banner_id'); + } + + // 类型范围查询 + public function scopeType($query, $type) + { + $query->where('type', '=', $type); + } + // 启用状态范围查询 public function scopeEnabled($query) { diff --git a/app/index/route/route.php b/app/index/route/route.php index 3acba5ae..32da2902 100644 --- a/app/index/route/route.php +++ b/app/index/route/route.php @@ -25,7 +25,7 @@ Route::group('product', function() { // 文章相关路由 Route::group('article', function() { // 文章列表页 - Route::get('index/:id', 'Article/index'); + Route::get('index/:pid', 'Article/index'); // 文章详情页 Route::get('detail/:id', 'Article/detail'); // 文章搜索页 diff --git a/app/index/view/article/index.html b/app/index/view/article/index.html index 5a5122dd..75145378 100644 --- a/app/index/view/article/index.html +++ b/app/index/view/article/index.html @@ -4,67 +4,44 @@ {/block} {block name="main"}
- +
- - + +
-
News
-
Blogs
+ {volist name="categorys" id="ca"} + {if condition="$Request.get.cid == $ca.id || (!$Request.has.cid && $key == 0)"} + + {else/} + + {/if} + {$ca.name} + + {/volist}
- +
- + + {notempty name="articles"} + {/notempty}
{/block} diff --git a/public/static/index/css/category.css b/public/static/index/css/category.css index ef94f887..d0269868 100755 --- a/public/static/index/css/category.css +++ b/public/static/index/css/category.css @@ -1,7 +1,9 @@ .orico_Page_category { width: 100%; position: relative; - height: 100vh; + height: auto; + min-height: 100vh; + padding-bottom: 3.75rem; overflow-y: auto; overflow-x: hidden; background: #f2f2f2; @@ -45,7 +47,7 @@ position: absolute; left: 1.875rem; top: 0.9375rem; - background: url(../categoryImg/search.png); + background: url(/static/index/images/search.png); z-index: 9; } .orico_Page_category .categoryMain .categorySearch .search { @@ -128,50 +130,25 @@ position: absolute; bottom: 1rem; } -.orico_Page_category .categoryMain .tabConten .Page { +.orico_Page_category .categoryMain .tabConten .pagination { zoom: 1; text-align: center; color: #555; clear: both; padding-bottom: 2rem; } -.orico_Page_category .categoryMain .tabConten .Page span { +.orico_Page_category .categoryMain .tabConten .pagination span { padding: 0px 0px; display: inline-block; } -.orico_Page_category .categoryMain .tabConten .Page .p_page { - display: flex; - align-items: center; - justify-content: center; -} -.orico_Page_category .categoryMain .tabConten .Page .p_page .a_prev, -.orico_Page_category .categoryMain .tabConten .Page .p_page .a_next { - display: inline-block; - width: 10px; - height: 21px; -} -.orico_Page_category .categoryMain .tabConten .Page .p_page .a_prev { - background: url(../categoryImg/pfl.png) no-repeat; - margin-right: 10px; - padding: 0 10px; -} -.orico_Page_category .categoryMain .tabConten .Page .p_page .a_next { - background: url(../categoryImg/prh.png) no-repeat; - margin-left: 10px; - padding: 0 10px; -} -.orico_Page_category .categoryMain .tabConten .Page .p_page .num a { +.orico_Page_category .categoryMain .tabConten .pagination li { display: inline-block; width: 34px; height: 22px; line-height: 22px; - text-align: center; - vertical-align: middle; font-size: 16px; - color: #444; } -.orico_Page_category .categoryMain .tabConten .Page .p_page .num a.a_cur, -.orico_Page_category .categoryMain .tabConten .Page .p_page .num a:hover { - background: #444; - color: #fff; +.orico_Page_category .categoryMain .tabConten .pagination li.active { + background-color: #444444; + color: #ffffff; }