From 1586fffb26e0b62c96559dbef497bfede2e47490 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=B0=B1=E7=9C=A0=E4=BB=AA=E5=BC=8F?= <854085467@qq.com>
Date: Wed, 30 Sep 2020 12:57:03 +0800
Subject: [PATCH] 3.0.3.RELEASE
---
component/pear/module/admin.js | 95 ++++++++++++--------------
component/pear/module/iconPicker.js | 9 ---
component/pear/module/menu.js | 101 +++++++++++++---------------
pear.config.json | 4 +-
view/document/icon.html | 1 -
view/document/select.html | 1 +
6 files changed, 93 insertions(+), 118 deletions(-)
diff --git a/component/pear/module/admin.js b/component/pear/module/admin.js
index b5f0f32..4207260 100644
--- a/component/pear/module/admin.js
+++ b/component/pear/module/admin.js
@@ -12,24 +12,26 @@ layui.define(['table', 'jquery', 'element', 'form', 'tab', 'menu', 'frame'],
var bodyFrame;
var sideMenu;
var bodyTab;
+ var config;
var pearAdmin = new function() {
- this.render = function(option) {
- readConfig().then(function(param){
+ this.render = function() {
+ readConfig().then(function(param) {
+ config = param;
pearAdmin.logoRender(param);
- pearAdmin.menuRender(param,option);
+ pearAdmin.menuRender(param);
pearAdmin.bodyRender(param);
pearAdmin.themeRender(param);
pearAdmin.keepLoad(param);
- })
+ })
}
-
+
this.logoRender = function(param) {
$(".layui-logo .logo").attr("src", param.logo.image);
$(".layui-logo .title").html(param.logo.title);
}
-
- this.menuRender = function(param,option) {
+
+ this.menuRender = function(param) {
sideMenu = pearMenu.render({
elem: 'sideMenu',
async: true,
@@ -38,15 +40,17 @@ layui.define(['table', 'jquery', 'element', 'form', 'tab', 'menu', 'frame'],
control: param.menu.control ? 'control' : false, // control
defaultMenu: 0,
accordion: param.menu.accordion,
- url: param.menu.data+"?currentUser="+option.currentUser,
+ url: param.menu.data,
parseData: false,
- change:function(){
+ change: function() {
compatible();
+ },
+ done() {
+ sideMenu.selectItem(param.menu.select);
}
})
- sideMenu.selectItem(param.menu.select);
}
-
+
this.bodyRender = function(param) {
if (param.tab.muiltTab) {
bodyTab = pearTab.render({
@@ -68,8 +72,8 @@ layui.define(['table', 'jquery', 'element', 'form', 'tab', 'menu', 'frame'],
}]
});
bodyTab.click(function(id) {
- if(!param.tab.keepState){
- bodyTab.refresh(false);
+ if (!param.tab.keepState) {
+ bodyTab.refresh(false);
}
bodyTab.positionTab();
sideMenu.selectItem(id);
@@ -128,22 +132,20 @@ layui.define(['table', 'jquery', 'element', 'form', 'tab', 'menu', 'frame'],
})
}
}
-
+
this.keepLoad = function(param) {
compatible()
setTimeout(function() {
$(".loader-main").fadeOut(200);
}, param.other.keepLoad)
}
-
+
this.themeRender = function(option) {
if (option.theme.allowCustom == false) {
$(".setting").remove();
}
var colorId = localStorage.getItem("theme-color");
var menu = localStorage.getItem("theme-menu");
- console.log("主题标识:"+colorId);
- console.log("菜单主题:"+menu);
var color = getColorById(colorId);
if (menu == "null") {
menu = option.theme.defaultMenu;
@@ -157,13 +159,13 @@ layui.define(['table', 'jquery', 'element', 'form', 'tab', 'menu', 'frame'],
this.colorSet(color.color);
this.menuSkin(menu);
}
-
+
this.menuSkin = function(theme) {
$(".pear-admin").removeClass("light-theme");
$(".pear-admin").removeClass("dark-theme");
$(".pear-admin").addClass(theme);
}
-
+
this.colorSet = function(color) {
var style = '';
// 自 定 义 菜 单 配 色
@@ -238,9 +240,9 @@ layui.define(['table', 'jquery', 'element', 'form', 'tab', 'menu', 'frame'],
});
}
});
-
- $("body").on("click",'[user-menu-id]',function(){
- if(getData().tab.muiltTab){
+
+ $("body").on("click", '[user-menu-id]', function() {
+ if (config.tab.muiltTab) {
bodyTab.addTabOnly({
id: $(this).attr("user-menu-id"),
title: $(this).attr("user-menu-title"),
@@ -248,7 +250,7 @@ layui.define(['table', 'jquery', 'element', 'form', 'tab', 'menu', 'frame'],
icon: "",
close: true
}, 300);
- }else{
+ } else {
bodyFrame.changePage($(this).attr("user-menu-url"), "", true);
}
})
@@ -278,7 +280,7 @@ layui.define(['table', 'jquery', 'element', 'form', 'tab', 'menu', 'frame'],
'
\n' +
'\n' +
'';
-
+
layer.open({
type: 1,
offset: 'r',
@@ -293,6 +295,7 @@ layui.define(['table', 'jquery', 'element', 'form', 'tab', 'menu', 'frame'],
content: html + buildColorHtml() + buildLinkHtml(),
success: function(layero, index) {
form.render();
+
var color = localStorage.getItem("theme-color");
var menu = localStorage.getItem("theme-menu");
@@ -317,7 +320,7 @@ layui.define(['table', 'jquery', 'element', 'form', 'tab', 'menu', 'frame'],
}
});
})
-
+
$('body').on('click', '[data-select-bgcolor]', function() {
var theme = $(this).attr('data-select-bgcolor');
$('[data-select-bgcolor]').removeClass("layui-this");
@@ -325,7 +328,7 @@ layui.define(['table', 'jquery', 'element', 'form', 'tab', 'menu', 'frame'],
localStorage.setItem("theme-menu", theme);
pearAdmin.menuSkin(theme);
});
-
+
$('body').on('click', '.select-color-item', function() {
$(".select-color-item").removeClass("layui-icon").removeClass("layui-icon-ok");
$(this).addClass("layui-icon").addClass("layui-icon-ok");
@@ -334,38 +337,27 @@ layui.define(['table', 'jquery', 'element', 'form', 'tab', 'menu', 'frame'],
var color = getColorById(colorId);
pearAdmin.colorSet(color.color);
});
-
- function getData() {
- $.ajaxSettings.async = false;
- var data = null;
+
+ function readConfig() {
+ var defer = $.Deferred();
$.getJSON("pear.config.json?fresh=" + Math.random(), function(result) {
- data = result;
+ defer.resolve(result)
});
- $.ajaxSettings.async = true;
- return data;
- }
-
- function readConfig(){
- var defer = $.Deferred();
- $.getJSON("pear.config.json?fresh=" + Math.random(), function(result) {
- defer.resolve(result)
- });
- return defer.promise();
+ return defer.promise();
}
function getColorById(id) {
var color;
var flag = false;
- var data = getData();
- $.each(data.colors, function(i, value) {
+ $.each(config.colors, function(i, value) {
if (value.id == id) {
color = value;
flag = true;
}
})
- if (flag == false || data.theme.allowCustom == false) {
- $.each(data.colors, function(i, value) {
- if (value.id == data.theme.defaultColor) {
+ if (flag == false || config.theme.allowCustom == false) {
+ $.each(config.colors, function(i, value) {
+ if (value.id == config.theme.defaultColor) {
color = value;
}
})
@@ -375,7 +367,7 @@ layui.define(['table', 'jquery', 'element', 'form', 'tab', 'menu', 'frame'],
function buildLinkHtml() {
var links = "";
- $.each(getData().links, function(i, value) {
+ $.each(config.links, function(i, value) {
links += ''
@@ -385,14 +377,14 @@ layui.define(['table', 'jquery', 'element', 'form', 'tab', 'menu', 'frame'],
function buildColorHtml() {
var colors = "";
- $.each(getData().colors, function(i, value) {
+ $.each(config.colors, function(i, value) {
colors += "";
})
return ""
}
-
+
function compatible() {
if ($(window).width() <= 768) {
sideMenu.collaspe();
@@ -407,7 +399,7 @@ layui.define(['table', 'jquery', 'element', 'form', 'tab', 'menu', 'frame'],
}
}
}
-
+
function screenFun(num) {
num = num || 1;
num = num * 1;
@@ -440,7 +432,6 @@ layui.define(['table', 'jquery', 'element', 'form', 'tab', 'menu', 'frame'],
res("返回值");
});
}
-
+
exports('admin', pearAdmin);
})
-
\ No newline at end of file
diff --git a/component/pear/module/iconPicker.js b/component/pear/module/iconPicker.js
index 373e282..a5fde00 100644
--- a/component/pear/module/iconPicker.js
+++ b/component/pear/module/iconPicker.js
@@ -1,9 +1,3 @@
-/**
- * Layui图标选择器
- * @author wujiawei0926@yeah.net
- * @version 1.1
- */
-
layui.define(['laypage', 'form'], function (exports) {
"use strict";
@@ -17,9 +11,6 @@ layui.define(['laypage', 'form'], function (exports) {
BODY = 'body',
TIPS = '请选择图标';
- /**
- * 渲染组件
- */
IconPicker.prototype.render = function(options){
var opts = options,
// DOM选择器
diff --git a/component/pear/module/menu.js b/component/pear/module/menu.js
index 8d513bd..f97f49f 100644
--- a/component/pear/module/menu.js
+++ b/component/pear/module/menu.js
@@ -25,58 +25,56 @@ layui.define(['table', 'jquery', 'element'], function(exports) {
theme: opt.theme,
data: opt.data ? opt.data : [],
change: opt.change ? opt.change : function() {
- console.log("切换")
},
done: opt.done ? opt.done : function() {}
}
- // 根 据 请 求 方 式 获 取 数 据
if (option.async) {
- option.data = getData(option.url);
- if (option.parseData != false) {
- option.parseData(option.data);
- }
+ getData(option.url).then(function(data){
+ option.data = data;
+ if (option.parseData != false) {
+ option.parseData(option.data);
+ }
+ if (option.data.length > 0) {
+ if (option.control != false) {
+ createMenuAndControl(option);
+ } else {
+ createMenu(option);
+ }
+ }
+ element.init();
+ downShow(option);
+ option.done();
+ });
}
-
- if (option.data.length > 0) {
- if (option.control != false) {
-
- createMenuAndControl(option);
- } else {
- createMenu(option);
- }
- }
- element.init();
- downShow(option);
- option.done();
- return new pearMenu(option);
+ return new pearMenu(opt);
}
pearMenu.prototype.click = function(clickEvent) {
var _this = this;
- $("#" + _this.option.elem + " .site-demo-active").parent().click(function() {
- var dom = $(this).children(".site-demo-active");
- var data = {
- menuId: dom.attr("menu-id"),
- menuTitle: dom.attr("menu-title"),
- menuPath: dom.attr("menu-title"),
- menuIcon: dom.attr("menu-icon"),
- menuUrl: dom.attr("menu-url")
- };
- var doms = hash(dom);
- if (doms.text() != '') {
- data['menuPath'] = doms.find("span").text() + " / " + data['menuPath'];
- }
- var domss = hash(doms);
- if (domss.text() != '') {
- data['menuPath'] = domss.find("span").text() + " / " + data['menuPath'];
- }
- var domsss = hash(domss);
- if (domsss.text() != '') {
- data['menuPath'] = domsss.find("span").text() + " / " + data['menuPath'];
- }
- clickEvent(dom, data);
- });
+ $("body").on("click","#" + _this.option.elem + " .site-demo-active",function(){
+ var dom = $(this);
+ var data = {
+ menuId: dom.attr("menu-id"),
+ menuTitle: dom.attr("menu-title"),
+ menuPath: dom.attr("menu-title"),
+ menuIcon: dom.attr("menu-icon"),
+ menuUrl: dom.attr("menu-url")
+ };
+ var doms = hash(dom);
+ if (doms.text() != '') {
+ data['menuPath'] = doms.find("span").text() + " / " + data['menuPath'];
+ }
+ var domss = hash(doms);
+ if (domss.text() != '') {
+ data['menuPath'] = domss.find("span").text() + " / " + data['menuPath'];
+ }
+ var domsss = hash(domss);
+ if (domsss.text() != '') {
+ data['menuPath'] = domsss.find("span").text() + " / " + data['menuPath'];
+ }
+ clickEvent(dom, data);
+ })
}
function hash(dom) {
@@ -91,7 +89,6 @@ layui.define(['table', 'jquery', 'element'], function(exports) {
}
pearMenu.prototype.selectItem = function(pearId) {
-
if (this.option.control != false) {
$("#" + this.option.elem + " a[menu-id='" + pearId + "']").parents(".layui-side-scroll ").find("ul").css({
display: "none"
@@ -144,19 +141,15 @@ layui.define(['table', 'jquery', 'element'], function(exports) {
}
}
-
- /** 同 步 请 求 获 取 数 据 */
- function getData(url) {
- $.ajaxSettings.async = false;
- var data = null;
- $.get(url+"&fresh=" + Math.random(), function(result) {
- data = result;
+
+ function getData(url){
+ var defer = $.Deferred();
+ $.get(url+"?fresh=" + Math.random(), function(result) {
+ defer.resolve(result)
});
- $.ajaxSettings.async = true;
- return data;
+ return defer.promise();
}
-
-
+
function createMenu(option) {
var menuHtml = '