Fix tab Right-click menu opens multiple times

develop
就眠仪式 2021-03-11 12:35:32 +08:00
parent f8f0cf8925
commit 1d868f2e98
2 changed files with 28 additions and 18 deletions

View File

@ -1,4 +1,4 @@
layui.define(['table', 'jquery', 'element', 'yaml', 'form', 'tab', 'menu', 'frame', 'theme','convert'],
layui.define(['table', 'jquery', 'element', 'yaml', 'form', 'tab', 'menu', 'frame', 'theme', 'convert'],
function(exports) {
"use strict";
@ -16,8 +16,8 @@ layui.define(['table', 'jquery', 'element', 'yaml', 'form', 'tab', 'menu', 'fram
let sideMenu;
let bodyTab;
let config;
let logout = function(){};
let logout = function() {};
const body = $('body');
const pearAdmin = new function() {
@ -33,14 +33,14 @@ layui.define(['table', 'jquery', 'element', 'yaml', 'form', 'tab', 'menu', 'fram
this.setConfigType = function(type) {
configType = type;
}
this.setAvatar = function(url,username){
this.setAvatar = function(url, username) {
var image = new Image();
image.src = "admin/images/avatar.jpg";
image.onload = function(){
image.onload = function() {
$(".layui-nav-img").attr("src", convert.imageToBase64(image));
}
$(".layui-nav-img").parent().append(username);
$(".layui-nav-img").parent().append(username);
}
this.render = function(initConfig) {
@ -158,7 +158,7 @@ layui.define(['table', 'jquery', 'element', 'yaml', 'form', 'tab', 'menu', 'fram
icon: data.menuIcon,
close: true
}, 300);
compatible();
})
@ -212,9 +212,9 @@ layui.define(['table', 'jquery', 'element', 'yaml', 'form', 'tab', 'menu', 'fram
pearAdmin.removeClass("dark-theme");
pearAdmin.addClass(theme);
}
this.logout = function(callback){
this.logout = function(callback) {
logout = callback;
}
};
@ -234,17 +234,17 @@ layui.define(['table', 'jquery', 'element', 'yaml', 'form', 'tab', 'menu', 'fram
admin.addClass("pear-mini");
}
}
body.on("click",".logout",function(){
body.on("click", ".logout", function() {
// 回调
var result = logout();
if(result){
if (result) {
// 清空缓存
bodyTab.clear();
}
})
body.on("click", ".collaspe,.pear-cover", function() {
collaspe();
});
@ -458,5 +458,6 @@ layui.define(['table', 'jquery', 'element', 'yaml', 'form', 'tab', 'menu', 'fram
res("返回值");
});
}
exports('admin', pearAdmin);
})

View File

@ -45,6 +45,8 @@ layui.define(['jquery', 'element'], function(exports) {
}
}
var lastIndex;
var tab = createTab(option);
$("#" + option.elem).html(tab);
$(".layui-tab[lay-filter='" + option.elem + "'] .layui-tab-prev").click(function() {
@ -73,7 +75,7 @@ layui.define(['jquery', 'element'], function(exports) {
var currentId = $(this).attr("lay-id");
var menu = "<ul><li class='item' id='" + option.elem + "closeThis'>关闭当前</li><li class='item' id='" + option.elem +
"closeOther'>关闭其他</li><li class='item' id='" + option.elem + "closeAll'>关闭所有</li></ul>"
"closeOther'>关闭其他</li><li class='item' id='" + option.elem + "closeAll'>关闭所有</li></ul>";
// 初始化
layer.open({
@ -87,8 +89,9 @@ layui.define(['jquery', 'element'], function(exports) {
offset: [top, left],
content: menu, //iframe的url,
success: function(layero, index) {
layer.close(lastIndex);
lastIndex = index;
menuEvent(option,index);
console.log("初始化")
var timer;
$(layero).on('mouseout', function() {
timer = setTimeout(function() {
@ -99,6 +102,12 @@ layui.define(['jquery', 'element'], function(exports) {
$(layero).on('mouseover', function() {
clearTimeout(timer);
});
// 清除 item 右击
$(layero).on('contextmenu',function(){
return false;
})
}
});
return false;