修改menu请求方式

v1.0
bobi 2019-05-18 19:45:12 +08:00
parent 79c45ee16d
commit e81a4370ad
4 changed files with 331 additions and 220 deletions

View File

@ -2,241 +2,281 @@
"status": 1000,
"msg": "操作成功",
"data": [
{
"title": "图表管理",
"icon": "",
"href": "",
"spread": false,
"children": [
{
"title": "地图",
"fontFamily": "my-icon",
"icon": "my-iconditu",
"spread": false,
"children": [
{
"title": "中国地图",
"icon": "",
"href": "pages/echarts/mapchina2.html",
"spread": false
},
{
"title": "地区地图",
"icon": "",
"href": "pages/echarts/mapchina.html",
"spread": false
}
]
},
{
"title": "数据图",
"fontFamily": "my-icon",
"icon": "my-icontubiao",
"spread": false,
"children": [
{
"title": "统计图",
"icon": "",
"href": "pages/echarts/map1.html",
"spread": false
},
{
"title": "折线图",
"icon": "",
"href": "pages/echarts/map2.html",
"spread": false
},
{
"title": "馅饼图",
"icon": "",
"href": "pages/echarts/map4.html",
"spread": false
},
{
"title": "圆形图",
"icon": "",
"href": "pages/echarts/map5.html",
"spread": false
},
{
"title": "指数图",
"icon": "",
"href": "pages/echarts/map6.html",
"spread": false
}
]
}
]
},
{
"title": "框架使用说明",
"fontFamily": "ok-icon",
"icon": "",
"spread": false,
"children": [
{
"title": "插件目录",
"href": "pages/help/plugDirectory.html",
"spread": false
},
{
"title": "内部添加导航",
"href": "pages/help/navOperate.html",
"spread": false
},
{
"title": "导航的图标",
"href": "pages/help/navIcon.html",
"spread": false
},
{
"title": "导航的参数",
"href": "pages/help/navParameter.html",
"spread": false
}
]
},
{
"title": "第三方js库",
"icon": "",
"children": [
{
"title": "二维码",
"href": "pages/tripartite/qrcode.html"
}
]
},
{
"title": "会员管理",
"icon": "",
"href": "",
"spread": false,
"path": "",
"font": "iconfont",
"icon": "",
"spread": true,
"children": [
{
"title": "用户列表",
"fontFamily": "layui-icon",
"icon": "",
"href": "pages/user/user.html",
"path": "pages/user/user.html",
"font": "iconfont",
"icon": "",
"spread": false
},
{
"title": "角色列表",
"icon": "",
"href": "pages/role/role.html",
"path": "pages/role/role.html",
"font": "iconfont",
"icon": "",
"spread": false
},
{
"title": "权限列表",
"icon": "",
"href": "pages/permission/permission.html",
"path": "pages/permission/permission.html",
"font": "iconfont",
"icon": "",
"spread": false
}
]
},
{
"title": "新闻管理",
"icon": "",
"href": "",
"path": "",
"font": "iconfont",
"icon": "",
"spread": false,
"children": [
{
"title": "文章列表",
"fontFamily": "layui-icon",
"icon": "",
"href": "pages/article/article.html",
"title": "新闻列表",
"path": "pages/article/article.html",
"font": "iconfont",
"icon": "",
"spread": false
}
]
},
{
"title": "多级导航",
"fontFamily": "ok-icon",
"icon": "ok-iconnavigation-2",
"title": "留言管理",
"path": "",
"font": "iconfont",
"icon": "",
"spread": false,
"children": [
{
"title": "二级导航",
"href": "",
"spread": false,
"children": [
{
"title": "三级导航1",
"fontFamily": "ok-icon",
"icon": "ok-iconairplay",
"href": "pages/home.html",
"spread": false
},
{
"title": "三级导航2",
"href": "",
"spread": false,
"children": [
{
"title": "四级导航1",
"href": "",
"spread": false
},
{
"title": "四级导航2",
"href": "",
"spread": false,
"children": [
{
"title": "五级导航",
"fontFamily": "ok-icon",
"icon": "&#xe971",
"href": "",
"spread": false
},
{
"title": "五级导航",
"href": "",
"spread": false
},
{
"title": "登录",
"icon": "",
"href": "pages/login.html",
"spread": false,
"target": "_blank"
}
]
}
]
}
]
"title": "留言列表",
"path": "pages/message/message.html",
"font": "iconfont",
"icon": "",
"spread": false
}
]
},
{
"title": "下载中心",
"path": "",
"font": "iconfont",
"icon": "",
"spread": false,
"children": [
{
"title": "下载列表",
"path": "pages/download/download.html",
"font": "iconfont",
"icon": "",
"spread": false
}
]
},
{
"title": "友情链接",
"path": "",
"font": "iconfont",
"icon": "",
"spread": false,
"children": [
{
"title": "链接列表",
"path": "pages/link/link.html",
"font": "iconfont",
"icon": "",
"spread": false
}
]
},
{
"title": "产品管理",
"path": "",
"font": "iconfont",
"icon": "",
"spread": false,
"children": [
{
"title": "产品列表",
"path": "pages/product/product.html",
"font": "iconfont",
"icon": "",
"spread": false
}
]
},
{
"title": "图表页面",
"path": "",
"font": "layui-icon",
"icon": "",
"spread": false,
"children": [
{
"title": "柱状图",
"path": "pages/map/map1.html",
"font": "iconfont",
"icon": "",
"spread": false
},
{
"title": "折线图",
"path": "pages/map/map2.html",
"font": "iconfont",
"icon": "",
"spread": false
},
{
"title": "折线堆叠图",
"path": "pages/map/map3.html",
"font": "iconfont",
"icon": "",
"spread": false
},
{
"title": "饼图",
"path": "pages/map/map4.html",
"font": "iconfont",
"icon": "",
"spread": false
},
{
"title": "环形图",
"path": "pages/map/map5.html",
"font": "iconfont",
"icon": "",
"spread": false
},
{
"title": "散布图",
"path": "pages/map/map6.html",
"font": "iconfont",
"icon": "",
"spread": false
}
]
},
{
"title": "系统管理",
"icon": "",
"href": "",
"path": "",
"font": "layui-icon",
"icon": "",
"spread": false,
"children": [
{
"title": "登录",
"icon": "",
"href": "pages/login.html",
"spread": false,
"target": "_blank"
"title": "网站配置",
"path": "pages/system/system-setting.html",
"font": "iconfont",
"icon": "",
"spread": false
},
{
"title": "系统日志",
"path": "pages/system/system-log.html",
"font": "iconfont",
"icon": "",
"spread": false
},
{
"title": "屏蔽词",
"path": "pages/system/system-shield.html",
"font": "iconfont",
"icon": "",
"spread": false
}
]
},
{
"title": "框架使用",
"path": "",
"font": "iconfont",
"icon": "",
"spread": false,
"children": [
{
"title": "okTab使用",
"path": "pages/use/use-okTab.html",
"font": "iconfont",
"icon": "",
"spread": false
},
{
"title": "okLayer使用",
"path": "pages/use/use-okLayer.html",
"font": "iconfont",
"icon": "",
"spread": false
},
{
"title": "okUtils使用",
"path": "pages/use/use-okUtils.html",
"font": "iconfont",
"icon": "",
"spread": false
},
{
"title": "Layui图标",
"path": "https://www.layui.com/doc/element/icon.html",
"font": "iconfont",
"icon": "",
"spread": false
},
{
"title": "Iconfont图标",
"path": "font/demo_index.html",
"font": "iconfont",
"icon": "",
"spread": false
}
]
},
{
"title": "其他页面",
"path": "",
"font": "iconfont",
"icon": "",
"spread": false,
"children": [
{
"title": "登陆页面",
"path": "pages/use/use-okTab.html",
"font": "iconfont",
"icon": "",
"spread": false
},
{
"title": "403页面",
"icon": "",
"href": "pages/common/403.html",
"path": "pages/use/use-okLayer.html",
"font": "iconfont",
"icon": "",
"spread": false
},
{
"title": "404页面",
"icon": "",
"href": "pages/common/404.html",
"path": "pages/use/use-okUtils.html",
"font": "iconfont",
"icon": "",
"spread": false
},
{
"title": "500页面",
"icon": "",
"href": "pages/common/500.html",
"path": "https://www.layui.com/doc/element/icon.html",
"font": "iconfont",
"icon": "",
"spread": false
},
{
"title": "捐赠列表",
"path": "font/demo_index.html",
"font": "iconfont",
"icon": "",
"spread": false
}
]

View File

@ -45,6 +45,7 @@
<div class="layui-side layui-bg-black">
<div class="layui-side-scroll">
<ul class="layui-nav layui-nav-tree" lay-shrink="all" lay-filter="navFilter">
<!-- 停用
<li class="layui-nav-item layui-nav-itemed">
<a href="javascript:;">
<i class="iconfont icon-huiyuan"></i> 会员管理
@ -142,6 +143,7 @@
<dd><a href="javascript:;" path="pages/other/donate.html"><i class="iconfont icon-juanzeng"></i> 捐赠列表</a></dd>
</dl>
</li>
-->
</ul>
</div>
</div>

View File

@ -34,46 +34,78 @@ layui.config({
}
});
// TODO 加载左侧菜单
// okUtils.ajax("data/menu.json", "get").done(function (response) {
// var html = "";
// for (var i = 0; i < response.length; i++) {
// var d = response[i];
// html += "<li class='layui-nav-item'>"
// html += "<a href='javascript:;'>"
// html += "<i class='iconfont icon-huiyuan'></i> " + response[i].title;
// html += "</a>"
// if (d.children != undefined && d.children.length > 0) {
// html += "<dl class='layui-nav-child'>"
// for (var j = 0; j < d.children.length; j++) {
// html += "<dd><a href='javascript:;' path='pages/user/user.html' tab-id='1-1'><i class='iconfont icon-dianliyonghuzongshu'></i> " + d.children[j].title + "</a></dd>";
// }
// html += "</dl>"
// }
// html += "</li>";
// }
// $(".layui-nav-tree").html(html);
// element.render("nav");
// }).fail(function (error) {
// console.log(error)
// });
// TODO 无限级菜单
okUtils.ajax("data/menu.json", "get").done(function (response) {
var html = "";
for (var i = 0; i < response.length; i++) {
var d = response[i];
html += liHtml(d);
html += "<a href='javascript:;'>"
html += iconHtml(d) + " " + response[i].title;
html += "</a>"
var children = d.children;
if (children != undefined && children.length > 0) {
html += "<dl class='layui-nav-child'>"
for (var j = 0; j < children.length; j++) {
html += "<dd><a href='javascript:;' path='" + children[j].path + "'>" + iconHtml(children[j]) + " " + children[j].title + "</a></dd>";
}
html += "</dl>"
}
html += "</li>";
}
$(".layui-nav-tree").html(html);
element.render("nav");
}).fail(function (error) {
console.log(error)
});
function iconHtml(obj) {
var html = "";
if (obj.icon) {
if (obj.font == "iconfont") {
html += "<i class='iconfont'>" + obj.icon + "</i>";
} else if (obj.font == "layui-icon") {
html += "<i class='layui-icon'> " + obj.icon + "</i>";
} else {
html += "<i class='iconfont'>" + obj.icon + "</i>";
}
} else {
console.warn(obj.title, "icon未定义");
}
return html;
}
function liHtml(obj) {
var html = "";
if (obj.spread) {
html += "<li class='layui-nav-item layui-nav-itemed'>";
} else {
html += "<li class='layui-nav-item'>";
}
return html;
}
/**
* 监听导航菜单的点击
*/
// element.on("nav(navFilter)", function (elem) {
// var path = elem.context.attributes.path;
// var tabId = elem.context.attributes["tab-id"];
// var text = elem.context.innerText;
// console.log(path, tabId, text)
// });
$(".layui-nav-child").find("dd").click(function () {
var title = $(this).text();
var path = $(this).children("a").attr("path");
okTab.add(title, path)
element.on("nav(navFilter)", function (elem) {
var attrNum = elem.context.attributes.length;
if (attrNum == 2) {
// var title = elem.context.innerHTML;
var title = elem.context.innerText;
title = title.substring(title.indexOf(" "), title.length);
var path = elem.context.attributes.path.textContent;
okTab.add(title, path)
}
});
// 停用
// $(".layui-nav-child").find("dd").click(function () {
// var title = $(this).text();
// var path = $(this).children("a").attr("path");
// okTab.add(title, path)
// });
/**
* 修改copyright结束时间
*/

37
pages/use/demo.html Normal file
View File

@ -0,0 +1,37 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>demo</title>
</head>
<body>
<script>
/**
*
* @param obj
* @returns {boolean}
*/
function isEmpty(obj) {
if (obj) {
return true;
}
// if (obj && typeof obj === "string") {
// return true;
// }
// if (obj && typeof obj === "number") {
// return true;
// }
return false;
}
console.log(isEmpty());
console.log(isEmpty(null));
console.log(isEmpty(""));
console.log(isEmpty(undefined));
console.log(isEmpty("hello"));
console.log(isEmpty(10));
console.log(isEmpty(true));
console.log(isEmpty(false));
</script>
</body>
</html>