From 764d19e2fe1d63e3d9485a67f54bd643317d4b8e Mon Sep 17 00:00:00 2001 From: sight <1453017105@qq.com> Date: Thu, 26 May 2022 06:04:32 +0800 Subject: [PATCH 1/2] =?UTF-8?q?[#I55HFB]1.fix(frame):=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E9=9D=9E=E8=A7=86=E5=9B=BE=E6=A8=A1=E5=BC=8F=E5=8A=A0=E8=BD=BD?= =?UTF-8?q?=E5=8A=A8=E7=94=BB=E4=B8=A2=E5=A4=B1=E7=9A=84=E9=97=AE=E9=A2=98?= =?UTF-8?q?=202.fix(frame):=E4=BF=AE=E5=A4=8D=E8=B7=A8=E5=9F=9F=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2=E6=97=A0=E6=B3=95=E5=88=B7=E6=96=B0=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98=203.fix(frame):=E4=BC=98=E5=8C=96=E5=8A=A0=E8=BD=BD?= =?UTF-8?q?=E5=8A=A8=E7=94=BB,=20onload=20=E4=BA=8B=E4=BB=B6=E6=9B=BF?= =?UTF-8?q?=E6=8D=A2=E5=AE=9A=E6=97=B6=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- component/pear/module/admin.js | 4 +-- component/pear/module/frame.js | 60 ++++++++++++---------------------- 2 files changed, 22 insertions(+), 42 deletions(-) diff --git a/component/pear/module/admin.js b/component/pear/module/admin.js index 48d6e89..b40b7e2 100644 --- a/component/pear/module/admin.js +++ b/component/pear/module/admin.js @@ -422,8 +422,8 @@ layui.define(['message', 'table', 'jquery', 'element', 'yaml', 'form', 'tab', 'm refreshA.addClass("layui-anim-rotate"); refreshA.addClass("layui-anim-loop"); refreshA.addClass("layui-icon-loading"); - if (isMuiltTab(config) === "true" || isMuiltTab(config) === true) bodyTab.refresh(400); - else bodyFrame.refresh(400); + if (isMuiltTab(config) === "true" || isMuiltTab(config) === true) bodyTab.refresh(true); + else bodyFrame.refresh(true); setTimeout(function() { refreshA.addClass("layui-icon-refresh-1"); refreshA.removeClass("layui-anim"); diff --git a/component/pear/module/frame.js b/component/pear/module/frame.js index ac6664c..a318ee7 100644 --- a/component/pear/module/frame.js +++ b/component/pear/module/frame.js @@ -24,53 +24,24 @@ layui.define(['jquery', 'element'], function (exports) { pearFrame.prototype.changePage = function (url, loading) { var $frameLoad = $("#" + this.option.elem).find(".pear-frame-loading"); - - /** - * 非视图模式下,切换侧栏导航上条目时,会产生 loading.css 非 function错误 - * frame.js?v=3.9.4:28 Uncaught TypeError: loading.css is not a function - at pearFrame.changePage (frame.js?v=3.9.4:28:12) - at admin.js?v=3.9.4:165:17 - at HTMLAnchorElement. (menu.js?v=3.9.4:122:4) - at HTMLBodyElement.dispatch (layui.js:2:22295) - at HTMLBodyElement.m.handle (layui.js:2:18997) - * - */ - if (loading && typeof loading.css ==='function') { - loading.css({ display: 'block' }); - } - $("#" + this.option.elem + " iframe").attr("src", url); - if (loading) { - setTimeout(function () { - $frameLoad.fadeOut(500); - }, 800) - } + var $frame = $("#" + this.option.elem + " iframe"); + $frame.attr("src", url); + frameLoading($frame, $frameLoad, loading); } pearFrame.prototype.changePageByElement = function (elem, url, title, loading) { var $frameLoad = $("#" + elem).find(".pear-frame-loading"); - if (loading) { - $frameLoad.css({ display: 'block' }); - } - $("#" + elem + " iframe").attr("src", url); + var $frame = $("#" + elem + " iframe"); + $frame.attr("src", url); $("#" + elem + " .title").html(title); - if (loading) { - setTimeout(function () { - $frameLoad.css({ display: 'none' }); - }, 400) - } + frameLoading($frame, $frameLoad, loading); } - pearFrame.prototype.refresh = function (time) { - if (time != false) { - var loading = $("#" + this.option.elem).find(".pear-frame-loading"); - loading.css({ display: 'block' }); - if (time != 0) { - setTimeout(function () { - loading.fadeOut(500); - }, time) - } - } - $("#" + this.option.elem).find("iframe")[0].contentWindow.location.reload(true); + pearFrame.prototype.refresh = function (loading) { + var $frameLoad = $("#" + this.option.elem).find(".pear-frame-loading"); + var $frame = $("#" + this.option.elem).find("iframe"); + $frame.attr("src", $frame.attr("src")); + frameLoading($frame, $frameLoad, loading); } function createFrameHTML(option) { @@ -83,5 +54,14 @@ layui.define(['jquery', 'element'], function (exports) { $("#" + option.elem).html("
" + iframe + loading + "
"); } + function frameLoading(iframeEl, loadingEl, isLoading) { + if (isLoading) { + loadingEl.css({ display: 'block' }); + iframeEl.load(function () { + loadingEl.fadeOut(1000); + }) + } + } + exports('frame', new pearFrame()); }); -- Gitee From 5908d165a5e15000f620e1a528bcc16e227419f5 Mon Sep 17 00:00:00 2001 From: sight <1453017105@qq.com> Date: Thu, 26 May 2022 06:16:10 +0800 Subject: [PATCH 2/2] =?UTF-8?q?1.fix(tab):=E4=BC=98=E5=8C=96=E5=8A=A0?= =?UTF-8?q?=E8=BD=BD=E5=8A=A8=E7=94=BB,=20onload=20=E4=BA=8B=E4=BB=B6?= =?UTF-8?q?=E6=9B=BF=E6=8D=A2=E5=AE=9A=E6=97=B6=E5=99=A8=202.fix(tab):?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=97=A0=E6=B3=95=E5=88=B7=E6=96=B0=E8=B7=A8?= =?UTF-8?q?=E5=9F=9F=E9=A1=B5=E9=9D=A2=E7=9A=84=E9=97=AE=E9=A2=98=203.fix(?= =?UTF-8?q?tab):=E4=BF=AE=E5=A4=8D=E4=B8=80=E4=B8=AA=20tab=20=E5=8A=A0?= =?UTF-8?q?=E8=BD=BD,=E5=85=B6=E5=AE=83=20tab=20=E5=9D=87=E6=97=A0?= =?UTF-8?q?=E6=B3=95=E6=9F=A5=E7=9C=8B=E7=9A=84=E9=97=AE=E9=A2=98,=20?= =?UTF-8?q?=E5=B0=86=E5=8A=A0=E8=BD=BD=E5=8A=A8=E7=94=BB=20DOM=20=E5=92=8C?= =?UTF-8?q?=20tab=20iframe=20=E5=81=9A=E5=90=8C=E7=BA=A7=E5=A4=84=E7=90=86?= =?UTF-8?q?,=20=E5=90=84=E4=B8=AA=E5=8A=A0=E8=BD=BD=E5=8A=A8=E7=94=BB?= =?UTF-8?q?=E4=B9=8B=E9=97=B4=E4=BA=92=E4=B8=8D=E5=BD=B1=E5=93=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- component/pear/module/tab.js | 130 +++++++++++------------------------ 1 file changed, 39 insertions(+), 91 deletions(-) diff --git a/component/pear/module/tab.js b/component/pear/module/tab.js index 34afa56..6a503b6 100644 --- a/component/pear/module/tab.js +++ b/component/pear/module/tab.js @@ -230,30 +230,15 @@ layui.define(['jquery', 'element'], function(exports) { '' } if ($(".layui-tab[lay-filter='" + elem + "'] .layui-tab-title li[lay-id]").length <= 0) { - - if (time != false && time != 0) { - - var load = '
' + - '
' + - '' + - '
' + - '
' - $("#" + elem).find(".pear-tab").append(load); - var pearLoad = $("#" + elem).find("#pear-tab-loading" + index); - pearLoad.css({ - display: "block" - }); - setTimeout(function() { - pearLoad.fadeOut(500); - }, time); - index++; - } element.tabAdd(elem, { title: title, content: '', id: opt.id }); + if (time != false && time != 0) { + tabIframeLoading(elem, opt.id); + } tabData.push(opt); sessionStorage.setItem(elem + "-pear-tab-data", JSON.stringify(tabData)); } else { @@ -265,29 +250,15 @@ layui.define(['jquery', 'element'], function(exports) { }) if (isData == false) { - if (time != false && time != 0) { - var load = '
' + - '
' + - '' + - '
' + - '
' - - $("#" + elem).find(".pear-tab").append(load); - var pearLoad = $("#" + elem).find("#pear-tab-loading" + index); - pearLoad.css({ - display: "block" - }); - setTimeout(function() { - pearLoad.fadeOut(500); - }, time); - index++; - } element.tabAdd(elem, { title: title, content: '', id: opt.id }); + if (time != false && time != 0) { + tabIframeLoading(this.option.elem, opt.id); + } tabData.push(opt); sessionStorage.setItem(elem + "-pear-tab-data", JSON.stringify(tabData)); @@ -308,28 +279,15 @@ layui.define(['jquery', 'element'], function(exports) { ''; } if ($(".layui-tab[lay-filter='" + this.option.elem + "'] .layui-tab-title li[lay-id]").length <= 0) { - if (time != false && time != 0) { - var load = '
' + - '
' + - '' + - '
' + - '
'; - $("#" + this.option.elem).find(".pear-tab").append(load); - var pearLoad = $("#" + this.option.elem).find("#pear-tab-loading" + index); - pearLoad.css({ - display: "block" - }); - setTimeout(function() { - pearLoad.fadeOut(500); - }, time); - index++; - } element.tabAdd(this.option.elem, { title: title, content: '', id: opt.id }); + if (time != false && time != 0) { + tabIframeLoading(this.option.elem, opt.id); + } tabData.push(opt); sessionStorage.setItem(this.option.elem + "-pear-tab-data", JSON.stringify(tabData)); sessionStorage.setItem(this.option.elem + "-pear-tab-data-current", opt.id); @@ -353,29 +311,15 @@ layui.define(['jquery', 'element'], function(exports) { } } - if (time != false && time != 0) { - var load = '
' + - '
' + - '' + - '
' + - '
' - - $("#" + this.option.elem).find(".pear-tab").append(load); - var pearLoad = $("#" + this.option.elem).find("#pear-tab-loading" + index); - pearLoad.css({ - display: "block" - }); - setTimeout(function() { - pearLoad.fadeOut(500); - }, time); - index++; - } element.tabAdd(this.option.elem, { title: title, content: '', id: opt.id }); + if (time != false && time != 0) { + tabIframeLoading(this.option.elem, opt.id); + } tabData.push(opt); sessionStorage.setItem(this.option.elem + "-pear-tab-data", JSON.stringify(tabData)); sessionStorage.setItem(this.option.elem + "-pear-tab-data-current", opt.id); @@ -386,35 +330,39 @@ layui.define(['jquery', 'element'], function(exports) { } // 刷 新 指 定 的 选 项 卡 - pearTab.prototype.refresh = function(time) { + pearTab.prototype.refresh = function (time) { // 刷 新 指 定 的 选 项 卡 if (time != false && time != 0) { - var load = '
' + - '
' + - '' + - '
' + - '
' - - var elem = this.option.elem; - $("#" + this.option.elem).find(".pear-tab").append(load); - var pearLoad = $("#" + this.option.elem).find("#pear-tab-loading" + index); - pearLoad.css({ - display: "block" - }); - index++; - setTimeout(function() { - pearLoad.fadeOut(500, function() { - pearLoad.remove(); - }); - }, time); - $(".layui-tab[lay-filter='" + elem + "'] .layui-tab-content .layui-show").find("iframe")[0].contentWindow - .location.reload(true); + tabIframeLoading(this.option.elem); } else { - $(".layui-tab[lay-filter='" + this.option.elem + "'] .layui-tab-content .layui-show").find("iframe")[0].contentWindow - .location.reload(true); + var $iframe = $(".layui-tab[lay-filter='" + this.option.elem + "'] .layui-tab-content .layui-show").find("iframe"); + $iframe.attr("src", $iframe.attr("src")); } } + function tabIframeLoading(elem, id) { + var load = '
' + + '
' + + '' + + '
' + + '
' + var $iframe = $(".layui-tab[lay-filter='" + elem + "'] .layui-tab-content .layui-show").find("iframe"); + if(id){ + $iframe = $(".layui-tab[lay-filter='" + elem + "'] .layui-tab-content").find("iframe[id='"+ id +"']"); + } + // loading 和 iframe 同级处理, 避免一个 tab 加载,其它 tab 无法查看的问题 + $iframe.parent().append(load); + var pearLoad = $("#" + elem).find("#pear-tab-loading" + index); + pearLoad.css({ display: "block" }); + index++; + $iframe.attr("src", $iframe.attr("src")); // 支持跨域刷新 iframe + $iframe.load(function () { + pearLoad.fadeOut(1000, function () { + pearLoad.remove(); + }); + }) + } + function tabDelete(elem, id, callback, option) { -- Gitee