From 1b9557cdd815fa0a497d329c305e269b7e4677bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B4=A4=E5=BF=83?= <3277200+sentsim@users.noreply.github.com> Date: Tue, 13 May 2025 00:19:59 +0800 Subject: [PATCH] =?UTF-8?q?feat(tabs):=20=E5=A2=9E=E5=BC=BA=E8=8B=A5?= =?UTF-8?q?=E5=B9=B2=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/tabs/examples/demo.md | 7 +- docs/tabs/index.md | 17 +++-- examples/tabs.html | 92 ++++++++++++++++--------- src/modules/tabs.js | 138 ++++++++++++++++++++----------------- 4 files changed, 149 insertions(+), 105 deletions(-) diff --git a/docs/tabs/examples/demo.md b/docs/tabs/examples/demo.md index fa250da9..4f2de33f 100644 --- a/docs/tabs/examples/demo.md +++ b/docs/tabs/examples/demo.md @@ -89,13 +89,12 @@ layui.use(function() { title: 'New Tab '+ n, // 此处加 n 仅为演示区分,实际应用不需要 content: 'New Tab Content '+ n, id: 'new-'+ n, - aaa: 'attr-'+ n, // 自定义属性,其中 aaa 可任意命名 - done: function(params) { - console.log(params); // 查看返回的参数 + done: function(data) { + console.log(data); // 查看返回的参数 // 给新标签头添加上下文菜单 dropdown.render($.extend({}, dropdownInst.config, { - elem: params.thisHeaderItem // 当前标签头元素 + elem: data.headerItem // 新标签头元素 --- headerItem 为 2.11.2 新增 })); } }, opts); diff --git a/docs/tabs/index.md b/docs/tabs/index.md index ba3e4e4c..d8d476b0 100644 --- a/docs/tabs/index.md +++ b/docs/tabs/index.md @@ -122,6 +122,12 @@ tabs.render({ tabs.add('test', { title: 'New Tab 1', content: 'New Tab Content 1', + done: function(data) { + console.log(data); // 标签相关数据 + + // 为新标签头添加任意属性 + data.headerItem.attr('lay-tips', '111'); + } }); ``` @@ -202,10 +208,10 @@ console.log(data); { options, // 标签配置信息 container, // 标签容器的相关元素 - thisHeaderItem, // 当前标签头部项 - thisBodyItem, // 当前标签内容项 - index, // 当前标签索引 - length, // 当前标签数 + thisHeaderItem, // 当前活动标签头部项 + thisBodyItem, // 当前活动标签内容项 + index, // 当前活动标签索引 + length, // 标签数量 } ``` @@ -228,12 +234,13 @@ var headerItem = tabs.getHeaderItem('test', 'abc'); // 获取 lay-id="abc" 的 `tabs.getBodyItem(id, index)` - 参数 `id` : 组件的实例 ID -- 参数 `index` : 标签索引 +- 参数 `index` : 标签索引或标签的 `lay-id` 属性值 2.11.2+ 该方法用于获取标签内容项元素。 ```js var bodyItem = tabs.getBodyItem('test', 3); // 获取索引为 3 的标签内容项元素 +var bodyItem = tabs.getBodyItem('test', 'abc'); // 获取 lay-id="abc" 的标签内容项元素 ```