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

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'] ?? '');
}
//新闻列表
public function news($categoryId)
{
dump('新闻资讯');
dump($categoryId);
}
//新闻详情
public function newsDetail($newsId)
{
dump('新闻资讯详情');
dump($newsId);
}
// 产品列表
public function product($categoryId)
{
dump('产品列表');
dump($categoryId);
}
// 产品列表
public function productDetail($productId)
{
dump('产品详情');
dump($productId);
}
// //新闻列表
// public function news($categoryId)
// {
// dump('新闻资讯');
// dump($categoryId);
//
// }
//
// //新闻详情
// public function newsDetail($newsId)
// {
// dump('新闻资讯详情');
// dump($newsId);
// }
//
// // 产品列表
//// public function product($categoryId)
//// {
//// dump('产品列表');
//// dump($categoryId);
//// }
//
// // 产品列表
// public function productDetail($productId)
// {
// dump('产品详情');
// dump($productId);
// }
}

View File

@ -8,38 +8,25 @@ class Page extends Base
private function getPageCommonData($categoryId)
{
$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;
}
// 默认单页页面
public function index($categoryId)
{
$resp = $this->getPageCommonData($categoryId);
if(!$resp) {
return $this->error('错误页面');
$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 {
return $this->error('页面错误');
}
return $this->view($this->data['category']['template_detail']);
}
// 营销页面
public function marketing($categoryId)
{
$resp = $this->getPageCommonData($categoryId);
if(!$resp) {
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;
$this->data['blocks'] = Block::getByCategoryId($categoryId);
return $this->view($category['template_detail']);
}
}

View File

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

View File

@ -11,13 +11,9 @@
use think\facade\Route;
Route::get('article/:id', "article/detail");
Route::get('articles/:categoryId', "article/index");
Route::get('page/:categoryId', "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");
Route::get('articles/:category_id', "article/index");
Route::get('page/:category_id', "page/index");

4
runtime/.gitignore vendored
View File

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

View File

@ -34,7 +34,7 @@
<p>{$product['summary']|raw}</p>
</div>
<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>
</div>
</div>
@ -49,7 +49,7 @@
<div class="w-1500">
<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>
<a href="{:url('/marketing/'.$marketingCId)}">了解详情+</a>
<a href="{:url('article/index', ['categoryId'=>$marketingCId])}">了解详情+</a>
</div>
</div>
</div>
@ -62,7 +62,7 @@
{if isset($newsEnterprises) && count($newsEnterprises) > 0}
{foreach $newsEnterprises as $news}
<li>
<a href="{:url('article/newsDetail', ['newsId'=>$news['id']])}">
<a href="{:url('article/detail', ['id'=>$news['id']])}">
<span>{$news['title']|raw}</span>
<i>{$news['create_time']|date='Y-m-d'}</i>
</a>
@ -75,7 +75,7 @@
{if isset($newsIndustries) && count($newsIndustries) > 0}
{foreach $newsIndustries as $news}
<li>
<a href="{:url('article/newsDetail', ['newsId'=>$news['id']])}">
<a href="{:url('article/detail', ['id'=>$news['id']])}">
<span>{$news['title']|raw}</span>
<i>{$news['create_time']|date='Y-m-d'}</i>
</a>

View File

@ -6,16 +6,8 @@
{if isset($footerMenus) && count($footerMenus) > 0}
{foreach footerMenus as $menu}
{php}
$aHref = 'javascript:;';
if (!empty($menu['url'])) {
$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']);
}
$aHref = getUri($menu);
$aHref = empty($aHref) ? 'javascript:;' : $aHref;
{/php}
<a href="{$aHref}">{$menu['title']}</a>
{/foreach}

View File

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