diff --git a/component/pear/module/admin.js b/component/pear/module/admin.js index 48d6e898c9b50117cd45c5d1af196b5187bd8243..b40b7e24983acc6bf0134f114d066cab4fb44378 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 ac6664ce160225fb9c4565fe5cdbbcb990754c28..a318ee7f9582da3f64a29367850c860cd873730c 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()); }); diff --git a/component/pear/module/tab.js b/component/pear/module/tab.js index 34afa56d1b0c83e8412b384fbacf7ef40dbd53c3..6a503b652a2c4bb88ab71dba8dd61ed1b3c83408 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) {