From 79b0a56f506b0553fa67e4ce7467a21d4d8660ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B4=A4=E5=BF=83?= <3277200+sentsim@users.noreply.github.com> Date: Sun, 16 Mar 2025 00:13:55 +0800 Subject: [PATCH 1/5] =?UTF-8?q?fix(component):=20=E4=BF=AE=E5=A4=8D=20relo?= =?UTF-8?q?ad=20=E6=97=B6=E4=BC=A0=E5=85=A5=E7=9A=84=E9=80=89=E9=A1=B9?= =?UTF-8?q?=E6=9C=AA=E6=AD=A3=E7=A1=AE=E5=90=88=E5=B9=B6=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/component.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/component.js b/src/modules/component.js index e84f026c..a900beb2 100644 --- a/src/modules/component.js +++ b/src/modules/component.js @@ -103,7 +103,7 @@ layui.define(['jquery', 'lay'], function(exports) { // 重载实例 Class.prototype.reload = function(options, type) { var that = this; - $.extend(settings.isDeepReload, that.config, options); + that.config = $.extend(settings.isDeepReload, {}, that.config, options); that.init(true, type); }; From 6ccc5a453d250537117646e8f9fe751153fd91a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B4=A4=E5=BF=83?= <3277200+sentsim@users.noreply.github.com> Date: Sun, 16 Mar 2025 00:14:18 +0800 Subject: [PATCH 2/5] =?UTF-8?q?fix(component):=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E5=85=83=E7=B4=A0=20lay-options=20=E5=B1=9E=E6=80=A7=E4=B8=8A?= =?UTF-8?q?=E7=9A=84=E9=85=8D=E7=BD=AE=E5=9C=A8=E9=87=8D=E8=BD=BD=E6=97=B6?= =?UTF-8?q?=E7=9A=84=E4=BC=98=E5=85=88=E7=BA=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/component.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/modules/component.js b/src/modules/component.js index a900beb2..2065668d 100644 --- a/src/modules/component.js +++ b/src/modules/component.js @@ -124,7 +124,13 @@ layui.define(['jquery', 'lay'], function(exports) { } // 合并 lay-options 属性上的配置信息 - $.extend(true, options, lay.options(elem[0])); + var layOptions = lay.options(elem[0]); + if (rerender) { + // 若重载渲染,则重载传入的 options 配置优先 + options = that.config = $.extend(layOptions, options); + } else { + $.extend(options, layOptions); // 若首次渲染,则 lay-options 配置优先 + } // 若重复执行 render,则视为 reload 处理 if (!rerender && elem.attr(MOD_ID)) { From bd892bf87effa582bf8e3655c710d52f4066b2a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B4=A4=E5=BF=83?= <3277200+sentsim@users.noreply.github.com> Date: Sun, 16 Mar 2025 00:15:17 +0800 Subject: [PATCH 3/5] =?UTF-8?q?feat(component):=20=E6=96=B0=E5=A2=9E=20cac?= =?UTF-8?q?he=20=E5=8E=9F=E5=9E=8B=E6=96=B9=E6=B3=95=EF=BC=8C=E7=94=A8?= =?UTF-8?q?=E4=BA=8E=E5=85=83=E7=B4=A0=E7=BC=93=E5=AD=98=E6=93=8D=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/component.js | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/src/modules/component.js b/src/modules/component.js index 2065668d..966f8c6a 100644 --- a/src/modules/component.js +++ b/src/modules/component.js @@ -20,7 +20,6 @@ layui.define(['jquery', 'lay'], function(exports) { // 组件名 var MOD_NAME = settings.name; - var MOD_INDEX = 'layui_'+ MOD_NAME +'_index'; // 组件索引名 var MOD_ID = 'lay-' + MOD_NAME + '-id'; // 用于记录组件实例 id 的属性名 // 组件基础对外接口 @@ -31,7 +30,7 @@ layui.define(['jquery', 'lay'], function(exports) { // 通用常量集,一般存放固定字符,如类名等 CONST: $.extend(true, { MOD_NAME: MOD_NAME, - MOD_INDEX: MOD_INDEX, + MOD_ID: MOD_ID, CLASS_THIS: 'layui-this', CLASS_SHOW: 'layui-show', @@ -179,21 +178,39 @@ layui.define(['jquery', 'lay'], function(exports) { Class.prototype.render = settings.render; // 渲染 Class.prototype.events = settings.events; // 事件 - // 元素操作缓存 - Class.prototype.cache = function(key, value) { + /** + * 元素缓存操作 + * @param {string} key - 缓存键 + * @param {*} value - 缓存值 + * @param {boolean} remove - 是否删除缓存 + * @returns {*} - 若 value 未传,则返回缓存值 + */ + Class.prototype.cache = function(key, value, remove) { var that = this; var options = that.config; var elem = options.elem; - + var MOD_CACHE_NAME = MOD_ID + '-cache'; if (!elem) return; - var CACHE_NAME = 'lay_'+ MOD_NAME + '_cache'; - var cache = elem.data(CACHE_NAME) || {}; + var cache = elem.data(MOD_CACHE_NAME) || {}; - if (value === undefined) return cache[key]; + // value 未传则获取缓存值 + if (value === undefined) { + return cache[key]; + } - cache[key] = value; - elem.data(CACHE_NAME, cache); + if (remove) { + delete cache[key]; // 删除缓存 + } else { + cache[key] = value; // 设置缓存 + } + + elem.data(MOD_CACHE_NAME, cache); + }; + + // 清除缓存 + Class.prototype.removeCache = function(key) { + this.cache(key, null, true); }; // 缓存所有实例对象 From 53ded26cb96009330977320b5991bbcd17468eb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B4=A4=E5=BF=83?= <3277200+sentsim@users.noreply.github.com> Date: Sun, 16 Mar 2025 00:15:25 +0800 Subject: [PATCH 4/5] =?UTF-8?q?fix:=20=E4=BC=98=E5=8C=96=20tabs=20?= =?UTF-8?q?=E9=87=8D=E8=BD=BD=E6=97=B6=E6=9C=AA=E6=8C=89=E7=85=A7=E4=BC=A0?= =?UTF-8?q?=E5=85=A5=E7=9A=84=20closable=20=E6=AD=A3=E7=A1=AE=E6=B8=B2?= =?UTF-8?q?=E6=9F=93=E5=8F=AF=E5=85=B3=E9=97=AD=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/css/layui.css | 1 + src/modules/tabs.js | 14 +++++--------- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/css/layui.css b/src/css/layui.css index f0c54bce..a16e8589 100644 --- a/src/css/layui.css +++ b/src/css/layui.css @@ -1317,6 +1317,7 @@ body .layui-table-tips .layui-layer-content{background: none; padding: 0; box-sh .layui-tabs-header li .layui-tabs-close{position: relative; display: inline-block; width: 16px; height: 16px; line-height: 18px; margin-left: 8px; top: 0px; text-align: center; font-size: 12px; color: #959595; border-radius: 50%; font-weight: 700; transition: all .16s; -webkit-transition: all .16s;} .layui-tabs-header li .layui-tabs-close:hover{ background-color: #ff5722; color: #fff;} +.layui-tabs-header li[lay-closable="false"] .layui-tabs-close{display: none;} .layui-tabs-body{padding: 16px 0;} .layui-tabs-item{display: none;} diff --git a/src/modules/tabs.js b/src/modules/tabs.js index 4c1ab889..b34802a0 100644 --- a/src/modules/tabs.js +++ b/src/modules/tabs.js @@ -459,7 +459,7 @@ layui.define('component', function(exports) { var that = this var options = that.config; - if(!options.closable) return; + if (!options.closable) return; opts = opts || {}; @@ -484,17 +484,13 @@ layui.define('component', function(exports) { var that = this; var options = that.config; var container = that.getContainer(); - var hasDel = that.cache('close'); // 是否开启关闭 if (options.closable) { - if (!hasDel) { - container.header.items.each(function(){ - that.appendClose($(this)); - }); - that.cache('close', true); - } - } else if(hasDel) { + container.header.items.each(function() { + that.appendClose($(this)); + }); + } else { container.header.items.each(function() { $(this).find('.'+ component.CONST.CLOSE).remove(); }); From 213fe5a2090a7aef26af71fb5a0d6dc517b9a915 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B4=A4=E5=BF=83?= <3277200+sentsim@users.noreply.github.com> Date: Wed, 19 Mar 2025 14:15:39 +0800 Subject: [PATCH 5/5] =?UTF-8?q?docs:=20=E6=B7=BB=E5=8A=A0=20component=20?= =?UTF-8?q?=E6=96=87=E6=A1=A3=E4=B8=AD=E5=AE=9E=E9=AA=8C=E6=80=A7=E9=80=89?= =?UTF-8?q?=E9=A1=B9=E6=A0=87=E8=AE=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/component/detail/options.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/component/detail/options.md b/docs/component/detail/options.md index 6045945f..592584e8 100644 --- a/docs/component/detail/options.md +++ b/docs/component/detail/options.md @@ -53,7 +53,7 @@ CONST: {