更新:取消路由地址语义化

virtual
zwesy 2020-11-25 20:15:51 +08:00
parent d5b8baedea
commit 417ce665fc
8 changed files with 58 additions and 92 deletions

View File

@ -50,32 +50,32 @@ class Article extends Base
return $this->view($category['template_list'] ?? ''); return $this->view($category['template_list'] ?? '');
} }
//新闻列表 // //新闻列表
public function news($categoryId) // public function news($categoryId)
{ // {
dump('新闻资讯'); // dump('新闻资讯');
dump($categoryId); // dump($categoryId);
//
} // }
//
//新闻详情 // //新闻详情
public function newsDetail($newsId) // public function newsDetail($newsId)
{ // {
dump('新闻资讯详情'); // dump('新闻资讯详情');
dump($newsId); // dump($newsId);
} // }
//
// 产品列表 // // 产品列表
public function product($categoryId) //// public function product($categoryId)
{ //// {
dump('产品列表'); //// dump('产品列表');
dump($categoryId); //// dump($categoryId);
} //// }
//
// 产品列表 // // 产品列表
public function productDetail($productId) // public function productDetail($productId)
{ // {
dump('产品详情'); // dump('产品详情');
dump($productId); // dump($productId);
} // }
} }

View File

@ -8,38 +8,25 @@ class Page extends Base
private function getPageCommonData($categoryId) private function getPageCommonData($categoryId)
{ {
$resp = true; $resp = true;
$category = Category::getById($categoryId);
if ($category) {
$description = $category['description'] ? $category['description'] : $this->system['seo_description'];
$this->setSeo($category['title'], $this->system['seo_keywords'], $description);
} else {
$resp = false;
}
$childCategory = Category::getChildrenByParentId($categoryId);
$this->data['categoryId'] = $categoryId;
$this->data['category'] = $category;
$this->data['childCategory'] = $childCategory;
$this->data['blocks'] = Block::getByCategoryId($categoryId);
return $resp; return $resp;
} }
// 默认单页页面 // 默认单页页面
public function index($categoryId) public function index($categoryId)
{ {
$resp = $this->getPageCommonData($categoryId); $category = Category::getById($categoryId);
if(!$resp) { if ($category) {
return $this->error('错误页面'); $description = $category['description'] ? $category['description'] : $this->system['seo_description'];
$this->setSeo($category['title'], $this->system['seo_keywords'], $description);
} else {
return $this->error('页面错误');
} }
return $this->view($this->data['category']['template_detail']); $childCategory = Category::getChildrenByParentId($categoryId);
} $this->data['categoryId'] = $categoryId;
$this->data['category'] = $category;
// 营销页面 $this->data['childCategory'] = $childCategory;
public function marketing($categoryId) $this->data['blocks'] = Block::getByCategoryId($categoryId);
{ return $this->view($category['template_detail']);
$resp = $this->getPageCommonData($categoryId);
if(!$resp) {
return $this->error('错误页面');
}
return $this->view($this->data['category']['template_detail']);
} }
} }

View File

@ -9,6 +9,7 @@ class Menu
public function index($categoryId) public function index($categoryId)
{ {
$menus = Cache::get('front_menus'); $menus = Cache::get('front_menus');
$menus = null;
if(empty($menus)){ if(empty($menus)){
$menus = Category::getListForFrontMenu(); $menus = Category::getListForFrontMenu();
Cache::set('front_menus', $menus, 3600 * 12); Cache::set('front_menus', $menus, 3600 * 12);

View File

@ -11,13 +11,9 @@
use think\facade\Route; use think\facade\Route;
Route::get('article/:id', "article/detail"); Route::get('article/:id', "article/detail");
Route::get('articles/:categoryId', "article/index"); Route::get('articles/:category_id', "article/index");
Route::get('page/:categoryId', "page/index"); Route::get('page/:category_id', "page/index");
// 新闻
Route::get('news/detail/:newsId', "article/newsDetail");
Route::get('news/:categoryId', "article/news");
// 产品
Route::get('product/detail/:productId', "article/productDetail");
Route::get('product/:categoryId', "article/product");
// 营销
Route::get('marketing/:categoryId', "page/marketing");

4
runtime/.gitignore vendored
View File

@ -1,4 +0,0 @@
*
!.gitignore

View File

@ -34,7 +34,7 @@
<p>{$product['summary']|raw}</p> <p>{$product['summary']|raw}</p>
</div> </div>
<div class="box2"> <div class="box2">
<a href="{:url('article/productDetail', ['productId'=>$product['id']])}">了解详情+</a> <a href="{:url('article/detail', ['id'=>$product['id']])}">了解详情+</a>
<i>{:str_pad($idx + 1, 2, '0', STR_PAD_LEFT)}</i> <i>{:str_pad($idx + 1, 2, '0', STR_PAD_LEFT)}</i>
</div> </div>
</div> </div>
@ -49,7 +49,7 @@
<div class="w-1500"> <div class="w-1500">
<div class="pull-left column-between"> <div class="pull-left column-between">
<div class="all-title-box1 w-100"><span>{$blocks['marketing_name']['value'] ?? ''}</span><p>{$blocks['marketing_describe']['value'] ?? ''}</p></div> <div class="all-title-box1 w-100"><span>{$blocks['marketing_name']['value'] ?? ''}</span><p>{$blocks['marketing_describe']['value'] ?? ''}</p></div>
<a href="{:url('/marketing/'.$marketingCId)}">了解详情+</a> <a href="{:url('article/index', ['categoryId'=>$marketingCId])}">了解详情+</a>
</div> </div>
</div> </div>
</div> </div>
@ -62,7 +62,7 @@
{if isset($newsEnterprises) && count($newsEnterprises) > 0} {if isset($newsEnterprises) && count($newsEnterprises) > 0}
{foreach $newsEnterprises as $news} {foreach $newsEnterprises as $news}
<li> <li>
<a href="{:url('article/newsDetail', ['newsId'=>$news['id']])}"> <a href="{:url('article/detail', ['id'=>$news['id']])}">
<span>{$news['title']|raw}</span> <span>{$news['title']|raw}</span>
<i>{$news['create_time']|date='Y-m-d'}</i> <i>{$news['create_time']|date='Y-m-d'}</i>
</a> </a>
@ -75,7 +75,7 @@
{if isset($newsIndustries) && count($newsIndustries) > 0} {if isset($newsIndustries) && count($newsIndustries) > 0}
{foreach $newsIndustries as $news} {foreach $newsIndustries as $news}
<li> <li>
<a href="{:url('article/newsDetail', ['newsId'=>$news['id']])}"> <a href="{:url('article/detail', ['id'=>$news['id']])}">
<span>{$news['title']|raw}</span> <span>{$news['title']|raw}</span>
<i>{$news['create_time']|date='Y-m-d'}</i> <i>{$news['create_time']|date='Y-m-d'}</i>
</a> </a>

View File

@ -6,16 +6,8 @@
{if isset($footerMenus) && count($footerMenus) > 0} {if isset($footerMenus) && count($footerMenus) > 0}
{foreach footerMenus as $menu} {foreach footerMenus as $menu}
{php} {php}
$aHref = 'javascript:;'; $aHref = getUri($menu);
if (!empty($menu['url'])) { $aHref = empty($aHref) ? 'javascript:;' : $aHref;
$aHref = $menu['url'];
} elseif ($menu['is_index']) {
$aHref = url('/');
} elseif (!empty($menu['template_list'])) {
$aHref = url('/'.$menu['template_list'].'/'.$menu['id']);
} elseif (!empty($menu['template'])) {
$aHref = url('/'.$menu['template'].'/'.$menu['id']);
}
{/php} {/php}
<a href="{$aHref}">{$menu['title']}</a> <a href="{$aHref}">{$menu['title']}</a>
{/foreach} {/foreach}

View File

@ -8,21 +8,15 @@ function getMenus($menus, $level = 1, $currentFirstId, $categoryId) {
if($level > 1) { if($level > 1) {
$menuHtml .= '<div class="'.$navClass.'" >'; $menuHtml .= '<div class="'.$navClass.'" >';
} }
foreach ($menus as $menu) { foreach ($menus as $menu) {
$activeClass = ''; $activeClass = '';
$aHref = 'javascript:;';
if ($currentFirstId == $menu['id'] || $categoryId == $menu['id'] || ($currentFirstId == 0 && $menu['is_index'])) { if ($currentFirstId == $menu['id'] || $categoryId == $menu['id'] || ($currentFirstId == 0 && $menu['is_index'])) {
$activeClass = ' active'; $activeClass = ' active';
} }
if (!empty($menu['url'])) { $aHref = getUri($menu);
$aHref = $menu['url']; $aHref = empty($aHref) ? 'javascript:;' : $aHref;
} elseif ($menu['is_index']) {
$aHref = url('/');
} elseif (!empty($menu['template_list'])) {
$aHref = url('/'.$menu['template_list'].'/'.$menu['id']);
} elseif (!empty($menu['template'])) {
$aHref = url('/'.$menu['template'].'/'.$menu['id']);
}
if($level == 1) { if($level == 1) {
$menuHtml .= '<li class="'.$activeClass.'" >'; $menuHtml .= '<li class="'.$activeClass.'" >';
$menuHtml .= '<span><a href="'.$aHref.'" target="'.$menu['style'].'">'.$menu['title'].'</a></span>'; $menuHtml .= '<span><a href="'.$aHref.'" target="'.$menu['style'].'">'.$menu['title'].'</a></span>';