From 1eb01c6706139df7416da8036f5fed01b5a3c770 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, 17 Jun 2025 15:09:36 +0800 Subject: [PATCH] =?UTF-8?q?fix(tabs):=20=E4=BC=98=E5=8C=96=20close=20?= =?UTF-8?q?=E6=96=B9=E6=B3=95=E5=9C=A8=E6=A0=87=E7=AD=BE=E9=A1=BA=E5=BA=8F?= =?UTF-8?q?=E6=89=93=E4=B9=B1=E6=97=B6=E4=BC=A0=E5=85=A5=20lay-id=20?= =?UTF-8?q?=E7=9A=84=E6=94=AF=E6=8C=81=20(#2690)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix(tabs): 优化 close 方法在标签顺序打乱时传入 lay-id 的支持 * fix(tabs): 优化 closeMult 方法 index 参数值为 lay-id 时的无效问题 * fix(tabs): 优化 `getHeaderItem` 等方法的 `index` 参数的类型检测 --- docs/tabs/index.md | 22 ++++++---- examples/tabs.html | 22 ++++++++++ src/modules/tabs.js | 105 +++++++++++++++++++++++++------------------- 3 files changed, 95 insertions(+), 54 deletions(-) diff --git a/docs/tabs/index.md b/docs/tabs/index.md index d8d476b0..de26219a 100644 --- a/docs/tabs/index.md +++ b/docs/tabs/index.md @@ -136,7 +136,7 @@ tabs.add('test', { `tabs.close(id, index, force)` - 参数 `id` : 组件的实例 ID -- 参数 `index` : 标签索引或标签的 `lay-id` 属性值 +- 参数 `index` : 若传入 number 类型,则为标签索引;若传入 string 类型,则为标签的 `lay-id` 属性值 - 参数 `force` : 是否强制关闭。若设置 `true` 将忽略 `beforeClose` 事件行为。默认 `false` 该方法用于关闭指定的标签项。 @@ -156,19 +156,23 @@ tabs.close('test', 'abc'); // 关闭 lay-id="abc" 的标签 | mode | 描述 | | --- | --- | -| other | 关闭除当前标签外的所有标签 | -| right | 关闭当前标签及右侧标签 | +| other | 关闭除当前标签外的其他标签 | +| right | 关闭当前标签的右侧所有标签 | | all | 关闭所有标签 | - 参数 `index` : 活动标签的索引或 `lay-id` 属性值,默认取当前选中标签的索引。一般用于标签右键事件。 -该方法用于批量关闭标签。 +该方法用于批量关闭标签,若标签项已设置不允许关闭(`lay-closable="false"`),则操作将被忽略。 ```js -tabs.closeMult(id, 'other'); // 关闭除当前标签外的所有标签 -tabs.closeMult(id, 'other', 3); // 关闭除索引为 3 的标签外的所有标签 -tabs.closeMult(id, 'right'); // 关闭当前标签及右侧标签 +tabs.closeMult(id, 'other'); // 关闭除当前活动标签外的其他标签 +tabs.closeMult(id, 'other', 3); // 关闭除索引为 3 的标签外的其他标签 +tabs.closeMult(id, 'other', 'ccc'); // 关闭除 lay-id="ccc" 的标签外的其他标签 + +tabs.closeMult(id, 'right'); // 关闭当前活动标签的右侧所有标签 tabs.closeMult(id, 'right', 3); // 关闭索引为 3 的标签的右侧所有标签 +tabs.closeMult(id, 'right', 'ccc'); // 关闭 lay-id="ccc" 的标签的右侧所有标签 + tabs.closeMult(id, 'all'); // 关闭所有标签 ``` @@ -220,7 +224,7 @@ console.log(data); `tabs.getHeaderItem(id, index)` - 参数 `id` : 组件的实例 ID -- 参数 `index` : 标签索引或标签的 `lay-id` 属性值 +- 参数 `index` : 若传入 number 类型,则为标签索引;若传入 string 类型,则为标签的 `lay-id` 属性值 该方法用于获取标签头部项元素。 @@ -234,7 +238,7 @@ var headerItem = tabs.getHeaderItem('test', 'abc'); // 获取 lay-id="abc" 的 `tabs.getBodyItem(id, index)` - 参数 `id` : 组件的实例 ID -- 参数 `index` : 标签索引或标签的 `lay-id` 属性值 2.11.2+ +- 参数 `index` : 若传入 number 类型,则为标签索引;若传入 string 类型,则为标签的 `lay-id` 属性值 2.11.2+ 该方法用于获取标签内容项元素。 diff --git a/examples/tabs.html b/examples/tabs.html index 631ee9d7..efc73c72 100644 --- a/examples/tabs.html +++ b/examples/tabs.html @@ -90,6 +90,26 @@ +