submit: 清理tabMenu缓存(okTab.removeTabStorage(callback))

master
zhizous 2019-12-17 00:55:43 +08:00
parent 62cc9787e4
commit 9ff8e6611e
2 changed files with 336 additions and 314 deletions

View File

@ -2,344 +2,348 @@
var objOkTab = ""; var objOkTab = "";
layui.use(["element", "layer", "okUtils", "okTab", "okLayer", "okContextMenu", "okHoliday"], function () { layui.use(["element", "layer", "okUtils", "okTab", "okLayer", "okContextMenu", "okHoliday"], function () {
var okUtils = layui.okUtils; var okUtils = layui.okUtils;
var $ = layui.jquery; var $ = layui.jquery;
var layer = layui.layer; var layer = layui.layer;
var okLayer = layui.okLayer; var okLayer = layui.okLayer;
var okHoliday = layui.okHoliday; var okHoliday = layui.okHoliday;
var okTab = layui.okTab({ var okTab = layui.okTab({
// 菜单请求路径 // 菜单请求路径
url: "data/navs.json", url: "data/navs.json",
// 允许同时选项卡的个数 // 允许同时选项卡的个数
openTabNum: 30, openTabNum: 30,
// 如果返回的结果和navs.json中的数据结构一致可省略这个方法 // 如果返回的结果和navs.json中的数据结构一致可省略这个方法
parseData: function (data) { parseData: function (data) {
return data; return data;
} }
}); });
objOkTab = okTab; objOkTab = okTab;
okLoading.close();/**关闭加载动画*/ okLoading.close();/**关闭加载动画*/
/** /**
* 左侧导航渲染完成之后的操作 * 左侧导航渲染完成之后的操作
*/ */
okTab.render(function () { okTab.render(function () {
/**tab栏的鼠标右键事件**/ /**tab栏的鼠标右键事件**/
$("body .ok-tab").okContextMenu({ $("body .ok-tab").okContextMenu({
width: 'auto', width: 'auto',
itemHeight: 30, itemHeight: 30,
menu: [ menu: [
{ {
text: "定位所在页", text: "定位所在页",
icon: "ok-icon ok-icon-location", icon: "ok-icon ok-icon-location",
callback: function () { callback: function () {
okTab.positionTab(); okTab.positionTab();
} }
}, },
{ {
text: "关闭当前页", text: "关闭当前页",
icon: "ok-icon ok-icon-roundclose", icon: "ok-icon ok-icon-roundclose",
callback: function () { callback: function () {
okTab.tabClose(1); okTab.tabClose(1);
} }
}, },
{ {
text: "关闭其他页", text: "关闭其他页",
icon: "ok-icon ok-icon-roundclose", icon: "ok-icon ok-icon-roundclose",
callback: function () { callback: function () {
okTab.tabClose(2); okTab.tabClose(2);
} }
}, },
{ {
text: "关闭所有页", text: "关闭所有页",
icon: "ok-icon ok-icon-roundclose", icon: "ok-icon ok-icon-roundclose",
callback: function () { callback: function () {
okTab.tabClose(3); okTab.tabClose(3);
} }
} }
] ]
}); });
}); });
/** /**
* 添加新窗口 * 添加新窗口
*/ */
$("body").on("click", "#navBar .layui-nav-item a, #userInfo a", function () { $("body").on("click", "#navBar .layui-nav-item a, #userInfo a", function () {
// 如果不存在子级 // 如果不存在子级
if ($(this).siblings().length == 0) { if ($(this).siblings().length == 0) {
okTab.tabAdd($(this)); okTab.tabAdd($(this));
} }
// 关闭其他展开的二级标签 // 关闭其他展开的二级标签
$(this).parent("li").siblings().removeClass("layui-nav-itemed"); $(this).parent("li").siblings().removeClass("layui-nav-itemed");
if (!$(this).attr("lay-id")) { if (!$(this).attr("lay-id")) {
var topLevelEle = $(this).parents("li.layui-nav-item"); var topLevelEle = $(this).parents("li.layui-nav-item");
var childs = $("#navBar > li > dl.layui-nav-child").not(topLevelEle.children("dl.layui-nav-child")); var childs = $("#navBar > li > dl.layui-nav-child").not(topLevelEle.children("dl.layui-nav-child"));
childs.removeAttr("style"); childs.removeAttr("style");
} }
}); });
/** /**
* 左侧菜单展开动画 * 左侧菜单展开动画
*/ */
$("#navBar").on("click", ".layui-nav-item a", function () { $("#navBar").on("click", ".layui-nav-item a", function () {
if (!$(this).attr("lay-id")) { if (!$(this).attr("lay-id")) {
var superEle = $(this).parent(); var superEle = $(this).parent();
var ele = $(this).next('.layui-nav-child'); var ele = $(this).next('.layui-nav-child');
var height = ele.height(); var height = ele.height();
ele.css({"display": "block"}); ele.css({"display": "block"});
// 是否是展开状态 // 是否是展开状态
if (superEle.is(".layui-nav-itemed")) { if (superEle.is(".layui-nav-itemed")) {
ele.height(0); ele.height(0);
ele.animate({height: height + "px"}, function () { ele.animate({height: height + "px"}, function () {
ele.css({height: "auto"}); ele.css({height: "auto"});
}); });
} else { } else {
ele.animate({height: 0}, function () { ele.animate({height: 0}, function () {
ele.removeAttr("style"); ele.removeAttr("style");
}); });
} }
} }
}); });
/** /**
* 左边菜单显隐功能 * 左边菜单显隐功能
*/ */
$(".ok-menu").click(function () { $(".ok-menu").click(function () {
$(".layui-layout-admin").toggleClass("ok-left-hide"); $(".layui-layout-admin").toggleClass("ok-left-hide");
$(this).find("i").toggleClass("ok-menu-hide"); $(this).find("i").toggleClass("ok-menu-hide");
localStorage.setItem("isResize", false); localStorage.setItem("isResize", false);
setTimeout(function () { setTimeout(function () {
localStorage.setItem("isResize", true); localStorage.setItem("isResize", true);
}, 1200); }, 1200);
}); });
/** /**
* 移动端的处理事件 * 移动端的处理事件
*/ */
$("body").on("click", ".layui-layout-admin .ok-left a[data-url], .ok-make", function () { $("body").on("click", ".layui-layout-admin .ok-left a[data-url], .ok-make", function () {
if ($(".layui-layout-admin").hasClass("ok-left-hide")) { if ($(".layui-layout-admin").hasClass("ok-left-hide")) {
$(".layui-layout-admin").removeClass("ok-left-hide"); $(".layui-layout-admin").removeClass("ok-left-hide");
$(".ok-menu").find('i').removeClass("ok-menu-hide"); $(".ok-menu").find('i').removeClass("ok-menu-hide");
} }
}); });
/** /**
* tab左右移动 * tab左右移动
*/ */
$("body").on("click", ".okNavMove", function () { $("body").on("click", ".okNavMove", function () {
var moveId = $(this).attr("data-id"); var moveId = $(this).attr("data-id");
var that = this; var that = this;
okTab.navMove(moveId, that); okTab.navMove(moveId, that);
}); });
/** /**
* 刷新当前tab页 * 刷新当前tab页
*/ */
$("body").on("click", ".ok-refresh", function () { $("body").on("click", ".ok-refresh", function () {
okTab.refresh(this); okTab.refresh(this, function (okTab) {
}); //刷新之后所处理的事件
});
});
/** /**
* 关闭tab页 * 关闭tab页
*/ */
$("body").on("click", "#tabAction a", function () { $("body").on("click", "#tabAction a", function () {
var num = $(this).attr("data-num"); var num = $(this).attr("data-num");
okTab.tabClose(num); okTab.tabClose(num);
}); });
/** /**
* 键盘的事件监听 * 键盘的事件监听
*/ */
$("body").on("keydown", function (event) { $("body").on("keydown", function (event) {
event = event || window.event || arguments.callee.caller.arguments[0]; event = event || window.event || arguments.callee.caller.arguments[0];
// 按 Esc // 按 Esc
if (event && event.keyCode === 27) { if (event && event.keyCode === 27) {
console.log("Esc"); console.log("Esc");
$("#fullScreen").children("i").eq(0).removeClass("layui-icon-screen-restore"); $("#fullScreen").children("i").eq(0).removeClass("layui-icon-screen-restore");
} }
// 按 F11 // 按 F11
if (event && event.keyCode == 122) { if (event && event.keyCode == 122) {
console.log("F11"); console.log("F11");
$("#fullScreen").children("i").eq(0).addClass("layui-icon-screen-restore"); $("#fullScreen").children("i").eq(0).addClass("layui-icon-screen-restore");
} }
}); });
/** /**
* 全屏/退出全屏 * 全屏/退出全屏
*/ */
$("body").on("click", "#fullScreen", function () { $("body").on("click", "#fullScreen", function () {
if ($(this).children("i").hasClass("layui-icon-screen-restore")) { if ($(this).children("i").hasClass("layui-icon-screen-restore")) {
screenFun(2).then(function () { screenFun(2).then(function () {
$("#fullScreen").children("i").eq(0).removeClass("layui-icon-screen-restore"); $("#fullScreen").children("i").eq(0).removeClass("layui-icon-screen-restore");
}); });
} else { } else {
screenFun(1).then(function () { screenFun(1).then(function () {
$("#fullScreen").children("i").eq(0).addClass("layui-icon-screen-restore"); $("#fullScreen").children("i").eq(0).addClass("layui-icon-screen-restore");
}); });
} }
}); });
/** /**
* 全屏和退出全屏的方法 * 全屏和退出全屏的方法
* @param num 1代表全屏 2代表退出全屏 * @param num 1代表全屏 2代表退出全屏
* @returns {Promise} * @returns {Promise}
*/ */
function screenFun(num) { function screenFun(num) {
num = num || 1; num = num || 1;
num = num * 1; num = num * 1;
var docElm = document.documentElement; var docElm = document.documentElement;
switch (num) { switch (num) {
case 1: case 1:
if (docElm.requestFullscreen) { if (docElm.requestFullscreen) {
docElm.requestFullscreen(); docElm.requestFullscreen();
} else if (docElm.mozRequestFullScreen) { } else if (docElm.mozRequestFullScreen) {
docElm.mozRequestFullScreen(); docElm.mozRequestFullScreen();
} else if (docElm.webkitRequestFullScreen) { } else if (docElm.webkitRequestFullScreen) {
docElm.webkitRequestFullScreen(); docElm.webkitRequestFullScreen();
} else if (docElm.msRequestFullscreen) { } else if (docElm.msRequestFullscreen) {
docElm.msRequestFullscreen(); docElm.msRequestFullscreen();
} }
break; break;
case 2: case 2:
if (document.exitFullscreen) { if (document.exitFullscreen) {
document.exitFullscreen(); document.exitFullscreen();
} else if (document.mozCancelFullScreen) { } else if (document.mozCancelFullScreen) {
document.mozCancelFullScreen(); document.mozCancelFullScreen();
} else if (document.webkitCancelFullScreen) { } else if (document.webkitCancelFullScreen) {
document.webkitCancelFullScreen(); document.webkitCancelFullScreen();
} else if (document.msExitFullscreen) { } else if (document.msExitFullscreen) {
document.msExitFullscreen(); document.msExitFullscreen();
} }
break; break;
} }
return new Promise(function (res, rej) { return new Promise(function (res, rej) {
res("返回值"); res("返回值");
}); });
} }
/** /**
* 系统公告 * 系统公告
*/ */
$(document).on("click", "#notice", noticeFun); $(document).on("click", "#notice", noticeFun);
!function () { !function () {
var notice = sessionStorage.getItem("notice"); var notice = sessionStorage.getItem("notice");
if (notice != "true") { if (notice != "true") {
noticeFun(); noticeFun();
} }
}(); }();
function noticeFun() { function noticeFun() {
var srcWidth = okUtils.getBodyWidth(); var srcWidth = okUtils.getBodyWidth();
layer.open({ layer.open({
type: 0, title: "系统公告", btn: "我知道啦", btnAlign: 'c', content: okHoliday.getContent(), type: 0, title: "系统公告", btn: "我知道啦", btnAlign: 'c', content: okHoliday.getContent(),
yes: function (index) { yes: function (index) {
if (srcWidth > 800) { if (srcWidth > 800) {
layer.tips('公告跑到这里去啦', '#notice', { layer.tips('公告跑到这里去啦', '#notice', {
tips: [1, '#000'], tips: [1, '#000'],
time: 2000 time: 2000
}); });
} }
sessionStorage.setItem("notice", "true"); sessionStorage.setItem("notice", "true");
layer.close(index); layer.close(index);
}, },
cancel: function (index) { cancel: function (index) {
if (srcWidth > 800) { if (srcWidth > 800) {
layer.tips('公告跑到这里去啦', '#notice', { layer.tips('公告跑到这里去啦', '#notice', {
tips: [1, '#000'], tips: [1, '#000'],
time: 2000 time: 2000
}); });
} }
} }
}); });
} }
/** /**
* 捐赠作者 * 捐赠作者
*/ */
$(".layui-footer button.donate").click(function () { $(".layui-footer button.donate").click(function () {
layer.tab({ layer.tab({
area: ["330px", "350px"], area: ["330px", "350px"],
tab: [{ tab: [{
title: "支付宝", title: "支付宝",
content: "<img src='images/zfb.jpg' width='200' height='300' style='margin: 0 auto; display: block;'>" content: "<img src='images/zfb.jpg' width='200' height='300' style='margin: 0 auto; display: block;'>"
}, { }, {
title: "微信", title: "微信",
content: "<img src='images/wx.jpg' width='200' height='300' style='margin: 0 auto; display: block;'>" content: "<img src='images/wx.jpg' width='200' height='300' style='margin: 0 auto; display: block;'>"
}] }]
}); });
}); });
/** /**
* QQ群交流 * QQ群交流
*/ */
$("body").on("click", ".layui-footer button.communication, #noticeQQ", function () { $("body").on("click", ".layui-footer button.communication, #noticeQQ", function () {
layer.tab({ layer.tab({
area: ["auto", "370px"], area: ["auto", "370px"],
tab: [{ tab: [{
title: "QQ群2", title: "QQ群2",
content: "<img src='images/qq2.png' width='200' height='300' style='margin: 0 auto; display: block;'/>" content: "<img src='images/qq2.png' width='200' height='300' style='margin: 0 auto; display: block;'/>"
}, { }, {
title: "QQ群1已满", title: "QQ群1已满",
content: "<img src='images/qq1.png' width='200' height='300' style='margin: 0 auto; display: block;'/>" content: "<img src='images/qq1.png' width='200' height='300' style='margin: 0 auto; display: block;'/>"
}] }]
}); });
}); });
/** /**
* 弹窗皮肤 * 弹窗皮肤
*/ */
$("#alertSkin").click(function () { $("#alertSkin").click(function () {
okLayer.open("皮肤动画", "pages/system/alertSkin.html", "50%", "45%", function (layero) { okLayer.open("皮肤动画", "pages/system/alertSkin.html", "50%", "45%", function (layero) {
}, function () { }, function () {
}); });
}); });
/** /**
* 退出操作 * 退出操作
*/ */
$("#logout").click(function () { $("#logout").click(function () {
okLayer.confirm("确定要退出吗?", function (index) { okLayer.confirm("确定要退出吗?", function (index) {
window.location = "pages/login.html"; okTab.removeTabStorage(function (res) {
}); window.location = "pages/login.html";
}); });
});
});
/** /**
* 锁定账户 * 锁定账户
*/ */
$("#lock").click(function () { $("#lock").click(function () {
okLayer.confirm("确定要锁定账户吗?", function (index) { okLayer.confirm("确定要锁定账户吗?", function (index) {
layer.close(index); layer.close(index);
$(".yy").show(); $(".yy").show();
layer.prompt({ layer.prompt({
btn: ['确定'], btn: ['确定'],
title: '输入密码解锁(123456)', title: '输入密码解锁(123456)',
closeBtn: 0, closeBtn: 0,
formType: 1 formType: 1
}, function (value, index, elem) { }, function (value, index, elem) {
if (value == "123456") { if (value == "123456") {
layer.close(index); layer.close(index);
$(".yy").hide(); $(".yy").hide();
} else { } else {
layer.msg('密码错误', {anim: 6, time: 1000}); layer.msg('密码错误', {anim: 6, time: 1000});
} }
}); });
}); });
}); });
console.log(" __ .___ .__ \n" + console.log(" __ .___ .__ \n" +
" ____ | | __ _____ __| _/_____ |__| ____ \n" + " ____ | | __ _____ __| _/_____ |__| ____ \n" +
" / _ \\| |/ / ______ \\__ \\ / __ |/ \\| |/ \\ \n" + " / _ \\| |/ / ______ \\__ \\ / __ |/ \\| |/ \\ \n" +
"( <_> ) < /_____/ / __ \\_/ /_/ | Y Y \\ | | \\\n" + "( <_> ) < /_____/ / __ \\_/ /_/ | Y Y \\ | | \\\n" +
" \\____/|__|_ \\ (____ /\\____ |__|_| /__|___| /\n" + " \\____/|__|_ \\ (____ /\\____ |__|_| /__|___| /\n" +
" \\/ \\/ \\/ \\/ \\/\n" + " \\/ \\/ \\/ \\/ \\/\n" +
"" + "" +
"版本v2.0\n" + "版本v2.0\n" +
"作者bobi\n" + "作者bobi\n" +
"邮箱bobi1234@foxmail.com\n" + "邮箱bobi1234@foxmail.com\n" +
"企鹅833539807\n" + "企鹅833539807\n" +
"描述:一个很赞的,扁平化风格的,响应式布局的后台管理模版,旨为后端程序员减压!"); "描述:一个很赞的,扁平化风格的,响应式布局的后台管理模版,旨为后端程序员减压!");
}); });

View File

@ -31,6 +31,16 @@ let OpenTabMenuFun = function ($, callback) {
} }
}; };
/**删除缓存中的tabMenu**/
let removeTabMenu = function (okTab, callback) {
sessionStorage.removeItem("tabMenu");
sessionStorage.removeItem("notice");
sessionStorage.removeItem("lay-id");
if (typeof callback == "function") {
callback(okTab);
}
};
/**存储打开的tabMenu**/ /**存储打开的tabMenu**/
function saveTabMenuFun($) { function saveTabMenuFun($) {
let tabTitle = $("<div>" + $("#tabTitle").html() + "</div>"); let tabTitle = $("<div>" + $("#tabTitle").html() + "</div>");
@ -258,6 +268,11 @@ layui.define(["element", "jquery"], function (exports) {
}); });
}; };
//删除缓存中的tab
okTab.prototype.removeTabStorage = function (callback) {
removeTabMenu(this, callback);
};
//添加tab页 //添加tab页
okTab.prototype.tabAdd = function (_thisa) { okTab.prototype.tabAdd = function (_thisa) {
var that = this; var that = this;
@ -366,10 +381,13 @@ layui.define(["element", "jquery"], function (exports) {
}; };
//刷新当前tab页 //刷新当前tab页
okTab.prototype.refresh = function (_this) { okTab.prototype.refresh = function (_this, callback) {
if (!($(_this).hasClass("refreshThis"))) { if (!($(_this).hasClass("refreshThis"))) {
$(_this).addClass("refreshThis"); $(_this).addClass("refreshThis");
$(".ok-tab-content .layui-show").find("iframe")[0].contentWindow.location.reload(true); $(".ok-tab-content .layui-show").find("iframe")[0].contentWindow.location.reload(true);
if(typeof callback == "function"){
callback(okTab);
}
setTimeout(function () { setTimeout(function () {
$(_this).removeClass("refreshThis"); $(_this).removeClass("refreshThis");
}, 2000) }, 2000)