mirror of https://github.com/layui/layui
refactor: 优化 layer.closeLast (#1652)
* refactor: 重构 layer.closeLast feat: 不指定 type 时, 将从所有类型的层中寻找最近打开的 fix: 捕获层关闭顺序错误 * feat(layer): layer.closeLast 的 type 参数支持数组 * fix: hideOnClose 隐藏时不应收集索引pull/1682/head
parent
e8dde4cc7f
commit
cecf33a83d
|
@ -398,6 +398,7 @@ layer.closeLast('page'); // 关闭最近一次打开的页面层
|
|||
layer.closeLast('iframe'); // 关闭最近一次打开的 iframe 层
|
||||
layer.closeLast('loading'); // 关闭最近一次打开的加载层
|
||||
layer.closeLast('tips'); // 关闭最近一次打开的 tips 层
|
||||
layer.closeLast(['dialog', 'page']); // 关闭最近一次打开的信息框或页面层,2.9.7+
|
||||
```
|
||||
|
||||
<h2 id="config" lay-pid="api" class="ws-anchor ws-bold">全局配置默认属性</h2>
|
||||
|
|
|
@ -1321,8 +1321,18 @@ layer.closeAll = function(type, callback){
|
|||
|
||||
// 根据弹层类型关闭最近打开的层
|
||||
layer.closeLast = function(type, callback){
|
||||
type = type || 'page';
|
||||
layer.close($('.layui-layer-'+ type +':last').attr("times"), callback);
|
||||
var layerIndexList = [];
|
||||
var isArrayType = $.isArray(type);
|
||||
$(typeof type === 'string' ? '.layui-layer-' + type : '.layui-layer').each(function(i, el){
|
||||
var layero = $(el);
|
||||
var shouldSkip = (isArrayType && type.indexOf(layero.attr('type')) === -1) || layero.css('display') === 'none';
|
||||
if(shouldSkip) return true;
|
||||
layerIndexList.push(Number(layero.attr('times')));
|
||||
});
|
||||
if(layerIndexList.length > 0){
|
||||
var layerIndexMax = Math.max.apply(null, layerIndexList);
|
||||
layer.close(layerIndexMax, callback);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue