static.assets.iartisan.plugins.lib.bodyTab.js Maven / Gradle / Ivy
The newest version!
/*
@Author: 驊驊龔頾
@Time: 2017-10
@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"){
data = JSON.parse(strData); //部分用户解析出来的是字符串,转换一下
}else{
data = strData;
}
var ulHtml = '';
for(var i=0;i';
}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 += ''+data[i].icon+'';
}
}
ulHtml += ''+data[i].title+'';
ulHtml += '';
ulHtml += '';
ulHtml += '';
for(var j=0;j';
}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 += ''+data[i].children[j].icon+'';
}
}
ulHtml += ''+data[i].children[j].title+'
';
}
ulHtml += "
";
}else{
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(menus)).height($(window).height()-210);
element.init(); //初始化页面元素
$(window).resize(function(){
$(".navBar").height($(window).height()-210);
})
}
//是否点击窗口切换刷新页面
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 :"