From 157071dcda51cfe7662f12d249e6456ae72f18c5 Mon Sep 17 00:00:00 2001 From: sight <1453017105@qq.com> Date: Fri, 27 May 2022 19:30:41 +0800 Subject: [PATCH 1/3] =?UTF-8?q?[#I596Q7]fix:=E6=B5=8F=E8=A7=88=E5=99=A8?= =?UTF-8?q?=E5=88=B7=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- component/pear/module/admin.js | 49 +++++++++++++++++++--------------- component/pear/module/frame.js | 18 +++++++++++-- 2 files changed, 43 insertions(+), 24 deletions(-) diff --git a/component/pear/module/admin.js b/component/pear/module/admin.js index b40b7e2..037dd3f 100644 --- a/component/pear/module/admin.js +++ b/component/pear/module/admin.js @@ -130,7 +130,7 @@ layui.define(['message', 'table', 'jquery', 'element', 'yaml', 'form', 'tab', 'm setTimeout(function() { sideMenu.selectItem(id); bodyTab.positionTab(); - }, 500) + }, 0) } } }); @@ -159,12 +159,17 @@ layui.define(['message', 'table', 'jquery', 'element', 'yaml', 'form', 'tab', 'm title: '首页', url: param.tab.index.href, width: '100%', - height: '100%' + height: '100%', + done: function(data){ + setTimeout(function () { + sideMenu.selectItem(data.id); + }, 0) + } }); sideMenu.click(function(dom, data) { - bodyFrame.changePage(data.menuUrl, true); - compatible() + bodyFrame.changePage(data.menuId, data.menuUrl, true); + compatible(); }) } } @@ -360,7 +365,7 @@ layui.define(['message', 'table', 'jquery', 'element', 'yaml', 'form', 'tab', 'm return; } } - + this.closeOtherTab = function() { if (isMuiltTab(config) === "true" || isMuiltTab(config) === true) { pearTab.delOtherTabByElem('content', function(id){ @@ -370,7 +375,7 @@ layui.define(['message', 'table', 'jquery', 'element', 'yaml', 'form', 'tab', 'm return; } } - + this.closeAllTab = function() { if (isMuiltTab(config) === "true" || isMuiltTab(config) === true) { pearTab.delAllTabByElem('content', function(id){ @@ -380,17 +385,17 @@ layui.define(['message', 'table', 'jquery', 'element', 'yaml', 'form', 'tab', 'm return; } } - + this.changeTabTitle = function(id, title) { pearTab.changeTabTitleById('content', id ,title); } - + this.changeIframe = function(id, title, url) { if (isMuiltTab(config) === "true" || isMuiltTab(config) === true) { return; } else { sideMenu.selectItem(id); - bodyFrame.changePage(url, true); + bodyFrame.changePage(id, url, true); } } @@ -401,7 +406,7 @@ layui.define(['message', 'table', 'jquery', 'element', 'yaml', 'form', 'tab', 'm pearAdmin.changeIframe(id, title, url) } } - + this.fullScreen = function() { if ($(".fullScreen").hasClass("layui-icon-screen-restore")) { screenFun(2).then(function() { @@ -556,7 +561,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 +569,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); @@ -585,13 +590,13 @@ layui.define(['message', 'table', 'jquery', 'element', 'yaml', 'form', 'tab', 'm var menuUrl = $(this).attr("smenu-url"); var menuIcon = $(this).attr("smenu-icon"); var menuTitle = $(this).attr("smenu-title"); - + if(sideMenu.isCollapse){ collapse(); } - + pearAdmin.jump(menuId,menuTitle,menuUrl) - + compatible(); layer.close(layeridx); }) @@ -603,7 +608,7 @@ layui.define(['message', 'table', 'jquery', 'element', 'yaml', 'form', 'tab', 'm $(this).removeClass("this"); }) - // 监听键盘事件 + // 监听键盘事件 // Enter:13 Spacebar:32 UpArrow:38 DownArrow:40 $(document).off("keydown").keydown(function (e) { if (e.keyCode === 13 || e.keyCode === 32) { @@ -637,8 +642,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() { @@ -661,7 +666,7 @@ layui.define(['message', 'table', 'jquery', 'element', 'yaml', 'form', 'tab', 'm close: true }, 300); } else { - bodyFrame.changePage($(this).attr("user-menu-url"), true); + bodyFrame.changePage($(this).attr("user-menu-id"), $(this).attr("user-menu-url"), true); } }); @@ -996,14 +1001,14 @@ 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(); } },50)); - function debounce(fn,await) { + function debounce(fn,awaitTime) { var timerID = null return function () { var arg = arguments[0] @@ -1012,7 +1017,7 @@ layui.define(['message', 'table', 'jquery', 'element', 'yaml', 'form', 'tab', 'm } timerID = setTimeout(function () { fn(arg) - }, await) + }, awaitTime) } } exports('admin', pearAdmin); diff --git a/component/pear/module/frame.js b/component/pear/module/frame.js index a318ee7..26e2749 100644 --- a/component/pear/module/frame.js +++ b/component/pear/module/frame.js @@ -14,19 +14,25 @@ layui.define(['jquery', 'element'], function (exports) { title: opt.title, width: opt.width, height: opt.height, - done: opt.done ? opt.done : function () { console.log("菜单渲染成功"); } + done: opt.done ? opt.done : function (data) { console.log("菜单渲染成功"); } + } + var cacheInfo = frameCache(option.elem); + if (cacheInfo) { + option.url = cacheInfo.url; } createFrameHTML(option); $("#" + option.elem).width(option.width); $("#" + option.elem).height(option.height); + option.done(cacheInfo); return new pearFrame(option); } - pearFrame.prototype.changePage = function (url, loading) { + pearFrame.prototype.changePage = function (id, url, loading) { var $frameLoad = $("#" + this.option.elem).find(".pear-frame-loading"); var $frame = $("#" + this.option.elem + " iframe"); $frame.attr("src", url); frameLoading($frame, $frameLoad, loading); + frameCache(this.option.elem, {id: id,url: url }); } pearFrame.prototype.changePageByElement = function (elem, url, title, loading) { @@ -63,5 +69,13 @@ layui.define(['jquery', 'element'], function (exports) { } } + function frameCache(elem, data){ + if (data){ + sessionStorage.setItem(elem + "-pear-frame-data-current", JSON.stringify(data)); + }else{ + return JSON.parse(sessionStorage.getItem(elem + "-pear-frame-data-current")); + } + } + exports('frame', new pearFrame()); }); -- Gitee From 4bc62d1e0a63f0a0c63bf3f806bbf346173149fe Mon Sep 17 00:00:00 2001 From: sight <1453017105@qq.com> Date: Sat, 28 May 2022 00:12:47 +0800 Subject: [PATCH 2/3] =?UTF-8?q?feat(frame):frame=20=E8=AE=B0=E5=BF=86=20fi?= =?UTF-8?q?x(admin):=20logout=20=E5=90=8E=20tab=20=E9=80=89=E9=A1=B9?= =?UTF-8?q?=E5=8D=A1=E7=BC=93=E5=AD=98=E6=9C=AA=E8=A2=AB=E6=B8=85=E9=99=A4?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- component/pear/module/admin.js | 36 +++++++++++++++++--------- component/pear/module/frame.js | 47 ++++++++++++++++++++++++---------- 2 files changed, 57 insertions(+), 26 deletions(-) diff --git a/component/pear/module/admin.js b/component/pear/module/admin.js index fc98013..404eb64 100644 --- a/component/pear/module/admin.js +++ b/component/pear/module/admin.js @@ -156,19 +156,25 @@ layui.define(['message', 'table', 'jquery', 'element', 'yaml', 'form', 'tab', 'm } else { bodyFrame = pearFrame.render({ elem: 'content', - title: '首页', - url: param.tab.index.href, + session: param.tab.session, width: '100%', height: '100%', + data: { + id: param.tab.index.id, + title: param.tab.index.title, + url: param.tab.index.href, + }, done: function(data){ - setTimeout(function () { - sideMenu.selectItem(data.id); - }, 0) + if(param.tab.session){ + setTimeout(function () { + sideMenu.selectItem(data.id); + }, 0) + } } }); sideMenu.click(function(dom, data) { - bodyFrame.changePage(data.menuId, data.menuUrl, true); + bodyFrame.changePage(data.menuId, data.menuTitle, data.menuUrl, true); compatible(); }) } @@ -395,7 +401,7 @@ layui.define(['message', 'table', 'jquery', 'element', 'yaml', 'form', 'tab', 'm return; } else { sideMenu.selectItem(id); - bodyFrame.changePage(id, url, true); + bodyFrame.changePage(id, title, url, true); } } @@ -457,9 +463,12 @@ layui.define(['message', 'table', 'jquery', 'element', 'yaml', 'form', 'tab', 'm } body.on("click", ".logout", function() { - if (logout() && bodyTab) { + if (bodyTab) { bodyTab.clear(); + } else if (bodyFrame){ + bodyFrame.clear(); } + logout(); }) body.on("click", ".collapse,.pear-cover", function() { @@ -673,16 +682,19 @@ layui.define(['message', 'table', 'jquery', 'element', 'yaml', 'form', 'tab', 'm }); body.on("click", '[user-menu-id]', function() { + var id = $(this).attr("user-menu-id"); + var title = $(this).attr("user-menu-title"); + var url = $(this).attr("user-menu-url"); if (isMuiltTab(config) === "true" || isMuiltTab(config) === true) { bodyTab.addTabOnly({ - id: $(this).attr("user-menu-id"), - title: $(this).attr("user-menu-title"), - url: $(this).attr("user-menu-url"), + id: id, + title: title, + url: url, icon: "", close: true }, 300); } else { - bodyFrame.changePage($(this).attr("user-menu-id"), $(this).attr("user-menu-url"), true); + bodyFrame.changePage(id, title, url, true); } }); diff --git a/component/pear/module/frame.js b/component/pear/module/frame.js index 26e2749..4a1098d 100644 --- a/component/pear/module/frame.js +++ b/component/pear/module/frame.js @@ -10,37 +10,45 @@ layui.define(['jquery', 'element'], function (exports) { pearFrame.prototype.render = function (opt) { var option = { elem: opt.elem, - url: opt.url, - title: opt.title, + data: opt.data, + session: opt.session, width: opt.width, height: opt.height, done: opt.done ? opt.done : function (data) { console.log("菜单渲染成功"); } } - var cacheInfo = frameCache(option.elem); - if (cacheInfo) { - option.url = cacheInfo.url; + if(option.session){ + var cacheInfo = frameCache(option.elem).get(); + if (cacheInfo) { + option.data = cacheInfo; + } + frameCache(option.elem, option.data).set(); } createFrameHTML(option); $("#" + option.elem).width(option.width); $("#" + option.elem).height(option.height); - option.done(cacheInfo); + option.done(option.data); return new pearFrame(option); } - pearFrame.prototype.changePage = function (id, url, loading) { + pearFrame.prototype.changePage = function (id, title, url, loading) { var $frameLoad = $("#" + this.option.elem).find(".pear-frame-loading"); var $frame = $("#" + this.option.elem + " iframe"); $frame.attr("src", url); frameLoading($frame, $frameLoad, loading); - frameCache(this.option.elem, {id: id,url: url }); + if (this.option.session){ + frameCache(this.option.elem, { id: id, title: title, url: url }).set(); + } } - pearFrame.prototype.changePageByElement = function (elem, url, title, loading) { + pearFrame.prototype.changePageByElement = function (elem, id, url, title, loading) { var $frameLoad = $("#" + elem).find(".pear-frame-loading"); var $frame = $("#" + elem + " iframe"); $frame.attr("src", url); $("#" + elem + " .title").html(title); frameLoading($frame, $frameLoad, loading); + if (this.option.session) { + frameCache(this.option.elem, { id: id, title: title, url: url }).set(); + } } pearFrame.prototype.refresh = function (loading) { @@ -50,8 +58,12 @@ layui.define(['jquery', 'element'], function (exports) { frameLoading($frame, $frameLoad, loading); } + pearFrame.prototype.clear = function(){ + frameCache(this.option.elem).remove(); + } + function createFrameHTML(option) { - var iframe = ""; + var iframe = ""; var loading = '
' + '
' + '' + @@ -70,10 +82,17 @@ layui.define(['jquery', 'element'], function (exports) { } function frameCache(elem, data){ - if (data){ - sessionStorage.setItem(elem + "-pear-frame-data-current", JSON.stringify(data)); - }else{ - return JSON.parse(sessionStorage.getItem(elem + "-pear-frame-data-current")); + var key = elem + "-pear-frame-data-current"; + return{ + set: function(){ + sessionStorage.setItem(key, JSON.stringify(data)); + }, + get: function(){ + return JSON.parse(sessionStorage.getItem(key)); + }, + remove: function(){ + sessionStorage.removeItem(key); + } } } -- Gitee From 6d69fcdaa005d640e79657f69b200b3b58671957 Mon Sep 17 00:00:00 2001 From: sight <1453017105@qq.com> Date: Sat, 28 May 2022 02:07:21 +0800 Subject: [PATCH 3/3] fix: admin logout --- component/pear/module/admin.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/component/pear/module/admin.js b/component/pear/module/admin.js index 404eb64..00cb58a 100644 --- a/component/pear/module/admin.js +++ b/component/pear/module/admin.js @@ -463,12 +463,10 @@ layui.define(['message', 'table', 'jquery', 'element', 'yaml', 'form', 'tab', 'm } body.on("click", ".logout", function() { - if (bodyTab) { - bodyTab.clear(); - } else if (bodyFrame){ - bodyFrame.clear(); + if(logout()){ + if(bodyTab) bodyTab.clear(); + if(bodyFrame) bodyFrame.clear(); } - logout(); }) body.on("click", ".collapse,.pear-cover", function() { -- Gitee