From 71c386e9a9bdd7d4dbfb0d95985e00615398bd20 Mon Sep 17 00:00:00 2001 From: sight <26325820+Sight-wcg@users.noreply.github.com> Date: Wed, 20 Nov 2024 10:37:45 +0800 Subject: [PATCH] =?UTF-8?q?feat(tab):=20=E6=96=B0=E5=A2=9E=20`lay-for`=20?= =?UTF-8?q?=E5=B1=9E=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/element.js | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/modules/element.js b/src/modules/element.js index 35d99957..6c0fb372 100644 --- a/src/modules/element.js +++ b/src/modules/element.js @@ -36,8 +36,8 @@ layui.define('jquery', function(exports){ Element.prototype.tabAdd = function(filter, options){ var tabElem = $('.layui-tab[lay-filter='+ filter +']'); var titElem = tabElem.children(TITLE); - var barElem = titElem.children('.layui-tab-bar'); - var contElem = tabElem.children('.layui-tab-content'); + var contentTarget = tabElem.attr('lay-for'); + var contElem = contentTarget ? $(contentTarget) : tabElem.children('.layui-tab-content'); var li = ''+ (options.title || 'unnaming') +''; - barElem[0] ? barElem.before(li) : titElem.append(li); + titElem.children('li').eq(-1).after(li); contElem.append('
'+ (options.content || '') +'
'); // call.hideTabMore(true); // 是否添加即切换 @@ -135,9 +135,13 @@ layui.define('jquery', function(exports){ var parents = options.headerElem ? othis.parent() : othis.parents('.layui-tab').eq(0); - var item = options.bodyElem + // 自定义 content 区域位置 + var contentTarget = parents.attr('lay-for'); + var item = options.bodyElem ? $(options.bodyElem) - : parents.children('.layui-tab-content').children('.layui-tab-item'); + : contentTarget + ? $(contentTarget).children('.layui-tab-item') + : parents.children('.layui-tab-content').children('.layui-tab-item'); var elemA = othis.find('a'); var isJump = elemA.attr('href') !== 'javascript:;' && elemA.attr('target') === '_blank'; // 是否存在跳转 var unselect = typeof othis.attr('lay-unselect') === 'string'; // 是否禁用选中 @@ -190,7 +194,10 @@ layui.define('jquery', function(exports){ var li = othis || $(this).parent(); var index = li.parent().children('li').index(li); var tabElem = li.closest('.layui-tab'); - var item = tabElem.children('.layui-tab-content').children('.layui-tab-item'); + var contentTarget = tabElem.attr('lay-for'); + var item = contentTarget + ? $(contentTarget).children('.layui-tab-item') + : tabElem.children('.layui-tab-content').children('.layui-tab-item'); var filter = tabElem.attr('lay-filter'); var hasId = li.attr('lay-id');