chaoyu/view/public/menu.html

79 lines
3.0 KiB
HTML
Raw Normal View History

2020-11-25 02:32:42 +00:00
{php}
2022-01-14 03:43:21 +00:00
//dump($menus);
2020-11-25 02:32:42 +00:00
function getMenus($menus, $level = 1, $currentFirstId, $categoryId) {
$menuHtml = '';
$levelList = ['nav-first','nav-second','nav-third'];
$navClass = $levelList[$level - 1] ?? '';
2020-11-25 02:32:42 +00:00
if (count($menus) > 0) {
$menuHtml .= '';
if($level > 1) {
$menuHtml .= '<div class="'.$navClass.'" >';
}
2020-11-25 12:15:51 +00:00
2020-11-25 02:32:42 +00:00
foreach ($menus as $menu) {
$activeClass = '';
if ($currentFirstId == $menu['id'] || $categoryId == $menu['id'] || ($currentFirstId == 0 && $menu['is_index'])) {
$activeClass = ' active';
}
2020-11-25 12:15:51 +00:00
$aHref = getUri($menu);
$aHref = empty($aHref) ? 'javascript:;' : $aHref;
$spanClass = '';
$hasChild = false;
if (isset($menu['children']) && count($menu['children']) > 0) {
$hasChild = true;
$spanClass = 'class="cur"';
}
if($level == 1) {
$menuHtml .= '<li class="'.$activeClass.'" >';
$menuHtml .= '<span '.$spanClass.'><a href="'.$aHref.'" target="'.$menu['style'].'">'.$menu['title'].'</a></span>';
if ($hasChild) {
$menuHtml .= getMenus($menu['children'], $level + 1, $currentFirstId, $categoryId);
}
$menuHtml .= '</li>';
} else {
2022-01-14 03:43:21 +00:00
if($menu['template_list']=='products'){
$menuHtml .= '<a href="'.$aHref.'#product" target="'.$menu['style'].'" class="'.$activeClass.'">';
}else if($menu['template_list']=='news'){
$menuHtml .= '<a href="'.$aHref.'#news" target="'.$menu['style'].'" class="'.$activeClass.'">';
}else
{
$menuHtml .= '<a href="'.$aHref.'" target="'.$menu['style'].'" class="'.$activeClass.'">';
2022-01-14 03:43:21 +00:00
}
$menuHtml .= '<span '.$spanClass.'>'.$menu['title'].'</span>';
if ($hasChild) {
$menuHtml .= getMenus($menu['children'], $level + 1, $currentFirstId, $categoryId);
}
$menuHtml .= '</a>';
2020-11-25 02:32:42 +00:00
}
}
if($level > 1) {
$menuHtml .= '</div>';
}
2020-11-25 02:32:42 +00:00
}
return $menuHtml;
}
{/php}
<div class="head-box w-100">
<div class="w-1500">
<div class="center-block w-100 between-center">
<div class="logo center-center">
<a href="{:url('/')}"><img src="__IMG__/logo.png"></a>
</div>
<div class="nav">
<ul>
{:getMenus($menus, 1, $currentFirstId, $categoryId)}
</ul>
</div>
2020-12-01 01:16:27 +00:00
<!-- <div class="language">
<a href="" class="active">中文</a> / <a href="">English</a>
2020-12-01 01:16:27 +00:00
</div> -->
<div class="nav_btn">
<i class="bar-top"></i>
<i class="bar-cen"></i>
<i class="bar-bom"></i>
</div>
</div>
</div>
</div>