From dcc30fbe5356b2b1ba963a0e48ca8d4217d062b7 Mon Sep 17 00:00:00 2001 From: sight <1453017105@qq.com> Date: Sun, 29 May 2022 21:11:29 +0800 Subject: [PATCH] =?UTF-8?q?feat(tab):=20=E6=96=B0=E5=A2=9E=20preload=20?= =?UTF-8?q?=E5=8F=82=E6=95=B0,=20=E6=8E=A7=E5=88=B6=E6=B5=8F=E8=A7=88?= =?UTF-8?q?=E5=99=A8=E5=88=B7=E6=96=B0=E6=97=B6=E6=98=AF=E5=90=A6=E9=A2=84?= =?UTF-8?q?=E5=8A=A0=E8=BD=BD=E9=9D=9E=E6=BF=80=E6=B4=BB=E6=A0=87=E7=AD=BE?= =?UTF-8?q?=E9=A1=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- component/pear/module/admin.js | 17 +++++++++-------- component/pear/module/tab.js | 25 +++++++++++++++++++------ config/pear.config.json | 1 + config/pear.config.yml | 2 ++ 4 files changed, 31 insertions(+), 14 deletions(-) diff --git a/component/pear/module/admin.js b/component/pear/module/admin.js index 2ecbb3c..aa8db22 100644 --- a/component/pear/module/admin.js +++ b/component/pear/module/admin.js @@ -116,6 +116,7 @@ layui.define(['message', 'table', 'jquery', 'element', 'yaml', 'form', 'tab', 'm session: param.tab.session, index: 0, tabMax: param.tab.max, + preload: param.tab.preload, closeEvent: function(id) { sideMenu.selectItem(id); }, @@ -380,7 +381,7 @@ layui.define(['message', 'table', 'jquery', 'element', 'yaml', 'form', 'tab', 'm return; } } - + this.changeTabTitle = function(id, title) { pearTab.changeTabTitleById('content', id ,title); } @@ -556,7 +557,7 @@ layui.define(['message', 'table', 'jquery', 'element', 'yaml', 'form', 'tab', 'm var $noData = $(".menu-search-no-data"); var $list = $(".menu-search-list"); var menuData = sideMenu.option.data; - + $layer.css("border-radius", "6px"); $input.off("focus").focus(); @@ -564,7 +565,7 @@ layui.define(['message', 'table', 'jquery', 'element', 'yaml', 'form', 'tab', 'm $input.off("input").on("input", debounce(function(){ var keywords = $input.val().trim(); var filteredMenus = filterHandle(menuData, keywords); - + if(filteredMenus.length){ var tiledMenus = tiledHandle(filteredMenus); var listHtml = createList(tiledMenus); @@ -587,7 +588,7 @@ layui.define(['message', 'table', 'jquery', 'element', 'yaml', 'form', 'tab', 'm var menuTitle = $(this).attr("smenu-title"); var menuType = $(this).attr("smenu-type"); var openableWindow = menuType === "1" || menuType === 1; - + if(sideMenu.isCollapse){ collapse(); } @@ -607,7 +608,7 @@ layui.define(['message', 'table', 'jquery', 'element', 'yaml', 'form', 'tab', 'm $(this).removeClass("this"); }) - // 监听键盘事件 + // 监听键盘事件 // Enter:13 Spacebar:32 UpArrow:38 DownArrow:40 Esc:27 $(document).off("keydown").keydown(function (e) { if (e.keyCode === 13 || e.keyCode === 32) { @@ -653,8 +654,8 @@ layui.define(['message', 'table', 'jquery', 'element', 'yaml', 'form', 'tab', 'm } }) }); - - + + body.on("click", ".fullScreen", function() { if ($(this).hasClass("layui-icon-screen-restore")) { screenFun(2).then(function() { @@ -1012,7 +1013,7 @@ layui.define(['message', 'table', 'jquery', 'element', 'yaml', 'form', 'tab', 'm $(".fullScreen").eq(0).removeClass("layui-icon-screen-restore"); } } - + $(window).on('resize', debounce(function () { if (!sideMenu.isCollapse && $(window).width() <= 768) { collapse(); diff --git a/component/pear/module/tab.js b/component/pear/module/tab.js index e4b09c1..d98cf57 100644 --- a/component/pear/module/tab.js +++ b/component/pear/module/tab.js @@ -25,6 +25,7 @@ layui.define(['jquery', 'element'], function(exports) { height: opt.height, tabMax: opt.tabMax, session: opt.session ? opt.session : false, + preload: opt.preload ? opt.preload : false, closeEvent: opt.closeEvent, success: opt.success ? opt.success : function(id) {} } @@ -125,6 +126,20 @@ layui.define(['jquery', 'element'], function(exports) { element.on('tab(' + this.option.elem + ')', function(data) { var id = $("#" + elem + " .layui-tab-title .layui-this").attr("lay-id"); sessionStorage.setItem(option.elem + "-pear-tab-data-current", id); + if (!option.preload) { + var $iframe = $(".layui-tab[lay-filter='" + elem + "'] .layui-tab-content").find("iframe[id='" + id + "']"); + var iframeUrl = $iframe.attr("src"); + if (!iframeUrl || iframeUrl === "about:blank") { + // 获取 url 并重载 + tabData.forEach(function (item, index) { + if (item.id === id) { + iframeUrl = item.url; + } + }) + tabIframeLoading(elem); + $iframe.attr("src", iframeUrl); + } + } callback(id); }); } @@ -171,7 +186,6 @@ layui.define(['jquery', 'element'], function(exports) { } var index = 0; - // 根据过滤 fliter 标识, 重置选项卡标题 pearTab.prototype.changeTabTitleById = function(elem, id, title) { var currentTab = $(".layui-tab[lay-filter='" + elem + "'] .layui-tab-title [lay-id='" + id + "'] .title"); @@ -185,7 +199,6 @@ layui.define(['jquery', 'element'], function(exports) { tabDelete(elem, id, callback); } } - // 根据过滤 filter 标识, 删除其他选项卡 pearTab.prototype.delOtherTabByElem = function(elem, callback) { var currentId = $(".layui-tab[lay-filter='" + elem + "'] .layui-tab-title .layui-this").attr("lay-id"); @@ -209,7 +222,6 @@ layui.define(['jquery', 'element'], function(exports) { } }) } - // 根据过滤 filter 标识, 删除当前选项卡 pearTab.prototype.delCurrentTabByElem = function(elem, callback) { var currentTab = $(".layui-tab[lay-filter='" + elem + "'] .layui-tab-title .layui-this"); @@ -335,10 +347,8 @@ layui.define(['jquery', 'element'], function(exports) { var $iframe = $(".layui-tab[lay-filter='" + this.option.elem + "'] .layui-tab-content .layui-show").find("iframe"); if (time != false && time != 0) { tabIframeLoading(this.option.elem); - $iframe.attr("src", $iframe.attr("src")); - } else { - $iframe.attr("src", $iframe.attr("src")); } + $iframe.attr("src", $iframe.attr("src")); } function tabIframeLoading(elem, id) { @@ -459,6 +469,9 @@ layui.define(['jquery', 'element'], function(exports) { '" src="' + item.url + '" frameborder="no" border="0" marginwidth="0" marginheight="0" style="width: 100%;height: 100%;">' } else { + if (!option.preload){ + item.url = "about:blank"; + } // 处 理 显 示 内 容 content += '