feat: 文章相关

This commit is contained in:
2025-04-12 14:34:07 +08:00
parent fde19ef98c
commit 33d5242e60
7 changed files with 123 additions and 82 deletions

View File

@@ -3,6 +3,10 @@ declare (strict_types = 1);
namespace app\index\controller; 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; use think\facade\View;
class Article extends Common class Article extends Common
@@ -12,6 +16,52 @@ class Article extends Common
*/ */
public function index() 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'); return View::fetch('index');
} }

View File

@@ -16,4 +16,29 @@ class ArticleCategoryModel extends ArticleCategoryBaseModel
use SoftDelete; use SoftDelete;
// 软删除字段 // 软删除字段
protected $deleteTime = 'deleted_at'; 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);
}
} }

View File

@@ -29,9 +29,9 @@ class ArticleModel extends ArticleBaseModel
return $query->where('recommend', '=', (int)$stat); 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);
} }
} }

View File

@@ -17,6 +17,18 @@ class SysBannerItemModel extends SysBannerItemBaseModel
// 软删除字段 // 软删除字段
protected $deleteTime = 'deleted_at'; 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) public function scopeEnabled($query)
{ {

View File

@@ -25,7 +25,7 @@ Route::group('product', function() {
// 文章相关路由 // 文章相关路由
Route::group('article', function() { Route::group('article', function() {
// 文章列表页 // 文章列表页
Route::get('index/:id', 'Article/index'); Route::get('index/:pid', 'Article/index');
// 文章详情页 // 文章详情页
Route::get('detail/:id', 'Article/detail'); Route::get('detail/:id', 'Article/detail');
// 文章搜索页 // 文章搜索页

View File

@@ -6,11 +6,18 @@
<div class="orico_Page_category"> <div class="orico_Page_category">
<!-- 内容 --> <!-- 内容 -->
<div class="categoryMain"> <div class="categoryMain">
<img src="categoryImg/eng-blog.jpg" class="categorybgimg" /> <img src="{$banner.image}" class="categorybgimg" />
<!-- 切换 --> <!-- 切换 -->
<div class="tabs"> <div class="tabs">
<div class="tabitme on">News</div> {volist name="categorys" id="ca"}
<div class="tabitme">Blogs</div> {if condition="$Request.get.cid == $ca.id || (!$Request.has.cid && $key == 0)"}
<a class="tabitme on" href="{:url('article/index', ['pid' => $ca.pid, 'cid' => $ca.id])}">
{else/}
<a class="tabitme" href="{:url('article/index', ['pid' => $ca.pid, 'cid' => $ca.id])}">
{/if}
{$ca.name}
</a>
{/volist}
</div> </div>
<!-- 搜索 --> <!-- 搜索 -->
<div class="categorySearch"> <div class="categorySearch">
@@ -18,53 +25,23 @@
<input type="text" placeholder="Search" class="search" id="article-search-in" value=""> <input type="text" placeholder="Search" class="search" id="article-search-in" value="">
</div> </div>
<!-- 切换内容 --> <!-- 切换内容 -->
{notempty name="articles"}
<div class="tabConten"> <div class="tabConten">
<div class="tbmain"> <div class="tbmain">
{volist name="articles" id="ar"}
<div class="Contenitem"> <div class="Contenitem">
<a> <a>
<img src="categoryImg/t1.jpg" /> <img src="{$ar.image}" />
<h3>ORICO Highlights Next-Gen Portable Data Storage and Charging Solution at Global <h3>{$ar.title}</h3>
Sources Mobile Electronics 2024 Fall</h3> <p>{$ar.desc}</p>
<p>Hong Kong AsiaWorld-Expo, October 18-21, 2024 - A long-time Global Sources Mobile
Electronics exhibitor, ORICO made a splash at the show with its cutting-edge
next-generation portable data storage and...</p>
</a>
</div>
<div class="Contenitem">
<a>
<img src="categoryImg/t1.jpg" />
<h3>ORICO Highlights Next-Gen Portable Data Storage and Charging Solution at Global
Sources Mobile Electronics 2024 Fall</h3>
<p>Hong Kong AsiaWorld-Expo, October 18-21, 2024 - A long-time Global Sources Mobile
Electronics exhibitor, ORICO made a splash at the show with its cutting-edge
next-generation portable data storage and...</p>
</a>
</div>
<div class="Contenitem">
<a>
<img src="categoryImg/t1.jpg" />
<h3>ORICO Highlights Next-Gen Portable Data Storage and Charging Solution at Global
Sources Mobile Electronics 2024 Fall</h3>
<p>Hong Kong AsiaWorld-Expo, October 18-21, 2024 - A long-time Global Sources Mobile
Electronics exhibitor, ORICO made a splash at the show with its cutting-edge
next-generation portable data storage and...</p>
</a> </a>
</div> </div>
{/volist}
</div> </div>
<!-- 分页--> <!-- 分页-->
<div class="Page"> <div>{$articles|raw}</div>
<span class="p_page">
<a class="a_prev"></a>
<em class="num">
<a class="a_cur">1</a>
<a>2</a>
<a>3</a>
<a>4</a>
</em>
<a class="a_next"></a>
</span>
</div>
</div> </div>
{/notempty}
</div> </div>
</div> </div>
{/block} {/block}

View File

@@ -1,7 +1,9 @@
.orico_Page_category { .orico_Page_category {
width: 100%; width: 100%;
position: relative; position: relative;
height: 100vh; height: auto;
min-height: 100vh;
padding-bottom: 3.75rem;
overflow-y: auto; overflow-y: auto;
overflow-x: hidden; overflow-x: hidden;
background: #f2f2f2; background: #f2f2f2;
@@ -45,7 +47,7 @@
position: absolute; position: absolute;
left: 1.875rem; left: 1.875rem;
top: 0.9375rem; top: 0.9375rem;
background: url(../categoryImg/search.png); background: url(/static/index/images/search.png);
z-index: 9; z-index: 9;
} }
.orico_Page_category .categoryMain .categorySearch .search { .orico_Page_category .categoryMain .categorySearch .search {
@@ -128,50 +130,25 @@
position: absolute; position: absolute;
bottom: 1rem; bottom: 1rem;
} }
.orico_Page_category .categoryMain .tabConten .Page { .orico_Page_category .categoryMain .tabConten .pagination {
zoom: 1; zoom: 1;
text-align: center; text-align: center;
color: #555; color: #555;
clear: both; clear: both;
padding-bottom: 2rem; padding-bottom: 2rem;
} }
.orico_Page_category .categoryMain .tabConten .Page span { .orico_Page_category .categoryMain .tabConten .pagination span {
padding: 0px 0px; padding: 0px 0px;
display: inline-block; display: inline-block;
} }
.orico_Page_category .categoryMain .tabConten .Page .p_page { .orico_Page_category .categoryMain .tabConten .pagination li {
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 {
display: inline-block; display: inline-block;
width: 34px; width: 34px;
height: 22px; height: 22px;
line-height: 22px; line-height: 22px;
text-align: center;
vertical-align: middle;
font-size: 16px; font-size: 16px;
color: #444;
} }
.orico_Page_category .categoryMain .tabConten .Page .p_page .num a.a_cur, .orico_Page_category .categoryMain .tabConten .pagination li.active {
.orico_Page_category .categoryMain .tabConten .Page .p_page .num a:hover { background-color: #444444;
background: #444; color: #ffffff;
color: #fff;
} }