';
// 声 明 头 部
var menu = ''
diff --git a/config/pear.config.json b/config/pear.config.json
index b1dba56..2fe2cef 100644
--- a/config/pear.config.json
+++ b/config/pear.config.json
@@ -9,7 +9,6 @@
"accordion": true,
"collapse": false,
"control": false,
- "controlWidth": 500,
"select": "10",
"async": true
},
diff --git a/config/pear.config.yml b/config/pear.config.yml
index 4b7cd70..3cfd272 100644
--- a/config/pear.config.yml
+++ b/config/pear.config.yml
@@ -16,8 +16,6 @@ menu:
collapse: false
## 是否开启多系统菜单模式
control: false
- ## 顶部菜单宽度 PX
- controlWidth: 500
## 默认选中的菜单项
select: "10"
## 是否开启异步菜单,false 时 data 属性设置为静态数据,true 时为后端接口
--
Gitee
From 6282f2b61cae5f85a3cad5da305ee62994af9fd1 Mon Sep 17 00:00:00 2001
From: fxw
Date: Tue, 17 Oct 2023 10:31:53 +0800
Subject: [PATCH 5/7] =?UTF-8?q?perf:=20=E2=9A=A1=20admin.js=20=E4=BB=A3?=
=?UTF-8?q?=E7=A0=81=E4=BC=98=E5=8C=96?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
component/pear/module/admin.js | 325 ++++++++++++++++-----------------
1 file changed, 158 insertions(+), 167 deletions(-)
diff --git a/component/pear/module/admin.js b/component/pear/module/admin.js
index ee1d902..e35f85c 100644
--- a/component/pear/module/admin.js
+++ b/component/pear/module/admin.js
@@ -2,7 +2,7 @@ layui.define(['message', 'table', 'jquery', 'element', 'yaml', 'form', 'tab', 'm
function(exports) {
"use strict";
- var $ = layui.jquery,
+ const $ = layui.jquery,
form = layui.form,
element = layui.element,
yaml = layui.yaml,
@@ -12,30 +12,31 @@ layui.define(['message', 'table', 'jquery', 'element', 'yaml', 'form', 'tab', 'm
pearFrame = layui.frame,
pearTheme = layui.theme,
message = layui.message,
- fullscreen=layui.fullscreen;
+ fullscreen = layui.fullscreen;
- var bodyFrame;
- var sideMenu;
- var bodyTab;
- var config;
- var logout = function() {};
- var msgInstance;
- var body = $('body');
+ let bodyFrame;
+ let sideMenu;
+ let bodyTab;
+ let config;
+ let logout = function () {
+ };
+ let msgInstance;
+ const body = $('body');
- var pearAdmin = new function() {
+ const pearAdmin = new function () {
- var configType = 'yml';
- var configPath = 'pear.config.yml';
+ let configType = 'yml';
+ let configPath = 'pear.config.yml';
- this.setConfigPath = function(path) {
+ this.setConfigPath = function (path) {
configPath = path;
}
- this.setConfigType = function(type) {
+ this.setConfigType = function (type) {
configType = type;
}
- this.render = function(initConfig) {
+ this.render = function (initConfig) {
if (initConfig !== undefined) {
applyConfig(initConfig);
} else {
@@ -43,11 +44,11 @@ layui.define(['message', 'table', 'jquery', 'element', 'yaml', 'form', 'tab', 'm
}
}
- this.readConfig = function() {
+ this.readConfig = function () {
if (configType === "yml") {
return yaml.load(configPath);
} else {
- var data;
+ let data;
$.ajax({
url: configPath,
type: 'get',
@@ -61,8 +62,8 @@ layui.define(['message', 'table', 'jquery', 'element', 'yaml', 'form', 'tab', 'm
}
}
- this.messageRender = function(option) {
- var option = {
+ this.messageRender = function (option) {
+ option = {
elem: '.message',
url: option.header.message,
height: '250px'
@@ -70,12 +71,12 @@ layui.define(['message', 'table', 'jquery', 'element', 'yaml', 'form', 'tab', 'm
msgInstance = message.render(option);
}
- this.logoRender = function(param) {
+ this.logoRender = function (param) {
$(".layui-logo .logo").attr("src", param.logo.image);
$(".layui-logo .title").html(param.logo.title);
}
- this.menuRender = function(param) {
+ this.menuRender = function (param) {
sideMenu = pearMenu.render({
elem: 'sideMenu',
async: param.menu.async !== undefined ? param.menu.async : true,
@@ -88,10 +89,10 @@ layui.define(['message', 'table', 'jquery', 'element', 'yaml', 'form', 'tab', 'm
url: param.menu.data,
data: param.menu.data,
parseData: false,
- change: function() {
+ change: function () {
compatible();
},
- done: function() {
+ done: function () {
sideMenu.isCollapse = param.menu.collapse;
sideMenu.selectItem(param.menu.select);
pearAdmin.collapse(param);
@@ -99,9 +100,9 @@ layui.define(['message', 'table', 'jquery', 'element', 'yaml', 'form', 'tab', 'm
});
}
- this.bodyRender = function(param) {
+ this.bodyRender = function (param) {
- body.on("click", ".refresh", function() {
+ body.on("click", ".refresh", function () {
refresh();
})
@@ -116,7 +117,7 @@ layui.define(['message', 'table', 'jquery', 'element', 'yaml', 'form', 'tab', 'm
index: 0,
tabMax: param.tab.max,
preload: param.tab.preload,
- closeEvent: function(id) {
+ closeEvent: function (id) {
sideMenu.selectItem(id);
},
data: [{
@@ -125,9 +126,9 @@ layui.define(['message', 'table', 'jquery', 'element', 'yaml', 'form', 'tab', 'm
title: param.tab.index.title,
close: false
}],
- success: function(id) {
+ success: function (id) {
if (param.tab.session) {
- setTimeout(function() {
+ setTimeout(function () {
sideMenu.selectItem(id);
bodyTab.positionTab();
}, 500)
@@ -135,7 +136,7 @@ layui.define(['message', 'table', 'jquery', 'element', 'yaml', 'form', 'tab', 'm
}
});
- bodyTab.click(function(id) {
+ bodyTab.click(function (id) {
if (!param.tab.keepState) {
bodyTab.refresh(false);
}
@@ -143,7 +144,7 @@ layui.define(['message', 'table', 'jquery', 'element', 'yaml', 'form', 'tab', 'm
sideMenu.selectItem(id);
})
- sideMenu.click(function(dom, data) {
+ sideMenu.click(function (dom, data) {
bodyTab.addTabOnly({
id: data.menuId,
title: data.menuTitle,
@@ -162,32 +163,32 @@ layui.define(['message', 'table', 'jquery', 'element', 'yaml', 'form', 'tab', 'm
height: '100%'
});
- sideMenu.click(function(dom, data) {
+ sideMenu.click(function (dom, data) {
bodyFrame.changePage(data.menuUrl, true);
compatible()
})
}
}
- this.keepLoad = function(param) {
+ this.keepLoad = function (param) {
compatible()
- setTimeout(function() {
+ setTimeout(function () {
$(".loader-main").fadeOut(200);
}, param.other.keepLoad)
}
- this.themeRender = function(option) {
+ this.themeRender = function (option) {
if (option.theme.allowCustom === false) {
$(".setting").remove();
}
- var colorId = localStorage.getItem("theme-color");
- var currentColor = getColorById(colorId);
+ const colorId = localStorage.getItem("theme-color");
+ const 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");
+ let menu = localStorage.getItem("theme-menu");
if (menu === null) {
menu = option.theme.defaultMenu;
} else {
@@ -196,7 +197,7 @@ layui.define(['message', 'table', 'jquery', 'element', 'yaml', 'form', 'tab', 'm
}
}
- var header = localStorage.getItem("theme-header");
+ let header = localStorage.getItem("theme-header");
if (header === null) {
header = option.theme.defaultHeader;
} else {
@@ -205,7 +206,7 @@ layui.define(['message', 'table', 'jquery', 'element', 'yaml', 'form', 'tab', 'm
}
}
- var banner = localStorage.getItem("theme-banner");
+ let banner = localStorage.getItem("theme-banner");
if (banner === null) {
banner = option.theme.banner;
} else {
@@ -214,7 +215,7 @@ layui.define(['message', 'table', 'jquery', 'element', 'yaml', 'form', 'tab', 'm
}
}
- var autoHead = localStorage.getItem("auto-head");
+ let autoHead = localStorage.getItem("auto-head");
if (autoHead === null) {
autoHead = option.other.autoHead;
} else {
@@ -223,7 +224,7 @@ layui.define(['message', 'table', 'jquery', 'element', 'yaml', 'form', 'tab', 'm
}
}
- var muiltTab = localStorage.getItem("muilt-tab");
+ let muiltTab = localStorage.getItem("muilt-tab");
if (muiltTab === null) {
muiltTab = option.tab.enable;
} else {
@@ -232,7 +233,7 @@ layui.define(['message', 'table', 'jquery', 'element', 'yaml', 'form', 'tab', 'm
}
}
- var control = localStorage.getItem("control");
+ let control = localStorage.getItem("control");
if (control === null) {
control = option.menu.control;
} else {
@@ -241,10 +242,10 @@ layui.define(['message', 'table', 'jquery', 'element', 'yaml', 'form', 'tab', 'm
}
}
- var footer = localStorage.getItem("footer");
- if( footer === null) {
+ let footer = localStorage.getItem("footer");
+ if (footer === null) {
footer = option.other.footer;
- }else{
+ } else {
if (option.theme.allowCustom === false) {
footer = option.other.footer;
}
@@ -263,9 +264,9 @@ layui.define(['message', 'table', 'jquery', 'element', 'yaml', 'form', 'tab', 'm
this.footer(footer);
}
- this.footer = function(footer){
- var bodyDOM = $(".pear-admin .layui-body");
- var footerDOM = $(".pear-admin .layui-footer");
+ this.footer = function (footer) {
+ const bodyDOM = $(".pear-admin .layui-body");
+ const footerDOM = $(".pear-admin .layui-footer");
if (footer === true || footer === "true") {
footerDOM.removeClass("close");
bodyDOM.css("bottom", footerDOM.outerHeight());
@@ -275,15 +276,15 @@ layui.define(['message', 'table', 'jquery', 'element', 'yaml', 'form', 'tab', 'm
}
}
- this.bannerSkin = function(theme) {
- var pearAdmin = $(".pear-admin");
+ this.bannerSkin = function (theme) {
+ const pearAdmin = $(".pear-admin");
pearAdmin.removeClass("banner-layout");
if (theme === true || theme === "true") {
pearAdmin.addClass("banner-layout");
}
}
- this.collapse = function(param) {
+ this.collapse = function (param) {
if (param.menu.collapse) {
if ($(window).width() >= 768) {
collapse()
@@ -291,43 +292,44 @@ layui.define(['message', 'table', 'jquery', 'element', 'yaml', 'form', 'tab', 'm
}
}
- this.menuSkin = function(theme) {
- var pearAdmin = $(".pear-admin .layui-side");
+ this.menuSkin = function (theme) {
+ const 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");
+ this.headerSkin = function (theme) {
+ const pearAdmin = $(".pear-admin .layui-header");
pearAdmin.removeClass("light-theme");
pearAdmin.removeClass("dark-theme");
pearAdmin.addClass(theme);
}
- this.logout = function(callback) {
+ this.logout = function (callback) {
logout = callback;
}
- this.message = function(callback) {
+ this.message = function (callback) {
if (callback != null) {
msgInstance.click(callback);
}
}
- this.collapseSide = function() {
+ this.collapseSide = function () {
collapse()
}
- this.refreshThis = function() {
+ this.refreshThis = function () {
refresh()
}
- this.refresh = function(id) {
- $("iframe[id='"+ id +"']").attr('src', $("iframe[id='"+ id +"']").attr('src'));
+ this.refresh = function (id) {
+ const iframe = $("iframe[id='" + id + "']");
+ iframe.attr('src', iframe.attr('src'));
}
- this.addTab = function(id, title, url) {
+ this.addTab = function (id, title, url) {
if (isMuiltTab(config) === "true" || isMuiltTab(config) === true) {
bodyTab.addTabOnly({
id: id,
@@ -336,79 +338,67 @@ layui.define(['message', 'table', 'jquery', 'element', 'yaml', 'form', 'tab', 'm
icon: null,
close: true
}, 400);
- } else {
- return;
}
}
- this.closeTab = function(id) {
+ this.closeTab = function (id) {
if (isMuiltTab(config) === "true" || isMuiltTab(config) === true) {
- pearTab.delTabByElem('content', id, function(currentId){
+ pearTab.delTabByElem('content', id, function (currentId) {
sideMenu.selectItem(currentId);
});
- } else {
- return;
}
}
- this.closeCurrentTab = function() {
+ this.closeCurrentTab = function () {
if (isMuiltTab(config) === "true" || isMuiltTab(config) === true) {
- pearTab.delCurrentTabByElem('content', function(id){
+ pearTab.delCurrentTabByElem('content', function (id) {
sideMenu.selectItem(id);
});
- } else {
- return;
}
}
-
- this.closeOtherTab = function() {
+
+ this.closeOtherTab = function () {
if (isMuiltTab(config) === "true" || isMuiltTab(config) === true) {
- pearTab.delOtherTabByElem('content', function(id){
+ pearTab.delOtherTabByElem('content', function (id) {
sideMenu.selectItem(id);
});
- } else {
- return;
}
}
-
- this.closeAllTab = function() {
+
+ this.closeAllTab = function () {
if (isMuiltTab(config) === "true" || isMuiltTab(config) === true) {
- pearTab.delAllTabByElem('content', function(id){
+ pearTab.delAllTabByElem('content', function (id) {
sideMenu.selectItem(id);
});
- } else {
- return;
}
}
- this.changeTabTitle = function(id, title) {
- pearTab.changeTabTitleById('content', id ,title);
+ 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 {
+
+ this.changeIframe = function (id, title, url) {
+ if (isMuiltTab(config) !== "true" && isMuiltTab(config) !== true) {
sideMenu.selectItem(id);
bodyFrame.changePage(url, true);
}
}
- this.jump = function(id, title, url) {
+ this.jump = function (id, title, url) {
if (isMuiltTab(config) === "true" || isMuiltTab(config) === true) {
pearAdmin.addTab(id, title, url)
} else {
pearAdmin.changeIframe(id, title, url)
}
}
-
- this.fullScreen = function() {
+
+ this.fullScreen = function () {
if ($(".fullScreen").hasClass("layui-icon-screen-restore")) {
- screenFun(2).then(function() {
+ screenFun(2).then(function () {
$(".fullScreen").eq(0).removeClass("layui-icon-screen-restore");
});
} else {
- screenFun(1).then(function() {
+ screenFun(1).then(function () {
$(".fullScreen").eq(0).addClass("layui-icon-screen-restore");
});
}
@@ -416,7 +406,7 @@ layui.define(['message', 'table', 'jquery', 'element', 'yaml', 'form', 'tab', 'm
};
function refresh() {
- var refreshA = $(".refresh a");
+ const refreshA = $(".refresh a");
refreshA.removeClass("layui-icon-refresh-1");
refreshA.addClass("layui-anim");
refreshA.addClass("layui-anim-rotate");
@@ -435,9 +425,9 @@ layui.define(['message', 'table', 'jquery', 'element', 'yaml', 'form', 'tab', 'm
function collapse() {
sideMenu.collapse();
- var admin = $(".pear-admin");
- var left = $(".layui-icon-spread-left")
- var right = $(".layui-icon-shrink-right")
+ const admin = $(".pear-admin");
+ const left = $(".layui-icon-spread-left");
+ const right = $(".layui-icon-shrink-right");
if (admin.is(".pear-mini")) {
left.addClass("layui-icon-shrink-right")
left.removeClass("layui-icon-spread-left")
@@ -463,14 +453,14 @@ layui.define(['message', 'table', 'jquery', 'element', 'yaml', 'form', 'tab', 'm
body.on("click", ".menuSearch", function () {
// 过滤菜单
- var filterHandle = function (filterData, val) {
+ const filterHandle = function (filterData, val) {
if (!val) return [];
- var filteredMenus = [];
+ const filteredMenus = [];
filterData = $.extend(true, {}, filterData);
$.each(filterData, function (index, item) {
if (item.children && item.children.length) {
var children = filterHandle(item.children, val)
- var obj = $.extend({}, item, { children: children });
+ var obj = $.extend({}, item, {children: children});
if (children && children.length) {
filteredMenus.push(obj);
} else if (item.title.indexOf(val) >= 0) {
@@ -482,25 +472,25 @@ layui.define(['message', 'table', 'jquery', 'element', 'yaml', 'form', 'tab', 'm
}
})
return filteredMenus;
- }
+ };
// 树转路径
- var tiledHandle = function (data) {
- var tiledMenus = [];
- var treeTiled = function (data, content) {
- var path = "";
- var separator = " / ";
+ const tiledHandle = function (data) {
+ const tiledMenus = [];
+ const treeTiled = function (data, content) {
+ let path = "";
+ const separator = " / ";
// 上级路径
if (!content) content = "";
$.each(data, function (index, item) {
if (item.children && item.children.length) {
path += content + item.title + separator;
- var childPath = treeTiled(item.children, path);
+ const childPath = treeTiled(item.children, path);
path += childPath;
if (!childPath) path = ""; // 重置路径
} else {
path += content + item.title
- tiledMenus.push({ path: path, info: item });
+ tiledMenus.push({path: path, info: item});
path = ""; //重置路径
}
})
@@ -509,11 +499,11 @@ layui.define(['message', 'table', 'jquery', 'element', 'yaml', 'form', 'tab', 'm
treeTiled(data);
return tiledMenus;
- }
+ };
// 创建搜索列表
- var createList = function (data) {
- var _listHtml = '';
+ const createList = function (data) {
+ let _listHtml = '';
$.each(data, function (index, item) {
_listHtml += '- ';
_listHtml += ' ' + item.path + '';
@@ -521,9 +511,9 @@ layui.define(['message', 'table', 'jquery', 'element', 'yaml', 'form', 'tab', 'm
_listHtml += '
'
})
return _listHtml;
- }
+ };
- var _html = [
+ const _html = [
'