/*
@Author:
@Time: 2018-04
@Tittle: bodyTab
@Description: 点击对应按钮添加新窗口
*/
var tabFilter,menu=[],liIndex,curNav,delMenu,
changeRefreshStr = window.sessionStorage.getItem("changeRefresh");
layui.define(["element","jquery"],function(exports){
var element = layui.element,
$ = layui.$,
layId,
Tab = function(){
this.tabConfig = {
openTabNum : undefined, //最大可打开窗口数量
tabFilter : "bodyTab", //添加窗口的filter
url : undefined //获取菜单json地址
}
};
//生成左侧菜单
Tab.prototype.navBar = function(strData){
var data;
if(typeof(strData) == "string"){
var data = JSON.parse(strData); //部分用户解析出来的是字符串,转换一下
}else{
data = strData;
}
var ulHtml = '';
for (var i = 0; i < data.length; i++) {
//第一个处于打开状态
if(i==0)
{
ulHtml += '
';
}
else
{
if (data[i].spread!="false" || data[i].spread == undefined) {
ulHtml += '';
}else{
ulHtml += '';
}
}
if(data[i].children != undefined && data[i].children.length > 0){
ulHtml += '';
if(data[i].icon != undefined && data[i].icon != ''){
if(data[i].icon.indexOf("icon-") != -1){
ulHtml += '';
}else{
ulHtml += '';
}
}
ulHtml += ''+data[i].title+'';
ulHtml += '';
ulHtml += '';
if (i == 0) {
ulHtml += '';
}
else {
//ulHtml += '';
ulHtml += '';
}
for (var j = 0; j < data[i].children.length; j++) {
var flowtype = data[i].children[j].flowtype == null || data[i].children[j].flowtype == "" ? "0" : data[i].children[j].flowtype;
var dataUrl = flowtype == "0" ? data[i].children[j].href : data[i].children[j].id
if (data[i].children[j].target == "_blank") {
ulHtml += '- ';
}else{
ulHtml += '
- ';
}
if(data[i].children[j].icon != undefined && data[i].children[j].icon != ''){
if(data[i].children[j].icon.indexOf("icon-") != -1){
ulHtml += '';
}else{
ulHtml += '';
}
}
ulHtml += ''+data[i].children[j].title+'
';
}
ulHtml += "
";
}else{
var flowtype = data[i].flowtype == null || "" ? "0" : data[i].flowtype;
var dataUrl = flowtype == "0" ? data[i].href : data[i].id
if (data[i].target == "_blank") {
ulHtml += '';
}else{
ulHtml += '';
}
if(data[i].icon != undefined && data[i].icon != ''){
if(data[i].icon.indexOf("icon-") != -1){
ulHtml += '';
}else{
ulHtml += ''; //' + data[i].icon + '
}
}
ulHtml += ''+data[i].title+'';
}
ulHtml += '
';
}
return ulHtml;
}
//获取二级菜单数据
Tab.prototype.render = function() {
//显示左侧菜单
var _this = this;
$(".navBar ul").html('').append(_this.navBar(dataStr)).height($(window).height()-82);
element.init(); //初始化页面元素
$(window).resize(function(){
$(".navBar").height($(window).height()-82);
})
}
//是否点击窗口切换刷新页面
Tab.prototype.changeRegresh = function(index){
if(changeRefreshStr == "true"){
$(".clildFrame .layui-tab-item").eq(index).find("iframe")[0].contentWindow.location.reload();
}
}
//参数设置
Tab.prototype.set = function(option) {
var _this = this;
$.extend(true, _this.tabConfig, option);
return _this;
};
//通过title获取lay-id
Tab.prototype.getLayId = function(title){
$(".layui-tab-title.top_tab li").each(function(){
if($(this).find("cite").text() == title){
layId = $(this).attr("lay-id");
}
})
return layId;
}
//通过title判断tab是否存在
Tab.prototype.hasTab = function(title){
var tabIndex = -1;
$(".layui-tab-title.top_tab li").each(function(){
if($(this).find("cite").text() == title){
tabIndex = 1;
}
})
return tabIndex;
}
//右侧内容tab操作
var tabIdIndex = 0;
Tab.prototype.tabAdd = function(_this){
if(window.sessionStorage.getItem("menu")){
menu = JSON.parse(window.sessionStorage.getItem("menu"));
}
var that = this;
var openTabNum = that.tabConfig.openTabNum;
tabFilter = that.tabConfig.tabFilter;
if(_this.attr("target") == "_blank"){
window.open(_this.attr("data-url"));
}else if(_this.attr("data-url") != undefined){
var title = '';
if(_this.find("i.seraph,i.layui-icon").attr("data-icon") != undefined){
if(_this.find("i.seraph").attr("data-icon") != undefined){
title += '';
}else{
title += ''+_this.find("i.layui-icon").attr("data-icon")+'';
}
}
//已打开的窗口中不存在
if(that.hasTab(_this.find("cite").text()) == -1 && _this.siblings("dl.layui-nav-child").length == 0){
if($(".layui-tab-title.top_tab li").length == openTabNum){
layer.msg('只能同时打开'+openTabNum+'个选项卡哦。不然系统会卡的!');
return;
}
tabIdIndex++;
title += ''+_this.find("cite").text()+'';
title += 'ဆ';
element.tabAdd(tabFilter, {
title : title,
content :"