var $, tab, dataStr, layer; layui.config({ base: "js/" }).extend({ "bodyTab": "bodyTab" }) layui.use(['bodyTab', 'form', 'element', 'layer', 'jquery'], function () { var form = layui.form, element = layui.element; $ = layui.$; if (window.sessionStorage.getItem("userInfo") != null) { //alert(sessionStorage.getItem('UserName')); getUserInfo(); //通过顶部菜单获取左侧二三级菜单 注:此处只做演示之用,实际开发中通过接口传参的方式获取导航数据 getData(); } else { var fy_root_c_cookie = $.cookie("fy_root_cookie"); console.log(fy_root_c_cookie); var fy_root_c_cookie_json = ""; if (fy_root_c_cookie != undefined) { fy_root_c_cookie_json = JSON.parse(fy_root_c_cookie) } if (typeof fy_root_c_cookie == 'string') { // if (fy_root_c_cookie != "" && fy_root_c_cookie != null && typeof fy_root_c_cookie == 'string') { // var fy_root_c_cookie_json = JSON.parse(fy_root_c_cookie) $.post("../ashx/SysUserHandler.ashx", { Action: "UserInfo2", UsersUid: fy_root_c_cookie_json.usersUid, random: new Date().getTime()//随机参数 }, function (res) { console.log(res); if (res.code == 1) { window.sessionStorage.setItem("userInfo", JSON.stringify(res.data)); //判断登录 if ($.cookie(".SessionCookie") == undefined || $.cookie(".SessionCookie") == null || $.cookie(".SessionCookie") == "null") { window.location.href = "login/index.html"; return false; } else { getUserInfo(); getData(); } } else { alert(res.msg); } }); } else { alert("您未登录或登录超时请登录后使用"); window.location.href = "homelogin/login.html"; } } function getUserInfo() { if (window.sessionStorage.getItem("userInfo") != null && window.sessionStorage.getItem("userInfo") != "null" && window.sessionStorage.getItem("userInfo") != undefined) { var userInfo = JSON.parse(window.sessionStorage.getItem("userInfo")); //$(".UserName").html(userInfo.USERS_NAME); $(".UserName").html("账户名:" + userInfo.USERS_NAME); $("#index_main_iframe").attr('src', 'main.html'); } else { //获取信息 $.post("../../ashx/SysUserHandler.ashx", { Action: "UserInfo" }, function (res) { if (res.code == 1) { $(".UserName").html("账户名:" + res.data.USERS_NAME); window.sessionStorage.setItem("userInfo", JSON.stringify(res.data)); $("#index_main_iframe").attr('src', 'main.html'); } else { } }); } } layer = parent.layer === undefined ? layui.layer : top.layer; tab = layui.bodyTab({ openTabNum: "50", //最大可打开窗口数量 url: "json/navs.json" //获取菜单json地址 }); //获取左侧菜单 function getData() { $.post("ashx/MenuHandler.ashx", { Action: "GetUserMenu", random: new Date().getTime()//随机参数 }, function (data) { dataStr = data; tab.render(); }); } //页面加载时判断左侧菜单是否显示 //通过顶部菜单获取左侧菜单 $(".topLevelMenus li,.mobileTopLevelMenus dd").click(function () { if ($(this).parents(".mobileTopLevelMenus").length != "0") { $(".topLevelMenus li").eq($(this).index()).addClass("layui-this").siblings().removeClass("layui-this"); } else { $(".mobileTopLevelMenus dd").eq($(this).index()).addClass("layui-this").siblings().removeClass("layui-this"); } $(".layui-layout-admin").removeClass("showMenu"); $("body").addClass("site-mobile"); getData(); //渲染顶部窗口 //tab.tabMove(); }) //隐藏左侧导航 $(".hideMenu").click(function () { if ($(".topLevelMenus li.layui-this a").data("url")) { layer.msg("此栏目状态下左侧菜单不可展开"); //主要为了避免左侧显示的内容与顶部菜单不匹配 return false; } $(".layui-layout-admin").toggleClass("showMenu"); //渲染顶部窗口 tab.tabMove(); }) //通过顶部菜单获取左侧二三级菜单 注:此处只做演示之用,实际开发中通过接口传参的方式获取导航数据 getData(); // 添加新窗口 $("body").on("click", ".layui-nav .layui-nav-item a:not('.mobileTopLevelMenus .layui-nav-item a')", function () { //如果不存在子级 if ($(this).siblings().length == 0) { addTab($(this)); $('body').removeClass('site-mobile'); //移动端点击菜单关闭菜单层 } $(this).parent("li").siblings().removeClass("layui-nav-itemed"); }) //刷新后还原打开的窗口 if (cacheStr == "true") { if (window.sessionStorage.getItem("menu") != null) { menu = JSON.parse(window.sessionStorage.getItem("menu")); curmenu = window.sessionStorage.getItem("curmenu"); var openTitle = ''; for (var i = 0; i < menu.length; i++) { openTitle = ''; if (menu[i].icon) { if (menu[i].icon.split("-")[0] == 'icon') { openTitle += ''; } else { openTitle += '' + menu[i].icon + ''; } } openTitle += '' + menu[i].title + ''; openTitle += ''; element.tabAdd("bodyTab", { title: openTitle, content: "