更新依赖pearadminlayui

This commit is contained in:
mkg
2021-10-02 16:11:07 +08:00
parent d30a3d79de
commit 24d2523385
519 changed files with 114403 additions and 91672 deletions
@@ -24,7 +24,6 @@ layui.define(['message', 'table', 'jquery', 'element', 'yaml', 'form', 'tab', 'm
var pearAdmin = new function() {
// 默认配置
var configType = 'yml';
var configPath = 'pear.config.yml';
@@ -36,15 +35,6 @@ layui.define(['message', 'table', 'jquery', 'element', 'yaml', 'form', 'tab', 'm
configType = type;
}
this.setAvatar = function(url, username) {
var image = new Image();
image.src = url || "admin/images/avatar.jpg";
image.onload = function() {
$(".layui-nav-img").attr("src", convert.imageToBase64(image));
}
$(".layui-nav-img").parent().append(username);
}
this.render = function(initConfig) {
if (initConfig !== undefined) {
applyConfig(initConfig);
@@ -92,12 +82,12 @@ layui.define(['message', 'table', 'jquery', 'element', 'yaml', 'form', 'tab', 'm
theme: "dark-theme",
height: '100%',
method: param.menu.method,
control: param.menu.control ? 'control' : false, // control
control: isControl(param) === 'true' || isControl(param) === true ? 'control' : false, // control
controlWidth: param.menu.controlWidth,
defaultMenu: 0,
accordion: param.menu.accordion,
url: param.menu.data,
data: param.menu.data, //async为false时,传入菜单数组
data: param.menu.data,
parseData: false,
change: function() {
compatible();
@@ -110,24 +100,12 @@ layui.define(['message', 'table', 'jquery', 'element', 'yaml', 'form', 'tab', 'm
}
this.bodyRender = function(param) {
body.on("click", ".refresh", function() {
var refreshA = $(".refresh a");
refreshA.removeClass("layui-icon-refresh-1");
refreshA.addClass("layui-anim");
refreshA.addClass("layui-anim-rotate");
refreshA.addClass("layui-anim-loop");
refreshA.addClass("layui-icon-loading");
if (param.tab.muiltTab) bodyTab.refresh(400);
else bodyFrame.refresh(400);
setTimeout(function() {
refreshA.addClass("layui-icon-refresh-1");
refreshA.removeClass("layui-anim");
refreshA.removeClass("layui-anim-rotate");
refreshA.removeClass("layui-anim-loop");
refreshA.removeClass("layui-icon-loading");
}, 600)
refresh();
})
if (param.tab.muiltTab) {
if (isMuiltTab(param) === "true" || isMuiltTab(param) === true) {
bodyTab = pearTab.render({
elem: 'content',
roll: true,
@@ -136,7 +114,7 @@ layui.define(['message', 'table', 'jquery', 'element', 'yaml', 'form', 'tab', 'm
height: '100%',
session: param.tab.session,
index: 0,
tabMax: param.tab.tabMax,
tabMax: param.tab.max,
closeEvent: function(id) {
sideMenu.selectItem(id);
},
@@ -155,6 +133,7 @@ layui.define(['message', 'table', 'jquery', 'element', 'yaml', 'form', 'tab', 'm
}
}
});
bodyTab.click(function(id) {
if (!param.tab.keepState) {
bodyTab.refresh(false);
@@ -185,7 +164,7 @@ layui.define(['message', 'table', 'jquery', 'element', 'yaml', 'form', 'tab', 'm
});
sideMenu.click(function(dom, data) {
bodyFrame.changePage(data.menuUrl, data.menuPath, true);
bodyFrame.changePage(data.menuUrl, true);
compatible()
})
}
@@ -198,6 +177,90 @@ layui.define(['message', 'table', 'jquery', 'element', 'yaml', 'form', 'tab', 'm
}, param.other.keepLoad)
}
this.themeRender = function(option) {
if (option.theme.allowCustom === false) {
$(".setting").remove();
}
var colorId = localStorage.getItem("theme-color");
var currentColor = getColorById(colorId);
localStorage.setItem("theme-color", currentColor.id);
localStorage.setItem("theme-color-color", currentColor.color);
localStorage.setItem("theme-color-second", currentColor.second);
pearTheme.changeTheme(window, isAutoHead(config));
var menu = localStorage.getItem("theme-menu");
if (menu === null) {
menu = option.theme.defaultMenu;
} else {
if (option.theme.allowCustom === false) {
menu = option.theme.defaultMenu;
}
}
var header = localStorage.getItem("theme-header");
if (header === null) {
header = option.theme.defaultHeader;
} else {
if (option.theme.allowCustom === false) {
header = option.theme.defaultHeader;
}
}
var banner = localStorage.getItem("theme-banner");
if (banner === null) {
banner = option.theme.banner;
} else {
if (option.theme.allowCustom === false) {
banner = option.theme.banner;
}
}
var autoHead = localStorage.getItem("auto-head");
if (autoHead === null) {
autoHead = option.other.autoHead;
} else {
if (option.theme.allowCustom === false) {
autoHead = option.other.autoHead;
}
}
var muiltTab = localStorage.getItem("muilt-tab");
if (muiltTab === null) {
muiltTab = option.tab.enable;
} else {
if (option.theme.allowCustom === false) {
muiltTab = option.tab.enable;
}
}
var control = localStorage.getItem("control");
if (control === null) {
control = option.menu.control;
} else {
if (option.theme.allowCustom === false) {
control = option.menu.control;
}
}
localStorage.setItem("muilt-tab",muiltTab);
localStorage.setItem("theme-banner", banner);
localStorage.setItem("theme-menu", menu);
localStorage.setItem("theme-header", header);
localStorage.setItem("auto-head", autoHead);
localStorage.setItem("control",control);
this.menuSkin(menu);
this.headerSkin(header);
this.bannerSkin(banner);
}
this.bannerSkin = function(theme) {
var pearAdmin = $(".pear-admin");
pearAdmin.removeClass("banner-layout");
if(theme === true || theme === "true") {
pearAdmin.addClass("banner-layout");
}
}
this.collaspe = function(param) {
if (param.menu.collaspe) {
if ($(window).width() >= 768) {
@@ -206,29 +269,15 @@ layui.define(['message', 'table', 'jquery', 'element', 'yaml', 'form', 'tab', 'm
}
}
this.themeRender = function(option) {
if (option.theme.allowCustom === false) {
$(".setting").remove();
}
var colorId = localStorage.getItem("theme-color");
var currentColor = getColorById(colorId);
localStorage.setItem("theme-color", currentColor.id);
localStorage.setItem("theme-color-context", currentColor.color);
pearTheme.changeTheme(window, option.other.autoHead);
var menu = localStorage.getItem("theme-menu");
if (menu == null) {
menu = option.theme.defaultMenu;
} else {
if (option.theme.allowCustom === false) {
menu = option.theme.defaultMenu;
}
}
localStorage.setItem("theme-menu", menu);
this.menuSkin(menu);
}
this.menuSkin = function(theme) {
var pearAdmin = $(".pear-admin");
var pearAdmin = $(".pear-admin .layui-side");
pearAdmin.removeClass("light-theme");
pearAdmin.removeClass("dark-theme");
pearAdmin.addClass(theme);
}
this.headerSkin = function(theme) {
var pearAdmin = $(".pear-admin .layui-header");
pearAdmin.removeClass("light-theme");
pearAdmin.removeClass("dark-theme");
pearAdmin.addClass(theme);
@@ -241,43 +290,45 @@ layui.define(['message', 'table', 'jquery', 'element', 'yaml', 'form', 'tab', 'm
this.message = function(callback) {
if (callback != null) {
msgInstance.click(callback);
} else {
msgInstance.click(messageTip);
}
}
this.jump = function(id, title, url) {
if (config.tab.muiltTab) {
if (isMuiltTab(config)==="true" || isMuiltTab(param) === true) {
bodyTab.addTabOnly({
id: id,
title: title,
url: url,
icon: null,
close: true
}, 300);
}, 400);
} else {
sideMenu.selectItem(id);
bodyFrame.changePage(url, title, true);
bodyFrame.changePage(url, true);
}
}
this.refresh = function() {
refresh();
}
};
var messageTip = function(id, title, context, form) {
layer.open({
type: 1,
title: '消息', //标题
area: ['390px', '330px'], //宽高
shade: 0.4, //遮罩透明度
content: "<div style='background-color:whitesmoke;'><div class='layui-card'><div class='layui-card-body'>来源 : &nbsp; " +
form + "</div><div class='layui-card-header' >标题 : &nbsp; " + title +
"</div><div class='layui-card-body' >内容 : &nbsp; " + context + "</div></div></div>", //支持获取DOM元素
btn: ['确认'], //按钮组
scrollbar: false, //屏蔽浏览器滚动条
yes: function(index) { //layer.msg('yes'); //点击确定回调
layer.close(index);
showToast();
}
});
function refresh() {
var refreshA = $(".refresh a");
refreshA.removeClass("layui-icon-refresh-1");
refreshA.addClass("layui-anim");
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);
setTimeout(function() {
refreshA.addClass("layui-icon-refresh-1");
refreshA.removeClass("layui-anim");
refreshA.removeClass("layui-anim-rotate");
refreshA.removeClass("layui-anim-loop");
refreshA.removeClass("layui-icon-loading");
}, 600)
}
function collaspe() {
@@ -297,11 +348,7 @@ layui.define(['message', 'table', 'jquery', 'element', 'yaml', 'form', 'tab', 'm
}
body.on("click", ".logout", function() {
// 回调
var result = logout();
if (result) {
// 清空缓存
if (logout()) {
bodyTab.clear();
}
})
@@ -323,7 +370,7 @@ layui.define(['message', 'table', 'jquery', 'element', 'yaml', 'form', 'tab', 'm
});
body.on("click", '[user-menu-id]', function() {
if (config.tab.muiltTab) {
if (isMuiltTab(config) === "true" || isMuiltTab(param) === true) {
bodyTab.addTabOnly({
id: $(this).attr("user-menu-id"),
title: $(this).attr("user-menu-title"),
@@ -332,13 +379,13 @@ 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-url"), true);
}
});
body.on("click", ".setting", function() {
var bgColorHtml =
var menuItem =
'<li class="layui-this" data-select-bgcolor="dark-theme" >' +
'<a href="javascript:;" data-skin="skin-blue" style="" class="clearfix full-opacity-hover">' +
'<div><span style="display:block; width: 20%; float: left; height: 12px; background: #28333E;"></span><span style="display:block; width: 80%; float: left; height: 12px; background: white;"></span></div>' +
@@ -346,7 +393,7 @@ layui.define(['message', 'table', 'jquery', 'element', 'yaml', 'form', 'tab', 'm
'</a>' +
'</li>';
bgColorHtml +=
menuItem +=
'<li data-select-bgcolor="light-theme" >' +
'<a href="javascript:;" data-skin="skin-blue" style="" class="clearfix full-opacity-hover">' +
'<div><span style="display:block; width: 20%; float: left; height: 12px; background: white;"></span><span style="display:block; width: 80%; float: left; height: 12px; background: white;"></span></div>' +
@@ -354,11 +401,54 @@ layui.define(['message', 'table', 'jquery', 'element', 'yaml', 'form', 'tab', 'm
'</a>' +
'</li>';
var html =
var menuHtml =
'<div class="pearone-color">\n' +
'<div class="color-title">整体风格</div>\n' +
'<div class="color-title">菜单风格</div>\n' +
'<div class="color-content">\n' +
'<ul>\n' + bgColorHtml + '</ul>\n' +
'<ul>\n' + menuItem + '</ul>\n' +
'</div>\n' +
'</div>';
var headItem =
'<li class="layui-this" data-select-header="light-theme" >' +
'<a href="javascript:;" data-skin="skin-blue" style="" class="clearfix full-opacity-hover">' +
'<div><span style="display:block; width: 20%; float: left; height: 12px; background: #28333E;"></span><span style="display:block; width: 80%; float: left; height: 12px; background: white;"></span></div>' +
'<div><span style="display:block; width: 20%; float: left; height: 40px; background: #28333E;"></span><span style="display:block; width: 80%; float: left; height: 40px; background: #f4f5f7;"></span></div>' +
'</a>' +
'</li>';
headItem +=
'<li data-select-header="dark-theme" >' +
'<a href="javascript:;" data-skin="skin-blue" style="" class="clearfix full-opacity-hover">' +
'<div><span style="display:block; width: 20%; float: left; height: 12px; background: #28333E;"></span><span style="display:block; width: 80%; float: left; height: 12px; background: #28333E;"></span></div>' +
'<div><span style="display:block; width: 20%; float: left; height: 40px; background: #28333E;"></span><span style="display:block; width: 80%; float: left; height: 40px; background: #f4f5f7;"></span></div>' +
'</a>' +
'</li>';
var headHtml =
'<div class="pearone-color">\n' +
'<div class="color-title">顶部风格</div>\n' +
'<div class="color-content">\n' +
'<ul>\n' + headItem + '</ul>\n' +
'</div>\n' +
'</div>';
var moreItem =
'<div class="layui-form-item"><div class="layui-input-inline"><input type="checkbox" name="control" lay-filter="control" lay-skin="switch" lay-text="开|关"></div><span class="set-text">菜单</span></div>';
moreItem +=
'<div class="layui-form-item"><div class="layui-input-inline"><input type="checkbox" name="muilt-tab" lay-filter="muilt-tab" lay-skin="switch" lay-text="开|关"></div><span class="set-text">视图</span></div>';
moreItem +=
'<div class="layui-form-item"><div class="layui-input-inline"><input type="checkbox" name="banner" lay-filter="banner" lay-skin="switch" lay-text="开|关"></div><span class="set-text">通栏</span></div>';
moreItem +=
'<div class="layui-form-item"><div class="layui-input-inline"><input type="checkbox" name="auto-head" lay-filter="auto-head" lay-skin="switch" lay-text="开|关"></div><span class="set-text">通色</span></div>';
var moreHtml = '<br><div class="pearone-color">\n' +
'<div class="color-title">更多设置</div>\n' +
'<div class="color-content">\n' +
'<form class="layui-form">\n' + moreItem + '</form>\n' +
'</div>\n' +
'</div>';
@@ -373,20 +463,30 @@ layui.define(['message', 'table', 'jquery', 'element', 'yaml', 'form', 'tab', 'm
anim: -1,
skin: 'layer-anim-right',
move: false,
content: html + buildColorHtml() + buildLinkHtml() + bottomTool(),
content: menuHtml + headHtml + buildColorHtml() + moreHtml + bottomTool(),
success: function(layero, index) {
form.render();
var color = localStorage.getItem("theme-color");
var menu = localStorage.getItem("theme-menu");
var header = localStorage.getItem("theme-header");
if (color !== "null") {
$(".select-color-item").removeClass("layui-icon").removeClass("layui-icon-ok");
$("*[color-id='" + color + "']").addClass("layui-icon").addClass("layui-icon-ok");
}
if (menu !== "null") {
$("*[data-select-bgcolor]").removeClass("layui-this");
$("[data-select-bgcolor='" + menu + "']").addClass("layui-this");
}
if (header !== "null") {
$("*[data-select-header]").removeClass("layui-this");
$("[data-select-header='" + header + "']").addClass("layui-this");
}
$('#layui-layer-shade' + index).click(function() {
var $layero = $('#layui-layer' + index);
$layero.animate({
@@ -404,6 +504,53 @@ layui.define(['message', 'table', 'jquery', 'element', 'yaml', 'form', 'tab', 'm
layer.close(index);
});
})
form.on('switch(control)', function(data) {
localStorage.setItem("control", this.checked);
window.location.reload();
})
form.on('switch(muilt-tab)', function(data) {
localStorage.setItem("muilt-tab", this.checked);
window.location.reload();
})
form.on('switch(auto-head)', function(data) {
localStorage.setItem("auto-head", this.checked);
pearTheme.changeTheme(window, this.checked);
})
form.on('switch(banner)', function(data) {
localStorage.setItem("theme-banner", this.checked);
pearAdmin.bannerSkin(this.checked);
})
if (localStorage.getItem('theme-banner') === 'true') {
$('input[name="banner"]').attr('checked', 'checked')
} else {
$('input[name="banner"]').removeAttr('checked')
}
if (localStorage.getItem('control') === 'true') {
$('input[name="control"]').attr('checked', 'checked')
} else {
$('input[name="control"]').removeAttr('checked')
}
if (localStorage.getItem('muilt-tab') === 'true') {
$('input[name="muilt-tab"]').attr('checked', 'checked')
} else {
$('input[name="muilt-tab"]').removeAttr('checked')
}
if (localStorage.getItem('auto-head') === 'true') {
$('input[name="auto-head"]').attr('checked', 'checked')
} else {
$('input[name="auto-head"]').removeAttr('checked')
}
form.render('checkbox');
}
});
});
@@ -419,6 +566,14 @@ layui.define(['message', 'table', 'jquery', 'element', 'yaml', 'form', 'tab', 'm
localStorage.setItem("theme-menu", theme);
pearAdmin.menuSkin(theme);
});
body.on('click', '[data-select-header]', function() {
var theme = $(this).attr('data-select-header');
$('[data-select-header]').removeClass("layui-this");
$(this).addClass("layui-this");
localStorage.setItem("theme-header", theme);
pearAdmin.headerSkin(theme);
});
body.on('click', '.select-color-item', function() {
$(".select-color-item").removeClass("layui-icon").removeClass("layui-icon-ok");
@@ -426,8 +581,9 @@ layui.define(['message', 'table', 'jquery', 'element', 'yaml', 'form', 'tab', 'm
var colorId = $(".select-color-item.layui-icon-ok").attr("color-id");
var currentColor = getColorById(colorId);
localStorage.setItem("theme-color", currentColor.id);
localStorage.setItem("theme-color-context", currentColor.color);
pearTheme.changeTheme(window, config.other.autoHead);
localStorage.setItem("theme-color-color", currentColor.color);
localStorage.setItem("theme-color-second", currentColor.second);
pearTheme.changeTheme(window, isAutoHead(config));
});
function applyConfig(param) {
@@ -461,18 +617,6 @@ layui.define(['message', 'table', 'jquery', 'element', 'yaml', 'form', 'tab', 'm
return color;
}
function buildLinkHtml() {
var links = "";
$.each(config.links, function(i, value) {
// value.target 存在,则为新窗口打开,增加 target="_blank" 属性
links += '<a class="more-menu-item" href="' + value.href + '" ' + (value.target ? ' target="_blank" ' : '') +
'>' +
'<i class="' + value.icon + '" style="font-size: 19px;"></i> ' + value.title +
'</a>'
})
return '<div class="more-menu-list">' + links + '</div>';
}
function buildColorHtml() {
var colors = "";
$.each(config.colors, function(i, value) {
@@ -529,6 +673,42 @@ layui.define(['message', 'table', 'jquery', 'element', 'yaml', 'form', 'tab', 'm
document.webkitFullscreenElement || false;
}
function isControl(option) {
if (option.theme.allowCustom) {
if (localStorage.getItem("control") != null) {
return localStorage.getItem("control")
} else {
return option.menu.control
}
} else {
return option.menu.control
}
}
function isAutoHead(option) {
if(option.theme.allowCustom) {
if(localStorage.getItem("auto-head") != null) {
return localStorage.getItem("auto-head");
} else {
return option.other.autoHead;
}
} else {
return option.other.autoHead;
}
}
function isMuiltTab(option) {
if (option.theme.allowCustom) {
if (localStorage.getItem("muilt-tab") != null) {
return localStorage.getItem("muilt-tab")
} else {
return option.tab.enable
}
} else {
return option.tab.enable
}
}
window.onresize = function() {
if (!isFullscreen()) {
$(".fullScreen").eq(0).removeClass("layui-icon-screen-restore");