From 4136f7af1222eae8d681d9b1923fe40f5cfec569 Mon Sep 17 00:00:00 2001 From: morning-star <26325820+Sight-wcg@users.noreply.github.com> Date: Tue, 27 Feb 2024 17:59:21 +0800 Subject: [PATCH] =?UTF-8?q?feat(dropdown):=20=E6=96=B0=E5=A2=9E=20close=20?= =?UTF-8?q?=E9=80=89=E9=A1=B9=20(#1605)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat(dropdown): 新增 close 选项 * update code * update code * update code * style(dropdown): 格式化测试代码 --------- Co-authored-by: 贤心 <3277200+sentsim@users.noreply.github.com> --- docs/dropdown/detail/options.md | 14 ++ examples/dropdown.html | 423 ++++++++++++++++++-------------- src/modules/dropdown.js | 17 +- 3 files changed, 267 insertions(+), 187 deletions(-) diff --git a/docs/dropdown/detail/options.md b/docs/dropdown/detail/options.md index 4f533019..5a88c7b5 100644 --- a/docs/dropdown/detail/options.md +++ b/docs/dropdown/detail/options.md @@ -302,6 +302,20 @@ click: function(data, othis){ 用法详见:[#示例](#examples) + + + +close 2.9.7+ + + +面板关闭后的回调函数。返回的参数如下: + +``` +close: function(elem){ + console.log(elem); // 当前组件绑定的目标元素对象 +} +``` + diff --git a/examples/dropdown.html b/examples/dropdown.html index 386db7be..f22ea4d4 100644 --- a/examples/dropdown.html +++ b/examples/dropdown.html @@ -37,225 +37,286 @@ diff --git a/src/modules/dropdown.js b/src/modules/dropdown.js index 7510b663..c92506fd 100644 --- a/src/modules/dropdown.js +++ b/src/modules/dropdown.js @@ -377,14 +377,19 @@ layui.define(['jquery', 'laytpl', 'lay', 'util'], function(exports){ Class.prototype.remove = function(){ var that = this; var options = that.config; - var elemPrev = thisModule.prevElem; + var prevContentElem = thisModule.prevElem; // 若存在已打开的面板元素,则移除 - if(elemPrev){ - elemPrev.data('prevElem') && ( - elemPrev.data('prevElem').data(MOD_INDEX +'_opened', false) - ); - elemPrev.remove(); + if(prevContentElem){ + var prevId = prevContentElem.attr('lay-id'); + var prevTriggerElem = prevContentElem.data('prevElem'); + var prevInstance = thisModule.getThis(prevId); + var prevOnClose = prevInstance.config.close; + + prevTriggerElem && prevTriggerElem.data(MOD_INDEX +'_opened', false); + prevContentElem.remove(); + delete thisModule.prevElem; + typeof prevOnClose === 'function' && prevOnClose.call(prevInstance.config, prevTriggerElem); } lay('.' + STR_ELEM_SHADE).remove(); };