二级菜单栏完善,接下来做后端渲染seo优化

deploy
a74589669 2019-08-24 00:38:04 +08:00
parent 0f0b0ec0b8
commit 30c3da8799
6 changed files with 63 additions and 57 deletions

View File

@ -34,10 +34,16 @@ class Doc extends Model
return $result;
}
public function docs($id){
$result = [];
if(is_integer($id)){
$db = static::getDB();
$stmt = $db->query('select title from doc where type = '.$id);
$result = $stmt->fetchAll();
$stmt = $db->query('select id,title from doc where type = '.$id);
$recv = $stmt->fetchAll();
foreach ($recv as $key => $value){
$s['id']= $value['id'];
$s['title']= $value['title'];
array_push($result,$s);
}
return $result;
}
}

View File

@ -27,7 +27,7 @@
bottom: auto;
left: 0px;
right: 0px;
width: 800px;
width: 820px;
height: 50px;
z-index: 0;
padding: 24px 0px 0px 0px;
@ -103,15 +103,7 @@
<!--寧섬꽉데-->
<ul class="navMenu" id="navMenu">
<!--꽉데淃-->
<li>
<!--arrow类给具有下级菜单项添加箭头图标-->
<a href="#" class="arrow">分类1</a>
<!--子菜单-->
<ul class="subMenu">
<li><a href="#">分类1</a></li>
<li><a href="#">分类1</a></li>
</ul>
</li>
</ul>
</ul>

View File

@ -5,6 +5,8 @@
width: 110px;
height: 100%;
padding-left: 4px;
padding-right: 10px;
background: #0b58a2;
border: #0b93d5 solid 1px;
border-radius: 1px;
@ -35,6 +37,7 @@ ul.navMenu{
text-decoration: none;
color: #f5f8f9;
border-top: 1px solid #222932;
text-align: center;
}
.navMenu>li.active>a,
@ -42,10 +45,11 @@ ul.navMenu{
.subMenu>li.active>a,
.subMenu>li>a:hover {
color: #f5f8f9;
background: #79c9ec;
cursor:default
}
.subMenu>li>a {
text-align: center;
display: block;
line-height: 36px;
font-size: 10px;
@ -60,7 +64,9 @@ ul.subMenu {
}
.subMenu>li>a {
padding-left: 20px;
padding-left: 0px;
padding-right: 30px;
}
a.arrow:after {

View File

@ -1,30 +0,0 @@
$(function() {
//初始化
$('.subMenu').hide();
$('li.active>.subMenu').show();
//给菜单项添加事件
$('.navMenu a').click(function() {
//获取所属列表ul
var $subMenuElement = $(this).next();
var $liElement = $(this).parent();
var $ulElement = $(this).parent().parent();
//没有子菜单,则直接返回
if (!$subMenuElement.is('ul')) {
$ulElement.find('li').removeClass('active');
$ulElement.find('ul.subMenu').slideUp();
$liElement.addClass('active');
return;
}
//如果存在子菜单,则打开或者关闭
if (!$liElement.hasClass('active')) {
$ulElement.find('li').removeClass('active');
$ulElement.find('ul.subMenu').slideUp();
$liElement.addClass('active');
$subMenuElement.slideDown();
} else {
//打开状态 则关闭本菜单
$subMenuElement.slideUp();
$liElement.removeClass('active');
}
});
});

View File

@ -1,5 +1,38 @@
console.log("shit2");
function updateMenu(){
//初始化
$('.subMenu').hide();
$('li.active>.subMenu').show();
//给菜单项添加事件
$('.navMenu a').click(function() {
//获取所属列表ul
var $subMenuElement = $(this).next();
var $liElement = $(this).parent();
var $ulElement = $(this).parent().parent();
//没有子菜单,则直接返回
if (!$subMenuElement.is('ul')) {
$ulElement.find('li').removeClass('active');
$ulElement.find('ul.subMenu').slideUp();
$liElement.addClass('active');
return;
}
//如果存在子菜单,则打开或者关闭
if (!$liElement.hasClass('active')) {
$ulElement.find('li').removeClass('active');
$ulElement.find('ul.subMenu').slideUp();
$liElement.addClass('active');
$subMenuElement.slideDown();
} else {
//打开状态 则关闭本菜单
$subMenuElement.slideUp();
$liElement.removeClass('active');
}
});
}
$(function() {
updateMenu();
});
$(document).ready(
function () {
console.log("test");
@ -18,7 +51,7 @@ $(document).ready(
console.log(obj);
Object.keys(obj).forEach(function (key) {
//$("#navMenu").style.border = "3px solid green";
$("#navMenu").append('<li id="doc_type_' + key + '"><a href="#" id="arrow_' + key + '">' + obj[key] + '</a></li>');
$("#navMenu").append('<li id="doc_type_' + key + '"><a href="#" id="arrow' + '">' + obj[key] + '</a></li>');
// 获取每种分组下的文章列表
$.ajax({
method: "POST",
@ -31,15 +64,20 @@ $(document).ready(
//xhr.setRequestHeader("x-requested-with","DESKTOP_WEB");
},
success: function (data) {
objs = data['data'];
// 获取每种分类
if (data['code'] == 200) {
// 每个子类下再添加文章内容
$("#doc_type_" + key).append('<ul class="subMenu" id = "type_id_' + key
+ '" style="display: none"></ul>');
Object.keys(objs).forEach(function (doc_id) {
$("#type_id_" + key).append('<li><a>'+ objs[doc_id].title + '</a></li>');
console.log(doc_id,objs[doc_id].title);
})
/*<ul class="subMenu">
<li><a href="#">分类1</a></li>
<li><a href="#">分类1</a></li>
</ul>*/
//obj = JSON.parse(data['data']);
$("#arrow_" + key).append('<ul class="subMenu"> </ul>');
}
}
}
@ -48,5 +86,6 @@ $(document).ready(
}
}
})
}
updateMenu();
}
);

View File

@ -1,25 +1,20 @@
<?php
/**
* Front controller
*
* PHP version 7.0
*/
/**
* Composer
*/
require dirname(__DIR__) . '/vendor/autoload.php';
require dirname(__DIR__) . '/App/Config.php';
/**
* Error and Exception handling
*/
error_reporting(E_ALL);
set_error_handler('Core\Error::errorHandler');
set_exception_handler('Core\Error::exceptionHandler');
/**
* Routing
*/
@ -34,9 +29,7 @@ try{
header('Access-Control-Allow-Origin:*');
header('Access-Control-Allow-Methods:OPTIONS, GET, POST'); // 允许optiongetpost请求
header('Access-Control-Allow-Headers:x-requested-with'); // 允许x-requested-with请求头
header('Access-Control-Allow-Headers:x-ijt'); // 允许x-requested-with请求头
header('Access-Control-Allow-Headers:content-type'); // 允许x-requested-with请求头
header('Access-Control-Allow-Headers:content-type,x-ijt'); // 允许x-requested-with请求头
//$this->_rsp();
print "";
return;