更新:新闻列表展示

virtual
zwesy 2020-12-04 14:33:02 +08:00
parent abb2071c29
commit 99740bfed9
9 changed files with 173 additions and 111 deletions

View File

@ -74,8 +74,9 @@ class Article extends Base
case 'products' :
$this->assignProducts($topCategory, $category, $categoryChildren);
break;
case 'news_center' :
case 'news' :
$this->assignNews($topCategory, $category);
$this->assignNews($topCategory, $category, $categoryChildren);
break;
default :
$this->data['items'] = MArticle::getListPageByCategory($category['id'], $category['number'] ? $category['number'] : 20);
@ -88,7 +89,7 @@ class Article extends Base
}
// 产品中心 - 展示当前分类和所有子类产品
// 产品 - 展示当前分类和所有子类产品
private function assignProducts($topCategory, $category, $categoryChildren)
{
$keyword = input('param.keyword', '');
@ -101,17 +102,32 @@ class Article extends Base
foreach ($children as $child) {
$cateIds[] = $child['id'];
}
$this->data['items'] = MArticle::getListPageByCategories($cateIds, $category['number'] ? $category['number'] : 20, $keyword);
$items = MArticle::getListPageByCategories($cateIds, $category['number'] ? $category['number'] : 20, $keyword);
$items->appends(['category_id'=>$category['id']]);
$this->data['items'] = $items;
$this->data['keyword'] = $keyword;
}
// 新闻
private function assignNews($topCategory, $category)
private function assignNews($topCategory, $category, $categoryChildren)
{
if($topCategory['id'] == $category['id']) {
// 新闻中心
$cateList = [];
$newsChildrenFlip = array_flip(Category::$CIdList['news_children']);
foreach ($categoryChildren as $cate) {
$cate['items'] = MArticle::getLatestByCategory($cate['id'], 4);
$cateList[$newsChildrenFlip[$cate['id']]] = $cate;
}
$this->data['cateList'] = $cateList;
} else {
// 新闻子栏目
$keyword = input('param.keyword', '');
$category['number'] = 2;
$this->data['items'] = MArticle::getListPageByCategory($category['id'], $category['number'] ? $category['number'] : 20, $keyword);
$this->data['keyword'] = $keyword;
}
}
}

View File

@ -15,7 +15,7 @@ class Article extends Base
->toArray();
}
//获取栏目下最新记录
public static function getLatestByCategory($categoryId, $limit = 5)
public static function getLatestByCategory($categoryId, $limit = 5, $order = [])
{
if(empty($categoryId)){
return [];
@ -23,8 +23,11 @@ class Article extends Base
if($limit <= 0){
$limit = 5;
}
if(empty($order)) {
$order = ['create_time' => 'desc'];
}
return self::where('category_id', $categoryId)
->order('create_time', 'desc')
->order($order)
->limit($limit)
->select()
->toArray();

View File

@ -27,11 +27,11 @@ class Category extends Base
'achievement' => 17, // 主要业绩
],
'achievement_manage' => 30, // 主要业绩管理
'news' => 18, //新闻(主)
'news' => 18, // 新闻动态
'news_children' => [
'enterprise' => 20, // 企业新闻
'industry' => 21, // 行业资讯
'dynamics' => 22, // 动态
'dynamics' => 22, // 新动态
],
];

View File

@ -274,7 +274,7 @@ input,select,textarea{outline:medium none; resize: none;}
.news-box1 .center-block ul li a{ width: 100%; float: left; margin-top: 3.125rem; border: 0.125rem solid #d7d7d7; background: #fff; padding: 2.5rem;}
.news-box1 .center-block ul li a .pull-left{ white-space: nowrap; font-size: 1.25rem; color: #00418f; font-weight: bold; padding-right: 2.5rem;}
.news-box1 .center-block ul li a .pull-right{ width: 100%;}
.news-box1 .center-block ul li a .pull-right .imgs{ width: 29%; float: left; height: 10rem; overflow: hidden;}
.news-box1 .center-block ul li a .pull-right .imgs{ width: 29%; float: left; height: 10rem; overflow: hidden; border: 1px solid #f1f1f1;}
.news-box1 .center-block ul li a .pull-right .imgs img{ width: 100%; height: 100%; object-fit: cover; transition: all .6s;}
.news-box1 .center-block ul li a .pull-right .info{ width: 71%; float: left; padding-left: 2.8125rem;}
.news-box1 .center-block ul li a .pull-right .info span{ display: block; font-size: 1.25rem; font-weight: bold; overflow: hidden; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 1;}
@ -294,6 +294,10 @@ input,select,textarea{outline:medium none; resize: none;}
.news-box3 .pull-right ul li a{ width: 100%; float: left; line-height: 20px; margin-bottom: 1.5625rem; font-size: 1rem;}
.news-box3 .pull-right ul li a span{ width: 70%; float: left; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;}
.news-box3 .pull-right ul li a i{ float: right;}
.news-box3 .more a{ float: right; font-size: 1rem; padding-right: 3.4375rem; line-height: 2.5rem; margin-top: 2.5rem; position: relative; color: #999;}
.news-box3 .more a::after{ content: ''; width: 2.5rem; height: 2.5rem; background: url(../image/icon_jt3.png) no-repeat center; background-size: 100%; position: absolute; right: 0; top: 0; transition: all .6s;}
.news-box3 .more a:hover{ color: #00418f;}
.news-box3 .more a:hover::after{ background-image: url(../image/icon_jt3_1.png);}
.news-info{ padding: 10rem 0 6rem;}
.news-info .top-box{ border-bottom: 1px solid #9E9E9E; padding-bottom: 1.875rem;}

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

View File

@ -10,10 +10,13 @@
// +----------------------------------------------------------------------
use think\facade\Route;
Route::rule('products', 'article/index')->name('products');
Route::get('article/:id', "article/detail");
Route::get('articles/:category_id', "article/index");
Route::get('page/:category_id', "page/index");
Route::rule('products', 'article/index')->name('products.search'); // 产品查询
Route::rule('news', 'article/index')->name('news.search'); // 新闻查询

View File

@ -1,106 +1,48 @@
{layout name="layout" /}
<div class="all_center_box">
{php}
$bgImg = '__IMG__/page_ban1.jpg'; // 默认背景图
if (isset($category) && !empty(trim($category['src'])) && file_exists('.'.$category['src'])) {
$bgImg = $category.src;
}
{/php}
<div class="page_banner wf100">
<div class="bg" style="background-image: url({$bgImg});"></div>
</div>
<div class="news_box w-100">
<div class="crumbs_box w-1500">
{:widget('crumbs/index', ['categoryId' => $categoryId])}
</div>
<div class="news_soso w-1500" aos="fade-up">
<div class="center-block ">
<input type="text" class="text" name="keyword" id="articleKeyword" placeholder="请输入关键字" />
<input type="button" class="btns" value="搜索" id="sosSubmit"/>
<!-- banner -->
<div class="page-banner w-100" style="background-image: url({:getImgSrc($topCategory, '__IMG__/page_ban4.jpg')});">
<div class="info">
<div class="w-1200">
<strong>{$category.title ?? ''}</strong>
<p>{:nl2br($category.description ?? '')}</p>
</div>
</div>
<div class="news_list w-100" aos="fade-up">
{if isset($childList) && count($childList) > 0}
{foreach $childList as $child}
<hr/>
<div class="news-child-title">{$child['category']['title'] ?? ''}</div>
{if count($child['items']) > 0}
<ul class="w-1500">
{foreach $child['items'] as $item}
{php}
if (!empty($item['link'])){
$url = $item['link'];
$target = 'target="_blank"';
} else {
$url = url('article/detail', ['id'=>$item['id']]);
$target = '';
}
$imgSrc = '__IMG__/article_bg.jpg';
if (!empty(trim($item['src'])) && file_exists('.'.$item['src'])) {
$imgSrc = $item['src'];
}
{/php}
<li>
<a href="{$url}" {$target}>
<div class="imgs wf100">
<img src="{$imgSrc}" alt="{$item['title']}" />
<span><i {if $item['hot']}class="active"{/if}></i></span>
</div>
<!-- -->
<div class="all-center-box">
<div class="news-box1 w-100">
<div class="w-1200 news-search-box">
<form action="{:url('article/index', ['category_id'=> $categoryId])}" method="get">
<input name="keyword" placeholder="关键词查询..." value="{$keyword ?? ''}"/>
<button type="submit">查询</button>
</form>
</div>
<div class="info w-100">
<div class="box1">
<span>{$item.create_time|date='Y.m.d'}</span>
<span>{$item['category_title'] ?? ''}</span>
</div>
<div class="box2 w-100">
<span>{$item['title']}</span>
<p>{$item['summary']}</p>
</div>
</div>
</a>
</li>
{/foreach}
</ul>
{/if}
{/foreach}
{elseif isset($items) && count($items) > 0 /}
<ul class="w-1500">
<div class="w-1200">
{if isset($items)}
<div class="center-block w-100">
<ul>
{foreach $items as $item}
{php}
if (!empty($item['link'])){
$url = $item['link'];
$target = 'target="_blank"';
} else {
$url = url('article/detail', ['id'=>$item['id']]);
$target = '';
}
$imgSrc = '__IMG__/article_bg.jpg';
if (!empty(trim($item['src'])) && file_exists('.'.$item['src'])) {
$imgSrc = $item['src'];
}
{/php}
<li>
<a href="{$url}" {$target}>
<div class="imgs wf100">
<img src="{$imgSrc}" alt="{$item['title']}" />
<span><i {if $item['hot']}class="active"{/if}></i></span>
</div>
<div class="info w-100">
<div class="box1">
<span>{$item.create_time|date='Y.m.d'}</span>
<span>{$item['category_title'] ?? ''}</span>
</div>
<div class="box2 w-100">
<span>{$item['title']}</span>
<p>{$item['summary']}</p>
<a href="{:url('article/detail', ['id'=>$item['id']])}" class="between-center">
<div class="pull-left">{$item['create_time']|date="Y.m.d"}</div>
<div class="pull-right">
<div class="imgs"><img src="{:getImgSrc($item, '__IMG__/default_bg.jpg')}" ></div>
<div class="info">
<span>{$item['title'] ?? ''}</span>
<p>{:nl2br($item['summary'] ?? '')}</p>
<i>了解详情+</i>
</div>
</div>
</a>
</li>
{/foreach}
</ul>
</div>
<div class="pager w-100">
{$items->render()|raw}
</div>
{/if}
</div>
</div>
</div>
</div>

View File

@ -0,0 +1,94 @@
{layout name="layout"}
<!-- banner -->
<div class="page-banner w-100" style="background-image: url({:getImgSrc($topCategory, '__IMG__/page_ban4.jpg')});">
<div class="info">
<div class="w-1200">
<strong>{$topCategory.title ?? ''}</strong>
<p>{:nl2br($topCategory.description ?? '')}</p>
</div>
</div>
</div>
<!-- -->
<div class="all-center-box">
<!-- Corporate -->
{if isset($cateList['enterprise']) && !empty($cateList['enterprise'])}
<div class="news-box1 w-100" id="news1">
<div class="w-1200">
<div class="all-title-box2 w-100"><span>{$cateList['enterprise']['title'] ?? ''}</span><p>{$cateList['enterprise']['description'] ?? ''}</p></div>
<div class="center-block w-100">
<ul>
{if isset($cateList['enterprise']['items']) && count($cateList['enterprise']['items']) > 0}
{foreach $cateList['enterprise']['items'] as $item}
<li>
<a href="{:url('article/detail', ['id'=>$item['id']])}" class="between-center">
<div class="pull-left">{$item['create_time']|date="Y.m.d"}</div>
<div class="pull-right">
<div class="imgs"><img src="{:getImgSrc($item, '__IMG__/default_bg.jpg')}" ></div>
<div class="info">
<span>{$item['title'] ?? ''}</span>
<p>{:nl2br($item['summary'] ?? '')}</p>
<i>了解详情+</i>
</div>
</div>
</a>
</li>
{/foreach}
{/if}
</ul>
</div>
<div class="more w-100"><a href="{:url('article/index', ['category_id'=>$cateList['enterprise']['id']])}">点击展开更多</a></div>
</div>
</div>
{/if}
<!-- Industry -->
{if isset($cateList['industry']) && !empty($cateList['industry'])}
<div class="news-box1 w-100 news-box2" id="news2">
<div class="w-1200">
<div class="all-title-box2 w-100"><span>{$cateList['industry']['title'] ?? ''}</span><p>{$cateList['industry']['description'] ?? ''}</p></div>
<div class="center-block w-100">
<ul>
{if isset($cateList['enterprise']['items']) && count($cateList['enterprise']['items']) > 0}
{foreach $cateList['enterprise']['items'] as $item}
<li>
<a href="{:url('article/detail', ['id'=>$item['id']])}" class="between-center">
<div class="pull-left">{$item['create_time']|date="Y.m.d"}</div>
<div class="pull-right">
<div class="imgs"><img src="image/img_6.png" ></div>
<div class="info">
<span>{$item['title'] ?? ''}</span>
<p>{:nl2br($item['summary'] ?? '')}</p>
<i>了解详情+</i>
</div>
</div>
</a>
</li>
{/foreach}
{/if}
</ul>
</div>
<div class="more w-100"><a href="">点击展开更多</a></div>
</div>
</div>
{/if}
<!-- Latest -->
{if isset($cateList['dynamics']) && !empty($cateList['dynamics'])}
<div class="news-box3 w-100" id="news3">
<div class="w-1200">
<div class="between-top">
<div class="all-title-box2"><span>{$cateList['dynamics']['title'] ?? ''}</span><p>{$cateList['dynamics']['description'] ?? ''}</p></div>
<div class="pull-right">
<ul>
{if isset($cateList['dynamics']['items']) && count($cateList['dynamics']['items']) > 0}
{foreach $cateList['dynamics']['items'] as $item}
<li><a href="{:url('article/detail', ['id'=>$item['id']])}"><span>{$item['title'] ?? ''}</span><i>{$item['create_time']|date="Y年m月d日"}</i></a></li>
{/foreach}
{/if}
</ul>
</div>
</div>
<div class="more w-100"><a href="{:url('article/index', ['category_id'=>$cateList['dynamics']['id']])}">点击展开更多</a></div>
</div>
</div>
{/if}
</div>

View File

@ -12,8 +12,8 @@
<!-- -->
<div class="all-center-box">
<div class="product-box w-100">
<div class="w-1200">
<form action="{:url('products')}" method="get">
<div class="w-1200 products-search-box">
<form action="{:url('products.search')}" method="get">
<select name="category_id">
<option value="{$topCategory.id}">产品选择</option>
{if isset($categoryChildren) && count($categoryChildren) >0}
@ -22,7 +22,7 @@
{/foreach}
{/if}
</select>
<input name="keyword" placeholder="关键词查询..."/>
<input name="keyword" placeholder="关键词查询..." value="{$keyword ?? ''}" />
<button type="submit">查询</button>
</form>
</div>
@ -31,7 +31,7 @@
<div class="center-block w-100">
<ul>
{foreach $items as $item}
<li><a href="{:url('article/detail', ['id' => $item.id])}"><span><img src="{$item.src ?? ''}" ></span><p>{$item.title}</p></a></li>
<li><a href="{:url('article/detail', ['id' => $item.id])}"><span><img src="{:getImgSrc($item, '__IMG__/default_bg.jpg')}" ></span><p>{$item.title}</p></a></li>
{/foreach}
</ul>
</div>