新增 pearTab.closeTab 事件,关联 SideMenu 关闭选中

develop
就眠仪式 2020-07-09 21:50:50 +08:00
parent 0fe4e75833
commit a7e41878b8
3 changed files with 19 additions and 22 deletions

View File

@ -23,7 +23,7 @@
"title": "百度一下", "title": "百度一下",
"icon": "layui-icon layui-icon-console", "icon": "layui-icon layui-icon-console",
"type": 1, "type": 1,
"openType": "_iframe", "openType": "_blank",
"href": "http://www.baidu.com" "href": "http://www.baidu.com"
}] }]
}, },

View File

@ -102,6 +102,9 @@ layui.define(['table', 'jquery', 'element', 'form', 'pearAuth', 'pearTab', 'pear
height: '100%', height: '100%',
index: 0, index: 0,
tabMax: 20, tabMax: 20,
closeEvent: function(id){
sideMenu.selectItem(id);
},
data: [{ data: [{
id: '0', id: '0',
url: option.index, url: option.index,
@ -111,7 +114,6 @@ layui.define(['table', 'jquery', 'element', 'form', 'pearAuth', 'pearTab', 'pear
}); });
bodyTab.click(function(id) { bodyTab.click(function(id) {
bodyTab.positionTab(); bodyTab.positionTab();
sideMenu.selectItem(id); sideMenu.selectItem(id);
}) })
@ -184,8 +186,6 @@ layui.define(['table', 'jquery', 'element', 'form', 'pearAuth', 'pearTab', 'pear
}, option.keepLoad) }, option.keepLoad)
} }
this.colorSet = function(color) { this.colorSet = function(color) {
var style = ''; var style = '';

View File

@ -20,7 +20,8 @@ layui.define(['jquery', 'element'], function(exports) {
index: opt.index, index: opt.index,
width: opt.width, width: opt.width,
height: opt.height, height: opt.height,
tabMax: opt.tabMax tabMax: opt.tabMax,
closeEvent: opt.closeEvent
} }
var tab = createTab(option); var tab = createTab(option);
@ -363,12 +364,10 @@ layui.define(['jquery', 'element'], function(exports) {
// 重写 Tab Delete 删除 源码存在 Bug 所以重写 // 重写 Tab Delete 删除 源码存在 Bug 所以重写
function tabDelete(elem, id) { function tabDelete(elem, id,callback) {
//根据 elem id 来删除指定的 layui title li //根据 elem id 来删除指定的 layui title li
console.log("进入");
var tabTitle = $(".layui-tab[lay-filter='" + elem + "']").find(".layui-tab-title"); var tabTitle = $(".layui-tab[lay-filter='" + elem + "']").find(".layui-tab-title");
// 删除指定 id 的 title // 删除指定 id 的 title
@ -377,15 +376,13 @@ layui.define(['jquery', 'element'], function(exports) {
var nextNode = removeTab.next("li"); var nextNode = removeTab.next("li");
console.log(nextNode.length); var currId ;
if (nextNode.length) { if (nextNode.length) {
nextNode.addClass("layui-this"); nextNode.addClass("layui-this");
var currId = nextNode.attr("lay-id"); currId = nextNode.attr("lay-id");
console.log("下:"+currId);
$("#" + elem + " [id='" + currId + "']").parent().addClass("layui-show"); $("#" + elem + " [id='" + currId + "']").parent().addClass("layui-show");
@ -395,13 +392,14 @@ layui.define(['jquery', 'element'], function(exports) {
prevNode.addClass("layui-this"); prevNode.addClass("layui-this");
var currId = prevNode.attr("lay-id"); currId = prevNode.attr("lay-id");
console.log("上:"+currId);
$("#" + elem + " [id='" + currId + "']").parent().addClass("layui-show"); $("#" + elem + " [id='" + currId + "']").parent().addClass("layui-show");
} }
callback(currId);
removeTab.remove(); removeTab.remove();
// 删除 content // 删除 content
@ -528,7 +526,7 @@ layui.define(['jquery', 'element'], function(exports) {
$(".layui-tab[lay-filter='" + option.elem + "']").on("click", ".layui-tab-close", function() { $(".layui-tab[lay-filter='" + option.elem + "']").on("click", ".layui-tab-close", function() {
var layid = $(this).parent().attr("lay-id"); var layid = $(this).parent().attr("lay-id");
tabDelete(option.elem, layid); tabDelete(option.elem, layid,option.closeEvent);
}) })
} }
@ -538,8 +536,7 @@ layui.define(['jquery', 'element'], function(exports) {
var currentTab = $(".layui-tab[lay-filter='" + option.elem + "'] .layui-tab-title .layui-this"); var currentTab = $(".layui-tab[lay-filter='" + option.elem + "'] .layui-tab-title .layui-this");
if (currentTab.find("span").is(".able-close")) { if (currentTab.find("span").is(".able-close")) {
var currentId = currentTab.attr("lay-id"); var currentId = currentTab.attr("lay-id");
tabDelete(option.elem, currentId); tabDelete(option.elem, currentId,option.closeEvent);
} }
}) })
@ -550,7 +547,7 @@ layui.define(['jquery', 'element'], function(exports) {
$.each(tabtitle, function(i) { $.each(tabtitle, function(i) {
if ($(this).attr("lay-id") != currentId) { if ($(this).attr("lay-id") != currentId) {
if ($(this).find("span").is(".able-close")) { if ($(this).find("span").is(".able-close")) {
tabDelete(option.elem, $(this).attr("lay-id")); tabDelete(option.elem, $(this).attr("lay-id"),option.closeEvent);
} }
} }
}) })
@ -562,7 +559,7 @@ layui.define(['jquery', 'element'], function(exports) {
var tabtitle = $(".layui-tab[lay-filter='" + option.elem + "'] .layui-tab-title li"); var tabtitle = $(".layui-tab[lay-filter='" + option.elem + "'] .layui-tab-title li");
$.each(tabtitle, function(i) { $.each(tabtitle, function(i) {
if ($(this).find("span").is(".able-close")) { if ($(this).find("span").is(".able-close")) {
tabDelete(option.elem, $(this).attr("lay-id")); tabDelete(option.elem, $(this).attr("lay-id"),option.closeEvent);
} }
}) })
}) })