调试菜单状态问题
This commit is contained in:
parent
ce23f8933e
commit
af5087aba8
|
|
@ -1,27 +1,41 @@
|
|||
initMenu();
|
||||
function initMenu(){
|
||||
function getIsCheckFun(list) {
|
||||
if (list && list.length > 0) {
|
||||
list.forEach((e) => {
|
||||
if (e.isCheck == 1) {
|
||||
console.log("有待审数据", e);
|
||||
}
|
||||
if (e.child && e.child.length > 0) {
|
||||
getIsCheckFun(e.child);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
function initMenu() {
|
||||
$.ajax({
|
||||
url: ctxPath + "/permissions/current",
|
||||
type:"get",
|
||||
async:false,
|
||||
success:function(data){
|
||||
if(!$.isArray(data)){
|
||||
location.href=ctxPath + '/login.html';
|
||||
type: "get",
|
||||
async: false,
|
||||
success: function (data) {
|
||||
if (!$.isArray(data)) {
|
||||
location.href = ctxPath + "/login.html";
|
||||
return;
|
||||
}
|
||||
var menu = $("#menu");
|
||||
$.each(data, function(i,item){
|
||||
$.each(data, function (i, item) {
|
||||
var a = $("<a href='javascript:;'></a>");
|
||||
|
||||
var css = item.css;
|
||||
if(css!=null && css!=""){
|
||||
a.append("<i aria-hidden='true' class='fa " + css +"'></i>");
|
||||
if (css != null && css != "") {
|
||||
a.append(
|
||||
"<i aria-hidden='true' class='fa " + css + "'></i>"
|
||||
);
|
||||
}
|
||||
a.append("<cite>"+item.name+"</cite>");
|
||||
a.append("<cite>" + item.name + "</cite>");
|
||||
a.attr("lay-id", item.id);
|
||||
|
||||
var href = item.href;
|
||||
if(href != null && href != ""){
|
||||
if (href != null && href != "") {
|
||||
a.attr("data-url", href);
|
||||
}
|
||||
|
||||
|
|
@ -33,26 +47,27 @@ function initMenu(){
|
|||
menu.append(li);
|
||||
|
||||
//多级菜单
|
||||
setChild(li, item.child)
|
||||
|
||||
setChild(li, item.child);
|
||||
});
|
||||
}
|
||||
// 递归获取菜单状态
|
||||
getIsCheckFun(data);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
function setChild(parentElement, child){
|
||||
if(child != null && child.length > 0){
|
||||
$.each(child, function(j,item2){
|
||||
function setChild(parentElement, child) {
|
||||
if (child != null && child.length > 0) {
|
||||
$.each(child, function (j, item2) {
|
||||
var ca = $("<a href='javascript:;'></a>");
|
||||
ca.attr("data-url", item2.href);
|
||||
ca.attr("lay-id", item2.id);
|
||||
|
||||
var css2 = item2.css;
|
||||
if(css2!=null && css2!=""){
|
||||
ca.append("<i aria-hidden='true' class='fa " + css2 +"'></i>");
|
||||
if (css2 != null && css2 != "") {
|
||||
ca.append("<i aria-hidden='true' class='fa " + css2 + "'></i>");
|
||||
}
|
||||
|
||||
ca.append("<cite>"+item2.name+"</cite>");
|
||||
ca.append("<cite>" + item2.name + "</cite>");
|
||||
|
||||
var dd = $("<dd></dd>");
|
||||
dd.append(ca);
|
||||
|
|
@ -70,12 +85,12 @@ function setChild(parentElement, child){
|
|||
|
||||
// 登陆用户头像昵称
|
||||
showLoginInfo();
|
||||
function showLoginInfo(){
|
||||
function showLoginInfo() {
|
||||
$.ajax({
|
||||
type : 'get',
|
||||
url : ctxPath + '/users/current',
|
||||
async : false,
|
||||
success : function(data) {
|
||||
type: "get",
|
||||
url: ctxPath + "/users/current",
|
||||
async: false,
|
||||
success: function (data) {
|
||||
$(".admin-header-user span").text(data.nickname);
|
||||
|
||||
var pro = window.location.protocol;
|
||||
|
|
@ -84,8 +99,8 @@ function showLoginInfo(){
|
|||
|
||||
var sex = data.sex;
|
||||
var url = data.headImgUrl;
|
||||
if(url == null || url == ""){
|
||||
if(sex == 1){
|
||||
if (url == null || url == "") {
|
||||
if (sex == 1) {
|
||||
url = ctxPath + "/img/avatars/sunny.png";
|
||||
} else {
|
||||
url = ctxPath + "/img/avatars/1.png";
|
||||
|
|
@ -97,61 +112,69 @@ function showLoginInfo(){
|
|||
}
|
||||
var img = $(".admin-header-user img");
|
||||
img.attr("src", url);
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
function logout(){
|
||||
function logout() {
|
||||
$.ajax({
|
||||
type : 'get',
|
||||
url : ctxPath + '/logout',
|
||||
success : function(data) {
|
||||
type: "get",
|
||||
url: ctxPath + "/logout",
|
||||
success: function (data) {
|
||||
localStorage.removeItem("token");
|
||||
location.href= ctxPath + '/login.html';
|
||||
}
|
||||
location.href = ctxPath + "/login.html";
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
var active;
|
||||
|
||||
layui.use(['layer', 'element'], function() {
|
||||
layui.use(["layer", "element"], function () {
|
||||
var $ = layui.jquery,
|
||||
layer = layui.layer;
|
||||
var element = layui.element; //导航的hover效果、二级菜单等功能,需要依赖element模块
|
||||
element.on('nav(demo)', function(elem){
|
||||
element.on("nav(demo)", function (elem) {
|
||||
//layer.msg(elem.text());
|
||||
});
|
||||
|
||||
//触发事件
|
||||
active = {
|
||||
tabAdd: function(obj){
|
||||
tabAdd: function (obj) {
|
||||
var lay_id = $(this).attr("lay-id");
|
||||
var title = $(this).html() + '<i class="layui-icon" data-id="' + lay_id + '"></i>';
|
||||
var title =
|
||||
$(this).html() +
|
||||
'<i class="layui-icon" data-id="' +
|
||||
lay_id +
|
||||
'"></i>';
|
||||
//新增一个Tab项
|
||||
element.tabAdd('admin-tab', {
|
||||
element.tabAdd("admin-tab", {
|
||||
title: title,
|
||||
content: '<iframe src="' + $(this).attr('data-url') + '"></iframe>',
|
||||
id: lay_id
|
||||
content:
|
||||
'<iframe src="' + $(this).attr("data-url") + '"></iframe>',
|
||||
id: lay_id,
|
||||
});
|
||||
element.tabChange("admin-tab", lay_id);
|
||||
},
|
||||
tabDelete: function(lay_id){
|
||||
tabDelete: function (lay_id) {
|
||||
element.tabDelete("admin-tab", lay_id);
|
||||
},
|
||||
tabChange: function(lay_id){
|
||||
element.tabChange('admin-tab', lay_id);
|
||||
}
|
||||
tabChange: function (lay_id) {
|
||||
element.tabChange("admin-tab", lay_id);
|
||||
},
|
||||
};
|
||||
//添加tab
|
||||
$(document).on('click','a',function(){
|
||||
if(!$(this)[0].hasAttribute('data-url') || $(this).attr('data-url')===''){
|
||||
$(document).on("click", "a", function () {
|
||||
if (
|
||||
!$(this)[0].hasAttribute("data-url") ||
|
||||
$(this).attr("data-url") === ""
|
||||
) {
|
||||
return;
|
||||
}
|
||||
var tabs = $(".layui-tab-title").children();
|
||||
var lay_id = $(this).attr("lay-id");
|
||||
|
||||
for(var i = 0; i < tabs.length; i++) {
|
||||
if($(tabs).eq(i).attr("lay-id") == lay_id) {
|
||||
for (var i = 0; i < tabs.length; i++) {
|
||||
if ($(tabs).eq(i).attr("lay-id") == lay_id) {
|
||||
active.tabChange(lay_id);
|
||||
return;
|
||||
}
|
||||
|
|
@ -161,54 +184,56 @@ layui.use(['layer', 'element'], function() {
|
|||
});
|
||||
|
||||
//iframe自适应
|
||||
function resize(){
|
||||
var $content = $('.admin-nav-card .layui-tab-content');
|
||||
function resize() {
|
||||
var $content = $(".admin-nav-card .layui-tab-content");
|
||||
$content.height($(this).height() - 147);
|
||||
$content.find('iframe').each(function() {
|
||||
$content.find("iframe").each(function () {
|
||||
$(this).height($content.height());
|
||||
});
|
||||
}
|
||||
$(window).on('resize', function() {
|
||||
var $content = $('.admin-nav-card .layui-tab-content');
|
||||
$(window)
|
||||
.on("resize", function () {
|
||||
var $content = $(".admin-nav-card .layui-tab-content");
|
||||
$content.height($(this).height() - 147);
|
||||
$content.find('iframe').each(function() {
|
||||
$content.find("iframe").each(function () {
|
||||
$(this).height($content.height());
|
||||
});
|
||||
}).resize();
|
||||
})
|
||||
.resize();
|
||||
|
||||
//toggle左侧菜单
|
||||
$('.admin-side-toggle').on('click', function() {
|
||||
var sideWidth = $('#admin-side').width();
|
||||
if(sideWidth === 200) {
|
||||
$('#admin-body').animate({
|
||||
left: '0'
|
||||
$(".admin-side-toggle").on("click", function () {
|
||||
var sideWidth = $("#admin-side").width();
|
||||
if (sideWidth === 200) {
|
||||
$("#admin-body").animate({
|
||||
left: "0",
|
||||
});
|
||||
$('#admin-footer').animate({
|
||||
left: '0'
|
||||
$("#admin-footer").animate({
|
||||
left: "0",
|
||||
});
|
||||
$('#admin-side').animate({
|
||||
width: '0'
|
||||
$("#admin-side").animate({
|
||||
width: "0",
|
||||
});
|
||||
} else {
|
||||
$('#admin-body').animate({
|
||||
left: '200px'
|
||||
$("#admin-body").animate({
|
||||
left: "200px",
|
||||
});
|
||||
$('#admin-footer').animate({
|
||||
left: '200px'
|
||||
$("#admin-footer").animate({
|
||||
left: "200px",
|
||||
});
|
||||
$('#admin-side').animate({
|
||||
width: '200px'
|
||||
$("#admin-side").animate({
|
||||
width: "200px",
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
//手机设备的简单适配
|
||||
var treeMobile = $('.site-tree-mobile'),
|
||||
shadeMobile = $('.site-mobile-shade');
|
||||
treeMobile.on('click', function () {
|
||||
$('body').addClass('site-mobile');
|
||||
var treeMobile = $(".site-tree-mobile"),
|
||||
shadeMobile = $(".site-mobile-shade");
|
||||
treeMobile.on("click", function () {
|
||||
$("body").addClass("site-mobile");
|
||||
});
|
||||
shadeMobile.on('click', function () {
|
||||
$('body').removeClass('site-mobile');
|
||||
shadeMobile.on("click", function () {
|
||||
$("body").removeClass("site-mobile");
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -61,6 +61,8 @@
|
|||
var pers = checkPermission();
|
||||
initMenuList();
|
||||
|
||||
|
||||
|
||||
function initMenuList() {
|
||||
$.ajax({
|
||||
type: 'get',
|
||||
|
|
@ -107,8 +109,7 @@
|
|||
tr += "</tr>"
|
||||
$("#dt-table").append(tr);
|
||||
}
|
||||
// 递归获取菜单状态
|
||||
getIsCheckFun(data)
|
||||
|
||||
|
||||
}
|
||||
});
|
||||
|
|
@ -146,18 +147,7 @@
|
|||
|
||||
$("#dt-table").treetable(option);
|
||||
|
||||
function getIsCheckFun(list) {
|
||||
if (list && list.length > 0) {
|
||||
list.forEach((e) => {
|
||||
if (e.isCheck === 1) {
|
||||
console.log('有待审数据', e)
|
||||
}
|
||||
if (e.child && e.child.length > 0) {
|
||||
getIsCheckFun(e.child)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
</script>
|
||||
Loading…
Reference in New Issue