From 289c3b49164b6451cd4d116123dbda3197b7086d Mon Sep 17 00:00:00 2001 From: morning-star <26325820+Sight-wcg@users.noreply.github.com> Date: Thu, 22 Feb 2024 11:48:06 +0800 Subject: [PATCH] =?UTF-8?q?fix(layer):=20height=20=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E4=B8=BA=20auto=EF=BC=8C=E6=81=A2=E5=A4=8D=E5=A4=A7=E5=B0=8F?= =?UTF-8?q?=E6=97=B6=E5=86=85=E5=AE=B9=E5=8C=BA=E9=AB=98=E5=BA=A6=E9=94=99?= =?UTF-8?q?=E8=AF=AF=20(#1617)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix(layer): height 设置为 auto,恢复大小时内容区高度错误 * fix: 最大化最小化时不应使用 recordHeight * update code * chore: 优化魔术字符 --------- Co-authored-by: 贤心 <3277200+sentsim@users.noreply.github.com> --- src/modules/layer.js | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/modules/layer.js b/src/modules/layer.js index af538baa..7378f048 100644 --- a/src/modules/layer.js +++ b/src/modules/layer.js @@ -259,6 +259,8 @@ doms.SHADE = 'layui-layer-shade'; doms.MOVE = 'layui-layer-move'; doms.SHADE_KEY = 'LAYUI-LAYER-SHADE-KEY'; +var RECORD_HEIGHT = 'LAYUI_LAYER_CONTENT_RECORD_HEIGHT'; + // 默认配置 Class.pt.config = { type: 0, @@ -967,6 +969,9 @@ Class.pt.openLayer = function(){ // 记录宽高坐标,用于还原 ready.record = function(layero){ if(!layero[0]) return window.console && console.error('index error'); + var type = layero.attr('type'); + var contentElem = layero.find('.layui-layer-content'); + var contentRecordHeightElem = type === ready.type[2] ? contentElem.children('iframe') : contentElem; var area = [ layero[0].style.width || layero.width(), layero[0].style.height || layero.height(), @@ -975,6 +980,7 @@ ready.record = function(layero){ ]; layero.find('.layui-layer-max').addClass('layui-layer-maxmin'); layero.attr({area: area}); + contentElem.data(RECORD_HEIGHT, contentRecordHeightElem.height()); }; // 设置页面滚动条 @@ -1026,7 +1032,7 @@ layer.iframeSrc = function(index, url){ // 设定层的样式 layer.style = function(index, options, limit){ var layero = $('#'+ doms[0] + index); - var contElem = layero.find('.layui-layer-content'); + var contentElem = layero.find('.layui-layer-content'); var type = layero.attr('type'); var titHeight = layero.find(doms[1]).outerHeight() || 0; var btnHeight = layero.find('.'+doms[6]).outerHeight() || 0; @@ -1054,10 +1060,10 @@ layer.style = function(index, options, limit){ height: (typeof options.height === 'number' ? options.height : layero.height()) - titHeight - btnHeight }); } else { - contElem.css({ + contentElem.css({ height: (typeof options.height === 'number' ? options.height : layero.height()) - titHeight - btnHeight - - parseFloat(contElem.css('padding-top')) - - parseFloat(contElem.css('padding-bottom')) + - parseFloat(contentElem.css('padding-top')) + - parseFloat(contentElem.css('padding-bottom')) }) } }; @@ -1128,9 +1134,11 @@ layer.min = function(index, options){ layer.restore = function(index){ var layero = $('#'+ doms[0] + index); var shadeo = $('#'+ doms.SHADE + index); + var contentElem = layero.find('.layui-layer-content'); var area = layero.attr('area').split(','); var type = layero.attr('type'); var options = layero.data('config') || {}; + var contentRecordHeight = contentElem.data(RECORD_HEIGHT); layero.removeData('maxminStatus'); // 移除最大最小状态 @@ -1150,6 +1158,13 @@ layer.restore = function(index){ // 恢复页面滚动条弹层打开时的状态 options.scrollbar ? ready.restScrollbar(index) : ready.setScrollbar(index); + + // #1604 + if(contentRecordHeight !== undefined){ + contentElem.removeData(RECORD_HEIGHT); + var contentRecordHeightElem = type === ready.type[2] ? contentElem.children('iframe') : contentElem; + contentRecordHeightElem.css({height: contentRecordHeight}); + } // 恢复遮罩 shadeo.show();