feature: 添加静态文件
This commit is contained in:
@@ -0,0 +1,888 @@
|
||||
layui.define(
|
||||
[
|
||||
"jquery",
|
||||
"tools",
|
||||
"element",
|
||||
"yaml",
|
||||
"form",
|
||||
"tabPage",
|
||||
"menu",
|
||||
"page",
|
||||
"fullscreen",
|
||||
"messageCenter",
|
||||
"menuSearch",
|
||||
],
|
||||
function (exports) {
|
||||
"use strict";
|
||||
|
||||
var $ = layui.jquery,
|
||||
form = layui.form,
|
||||
yaml = layui.yaml,
|
||||
page = layui.page,
|
||||
menu = layui.menu,
|
||||
messageCenter = layui.messageCenter,
|
||||
menuSearch = layui.menuSearch,
|
||||
fullscreen = layui.fullscreen,
|
||||
tools = layui.tools,
|
||||
tabPage = layui.tabPage;
|
||||
|
||||
var sideMenu;
|
||||
|
||||
var configurationCache;
|
||||
|
||||
var bodyTab;
|
||||
|
||||
var bodyFrame;
|
||||
|
||||
var logout = function () {};
|
||||
|
||||
var body = $("body");
|
||||
|
||||
var pearAdmin = new (function () {
|
||||
this.configuration = {};
|
||||
|
||||
this.configurationPath = "pear.config.yml";
|
||||
|
||||
this.instances = {};
|
||||
|
||||
/**
|
||||
* @since Pear Admin 4.0
|
||||
*
|
||||
* 获取 pear.config 实现 [ default ]
|
||||
*/
|
||||
this.configurationProvider = () => {
|
||||
return new Promise((resolve) => {
|
||||
if (this.configurationPath.indexOf("json") > -1) {
|
||||
$.ajax({
|
||||
type: "get",
|
||||
url: this.configurationPath,
|
||||
dataType: "json",
|
||||
async: false,
|
||||
success: (result) => {
|
||||
resolve(result);
|
||||
},
|
||||
});
|
||||
} else {
|
||||
resolve(yaml.load(this.configurationPath));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* @since Pear Admin 4.0
|
||||
*
|
||||
* 配置 pear.config 路径
|
||||
*/
|
||||
this.setConfigurationPath = (path) => {
|
||||
this.configurationPath = path;
|
||||
};
|
||||
|
||||
/**
|
||||
* @since Pear Admin 4.0
|
||||
*
|
||||
* 获取 pear.config 实现 [ implement ]
|
||||
*/
|
||||
this.setConfigurationProvider = (provider) => {
|
||||
this.configurationProvider = provider;
|
||||
};
|
||||
|
||||
/**
|
||||
* @since Pear Admin 4.0
|
||||
*
|
||||
* 获取 pear.config 配置
|
||||
*/
|
||||
this.getConfiguration = () => {
|
||||
return this.configuration;
|
||||
};
|
||||
|
||||
/**
|
||||
* @since Pear Admin 4.0
|
||||
*
|
||||
* Core Function.
|
||||
*
|
||||
* @param {*} options
|
||||
*/
|
||||
this.render = (options) => {
|
||||
if (options !== undefined) {
|
||||
pearAdmin.apply(options);
|
||||
} else {
|
||||
this.configurationProvider().then((result) => {
|
||||
pearAdmin.apply(result);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @since Pear Admin 4.0
|
||||
*
|
||||
* 启动构建
|
||||
*/
|
||||
this.apply = function (configuration) {
|
||||
configurationCache = configuration;
|
||||
pearAdmin.logoRender(configuration);
|
||||
pearAdmin.menuRender(configuration);
|
||||
pearAdmin.menuSearchRender(configuration);
|
||||
pearAdmin.bodyRender(configuration);
|
||||
pearAdmin.messageCenterRender(configuration);
|
||||
pearAdmin.themeRender(configuration);
|
||||
pearAdmin.keepLoad(configuration);
|
||||
};
|
||||
|
||||
/**
|
||||
* @since Pear Admin 4.0
|
||||
*/
|
||||
this.menuSearchRender = function (options) {
|
||||
menuSearch.render({
|
||||
elem: ".menuSearch",
|
||||
dataProvider: () => sideMenu.cache(),
|
||||
select: (node) => {
|
||||
if (node.type == "1") {
|
||||
sideMenu.selectItem(node.id);
|
||||
if (node.openType === "_layer") {
|
||||
layer.open({
|
||||
type: 2,
|
||||
title: data.title,
|
||||
content: data.url,
|
||||
area: ["80%", "80%"],
|
||||
maxmin: true,
|
||||
});
|
||||
} else {
|
||||
if (
|
||||
isMuiltTab(options) === "true" ||
|
||||
isMuiltTab(options) === true
|
||||
) {
|
||||
bodyTab.addTabOnly({
|
||||
id: node.id,
|
||||
title: node.title,
|
||||
type: node.openType,
|
||||
url: node.url,
|
||||
icon: node.icon,
|
||||
close: true,
|
||||
});
|
||||
} else {
|
||||
bodyFrame.changePage({
|
||||
href: node.url,
|
||||
type: node.openType,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
this.messageCenterRender = function (options) {
|
||||
messageCenter.render({
|
||||
elem: ".message",
|
||||
url: options.header.message,
|
||||
height: "250px",
|
||||
});
|
||||
};
|
||||
|
||||
this.logoRender = function (param) {
|
||||
$(".layui-logo .logo").attr("src", param.logo.image);
|
||||
$(".layui-logo .title").html(param.logo.title);
|
||||
};
|
||||
|
||||
this.menuRender = function (param) {
|
||||
sideMenu = menu.render({
|
||||
elem: "sideMenu",
|
||||
async: param.menu.async,
|
||||
method: param.menu.method,
|
||||
control:
|
||||
isControl(param) === "true" || isControl(param) === true
|
||||
? "control"
|
||||
: false,
|
||||
controlWidth: param.menu.controlWidth,
|
||||
accordion: param.menu.accordion,
|
||||
data: param.menu.data,
|
||||
url: param.menu.data,
|
||||
parseData: false,
|
||||
defaultMenu: 0,
|
||||
change: function () {
|
||||
compatible();
|
||||
},
|
||||
done: function () {
|
||||
sideMenu.isCollapse = param.menu.collapse;
|
||||
sideMenu.selectItem(param.menu.select);
|
||||
pearAdmin.collapse(param);
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
this.bodyRender = function (param) {
|
||||
body.on("click", ".refresh", function () {
|
||||
refresh();
|
||||
});
|
||||
|
||||
if (isMuiltTab(param) === "true" || isMuiltTab(param) === true) {
|
||||
bodyTab = tabPage.render({
|
||||
elem: "content",
|
||||
session: param.tab.session,
|
||||
index: 0,
|
||||
tabMax: param.tab.max,
|
||||
preload: param.tab.preload,
|
||||
closeEvent: function (id) {
|
||||
sideMenu.selectItem(id);
|
||||
},
|
||||
data: [
|
||||
{
|
||||
id: param.tab.index.id,
|
||||
url: param.tab.index.href,
|
||||
title: param.tab.index.title,
|
||||
close: false,
|
||||
},
|
||||
],
|
||||
success: function (id) {
|
||||
if (param.tab.session) {
|
||||
setTimeout(function () {
|
||||
sideMenu.selectItem(id);
|
||||
bodyTab.positionTab();
|
||||
}, 500);
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
bodyTab.click(function (id) {
|
||||
if (!param.tab.keepState) {
|
||||
bodyTab.refresh(false);
|
||||
}
|
||||
bodyTab.positionTab();
|
||||
sideMenu.selectItem(id);
|
||||
});
|
||||
|
||||
sideMenu.click(function (dom, data) {
|
||||
if (data.menuOpenType === "_layer") {
|
||||
layer.open({
|
||||
type: 2,
|
||||
title: data.menuTitle,
|
||||
content: data.menuUrl,
|
||||
area: ["80%", "80%"],
|
||||
maxmin: true,
|
||||
});
|
||||
} else {
|
||||
bodyTab.addTabOnly({
|
||||
id: data.menuId,
|
||||
title: data.menuTitle,
|
||||
type: data.menuOpenType,
|
||||
url: data.menuUrl,
|
||||
icon: data.menuIcon,
|
||||
close: true,
|
||||
});
|
||||
}
|
||||
compatible();
|
||||
});
|
||||
} else {
|
||||
bodyFrame = page.render({
|
||||
elem: "content",
|
||||
title: "首页",
|
||||
url: param.tab.index.href,
|
||||
});
|
||||
|
||||
sideMenu.click(function (dom, data) {
|
||||
if (data.menuOpenType === "_layer") {
|
||||
layer.open({
|
||||
type: 2,
|
||||
title: data.menuTitle,
|
||||
content: data.menuUrl,
|
||||
area: ["80%", "80%"],
|
||||
maxmin: true,
|
||||
});
|
||||
} else {
|
||||
bodyFrame.changePage({
|
||||
href: data.menuUrl,
|
||||
type: data.menuOpenType,
|
||||
});
|
||||
}
|
||||
compatible();
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
this.keepLoad = function (param) {
|
||||
compatible();
|
||||
setTimeout(function () {
|
||||
$(".loader-wrapper").fadeOut(200);
|
||||
}, param.other.keepLoad);
|
||||
};
|
||||
|
||||
this.changeTheme = function () {
|
||||
const variableKey = "--global-primary-color";
|
||||
const variableVal = localStorage.getItem("theme-color-color");
|
||||
document.documentElement.style.setProperty(variableKey, variableVal);
|
||||
};
|
||||
|
||||
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);
|
||||
pearAdmin.changeTheme();
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
var footer = localStorage.getItem("footer");
|
||||
if (footer === null) {
|
||||
footer = option.other.footer;
|
||||
} else {
|
||||
if (option.theme.allowCustom === false) {
|
||||
footer = option.other.footer;
|
||||
}
|
||||
}
|
||||
|
||||
var dark = localStorage.getItem("dark");
|
||||
if (dark === null) {
|
||||
dark = option.theme.dark;
|
||||
} else {
|
||||
if (option.theme.allowCustom === false) {
|
||||
dark = option.theme.dark;
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
localStorage.setItem("footer", footer);
|
||||
localStorage.setItem("dark", dark);
|
||||
this.menuSkin(menu);
|
||||
this.headerSkin(header);
|
||||
this.bannerSkin(banner);
|
||||
this.enableDark(dark);
|
||||
this.footer(footer);
|
||||
};
|
||||
|
||||
this.footer = function (footer) {
|
||||
var bodyDOM = $(".pear-admin .layui-body");
|
||||
var footerDOM = $(".pear-admin .layui-footer");
|
||||
if (footer === true || footer === "true") {
|
||||
footerDOM.removeClass("close");
|
||||
bodyDOM.css("bottom", footerDOM.outerHeight());
|
||||
} else {
|
||||
footerDOM.addClass("close");
|
||||
bodyDOM.css("bottom", "");
|
||||
}
|
||||
};
|
||||
|
||||
this.bannerSkin = function (theme) {
|
||||
var pearAdmin = $(".pear-admin");
|
||||
pearAdmin.removeClass("banner-layout");
|
||||
if (theme === true || theme === "true") {
|
||||
pearAdmin.addClass("banner-layout");
|
||||
}
|
||||
};
|
||||
|
||||
this.enableDark = function (checked) {
|
||||
var $pearAdmin = $(".pear-admin");
|
||||
$pearAdmin.removeClass("pear-admin-dark");
|
||||
if (checked === true || checked === "true") {
|
||||
$pearAdmin.addClass("pear-admin-dark");
|
||||
}
|
||||
};
|
||||
|
||||
this.collapse = function (param) {
|
||||
if (param.menu.collapse) {
|
||||
if ($(window).width() >= 768) {
|
||||
collapse();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
this.menuSkin = function (theme) {
|
||||
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("dark-theme");
|
||||
pearAdmin.removeClass("light-theme");
|
||||
pearAdmin.removeClass("auto-theme");
|
||||
pearAdmin.addClass(theme);
|
||||
};
|
||||
|
||||
this.logout = function (callback) {
|
||||
logout = callback;
|
||||
};
|
||||
})();
|
||||
|
||||
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(configurationCache) === "true" ||
|
||||
isMuiltTab(configurationCache) === true
|
||||
)
|
||||
bodyTab.refresh(true);
|
||||
else bodyFrame.refresh(true);
|
||||
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 collapse() {
|
||||
sideMenu.collapse();
|
||||
var admin = $(".pear-admin");
|
||||
var left = $(".layui-icon-spread-left");
|
||||
var right = $(".layui-icon-shrink-right");
|
||||
if (admin.is(".pear-mini")) {
|
||||
left.addClass("layui-icon-shrink-right");
|
||||
left.removeClass("layui-icon-spread-left");
|
||||
admin.removeClass("pear-mini");
|
||||
sideMenu.isCollapse = false;
|
||||
} else {
|
||||
right.addClass("layui-icon-spread-left");
|
||||
right.removeClass("layui-icon-shrink-right");
|
||||
admin.addClass("pear-mini");
|
||||
sideMenu.isCollapse = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @since Pear Admin 4.0
|
||||
*
|
||||
* 使用 admin.logout(Function) 实现注销
|
||||
*
|
||||
* Promise<boolean> 作为返回值类型时,泛型内容为 true 时视为注销成功,则清除 bodyTab 缓存
|
||||
*
|
||||
* 否则视为注销失败,不做任何处置。
|
||||
*/
|
||||
body.on("click", ".logout", function () {
|
||||
var promise = logout();
|
||||
if (promise != undefined) {
|
||||
promise.then((asyncResult) => {
|
||||
if (asyncResult) {
|
||||
bodyTab.clear();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
bodyTab.clear();
|
||||
}
|
||||
});
|
||||
|
||||
body.on("click", ".collapse,.pear-cover", function () {
|
||||
collapse();
|
||||
});
|
||||
|
||||
body.on("click", ".fullScreen", function () {
|
||||
if ($(this).hasClass("layui-icon-screen-restore")) {
|
||||
fullscreen.fullClose().then(function () {
|
||||
$(".fullScreen").eq(0).removeClass("layui-icon-screen-restore");
|
||||
});
|
||||
} else {
|
||||
fullscreen.fullScreen().then(function () {
|
||||
$(".fullScreen").eq(0).addClass("layui-icon-screen-restore");
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
body.on("click", "[user-menu-id]", function () {
|
||||
if (
|
||||
isMuiltTab(configurationCache) === "true" ||
|
||||
isMuiltTab(configurationCache) === true
|
||||
) {
|
||||
bodyTab.addTabOnly(
|
||||
{
|
||||
id: $(this).attr("user-menu-id"),
|
||||
title: $(this).attr("user-menu-title"),
|
||||
url: $(this).attr("user-menu-url"),
|
||||
icon: "",
|
||||
close: true,
|
||||
},
|
||||
300,
|
||||
);
|
||||
} else {
|
||||
bodyFrame.changePage($(this).attr("user-menu-url"), true);
|
||||
}
|
||||
});
|
||||
|
||||
body.on("click", ".setting", function () {
|
||||
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>' +
|
||||
'<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>";
|
||||
|
||||
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>' +
|
||||
'<div><span style="display:block; width: 20%; float: left; height: 40px; background: white;"></span><span style="display:block; width: 80%; float: left; height: 40px; background: #f4f5f7;"></span></div>' +
|
||||
"</a>" +
|
||||
"</li>";
|
||||
|
||||
var menuHtml =
|
||||
'<div class="pearone-color">\n' +
|
||||
'<div class="color-title">菜单风格</div>\n' +
|
||||
'<div class="color-content">\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>";
|
||||
|
||||
headItem +=
|
||||
'<li data-select-header="auto-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: var(--global-primary-color);" ></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" style="width:200px;"><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" style="width:200px;"><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" style="width:200px;"><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" style="width:200px;"><input type="checkbox" name="footer" lay-filter="footer" lay-skin="switch" lay-text="开|关"></div><span class="set-text">开启页脚</span></div>';
|
||||
|
||||
moreItem +=
|
||||
'<div class="layui-form-item"><div class="layui-input-inline" style="width:200px;"><input type="checkbox" name="dark" lay-filter="dark" 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>";
|
||||
|
||||
layer.open({
|
||||
type: 1,
|
||||
offset: "r",
|
||||
area: ["320px", "100%"],
|
||||
title: false,
|
||||
shade: 0.1,
|
||||
closeBtn: 0,
|
||||
shadeClose: false,
|
||||
anim: -1,
|
||||
skin: "layer-anim-right",
|
||||
move: false,
|
||||
content: menuHtml + headHtml + buildColorHtml() + moreHtml,
|
||||
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(
|
||||
{
|
||||
left: $layero.offset().left + $layero.width(),
|
||||
},
|
||||
200,
|
||||
function () {
|
||||
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);
|
||||
pearAdmin.changeTheme();
|
||||
});
|
||||
|
||||
form.on("switch(banner)", function (data) {
|
||||
localStorage.setItem("theme-banner", this.checked);
|
||||
pearAdmin.bannerSkin(this.checked);
|
||||
});
|
||||
|
||||
form.on("switch(footer)", function (data) {
|
||||
localStorage.setItem("footer", this.checked);
|
||||
pearAdmin.footer(this.checked);
|
||||
});
|
||||
|
||||
form.on("switch(dark)", function (data) {
|
||||
localStorage.setItem("dark", this.checked);
|
||||
pearAdmin.enableDark(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("footer") === "true") {
|
||||
$('input[name="footer"]').attr("checked", "checked");
|
||||
} else {
|
||||
$('input[name="footer"]').removeAttr("checked");
|
||||
}
|
||||
|
||||
if (localStorage.getItem("dark") === "true") {
|
||||
$('input[name="dark"]').attr("checked", "checked");
|
||||
} else {
|
||||
$('input[name="dark"]').removeAttr("checked");
|
||||
}
|
||||
|
||||
form.render("checkbox");
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
body.on("click", "[data-select-bgcolor]", function () {
|
||||
var theme = $(this).attr("data-select-bgcolor");
|
||||
$("[data-select-bgcolor]").removeClass("layui-this");
|
||||
$(this).addClass("layui-this");
|
||||
localStorage.setItem("theme-menu", theme);
|
||||
pearAdmin.menuSkin(theme);
|
||||
});
|
||||
|
||||
body.on("click", "[data-select-header]", function () {
|
||||
var headerColor = $(this).attr("data-select-header");
|
||||
$("[data-select-header]").removeClass("layui-this");
|
||||
$(this).addClass("layui-this");
|
||||
localStorage.setItem("theme-header", headerColor);
|
||||
if (headerColor == "auto-theme") {
|
||||
localStorage.setItem("auto-head", true);
|
||||
pearAdmin.changeTheme();
|
||||
} else {
|
||||
localStorage.setItem("auto-head", false);
|
||||
pearAdmin.changeTheme();
|
||||
}
|
||||
pearAdmin.headerSkin(headerColor);
|
||||
});
|
||||
|
||||
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");
|
||||
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-color", currentColor.color);
|
||||
localStorage.setItem("theme-color-second", currentColor.second);
|
||||
pearAdmin.changeTheme();
|
||||
});
|
||||
|
||||
function getColorById(id) {
|
||||
var color;
|
||||
var flag = false;
|
||||
$.each(configurationCache.colors, function (i, value) {
|
||||
if (value.id === id) {
|
||||
color = value;
|
||||
flag = true;
|
||||
}
|
||||
});
|
||||
if (flag === false || configurationCache.theme.allowCustom === false) {
|
||||
$.each(configurationCache.colors, function (i, value) {
|
||||
if (value.id === configurationCache.theme.defaultColor) {
|
||||
color = value;
|
||||
}
|
||||
});
|
||||
}
|
||||
return color;
|
||||
}
|
||||
|
||||
function buildColorHtml() {
|
||||
var colors = "";
|
||||
$.each(configurationCache.colors, function (i, value) {
|
||||
colors +=
|
||||
"<span class='select-color-item' color-id='" +
|
||||
value.id +
|
||||
"' style='background-color:" +
|
||||
value.color +
|
||||
";'></span>";
|
||||
});
|
||||
return (
|
||||
"<div class='select-color'><div class='select-color-title'>主题颜色</div><div class='select-color-content'>" +
|
||||
colors +
|
||||
"</div></div>"
|
||||
);
|
||||
}
|
||||
|
||||
function compatible() {
|
||||
if ($(window).width() <= 768) {
|
||||
collapse();
|
||||
}
|
||||
}
|
||||
|
||||
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 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 (!fullscreen.isFullscreen()) {
|
||||
$(".fullScreen").eq(0).removeClass("layui-icon-screen-restore");
|
||||
}
|
||||
};
|
||||
|
||||
$(window).on(
|
||||
"resize",
|
||||
tools.debounce(function () {
|
||||
if (sideMenu && !sideMenu.isCollapse && $(window).width() <= 768) {
|
||||
collapse();
|
||||
}
|
||||
}, 50),
|
||||
);
|
||||
|
||||
exports("admin", pearAdmin);
|
||||
},
|
||||
);
|
||||
@@ -0,0 +1,60 @@
|
||||
layui.define(["jquery"], function (exports) {
|
||||
"use strict";
|
||||
|
||||
/**
|
||||
* @since Pear Admin 4.0
|
||||
*
|
||||
* Button component
|
||||
* */
|
||||
var MOD_NAME = "button",
|
||||
$ = layui.jquery;
|
||||
|
||||
var button = function (opt) {
|
||||
this.option = opt;
|
||||
};
|
||||
|
||||
/**
|
||||
* @since Pear Admin 4.0
|
||||
*
|
||||
* Button start loading
|
||||
* */
|
||||
button.prototype.load = function (opt) {
|
||||
var options = {
|
||||
elem: opt.elem,
|
||||
time: opt.time ? opt.time : false,
|
||||
done: opt.done ? opt.done : function () {},
|
||||
};
|
||||
|
||||
var text = $(options.elem).html();
|
||||
|
||||
$(options.elem).html(
|
||||
"<i class='layui-anim layui-anim-rotate layui-icon layui-anim-loop layui-icon-loading'/>",
|
||||
);
|
||||
$(options.elem).attr("disabled", "disabled");
|
||||
|
||||
var $button = $(options.elem);
|
||||
|
||||
if (options.time != "" || options.time != false) {
|
||||
setTimeout(function () {
|
||||
$button.attr("disabled", false);
|
||||
$button.html(text);
|
||||
options.done();
|
||||
}, options.time);
|
||||
}
|
||||
options.text = text;
|
||||
return new button(options);
|
||||
};
|
||||
|
||||
/**
|
||||
* @since Pear Admin 4.0
|
||||
*
|
||||
* Button stop loaded
|
||||
* */
|
||||
button.prototype.stop = function (success) {
|
||||
$(this.option.elem).attr("disabled", false);
|
||||
$(this.option.elem).html(this.option.text);
|
||||
success && success();
|
||||
};
|
||||
|
||||
exports(MOD_NAME, new button());
|
||||
});
|
||||
@@ -0,0 +1,34 @@
|
||||
layui.define(["jquery", "element"], function (exports) {
|
||||
"use strict";
|
||||
|
||||
var MOD_NAME = "count",
|
||||
$ = layui.jquery,
|
||||
element = layui.element;
|
||||
|
||||
var count = new (function () {
|
||||
this.up = function (targetEle, options) {
|
||||
options = options || {};
|
||||
|
||||
var $this = document.getElementById(targetEle),
|
||||
time = options.time,
|
||||
finalNum = options.num,
|
||||
regulator = options.regulator,
|
||||
step = finalNum / (time / regulator),
|
||||
count = 0.0,
|
||||
initial = 0;
|
||||
|
||||
var timer = setInterval(function () {
|
||||
count = count + step;
|
||||
if (count >= finalNum) {
|
||||
clearInterval(timer);
|
||||
count = finalNum;
|
||||
}
|
||||
var t = count.toFixed(options.bit ? options.bit : 0);
|
||||
if (t == initial) return;
|
||||
initial = t;
|
||||
$this.innerHTML = initial;
|
||||
}, 30);
|
||||
};
|
||||
})();
|
||||
exports(MOD_NAME, count);
|
||||
});
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,406 @@
|
||||
layui.define(function (exports) {
|
||||
exports("echartsTheme", {
|
||||
color: ["#3fb1e3", "#6be6c1", "#626c91", "#a0a7e6", "#c4ebad", "#96dee8"],
|
||||
backgroundColor: "rgba(252,252,252,0)",
|
||||
textStyle: {},
|
||||
title: {
|
||||
textStyle: {
|
||||
color: "#666666",
|
||||
},
|
||||
subtextStyle: {
|
||||
color: "#999999",
|
||||
},
|
||||
},
|
||||
line: {
|
||||
itemStyle: {
|
||||
borderWidth: "3",
|
||||
},
|
||||
lineStyle: {
|
||||
width: "4",
|
||||
},
|
||||
symbolSize: "10",
|
||||
symbol: "emptyCircle",
|
||||
smooth: true,
|
||||
},
|
||||
radar: {
|
||||
itemStyle: {
|
||||
borderWidth: "3",
|
||||
},
|
||||
lineStyle: {
|
||||
width: "4",
|
||||
},
|
||||
symbolSize: "10",
|
||||
symbol: "emptyCircle",
|
||||
smooth: true,
|
||||
},
|
||||
bar: {
|
||||
itemStyle: {
|
||||
barBorderWidth: 0,
|
||||
barBorderColor: "#ccc",
|
||||
},
|
||||
emphasis: {
|
||||
itemStyle: {
|
||||
barBorderWidth: 0,
|
||||
barBorderColor: "#ccc",
|
||||
},
|
||||
},
|
||||
},
|
||||
pie: {
|
||||
itemStyle: {
|
||||
borderWidth: 0,
|
||||
borderColor: "#ccc",
|
||||
},
|
||||
emphasis: {
|
||||
itemStyle: {
|
||||
borderWidth: 0,
|
||||
borderColor: "#ccc",
|
||||
},
|
||||
},
|
||||
},
|
||||
scatter: {
|
||||
itemStyle: {
|
||||
borderWidth: 0,
|
||||
borderColor: "#ccc",
|
||||
},
|
||||
emphasis: {
|
||||
itemStyle: {
|
||||
borderWidth: 0,
|
||||
borderColor: "#ccc",
|
||||
},
|
||||
},
|
||||
},
|
||||
boxplot: {
|
||||
itemStyle: {
|
||||
borderWidth: 0,
|
||||
borderColor: "#ccc",
|
||||
},
|
||||
emphasis: {
|
||||
itemStyle: {
|
||||
borderWidth: 0,
|
||||
borderColor: "#ccc",
|
||||
},
|
||||
},
|
||||
},
|
||||
parallel: {
|
||||
itemStyle: {
|
||||
borderWidth: 0,
|
||||
borderColor: "#ccc",
|
||||
},
|
||||
emphasis: {
|
||||
itemStyle: {
|
||||
borderWidth: 0,
|
||||
borderColor: "#ccc",
|
||||
},
|
||||
},
|
||||
},
|
||||
sankey: {
|
||||
itemStyle: {
|
||||
borderWidth: 0,
|
||||
borderColor: "#ccc",
|
||||
},
|
||||
emphasis: {
|
||||
itemStyle: {
|
||||
borderWidth: 0,
|
||||
borderColor: "#ccc",
|
||||
},
|
||||
},
|
||||
},
|
||||
funnel: {
|
||||
itemStyle: {
|
||||
borderWidth: 0,
|
||||
borderColor: "#ccc",
|
||||
},
|
||||
emphasis: {
|
||||
itemStyle: {
|
||||
borderWidth: 0,
|
||||
borderColor: "#ccc",
|
||||
},
|
||||
},
|
||||
},
|
||||
gauge: {
|
||||
itemStyle: {
|
||||
borderWidth: 0,
|
||||
borderColor: "#ccc",
|
||||
},
|
||||
emphasis: {
|
||||
itemStyle: {
|
||||
borderWidth: 0,
|
||||
borderColor: "#ccc",
|
||||
},
|
||||
},
|
||||
},
|
||||
candlestick: {
|
||||
itemStyle: {
|
||||
color: "#e6a0d2",
|
||||
color0: "transparent",
|
||||
borderColor: "#e6a0d2",
|
||||
borderColor0: "#3fb1e3",
|
||||
borderWidth: "2",
|
||||
},
|
||||
},
|
||||
graph: {
|
||||
itemStyle: {
|
||||
borderWidth: 0,
|
||||
borderColor: "#ccc",
|
||||
},
|
||||
lineStyle: {
|
||||
width: "1",
|
||||
color: "#cccccc",
|
||||
},
|
||||
symbolSize: "10",
|
||||
symbol: "emptyCircle",
|
||||
smooth: true,
|
||||
color: ["#3fb1e3", "#6be6c1", "#626c91", "#a0a7e6", "#c4ebad", "#96dee8"],
|
||||
label: {
|
||||
color: "#ffffff",
|
||||
},
|
||||
},
|
||||
map: {
|
||||
itemStyle: {
|
||||
areaColor: "#eeeeee",
|
||||
borderColor: "#aaaaaa",
|
||||
borderWidth: 0.5,
|
||||
},
|
||||
label: {
|
||||
color: "#ffffff",
|
||||
},
|
||||
emphasis: {
|
||||
itemStyle: {
|
||||
areaColor: "rgba(63,177,227,0.25)",
|
||||
borderColor: "#3fb1e3",
|
||||
borderWidth: 1,
|
||||
},
|
||||
label: {
|
||||
color: "rgb(63,177,227)",
|
||||
},
|
||||
},
|
||||
},
|
||||
geo: {
|
||||
itemStyle: {
|
||||
areaColor: "#eeeeee",
|
||||
borderColor: "#aaaaaa",
|
||||
borderWidth: 0.5,
|
||||
},
|
||||
label: {
|
||||
color: "#ffffff",
|
||||
},
|
||||
emphasis: {
|
||||
itemStyle: {
|
||||
areaColor: "rgba(63,177,227,0.25)",
|
||||
borderColor: "#3fb1e3",
|
||||
borderWidth: 1,
|
||||
},
|
||||
label: {
|
||||
color: "rgb(63,177,227)",
|
||||
},
|
||||
},
|
||||
},
|
||||
categoryAxis: {
|
||||
axisLine: {
|
||||
show: true,
|
||||
lineStyle: {
|
||||
color: "#cccccc",
|
||||
},
|
||||
},
|
||||
axisTick: {
|
||||
show: false,
|
||||
lineStyle: {
|
||||
color: "#333",
|
||||
},
|
||||
},
|
||||
axisLabel: {
|
||||
show: true,
|
||||
|
||||
color: "#999999",
|
||||
},
|
||||
splitLine: {
|
||||
show: true,
|
||||
lineStyle: {
|
||||
color: ["#eeeeee"],
|
||||
},
|
||||
},
|
||||
splitArea: {
|
||||
show: false,
|
||||
areaStyle: {
|
||||
color: ["rgba(250,250,250,0.05)", "rgba(200,200,200,0.02)"],
|
||||
},
|
||||
},
|
||||
},
|
||||
valueAxis: {
|
||||
axisLine: {
|
||||
show: true,
|
||||
lineStyle: {
|
||||
color: "#cccccc",
|
||||
},
|
||||
},
|
||||
axisTick: {
|
||||
show: false,
|
||||
lineStyle: {
|
||||
color: "#333",
|
||||
},
|
||||
},
|
||||
axisLabel: {
|
||||
show: true,
|
||||
color: "#999999",
|
||||
},
|
||||
splitLine: {
|
||||
show: true,
|
||||
lineStyle: {
|
||||
color: ["#eeeeee"],
|
||||
},
|
||||
},
|
||||
splitArea: {
|
||||
show: false,
|
||||
areaStyle: {
|
||||
color: ["rgba(250,250,250,0.05)", "rgba(200,200,200,0.02)"],
|
||||
},
|
||||
},
|
||||
},
|
||||
logAxis: {
|
||||
axisLine: {
|
||||
show: true,
|
||||
lineStyle: {
|
||||
color: "#cccccc",
|
||||
},
|
||||
},
|
||||
axisTick: {
|
||||
show: false,
|
||||
lineStyle: {
|
||||
color: "#333",
|
||||
},
|
||||
},
|
||||
axisLabel: {
|
||||
show: true,
|
||||
color: "#999999",
|
||||
},
|
||||
splitLine: {
|
||||
show: true,
|
||||
lineStyle: {
|
||||
color: ["#eeeeee"],
|
||||
},
|
||||
},
|
||||
splitArea: {
|
||||
show: false,
|
||||
areaStyle: {
|
||||
color: ["rgba(250,250,250,0.05)", "rgba(200,200,200,0.02)"],
|
||||
},
|
||||
},
|
||||
},
|
||||
timeAxis: {
|
||||
axisLine: {
|
||||
show: true,
|
||||
lineStyle: {
|
||||
color: "#cccccc",
|
||||
},
|
||||
},
|
||||
axisTick: {
|
||||
show: false,
|
||||
lineStyle: {
|
||||
color: "#333",
|
||||
},
|
||||
},
|
||||
axisLabel: {
|
||||
show: true,
|
||||
|
||||
color: "#999999",
|
||||
},
|
||||
splitLine: {
|
||||
show: true,
|
||||
lineStyle: {
|
||||
color: ["#eeeeee"],
|
||||
},
|
||||
},
|
||||
splitArea: {
|
||||
show: false,
|
||||
areaStyle: {
|
||||
color: ["rgba(250,250,250,0.05)", "rgba(200,200,200,0.02)"],
|
||||
},
|
||||
},
|
||||
},
|
||||
toolbox: {
|
||||
iconStyle: {
|
||||
borderColor: "#999999",
|
||||
},
|
||||
emphasis: {
|
||||
iconStyle: {
|
||||
borderColor: "#666666",
|
||||
},
|
||||
},
|
||||
},
|
||||
legend: {
|
||||
textStyle: {
|
||||
color: "#999999",
|
||||
},
|
||||
},
|
||||
tooltip: {
|
||||
axisPointer: {
|
||||
lineStyle: {
|
||||
color: "#cccccc",
|
||||
width: 1,
|
||||
},
|
||||
crossStyle: {
|
||||
color: "#cccccc",
|
||||
width: 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
timeline: {
|
||||
lineStyle: {
|
||||
color: "#626c91",
|
||||
width: 1,
|
||||
},
|
||||
itemStyle: {
|
||||
color: "#626c91",
|
||||
borderWidth: 1,
|
||||
},
|
||||
controlStyle: {
|
||||
color: "#626c91",
|
||||
borderColor: "#626c91",
|
||||
borderWidth: 0.5,
|
||||
},
|
||||
checkpointStyle: {
|
||||
color: "#3fb1e3",
|
||||
borderColor: "rgba(63,177,227,0.15)",
|
||||
},
|
||||
label: {
|
||||
color: "#626c91",
|
||||
},
|
||||
emphasis: {
|
||||
itemStyle: {
|
||||
color: "#626c91",
|
||||
},
|
||||
controlStyle: {
|
||||
color: "#626c91",
|
||||
borderColor: "#626c91",
|
||||
borderWidth: 0.5,
|
||||
},
|
||||
label: {
|
||||
color: "#626c91",
|
||||
},
|
||||
},
|
||||
},
|
||||
visualMap: {
|
||||
color: ["#2a99c9", "#afe8ff"],
|
||||
},
|
||||
dataZoom: {
|
||||
backgroundColor: "rgba(255,255,255,0)",
|
||||
dataBackgroundColor: "rgba(222,222,222,1)",
|
||||
fillerColor: "rgba(114,230,212,0.25)",
|
||||
handleColor: "#cccccc",
|
||||
handleSize: "100%",
|
||||
textStyle: {
|
||||
color: "#999999",
|
||||
},
|
||||
},
|
||||
markPoint: {
|
||||
label: {
|
||||
color: "#ffffff",
|
||||
},
|
||||
emphasis: {
|
||||
label: {
|
||||
color: "#ffffff",
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,519 @@
|
||||
/* NProgress, (c) 2013, 2014 Rico Sta. Cruz - http://ricostacruz.com/nprogress
|
||||
* @license MIT */
|
||||
|
||||
(function (root, factory) {
|
||||
if (typeof define === "function" && define.amd) {
|
||||
define(factory);
|
||||
} else if (typeof exports === "object") {
|
||||
module.exports = factory();
|
||||
} else {
|
||||
root.NProgress = factory();
|
||||
}
|
||||
})(this, function () {
|
||||
var NProgress = {};
|
||||
|
||||
NProgress.version = "0.2.0";
|
||||
|
||||
var Settings = (NProgress.settings = {
|
||||
minimum: 0.08,
|
||||
easing: "linear",
|
||||
positionUsing: "",
|
||||
speed: 200,
|
||||
trickle: true,
|
||||
trickleSpeed: 200,
|
||||
showSpinner: true,
|
||||
barSelector: '[role="bar"]',
|
||||
spinnerSelector: '[role="spinner"]',
|
||||
parent: "body",
|
||||
template:
|
||||
'<div class="bar" role="bar"><div class="peg"></div></div><div class="spinner" role="spinner"><div class="spinner-icon"></div></div>',
|
||||
});
|
||||
|
||||
/**
|
||||
* Updates configuration.
|
||||
*
|
||||
* NProgress.configure({
|
||||
* minimum: 0.1
|
||||
* });
|
||||
*/
|
||||
NProgress.configure = function (options) {
|
||||
var key, value;
|
||||
for (key in options) {
|
||||
value = options[key];
|
||||
if (value !== undefined && options.hasOwnProperty(key))
|
||||
Settings[key] = value;
|
||||
}
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Last number.
|
||||
*/
|
||||
|
||||
NProgress.status = null;
|
||||
|
||||
/**
|
||||
* Sets the progress bar status, where `n` is a number from `0.0` to `1.0`.
|
||||
*
|
||||
* NProgress.set(0.4);
|
||||
* NProgress.set(1.0);
|
||||
*/
|
||||
|
||||
NProgress.set = function (n) {
|
||||
var started = NProgress.isStarted();
|
||||
|
||||
n = clamp(n, Settings.minimum, 1);
|
||||
NProgress.status = n === 1 ? null : n;
|
||||
|
||||
var progress = NProgress.render(!started),
|
||||
bar = progress.querySelector(Settings.barSelector),
|
||||
speed = Settings.speed,
|
||||
ease = Settings.easing;
|
||||
|
||||
progress.offsetWidth; /* Repaint */
|
||||
|
||||
queue(function (next) {
|
||||
// Set positionUsing if it hasn't already been set
|
||||
if (Settings.positionUsing === "")
|
||||
Settings.positionUsing = NProgress.getPositioningCSS();
|
||||
|
||||
// Add transition
|
||||
css(bar, barPositionCSS(n, speed, ease));
|
||||
|
||||
if (n === 1) {
|
||||
// Fade out
|
||||
css(progress, {
|
||||
transition: "none",
|
||||
opacity: 1,
|
||||
});
|
||||
progress.offsetWidth; /* Repaint */
|
||||
|
||||
setTimeout(function () {
|
||||
css(progress, {
|
||||
transition: "all " + speed + "ms linear",
|
||||
opacity: 0,
|
||||
});
|
||||
setTimeout(function () {
|
||||
NProgress.remove();
|
||||
next();
|
||||
}, speed);
|
||||
}, speed);
|
||||
} else {
|
||||
setTimeout(next, speed);
|
||||
}
|
||||
});
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
NProgress.isStarted = function () {
|
||||
return typeof NProgress.status === "number";
|
||||
};
|
||||
|
||||
/**
|
||||
* Shows the progress bar.
|
||||
* This is the same as setting the status to 0%, except that it doesn't go backwards.
|
||||
*
|
||||
* NProgress.start();
|
||||
*
|
||||
*/
|
||||
NProgress.start = function () {
|
||||
if (!NProgress.status) NProgress.set(0);
|
||||
|
||||
var work = function () {
|
||||
setTimeout(function () {
|
||||
if (!NProgress.status) return;
|
||||
NProgress.trickle();
|
||||
work();
|
||||
}, Settings.trickleSpeed);
|
||||
};
|
||||
|
||||
if (Settings.trickle) work();
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Hides the progress bar.
|
||||
* This is the *sort of* the same as setting the status to 100%, with the
|
||||
* difference being `done()` makes some placebo effect of some realistic motion.
|
||||
*
|
||||
* NProgress.done();
|
||||
*
|
||||
* If `true` is passed, it will show the progress bar even if its hidden.
|
||||
*
|
||||
* NProgress.done(true);
|
||||
*/
|
||||
|
||||
NProgress.done = function (force) {
|
||||
if (!force && !NProgress.status) return this;
|
||||
|
||||
return NProgress.inc(0.3 + 0.5 * Math.random()).set(1);
|
||||
};
|
||||
|
||||
/**
|
||||
* Increments by a random amount.
|
||||
*/
|
||||
|
||||
NProgress.inc = function (amount) {
|
||||
var n = NProgress.status;
|
||||
|
||||
if (!n) {
|
||||
return NProgress.start();
|
||||
} else if (n > 1) {
|
||||
return;
|
||||
} else {
|
||||
if (typeof amount !== "number") {
|
||||
if (n >= 0 && n < 0.2) {
|
||||
amount = 0.1;
|
||||
} else if (n >= 0.2 && n < 0.5) {
|
||||
amount = 0.04;
|
||||
} else if (n >= 0.5 && n < 0.8) {
|
||||
amount = 0.02;
|
||||
} else if (n >= 0.8 && n < 0.99) {
|
||||
amount = 0.005;
|
||||
} else {
|
||||
amount = 0;
|
||||
}
|
||||
}
|
||||
|
||||
n = clamp(n + amount, 0, 0.994);
|
||||
return NProgress.set(n);
|
||||
}
|
||||
};
|
||||
|
||||
NProgress.trickle = function () {
|
||||
return NProgress.inc();
|
||||
};
|
||||
|
||||
/**
|
||||
* Waits for all supplied jQuery promises and
|
||||
* increases the progress as the promises resolve.
|
||||
*
|
||||
* @param $promise jQUery Promise
|
||||
*/
|
||||
(function () {
|
||||
var initial = 0,
|
||||
current = 0;
|
||||
|
||||
NProgress.promise = function ($promise) {
|
||||
if (!$promise || $promise.state() === "resolved") {
|
||||
return this;
|
||||
}
|
||||
|
||||
if (current === 0) {
|
||||
NProgress.start();
|
||||
}
|
||||
|
||||
initial++;
|
||||
current++;
|
||||
|
||||
$promise.always(function () {
|
||||
current--;
|
||||
if (current === 0) {
|
||||
initial = 0;
|
||||
NProgress.done();
|
||||
} else {
|
||||
NProgress.set((initial - current) / initial);
|
||||
}
|
||||
});
|
||||
|
||||
return this;
|
||||
};
|
||||
})();
|
||||
|
||||
/**
|
||||
* (Internal) renders the progress bar markup based on the `template`
|
||||
* setting.
|
||||
*/
|
||||
|
||||
NProgress.render = function (fromStart) {
|
||||
if (NProgress.isRendered()) return document.getElementById("nprogress");
|
||||
|
||||
addClass(document.documentElement, "nprogress-busy");
|
||||
|
||||
var progress = document.createElement("div");
|
||||
progress.id = "nprogress";
|
||||
progress.innerHTML = Settings.template;
|
||||
|
||||
var bar = progress.querySelector(Settings.barSelector),
|
||||
perc = fromStart ? "-100" : toBarPerc(NProgress.status || 0),
|
||||
parent = isDOM(Settings.parent)
|
||||
? Settings.parent
|
||||
: document.querySelector(Settings.parent),
|
||||
spinner;
|
||||
|
||||
css(bar, {
|
||||
transition: "all 0 linear",
|
||||
transform: "translate3d(" + perc + "%,0,0)",
|
||||
});
|
||||
|
||||
if (!Settings.showSpinner) {
|
||||
spinner = progress.querySelector(Settings.spinnerSelector);
|
||||
spinner && removeElement(spinner);
|
||||
}
|
||||
|
||||
if (parent != document.body) {
|
||||
addClass(parent, "nprogress-custom-parent");
|
||||
}
|
||||
|
||||
parent.appendChild(progress);
|
||||
return progress;
|
||||
};
|
||||
|
||||
/**
|
||||
* Removes the element. Opposite of render().
|
||||
*/
|
||||
|
||||
NProgress.remove = function () {
|
||||
removeClass(document.documentElement, "nprogress-busy");
|
||||
var parent = isDOM(Settings.parent)
|
||||
? Settings.parent
|
||||
: document.querySelector(Settings.parent);
|
||||
removeClass(parent, "nprogress-custom-parent");
|
||||
var progress = document.getElementById("nprogress");
|
||||
progress && removeElement(progress);
|
||||
};
|
||||
|
||||
/**
|
||||
* Checks if the progress bar is rendered.
|
||||
*/
|
||||
|
||||
NProgress.isRendered = function () {
|
||||
return !!document.getElementById("nprogress");
|
||||
};
|
||||
|
||||
/**
|
||||
* Determine which positioning CSS rule to use.
|
||||
*/
|
||||
|
||||
NProgress.getPositioningCSS = function () {
|
||||
// Sniff on document.body.style
|
||||
var bodyStyle = document.body.style;
|
||||
|
||||
// Sniff prefixes
|
||||
var vendorPrefix =
|
||||
"WebkitTransform" in bodyStyle
|
||||
? "Webkit"
|
||||
: "MozTransform" in bodyStyle
|
||||
? "Moz"
|
||||
: "msTransform" in bodyStyle
|
||||
? "ms"
|
||||
: "OTransform" in bodyStyle
|
||||
? "O"
|
||||
: "";
|
||||
|
||||
if (vendorPrefix + "Perspective" in bodyStyle) {
|
||||
// Modern browsers with 3D support, e.g. Webkit, IE10
|
||||
return "translate3d";
|
||||
} else if (vendorPrefix + "Transform" in bodyStyle) {
|
||||
// Browsers without 3D support, e.g. IE9
|
||||
return "translate";
|
||||
} else {
|
||||
// Browsers without translate() support, e.g. IE7-8
|
||||
return "margin";
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Helpers
|
||||
*/
|
||||
|
||||
function isDOM(obj) {
|
||||
if (typeof HTMLElement === "object") {
|
||||
return obj instanceof HTMLElement;
|
||||
}
|
||||
return (
|
||||
obj &&
|
||||
typeof obj === "object" &&
|
||||
obj.nodeType === 1 &&
|
||||
typeof obj.nodeName === "string"
|
||||
);
|
||||
}
|
||||
|
||||
function clamp(n, min, max) {
|
||||
if (n < min) return min;
|
||||
if (n > max) return max;
|
||||
return n;
|
||||
}
|
||||
|
||||
/**
|
||||
* (Internal) converts a percentage (`0..1`) to a bar translateX
|
||||
* percentage (`-100%..0%`).
|
||||
*/
|
||||
|
||||
function toBarPerc(n) {
|
||||
return (-1 + n) * 100;
|
||||
}
|
||||
|
||||
/**
|
||||
* (Internal) returns the correct CSS for changing the bar's
|
||||
* position given an n percentage, and speed and ease from Settings
|
||||
*/
|
||||
|
||||
function barPositionCSS(n, speed, ease) {
|
||||
var barCSS;
|
||||
|
||||
if (Settings.positionUsing === "translate3d") {
|
||||
barCSS = { transform: "translate3d(" + toBarPerc(n) + "%,0,0)" };
|
||||
} else if (Settings.positionUsing === "translate") {
|
||||
barCSS = { transform: "translate(" + toBarPerc(n) + "%,0)" };
|
||||
} else {
|
||||
barCSS = { "margin-left": toBarPerc(n) + "%" };
|
||||
}
|
||||
|
||||
barCSS.transition = "all " + speed + "ms " + ease;
|
||||
|
||||
return barCSS;
|
||||
}
|
||||
|
||||
/**
|
||||
* (Internal) Queues a function to be executed.
|
||||
*/
|
||||
|
||||
var queue = (function () {
|
||||
var pending = [];
|
||||
|
||||
function next() {
|
||||
var fn = pending.shift();
|
||||
if (fn) {
|
||||
fn(next);
|
||||
}
|
||||
}
|
||||
|
||||
return function (fn) {
|
||||
pending.push(fn);
|
||||
if (pending.length == 1) next();
|
||||
};
|
||||
})();
|
||||
|
||||
/**
|
||||
* (Internal) Applies css properties to an element, similar to the jQuery
|
||||
* css method.
|
||||
*
|
||||
* While this helper does assist with vendor prefixed property names, it
|
||||
* does not perform any manipulation of values prior to setting styles.
|
||||
*/
|
||||
|
||||
var css = (function () {
|
||||
var cssPrefixes = ["Webkit", "O", "Moz", "ms"],
|
||||
cssProps = {};
|
||||
|
||||
function camelCase(string) {
|
||||
return string
|
||||
.replace(/^-ms-/, "ms-")
|
||||
.replace(/-([\da-z])/gi, function (match, letter) {
|
||||
return letter.toUpperCase();
|
||||
});
|
||||
}
|
||||
|
||||
function getVendorProp(name) {
|
||||
var style = document.body.style;
|
||||
if (name in style) return name;
|
||||
|
||||
var i = cssPrefixes.length,
|
||||
capName = name.charAt(0).toUpperCase() + name.slice(1),
|
||||
vendorName;
|
||||
while (i--) {
|
||||
vendorName = cssPrefixes[i] + capName;
|
||||
if (vendorName in style) return vendorName;
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
function getStyleProp(name) {
|
||||
name = camelCase(name);
|
||||
return cssProps[name] || (cssProps[name] = getVendorProp(name));
|
||||
}
|
||||
|
||||
function applyCss(element, prop, value) {
|
||||
prop = getStyleProp(prop);
|
||||
element.style[prop] = value;
|
||||
}
|
||||
|
||||
return function (element, properties) {
|
||||
var args = arguments,
|
||||
prop,
|
||||
value;
|
||||
|
||||
if (args.length == 2) {
|
||||
for (prop in properties) {
|
||||
value = properties[prop];
|
||||
if (value !== undefined && properties.hasOwnProperty(prop))
|
||||
applyCss(element, prop, value);
|
||||
}
|
||||
} else {
|
||||
applyCss(element, args[1], args[2]);
|
||||
}
|
||||
};
|
||||
})();
|
||||
|
||||
/**
|
||||
* (Internal) Determines if an element or space separated list of class names contains a class name.
|
||||
*/
|
||||
|
||||
function hasClass(element, name) {
|
||||
var list = typeof element == "string" ? element : classList(element);
|
||||
return list.indexOf(" " + name + " ") >= 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* (Internal) Adds a class to an element.
|
||||
*/
|
||||
|
||||
function addClass(element, name) {
|
||||
var oldList = classList(element),
|
||||
newList = oldList + name;
|
||||
|
||||
if (hasClass(oldList, name)) return;
|
||||
|
||||
// Trim the opening space.
|
||||
element.className = newList.substring(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* (Internal) Removes a class from an element.
|
||||
*/
|
||||
|
||||
function removeClass(element, name) {
|
||||
var oldList = classList(element),
|
||||
newList;
|
||||
|
||||
if (!hasClass(element, name)) return;
|
||||
|
||||
// Replace the class name.
|
||||
newList = oldList.replace(" " + name + " ", " ");
|
||||
|
||||
// Trim the opening and closing spaces.
|
||||
element.className = newList.substring(1, newList.length - 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* (Internal) Gets a space separated list of the class names on the element.
|
||||
* The list is wrapped with a single space on each end to facilitate finding
|
||||
* matches within the list.
|
||||
*/
|
||||
|
||||
function classList(element) {
|
||||
return (" " + ((element && element.className) || "") + " ").replace(
|
||||
/\s+/gi,
|
||||
" ",
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* (Internal) Removes an element from the DOM.
|
||||
*/
|
||||
|
||||
function removeElement(element) {
|
||||
element && element.parentNode && element.parentNode.removeChild(element);
|
||||
}
|
||||
|
||||
return NProgress;
|
||||
});
|
||||
|
||||
layui.define([], function (exports) {
|
||||
exports("nprogress", NProgress);
|
||||
});
|
||||
@@ -0,0 +1,58 @@
|
||||
layui.define(["layer"], function (exports) {
|
||||
"use strict";
|
||||
|
||||
var MOD_NAME = "popup",
|
||||
layer = layui.layer;
|
||||
|
||||
var popup = new (function () {
|
||||
(this.success = function (msg) {
|
||||
layer.msg(msg, {
|
||||
icon: 1,
|
||||
time: 1000,
|
||||
});
|
||||
}),
|
||||
(this.failure = function (msg) {
|
||||
layer.msg(msg, {
|
||||
icon: 2,
|
||||
time: 1000,
|
||||
});
|
||||
}),
|
||||
(this.warning = function (msg) {
|
||||
layer.msg(msg, {
|
||||
icon: 3,
|
||||
time: 1000,
|
||||
});
|
||||
}),
|
||||
(this.success = function (msg, callback) {
|
||||
layer.msg(
|
||||
msg,
|
||||
{
|
||||
icon: 1,
|
||||
time: 1000,
|
||||
},
|
||||
callback,
|
||||
);
|
||||
}),
|
||||
(this.failure = function (msg, callback) {
|
||||
layer.msg(
|
||||
msg,
|
||||
{
|
||||
icon: 2,
|
||||
time: 1000,
|
||||
},
|
||||
callback,
|
||||
);
|
||||
}),
|
||||
(this.warming = function (msg, callback) {
|
||||
layer.msg(
|
||||
msg,
|
||||
{
|
||||
icon: 3,
|
||||
time: 1000,
|
||||
},
|
||||
callback,
|
||||
);
|
||||
});
|
||||
})();
|
||||
exports(MOD_NAME, popup);
|
||||
});
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,65 @@
|
||||
layui.define(["jquery", "element"], function (exports) {
|
||||
var $ = layui.jquery;
|
||||
var defer = $.Deferred();
|
||||
var fullScreen = new (function () {
|
||||
this.func = null;
|
||||
|
||||
this.onFullchange = function (func) {
|
||||
this.func = func;
|
||||
var evts = [
|
||||
"fullscreenchange",
|
||||
"webkitfullscreenchange",
|
||||
"mozfullscreenchange",
|
||||
"MSFullscreenChange",
|
||||
];
|
||||
for (var i = 0; i < evts.length && func; i++) {
|
||||
window.addEventListener(evts[i], this.func);
|
||||
}
|
||||
};
|
||||
|
||||
this.fullScreen = function (dom) {
|
||||
var docElm =
|
||||
(dom && document.querySelector(dom)) || document.documentElement;
|
||||
if (docElm.requestFullscreen) {
|
||||
docElm.requestFullscreen();
|
||||
} else if (docElm.mozRequestFullScreen) {
|
||||
docElm.mozRequestFullScreen();
|
||||
} else if (docElm.webkitRequestFullScreen) {
|
||||
docElm.webkitRequestFullScreen();
|
||||
} else if (docElm.msRequestFullscreen) {
|
||||
docElm.msRequestFullscreen();
|
||||
} else {
|
||||
defer.reject("");
|
||||
}
|
||||
defer.resolve("返回值");
|
||||
return defer.promise();
|
||||
};
|
||||
|
||||
this.fullClose = function () {
|
||||
if (this.isFullscreen()) {
|
||||
if (document.exitFullscreen) {
|
||||
document.exitFullscreen();
|
||||
} else if (document.mozCancelFullScreen) {
|
||||
document.mozCancelFullScreen();
|
||||
} else if (document.webkitCancelFullScreen) {
|
||||
document.webkitCancelFullScreen();
|
||||
} else if (document.msExitFullscreen) {
|
||||
document.msExitFullscreen();
|
||||
}
|
||||
}
|
||||
defer.resolve("返回值");
|
||||
return defer.promise();
|
||||
};
|
||||
|
||||
this.isFullscreen = function () {
|
||||
return (
|
||||
document.fullscreenElement ||
|
||||
document.msFullscreenElement ||
|
||||
document.mozFullScreenElement ||
|
||||
document.webkitFullscreenElement ||
|
||||
false
|
||||
);
|
||||
};
|
||||
})();
|
||||
exports("fullscreen", fullScreen);
|
||||
});
|
||||
@@ -0,0 +1,834 @@
|
||||
layui.define(["table", "jquery", "element"], function (exports) {
|
||||
"use strict";
|
||||
|
||||
var MOD_NAME = "menu",
|
||||
$ = layui.jquery,
|
||||
element = layui.element;
|
||||
|
||||
var menu = function (opt) {
|
||||
this.option = opt;
|
||||
};
|
||||
|
||||
menu.prototype.render = function (opt) {
|
||||
var option = {
|
||||
elem: opt.elem,
|
||||
async: opt.async || true,
|
||||
parseData: opt.parseData,
|
||||
url: opt.url,
|
||||
method: opt.method ? opt.method : "GET",
|
||||
defaultOpen: opt.defaultOpen,
|
||||
defaultSelect: opt.defaultSelect,
|
||||
control: opt.control,
|
||||
controlWidth: opt.controlWidth ? opt.controlWidth : "auto",
|
||||
defaultMenu: opt.defaultMenu || 0,
|
||||
accordion: opt.accordion,
|
||||
height: opt.height || "100%",
|
||||
theme: opt.theme || "dark-theme",
|
||||
data: opt.data ? opt.data : [],
|
||||
change: opt.change ? opt.change : function () {},
|
||||
done: opt.done ? opt.done : function () {},
|
||||
};
|
||||
|
||||
var tempDone = option.done;
|
||||
|
||||
option.done = function () {
|
||||
if (option.control) {
|
||||
rationalizeHeaderControlWidthAuto(option);
|
||||
}
|
||||
tempDone();
|
||||
};
|
||||
|
||||
if (option.async) {
|
||||
if (option.method === "GET") {
|
||||
getData(option.url).then(function (data) {
|
||||
option.data = data;
|
||||
renderMenu(option);
|
||||
});
|
||||
} else {
|
||||
postData(option.url).then(function (data) {
|
||||
option.data = data;
|
||||
renderMenu(option);
|
||||
});
|
||||
}
|
||||
} else {
|
||||
window.setTimeout(function () {
|
||||
renderMenu(option);
|
||||
}, 500);
|
||||
}
|
||||
|
||||
$("#" + opt.elem).height(option.height);
|
||||
|
||||
setTimeout(function () {
|
||||
$("#" + opt.control + " .control").on(
|
||||
"mousewheel DOMMouseScroll",
|
||||
function (event) {
|
||||
var delta =
|
||||
(event.originalEvent.wheelDelta &&
|
||||
(event.originalEvent.wheelDelta > 0 ? 1 : -1)) || // chrome & ie
|
||||
(event.originalEvent.detail &&
|
||||
(event.originalEvent.detail > 0 ? -1 : 1)); // firefox
|
||||
|
||||
if (delta > 0) {
|
||||
for (var num = 1; num < 20; num++) {
|
||||
setTimeout(function () {
|
||||
if (
|
||||
$("#" + opt.control + " .control ul")
|
||||
.css("left")
|
||||
.replace("px", "") < 0
|
||||
) {
|
||||
$("#" + opt.control + " .control ul").css("left", "+=2px");
|
||||
}
|
||||
}, 10);
|
||||
}
|
||||
} else if (delta < 0) {
|
||||
if (
|
||||
Number(
|
||||
$("#" + opt.control + " .control ul")
|
||||
.css("left")
|
||||
.replace("px", ""),
|
||||
) +
|
||||
($("#" + opt.control + " .control ul").width() -
|
||||
$("#" + opt.control + " .control").width()) >
|
||||
0
|
||||
) {
|
||||
for (var num = 1; num < 20; num++) {
|
||||
setTimeout(function () {
|
||||
$("#" + opt.control + " .control ul").css("left", "-=2px");
|
||||
}, 10);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
}, 1000);
|
||||
|
||||
return new menu(option);
|
||||
};
|
||||
|
||||
menu.prototype.cache = function () {
|
||||
return this.option.data;
|
||||
};
|
||||
|
||||
menu.prototype.click = function (clickEvent) {
|
||||
var _this = this;
|
||||
$("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"),
|
||||
menuType: dom.attr("menu-type"),
|
||||
menuOpenType: dom.attr("menu-open-type"),
|
||||
};
|
||||
var doms = hash(dom);
|
||||
if (doms != null) {
|
||||
if (doms.text() != "") {
|
||||
data["menuPath"] =
|
||||
doms.find("span").text() + " / " + data["menuPath"];
|
||||
}
|
||||
}
|
||||
if (doms != null) {
|
||||
var domss = hash(doms);
|
||||
if (domss != null) {
|
||||
if (domss.text() != "") {
|
||||
data["menuPath"] =
|
||||
domss.find("span").text() + " / " + data["menuPath"];
|
||||
}
|
||||
}
|
||||
}
|
||||
if (domss != null) {
|
||||
var domsss = hash(domss);
|
||||
if (domsss != null) {
|
||||
if (domsss.text() != "") {
|
||||
data["menuPath"] =
|
||||
domsss.find("span").text() + " / " + data["menuPath"];
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($("#" + _this.option.elem).is(".pear-nav-mini")) {
|
||||
if (_this.option.accordion) {
|
||||
activeMenus = $(this).parent().parent().parent().children("a");
|
||||
} else {
|
||||
activeMenus.push($(this).parent().parent().parent().children("a"));
|
||||
}
|
||||
}
|
||||
clickEvent(dom, data);
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
function hash(dom) {
|
||||
var d = dom.parent().parent().prev();
|
||||
if (d.prop("tagName") === "UL") {
|
||||
return null;
|
||||
}
|
||||
return d;
|
||||
}
|
||||
|
||||
menu.prototype.skin = function (skin) {
|
||||
var menu = $(
|
||||
".pear-nav-tree[lay-filter='" + this.option.elem + "']",
|
||||
).parent();
|
||||
menu.removeClass("dark-theme");
|
||||
menu.removeClass("light-theme");
|
||||
menu.addClass(skin);
|
||||
};
|
||||
|
||||
menu.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",
|
||||
});
|
||||
$("#" + this.option.elem + " a[menu-id='" + pearId + "']")
|
||||
.parents(".layui-side-scroll ")
|
||||
.find(".layui-this")
|
||||
.removeClass("layui-this");
|
||||
$("#" + this.option.elem + " a[menu-id='" + pearId + "']")
|
||||
.parents("ul")
|
||||
.css({
|
||||
display: "block",
|
||||
});
|
||||
var controlId = $("#" + this.option.elem + " a[menu-id='" + pearId + "']")
|
||||
.parents("ul")
|
||||
.attr("pear-id");
|
||||
if (controlId != undefined) {
|
||||
$("#" + this.option.control)
|
||||
.find(".layui-this")
|
||||
.removeClass("layui-this");
|
||||
$("#" + this.option.control)
|
||||
.find("[pear-id='" + controlId + "']")
|
||||
.addClass("layui-this");
|
||||
}
|
||||
}
|
||||
|
||||
$("#" + this.option.elem + " a[menu-id='" + pearId + "']")
|
||||
.parents(".pear-nav-tree")
|
||||
.find(".layui-this")
|
||||
.removeClass("layui-this");
|
||||
if (!$("#" + this.option.elem).is(".pear-nav-mini")) {
|
||||
var openEle = null;
|
||||
var openEleHeight = 0;
|
||||
$(
|
||||
$("#" + this.option.elem + " a[menu-id='" + pearId + "']")
|
||||
.parents(".layui-nav-child")
|
||||
.get()
|
||||
.reverse(),
|
||||
).each(function () {
|
||||
if (!$(this).parent().is(".layui-nav-itemed")) {
|
||||
if (openEleHeight == 0) {
|
||||
openEle = $(this);
|
||||
} else {
|
||||
$(this).parent().addClass("layui-nav-itemed");
|
||||
$(this).css({
|
||||
height: "auto",
|
||||
});
|
||||
}
|
||||
openEleHeight += $(this).children("dd").length * 48;
|
||||
}
|
||||
});
|
||||
if (this.option.accordion) {
|
||||
if (openEleHeight > 0) {
|
||||
var currentDom = openEle
|
||||
.parent()
|
||||
.siblings(".layui-nav-itemed")
|
||||
.children(".layui-nav-child");
|
||||
currentDom.animate(
|
||||
{
|
||||
height: "0px",
|
||||
},
|
||||
240,
|
||||
function () {
|
||||
currentDom.css({
|
||||
height: "auto",
|
||||
});
|
||||
$(this).parent().removeClass("layui-nav-itemed");
|
||||
$(this).find(".layui-nav-itemed").removeClass("layui-nav-itemed");
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
if (openEleHeight > 0) {
|
||||
openEle.parent().addClass("layui-nav-itemed");
|
||||
openEle.height(0);
|
||||
openEle.animate(
|
||||
{
|
||||
height: openEleHeight + "px",
|
||||
},
|
||||
240,
|
||||
function () {
|
||||
$(this).css({ height: "auto" });
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
$("#" + this.option.elem + " a[menu-id='" + pearId + "']")
|
||||
.parent()
|
||||
.addClass("layui-this");
|
||||
};
|
||||
|
||||
var activeMenus;
|
||||
menu.prototype.collapse = function (time) {
|
||||
var elem = this.option.elem;
|
||||
var config = this.option;
|
||||
if ($("#" + this.option.elem).is(".pear-nav-mini")) {
|
||||
$.each(activeMenus, function (i, item) {
|
||||
$("#" + elem + " a[menu-id='" + $(this).attr("menu-id") + "']")
|
||||
.parent()
|
||||
.addClass("layui-nav-itemed");
|
||||
});
|
||||
$("#" + this.option.elem).removeClass("pear-nav-mini");
|
||||
$("#" + this.option.elem).animate(
|
||||
{
|
||||
width: "220px",
|
||||
},
|
||||
180,
|
||||
);
|
||||
isHoverMenu(false, config);
|
||||
var that = this;
|
||||
$("#" + this.option.elem)
|
||||
.promise()
|
||||
.done(function () {
|
||||
if (that.option.control) {
|
||||
rationalizeHeaderControlWidth(that.option);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
activeMenus = $("#" + this.option.elem).find(".layui-nav-itemed>a");
|
||||
$("#" + this.option.elem)
|
||||
.find(".layui-nav-itemed")
|
||||
.removeClass("layui-nav-itemed");
|
||||
$("#" + this.option.elem).addClass("pear-nav-mini");
|
||||
$("#" + this.option.elem).animate(
|
||||
{
|
||||
width: "60px",
|
||||
},
|
||||
400,
|
||||
);
|
||||
var that = this;
|
||||
$("#" + this.option.elem)
|
||||
.promise()
|
||||
.done(function () {
|
||||
isHoverMenu(true, config);
|
||||
if (that.option.control) {
|
||||
rationalizeHeaderControlWidth(that.option);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
function getData(url) {
|
||||
var defer = $.Deferred();
|
||||
var symbol = url.indexOf("?") !== -1 ? "&" : "?";
|
||||
$.get(url + symbol + "fresh=" + Math.random(), function (result) {
|
||||
defer.resolve(result);
|
||||
});
|
||||
return defer.promise();
|
||||
}
|
||||
|
||||
function postData(url) {
|
||||
var defer = $.Deferred();
|
||||
var symbol = url.indexOf("?") !== -1 ? "&" : "?";
|
||||
$.post(
|
||||
url + symbol + "fresh=" + Math.random(),
|
||||
function (result) {
|
||||
defer.resolve(result);
|
||||
},
|
||||
"json",
|
||||
);
|
||||
return defer.promise();
|
||||
}
|
||||
|
||||
function renderMenu(option) {
|
||||
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();
|
||||
}
|
||||
|
||||
function createMenu(option) {
|
||||
var menuHtml =
|
||||
'<div style="height:100%!important;" class="pear-side-scroll layui-side-scroll ' +
|
||||
option.theme +
|
||||
'"><ul lay-filter="' +
|
||||
option.elem +
|
||||
'" class="layui-nav arrow pear-menu layui-nav-tree pear-nav-tree">';
|
||||
$.each(option.data, function (i, item) {
|
||||
var content = '<li class="layui-nav-item" >';
|
||||
if (i == option.defaultOpen) {
|
||||
content = '<li class="layui-nav-item layui-nav-itemed" >';
|
||||
}
|
||||
var href = "javascript:;";
|
||||
var target = "";
|
||||
var className = "site-demo-active";
|
||||
if (item.openType == "_blank" && item.type == 1) {
|
||||
href = item.href;
|
||||
target = "target='_blank'";
|
||||
className = "";
|
||||
}
|
||||
if (item.type == 0) {
|
||||
// 创 建 目 录 结 构
|
||||
content +=
|
||||
'<a href="javascript:;" menu-type="' +
|
||||
item.type +
|
||||
'" menu-id="' +
|
||||
item.id +
|
||||
'" href="' +
|
||||
href +
|
||||
'" ' +
|
||||
target +
|
||||
'><i class="' +
|
||||
item.icon +
|
||||
'"></i><span>' +
|
||||
item.title +
|
||||
"</span></a>";
|
||||
} else if (item.type == 1) {
|
||||
content +=
|
||||
'<a class="' +
|
||||
className +
|
||||
'" menu-type="' +
|
||||
item.type +
|
||||
'" menu-open-type="' +
|
||||
item.openType +
|
||||
'" menu-url="' +
|
||||
item.href +
|
||||
'" menu-id="' +
|
||||
item.id +
|
||||
'" menu-title="' +
|
||||
item.title +
|
||||
'" href="' +
|
||||
href +
|
||||
'" ' +
|
||||
target +
|
||||
'><i class="' +
|
||||
item.icon +
|
||||
'"></i><span>' +
|
||||
item.title +
|
||||
"</span></a>";
|
||||
}
|
||||
// 调 用 递 归 方 法 加 载 无 限 层 级 的 子 菜 单
|
||||
content += loadchild(item);
|
||||
// 结 束 一 个 根 菜 单 项
|
||||
content += "</li>";
|
||||
menuHtml += content;
|
||||
});
|
||||
// 结 束 菜 单 结 构 的 初 始 化
|
||||
menuHtml += "</ul></div>";
|
||||
// 将 菜 单 拼 接 到 初 始 化 容 器 中
|
||||
$("#" + option.elem).html(menuHtml);
|
||||
}
|
||||
|
||||
function createMenuAndControl(option) {
|
||||
var control =
|
||||
'<div style="width: ' +
|
||||
option.controlWidth +
|
||||
'px;white-space: nowrap;overflow-x: scroll;overflow: hidden;" class="control"><ul class="layui-nav pear-nav-control pc layui-hide-xs" style="width: fit-content;">';
|
||||
var controlPe = '<ul class="layui-nav pear-nav-control layui-hide-sm">';
|
||||
// 声 明 头 部
|
||||
var menu = '<div class="layui-side-scroll ' + option.theme + '">';
|
||||
// 开 启 同 步 操 作
|
||||
var index = 0;
|
||||
var controlItemPe = '<dl class="layui-nav-child">';
|
||||
$.each(option.data, function (i, item) {
|
||||
var menuItem = "";
|
||||
var controlItem = "";
|
||||
if (i === option.defaultMenu) {
|
||||
controlItem =
|
||||
'<li pear-href="' +
|
||||
item.href +
|
||||
'" pear-title="' +
|
||||
item.title +
|
||||
'" pear-id="' +
|
||||
item.id +
|
||||
'" class="layui-this layui-nav-item"><a href="#">' +
|
||||
item.title +
|
||||
"</a></li>";
|
||||
menuItem =
|
||||
'<ul pear-id="' +
|
||||
item.id +
|
||||
'" lay-filter="' +
|
||||
option.elem +
|
||||
'" class="layui-nav arrow layui-nav-tree pear-nav-tree">';
|
||||
|
||||
controlPe +=
|
||||
'<li class="layui-nav-item"><a class="pe-title" href="javascript:;" >' +
|
||||
item.title +
|
||||
"</a>";
|
||||
|
||||
controlItemPe +=
|
||||
'<dd pear-href="' +
|
||||
item.href +
|
||||
'" pear-title="' +
|
||||
item.title +
|
||||
'" pear-id="' +
|
||||
item.id +
|
||||
'"><a href="javascript:void(0);">' +
|
||||
item.title +
|
||||
"</a></dd>";
|
||||
} else {
|
||||
controlItem =
|
||||
'<li pear-href="' +
|
||||
item.href +
|
||||
'" pear-title="' +
|
||||
item.title +
|
||||
'" pear-id="' +
|
||||
item.id +
|
||||
'" class="layui-nav-item"><a href="#">' +
|
||||
item.title +
|
||||
"</a></li>";
|
||||
|
||||
menuItem =
|
||||
'<ul style="display:none" pear-id="' +
|
||||
item.id +
|
||||
'" lay-filter="' +
|
||||
option.elem +
|
||||
'" class="layui-nav arrow layui-nav-tree pear-nav-tree">';
|
||||
|
||||
controlItemPe +=
|
||||
'<dd pear-href="' +
|
||||
item.href +
|
||||
'" pear-title="' +
|
||||
item.title +
|
||||
'" pear-id="' +
|
||||
item.id +
|
||||
'"><a href="javascript:void(0);">' +
|
||||
item.title +
|
||||
"</a></dd>";
|
||||
}
|
||||
index++;
|
||||
$.each(item.children, function (i, note) {
|
||||
// 创 建 每 一 个 菜 单 项
|
||||
var content = '<li class="layui-nav-item" >';
|
||||
var href = "javascript:;";
|
||||
var target = "";
|
||||
var className = "site-demo-active";
|
||||
if (note.openType == "_blank" && note.type == 1) {
|
||||
href = note.href;
|
||||
target = "target='_blank'";
|
||||
className = "";
|
||||
}
|
||||
// 判 断 菜 单 类 型 0 是 不可跳转的目录 1 是 可 点 击 跳 转 的 菜 单
|
||||
if (note.type == 0) {
|
||||
// 创 建 目 录 结 构
|
||||
content +=
|
||||
'<a href="' +
|
||||
href +
|
||||
'" ' +
|
||||
target +
|
||||
' menu-type="' +
|
||||
note.type +
|
||||
'" menu-id="' +
|
||||
note.id +
|
||||
'" ><i class="' +
|
||||
note.icon +
|
||||
'"></i><span>' +
|
||||
note.title +
|
||||
"</span></a>";
|
||||
} else if (note.type == 1) {
|
||||
// 创 建 菜 单 结 构
|
||||
content +=
|
||||
"<a " +
|
||||
target +
|
||||
' class="' +
|
||||
className +
|
||||
'" menu-open-type="' +
|
||||
note.openType +
|
||||
'" menu-type="' +
|
||||
note.type +
|
||||
'" menu-url="' +
|
||||
note.href +
|
||||
'" menu-id="' +
|
||||
note.id +
|
||||
'" menu-title="' +
|
||||
note.title +
|
||||
'" href="' +
|
||||
href +
|
||||
'"><i class="' +
|
||||
note.icon +
|
||||
'"></i><span>' +
|
||||
note.title +
|
||||
"</span></a>";
|
||||
}
|
||||
content += loadchild(note);
|
||||
content += "</li>";
|
||||
menuItem += content;
|
||||
});
|
||||
menu += menuItem + "</ul>";
|
||||
control += controlItem;
|
||||
});
|
||||
controlItemPe += "</li></dl></ul>";
|
||||
controlPe += controlItemPe;
|
||||
$("#" + option.control).html(control + "</div>");
|
||||
$("#" + option.control).append(controlPe);
|
||||
$("#" + option.elem).html(menu);
|
||||
$("#" + option.control + " .pear-nav-control").on(
|
||||
"click",
|
||||
"[pear-id]",
|
||||
function () {
|
||||
$("#" + option.elem)
|
||||
.find(".pear-nav-tree")
|
||||
.css({
|
||||
display: "none",
|
||||
});
|
||||
$("#" + option.elem)
|
||||
.find(".pear-nav-tree[pear-id='" + $(this).attr("pear-id") + "']")
|
||||
.css({
|
||||
display: "block",
|
||||
});
|
||||
$("#" + option.control)
|
||||
.find(".pe-title")
|
||||
.html($(this).attr("pear-title"));
|
||||
$("#" + option.control).find("");
|
||||
option.change(
|
||||
$(this).attr("pear-id"),
|
||||
$(this).attr("pear-title"),
|
||||
$(this).attr("pear-href"),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
/** 加载子菜单 (递归)*/
|
||||
function loadchild(obj) {
|
||||
// 判 单 是 否 是 菜 单, 如 果 是 菜 单 直 接 返 回
|
||||
if (obj.type == 1) {
|
||||
return "";
|
||||
}
|
||||
// 创 建 子 菜 单 结 构
|
||||
var content = '<dl class="layui-nav-child">';
|
||||
// 如 果 嵌 套 不 等 于 空
|
||||
if (obj.children != null && obj.children.length > 0) {
|
||||
// 遍 历 子 项 目
|
||||
$.each(obj.children, function (i, note) {
|
||||
// 创 建 子 项 结 构
|
||||
content += "<dd>";
|
||||
var href = "javascript:;";
|
||||
var target = "";
|
||||
var className = "site-demo-active";
|
||||
if (note.openType == "_blank" && note.type == 1) {
|
||||
href = note.href;
|
||||
target = "target='_blank'";
|
||||
className = "";
|
||||
}
|
||||
// 判 断 子 项 类 型
|
||||
if (note.type == 0) {
|
||||
// 创 建 目 录 结 构
|
||||
content +=
|
||||
"<a " +
|
||||
target +
|
||||
' href="' +
|
||||
href +
|
||||
'" menu-type="' +
|
||||
note.type +
|
||||
'" menu-id="' +
|
||||
note.id +
|
||||
'"><i class="' +
|
||||
note.icon +
|
||||
'"></i><span>' +
|
||||
note.title +
|
||||
"</span></a>";
|
||||
} else if (note.type == 1) {
|
||||
// 创 建 菜 单 结 构
|
||||
content +=
|
||||
"<a " +
|
||||
target +
|
||||
' class="' +
|
||||
className +
|
||||
'" menu-open-type="' +
|
||||
note.openType +
|
||||
'" menu-type="' +
|
||||
note.type +
|
||||
'" menu-url="' +
|
||||
note.href +
|
||||
'" menu-id="' +
|
||||
note.id +
|
||||
'" menu-title="' +
|
||||
note.title +
|
||||
'" menu-icon="' +
|
||||
note.icon +
|
||||
'" href="' +
|
||||
href +
|
||||
'" ><i class="' +
|
||||
note.icon +
|
||||
'"></i><span>' +
|
||||
note.title +
|
||||
"</span></a>";
|
||||
}
|
||||
// 加 载 子 项 目 录
|
||||
content += loadchild(note);
|
||||
// 结 束 当 前 子 菜 单
|
||||
content += "</dd>";
|
||||
});
|
||||
// 封 装
|
||||
} else {
|
||||
content +=
|
||||
'<dd style="background-color: transparent!important;"><a style="background-color: transparent!important;margin-left: 26px">目录为空</a></dd>';
|
||||
}
|
||||
content += "</dl>";
|
||||
return content;
|
||||
}
|
||||
|
||||
function downShow(option) {
|
||||
$("body #" + option.elem).on("click", "a[menu-type='0']", function () {
|
||||
if (!$("#" + option.elem).is(".pear-nav-mini")) {
|
||||
var superEle = $(this).parent();
|
||||
var ele = $(this).next(".layui-nav-child");
|
||||
var heights = ele.children("dd").length * 48;
|
||||
|
||||
if ($(this).parent().is(".layui-nav-itemed")) {
|
||||
if (option.accordion) {
|
||||
var currentDom = $(this)
|
||||
.parent()
|
||||
.siblings(".layui-nav-itemed")
|
||||
.children(".layui-nav-child");
|
||||
currentDom.animate(
|
||||
{
|
||||
height: "0px",
|
||||
},
|
||||
240,
|
||||
function () {
|
||||
currentDom.css({
|
||||
height: "auto",
|
||||
});
|
||||
$(this).parent().removeClass("layui-nav-itemed");
|
||||
$(this)
|
||||
.find(".layui-nav-itemed")
|
||||
.removeClass("layui-nav-itemed");
|
||||
},
|
||||
);
|
||||
}
|
||||
ele.height(0);
|
||||
ele.animate(
|
||||
{
|
||||
height: heights + "px",
|
||||
},
|
||||
240,
|
||||
function () {
|
||||
ele.css({
|
||||
height: "auto",
|
||||
});
|
||||
},
|
||||
);
|
||||
} else {
|
||||
$(this).parent().addClass("layui-nav-itemed");
|
||||
ele.animate(
|
||||
{
|
||||
height: "0px",
|
||||
},
|
||||
240,
|
||||
function () {
|
||||
ele.css({
|
||||
height: "auto",
|
||||
});
|
||||
$(this).parent().removeClass("layui-nav-itemed");
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/** 二 级 悬 浮 菜 单*/
|
||||
function isHoverMenu(b, option) {
|
||||
if (b) {
|
||||
var navItem = "#" + option.elem + ".pear-nav-mini .layui-nav-item";
|
||||
var navChildDl = navItem + " .layui-nav-child>dl";
|
||||
var navChildDd = navItem + " .layui-nav-child>dd";
|
||||
|
||||
$(navItem + "," + navChildDd).mouseenter(function () {
|
||||
var _this = $(this);
|
||||
_this
|
||||
.siblings()
|
||||
.find(".layui-nav-child")
|
||||
.removeClass("layui-nav-hover")
|
||||
.css({
|
||||
left: 0,
|
||||
top: 0,
|
||||
});
|
||||
_this.children(".layui-nav-child").addClass("layui-nav-hover");
|
||||
var height = $(window).height();
|
||||
var topLength = _this.offset().top;
|
||||
var thisHeight = _this.children(".layui-nav-child").height();
|
||||
if (thisHeight + topLength > height) {
|
||||
topLength = height - thisHeight - 10;
|
||||
}
|
||||
var left = _this.offset().left + 60;
|
||||
if (!_this.hasClass("layui-nav-item")) {
|
||||
left = _this.offset().left + _this.width();
|
||||
}
|
||||
_this.children(".layui-nav-child").offset({
|
||||
top: topLength,
|
||||
left: left,
|
||||
});
|
||||
});
|
||||
|
||||
$(navItem + "," + navChildDl).mouseleave(function () {
|
||||
var _this = $(this);
|
||||
_this
|
||||
.closest(".layui-nav-item")
|
||||
.find(".layui-nav-child")
|
||||
.removeClass("layui-nav-hover")
|
||||
.css({
|
||||
left: 0,
|
||||
top: 0,
|
||||
});
|
||||
});
|
||||
} else {
|
||||
$("#" + option.elem + " .layui-nav-item")
|
||||
.off("mouseenter")
|
||||
.unbind("mouseleave");
|
||||
$("#" + option.elem + " dd")
|
||||
.off("mouseenter")
|
||||
.unbind("mouseleave");
|
||||
}
|
||||
}
|
||||
|
||||
function rationalizeHeaderControlWidth(option) {
|
||||
var $headerControl = $("#" + option.control);
|
||||
var $nextEl = $headerControl.next();
|
||||
var rationalizeWidth;
|
||||
if ($nextEl.length) {
|
||||
rationalizeWidth =
|
||||
$nextEl.position().left - $headerControl.position().left;
|
||||
} else {
|
||||
rationalizeWidth =
|
||||
$headerControl.parent().innerWidth() - $headerControl.position().left;
|
||||
}
|
||||
|
||||
if (option.controlWidth && rationalizeWidth >= option.controlWidth) {
|
||||
rationalizeWidth = option.controlWidth;
|
||||
}
|
||||
$("#" + option.control + " .control").css({
|
||||
width: rationalizeWidth,
|
||||
transition: "width .15s",
|
||||
});
|
||||
}
|
||||
|
||||
function rationalizeHeaderControlWidthAuto(option) {
|
||||
$(window).on("resize", function () {
|
||||
rationalizeHeaderControlWidth(option);
|
||||
});
|
||||
|
||||
$(document).ready(function () {
|
||||
rationalizeHeaderControlWidth(option);
|
||||
});
|
||||
}
|
||||
|
||||
exports(MOD_NAME, new menu());
|
||||
});
|
||||
@@ -0,0 +1,241 @@
|
||||
layui.define(["jquery", "tools"], function (exports) {
|
||||
"use strict";
|
||||
|
||||
/**
|
||||
* @since Pear Admin 4.0
|
||||
*
|
||||
* Button component
|
||||
* */
|
||||
var MOD_NAME = "menuSearch",
|
||||
tools = layui.tools,
|
||||
$ = layui.jquery;
|
||||
|
||||
var menuSearch = function (opt) {
|
||||
this.option = opt;
|
||||
};
|
||||
|
||||
/**
|
||||
* @since Pear Admin 4.0
|
||||
*
|
||||
* Button start loading
|
||||
* */
|
||||
menuSearch.prototype.render = function (opt) {
|
||||
var options = {
|
||||
select: opt.select,
|
||||
elem: opt.elem,
|
||||
dataProvider: opt.dataProvider,
|
||||
};
|
||||
|
||||
$("body").on("click", options.elem, function () {
|
||||
var _html = [
|
||||
`<div class="menu-search-content">
|
||||
<div class="layui-form menu-search-input-wrapper">
|
||||
<div class=" layui-input-wrap layui-input-wrap-prefix">
|
||||
<div class="layui-input-prefix">
|
||||
<i class="layui-icon layui-icon-search"></i>
|
||||
</div>
|
||||
<input type="text" name="menuSearch" value="" placeholder="搜索菜单" autocomplete="off" class="layui-input" lay-affix="clear">
|
||||
</div>
|
||||
</div>
|
||||
<div class="menu-search-no-data">暂 无 信 息</div>
|
||||
<ul class="menu-search-list">
|
||||
</ul>
|
||||
<div class="menu-search-tips">
|
||||
<div>
|
||||
<span class="mr-1">选择</span><kbd class="mr-1 w-5"> ↑ </kbd><kbd class="mr-5 w-5"> ↓ </kbd>
|
||||
<span class="mr-1">确定</span><kbd class="mr-5"> Enter </kbd><span class="mr-1">关闭</span><kbd class="mr-1"> Esc </kbd>
|
||||
</div>
|
||||
</div>
|
||||
</div>`,
|
||||
].join("");
|
||||
|
||||
layer.open({
|
||||
type: 1,
|
||||
offset: "10%",
|
||||
area: ["600px"],
|
||||
title: false,
|
||||
closeBtn: 0,
|
||||
shadeClose: true,
|
||||
anim: 0,
|
||||
move: false,
|
||||
content: _html,
|
||||
success: function (layero, layeridx) {
|
||||
var $layer = layero;
|
||||
var $content = $(layero).children(".layui-layer-content");
|
||||
var $input = $(".menu-search-input-wrapper input");
|
||||
var $noData = $(".menu-search-no-data");
|
||||
var $list = $(".menu-search-list");
|
||||
var menuData = options.dataProvider();
|
||||
|
||||
$layer.css("border-radius", "6px");
|
||||
$input.off("focus").focus();
|
||||
|
||||
// 搜索输入事件
|
||||
$input.off("input").on(
|
||||
"input",
|
||||
tools.debounce(function () {
|
||||
var keywords = $input.val().trim();
|
||||
var filteredMenus = filterHandle(menuData, keywords);
|
||||
|
||||
if (filteredMenus.length) {
|
||||
var tiledMenus = tiledHandle(filteredMenus);
|
||||
var listHtml = createList(tiledMenus);
|
||||
$noData.css("display", "none");
|
||||
$list
|
||||
.html("")
|
||||
.append(listHtml)
|
||||
.children(":first")
|
||||
.addClass("this");
|
||||
} else {
|
||||
$list.html("");
|
||||
$noData.css("display", "flex");
|
||||
}
|
||||
var currentHeight = $(".menu-search-content").outerHeight();
|
||||
$layer.css("height", currentHeight);
|
||||
$content.css("height", currentHeight);
|
||||
}, 500),
|
||||
);
|
||||
|
||||
// 列表点击事件
|
||||
$list.off("click").on("click", "li", function () {
|
||||
var id = $(this).attr("smenu-id");
|
||||
var title = $(this).attr("smenu-title");
|
||||
var url = $(this).attr("smenu-url");
|
||||
var type = $(this).attr("smenu-type");
|
||||
var openType = $(this).attr("smenu-open-type");
|
||||
|
||||
options.select({ id, title, url, type, openType });
|
||||
|
||||
layer.close(layeridx);
|
||||
});
|
||||
|
||||
$list
|
||||
.off("mouseenter")
|
||||
.on("mouseenter", "li", function () {
|
||||
$(".menu-search-list li.this").removeClass("this");
|
||||
$(this).addClass("this");
|
||||
})
|
||||
.off("mouseleave")
|
||||
.on("mouseleave", "li", function () {
|
||||
$(this).removeClass("this");
|
||||
});
|
||||
|
||||
// 监听键盘事件
|
||||
$(document)
|
||||
.off("keydown")
|
||||
.keydown(function (e) {
|
||||
if (e.keyCode === 13 || e.keyCode === 32) {
|
||||
e.preventDefault();
|
||||
var id = $(this).attr("smenu-id");
|
||||
var title = $(this).attr("smenu-title");
|
||||
var url = $(this).attr("smenu-url");
|
||||
var type = $(this).attr("smenu-type");
|
||||
var openType = $(this).attr("smenu-open-type");
|
||||
|
||||
options.select({ id, title, url, type, openType });
|
||||
|
||||
layer.close(layeridx);
|
||||
} else if (e.keyCode === 38) {
|
||||
e.preventDefault();
|
||||
var prevEl = $(".menu-search-list li.this").prev();
|
||||
$(".menu-search-list li.this").removeClass("this");
|
||||
if (prevEl.length !== 0) {
|
||||
prevEl.addClass("this");
|
||||
} else {
|
||||
$list.children().last().addClass("this");
|
||||
}
|
||||
} else if (e.keyCode === 40) {
|
||||
e.preventDefault();
|
||||
var nextEl = $(".menu-search-list li.this").next();
|
||||
$(".menu-search-list li.this").removeClass("this");
|
||||
if (nextEl.length !== 0) {
|
||||
nextEl.addClass("this");
|
||||
} else {
|
||||
$list.children().first().addClass("this");
|
||||
}
|
||||
} else if (e.keyCode === 27) {
|
||||
e.preventDefault();
|
||||
layer.close(layeridx);
|
||||
}
|
||||
});
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
return new menuSearch(options);
|
||||
};
|
||||
|
||||
/**
|
||||
* @since Pear Admin 4.0
|
||||
*
|
||||
* 创建结果列表
|
||||
*/
|
||||
var createList = function (data) {
|
||||
var listHtml = "";
|
||||
$.each(data, function (index, item) {
|
||||
listHtml += `<li smenu-open-type="${item.info.openType}" smenu-id="${item.info.id}" smenu-icon="'${item.info.icon}" smenu-url="${item.info.href}" smenu-title="${item.info.title}" smenu-type="${item.info.type}">
|
||||
<span><i style="margin-right:10px" class="${item.info.icon}"></i>${item.path}</span>
|
||||
<i class="layui-icon layui-icon-right"></i>
|
||||
</li>`;
|
||||
});
|
||||
return listHtml;
|
||||
};
|
||||
|
||||
/**
|
||||
* @since Pear Admin 4.0
|
||||
*
|
||||
* Tree 转 path 列表
|
||||
*/
|
||||
var tiledHandle = function (data) {
|
||||
var tiledMenus = [];
|
||||
var treeTiled = function (data, content) {
|
||||
var path = "";
|
||||
var 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);
|
||||
path += childPath;
|
||||
if (!childPath) path = ""; // 重置路径
|
||||
} else {
|
||||
path += content + item.title;
|
||||
tiledMenus.push({ path: path, info: item });
|
||||
path = ""; //重置路径
|
||||
}
|
||||
});
|
||||
return path;
|
||||
};
|
||||
treeTiled(data);
|
||||
|
||||
return tiledMenus;
|
||||
};
|
||||
|
||||
/**
|
||||
* @since Pear Admin 4.0
|
||||
*
|
||||
* 查询匹配算法
|
||||
*/
|
||||
var filterHandle = function (filterData, val) {
|
||||
if (!val) return [];
|
||||
var 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 });
|
||||
if (children && children.length) {
|
||||
filteredMenus.push(obj);
|
||||
} else if (item.title.indexOf(val) >= 0) {
|
||||
item.children = []; // 父级匹配但子级不匹配,就去除子级
|
||||
filteredMenus.push($.extend({}, item));
|
||||
}
|
||||
} else if (item.title.indexOf(val) >= 0) {
|
||||
filteredMenus.push(item);
|
||||
}
|
||||
});
|
||||
return filteredMenus;
|
||||
};
|
||||
|
||||
exports(MOD_NAME, new menuSearch());
|
||||
});
|
||||
@@ -0,0 +1,103 @@
|
||||
layui.define(["table", "jquery", "element", "dropdown"], function (exports) {
|
||||
"use strict";
|
||||
|
||||
var MOD_NAME = "messageCenter",
|
||||
$ = layui.jquery,
|
||||
dropdown = layui.dropdown;
|
||||
|
||||
var message = function (opt) {
|
||||
this.option = opt;
|
||||
};
|
||||
|
||||
message.prototype.render = function (opt) {
|
||||
var option = {
|
||||
elem: opt.elem,
|
||||
url: opt.url ? opt.url : false,
|
||||
height: opt.height,
|
||||
data: opt.data,
|
||||
};
|
||||
if (option.url != false) {
|
||||
$.get(option.url, function (result) {
|
||||
const { code, success, data } = result;
|
||||
$(`${opt.elem}`).append(`<li class="layui-nav-item" lay-unselect="">
|
||||
<a href="#" class="notice layui-icon layui-icon-notice"></a>
|
||||
</li>`);
|
||||
if (code == 200 || success) {
|
||||
option.data = data;
|
||||
dropdown.render({
|
||||
elem: option.elem,
|
||||
align: "center",
|
||||
content: createHtml(option),
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
return new message(option);
|
||||
};
|
||||
|
||||
message.prototype.click = function (callback) {
|
||||
$("*[notice-id]").click(function (event) {
|
||||
event.preventDefault();
|
||||
var id = $(this).attr("notice-id");
|
||||
var title = $(this).attr("notice-title");
|
||||
var context = $(this).attr("notice-context");
|
||||
var form = $(this).attr("notice-form");
|
||||
callback(id, title, context, form);
|
||||
});
|
||||
};
|
||||
|
||||
function createHtml(option) {
|
||||
var count = 0;
|
||||
var notice =
|
||||
'<div class="pear-message-center"><div class="layui-tab layui-tab-brief">';
|
||||
var noticeTitle = '<ul class="layui-tab-title">';
|
||||
var noticeContent =
|
||||
'<div class="layui-tab-content" style="height:' +
|
||||
option.height +
|
||||
';overflow-x: hidden;padding:0px;">';
|
||||
|
||||
$.each(option.data, function (i, item) {
|
||||
noticeTitle += `<li class="${i === 0 ? "layui-this" : ""}">${
|
||||
item.title
|
||||
}</li>`;
|
||||
noticeContent += '<div class="layui-tab-item layui-show">';
|
||||
|
||||
$.each(item.children, function (i, note) {
|
||||
count++;
|
||||
noticeContent +=
|
||||
'<div class="message-item" notice-form="' +
|
||||
note.form +
|
||||
'" notice-context="' +
|
||||
note.context +
|
||||
'" notice-title="' +
|
||||
note.title +
|
||||
'" notice-id="' +
|
||||
note.id +
|
||||
'">';
|
||||
|
||||
noticeContent +=
|
||||
'<img src="' +
|
||||
note.avatar +
|
||||
'"/><div style="display:inline-block;">' +
|
||||
note.title +
|
||||
"</div>" +
|
||||
'<div class="extra">' +
|
||||
note.time +
|
||||
"</div>" +
|
||||
"</div>";
|
||||
});
|
||||
|
||||
noticeContent += "</div>";
|
||||
});
|
||||
|
||||
noticeTitle += "</ul>";
|
||||
noticeContent += "</div>";
|
||||
notice += noticeTitle;
|
||||
notice += noticeContent;
|
||||
notice += "</div></div>";
|
||||
|
||||
return notice;
|
||||
}
|
||||
|
||||
exports(MOD_NAME, new message());
|
||||
});
|
||||
@@ -0,0 +1,138 @@
|
||||
layui.define(["jquery", "element"], function (exports) {
|
||||
"use strict";
|
||||
|
||||
var $ = layui.jquery;
|
||||
var element = layui.element;
|
||||
|
||||
var page = function (opt) {
|
||||
this.option = opt;
|
||||
};
|
||||
|
||||
/**
|
||||
* @since Pear Admin 4.0
|
||||
*
|
||||
* 创建 Page 页面
|
||||
*/
|
||||
page.prototype.render = function (opt) {
|
||||
var option = {
|
||||
elem: opt.elem,
|
||||
url: opt.url,
|
||||
width: opt.width || "100%",
|
||||
height: opt.height || "100%",
|
||||
title: opt.title,
|
||||
};
|
||||
renderContent(option);
|
||||
return new page(option);
|
||||
};
|
||||
|
||||
/**
|
||||
* @since Pear Admin 4.0
|
||||
*
|
||||
* 切换 Page 页面
|
||||
*/
|
||||
page.prototype.changePage = function (options) {
|
||||
const $frame = $(`#${this.option.elem} .pear-page-content`);
|
||||
|
||||
if (options.type === "_iframe") {
|
||||
$frame.html(
|
||||
`<iframe src='${options.href}' scrolling='auto' frameborder='0' allowfullscreen='true'></iframe>`,
|
||||
);
|
||||
} else {
|
||||
$.ajax({
|
||||
url: options.href,
|
||||
type: "get",
|
||||
dataType: "html",
|
||||
success: function (data) {
|
||||
$frame.html(data);
|
||||
},
|
||||
error: function (xhr) {
|
||||
return layer.msg(
|
||||
"Status:" + xhr.status + "," + xhr.statusText + ",请稍后再试!",
|
||||
);
|
||||
},
|
||||
});
|
||||
}
|
||||
$frame.attr("type", options.type);
|
||||
$frame.attr("href", options.href);
|
||||
};
|
||||
|
||||
page.prototype.refresh = function (loading) {
|
||||
var $frameLoad = $(`#${this.option.elem} .pear-page-loading`);
|
||||
var $frame = $(`#${this.option.elem} .pear-page-content`);
|
||||
|
||||
if (loading) {
|
||||
$frameLoad.css({
|
||||
display: "block",
|
||||
});
|
||||
}
|
||||
|
||||
if ($frame.attr("type") === "_iframe") {
|
||||
$frame.html(
|
||||
`<iframe src='${$frame.attr(
|
||||
"href",
|
||||
)}' scrolling='auto' frameborder='0' allowfullscreen='true'></iframe>`,
|
||||
);
|
||||
|
||||
const $contentFrame = $frame.find("iframe");
|
||||
|
||||
$contentFrame.on("load", () => {
|
||||
$frameLoad.fadeOut(1000);
|
||||
});
|
||||
} else {
|
||||
$.ajax({
|
||||
type: "get",
|
||||
url: $frame.attr("href"),
|
||||
dataType: "html",
|
||||
success: function (data) {
|
||||
$frame.html(data);
|
||||
$frameLoad.fadeOut(1000);
|
||||
element.init();
|
||||
},
|
||||
error: function (xhr) {
|
||||
return layer.msg(
|
||||
"Status:" + xhr.status + "," + xhr.statusText + ",请稍后再试!",
|
||||
);
|
||||
},
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
function renderContent(option) {
|
||||
$("#" + option.elem).html(`
|
||||
<div class='pear-page'>
|
||||
<div class='pear-page-content' type='${option.type}' href='${option.url}'></div>
|
||||
<div class="pear-page-loading">
|
||||
<div class="ball-loader">
|
||||
<span></span>
|
||||
<span></span>
|
||||
<span></span>
|
||||
<span></span>
|
||||
</div>
|
||||
</div>
|
||||
</div>`);
|
||||
|
||||
var $frame = $("#" + option.elem).find(".pear-page-content");
|
||||
|
||||
if (option.type === "_iframe") {
|
||||
$frame.html(
|
||||
`<iframe src='${option.url}' scrolling='auto' frameborder='0' allowfullscreen='true'></iframe>`,
|
||||
);
|
||||
} else {
|
||||
$.ajax({
|
||||
url: option.url,
|
||||
type: "get",
|
||||
dataType: "html",
|
||||
success: function (data) {
|
||||
$frame.html(data);
|
||||
},
|
||||
error: function (xhr) {
|
||||
return layer.msg(
|
||||
"Status:" + xhr.status + "," + xhr.statusText + ",请稍后再试!",
|
||||
);
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
exports("page", new page());
|
||||
});
|
||||
@@ -0,0 +1,797 @@
|
||||
layui.define(["jquery", "element", "dropdown"], function (exports) {
|
||||
"use strict";
|
||||
|
||||
var MOD_NAME = "tabPage",
|
||||
$ = layui.jquery,
|
||||
dropdown = layui.dropdown,
|
||||
element = layui.element;
|
||||
|
||||
var tabPage = function (opt) {
|
||||
this.option = opt;
|
||||
};
|
||||
|
||||
var tabData = new Array();
|
||||
var tabDataCurrent = 0;
|
||||
var contextTabDOM;
|
||||
|
||||
tabPage.prototype.render = function (opt) {
|
||||
var option = {
|
||||
elem: opt.elem,
|
||||
data: opt.data,
|
||||
index: opt.index,
|
||||
tool: opt.tool || true,
|
||||
roll: opt.roll || true,
|
||||
success: opt.success ? opt.success : function (id) {},
|
||||
session: opt.session ? opt.session : false,
|
||||
preload: opt.preload ? opt.preload : false,
|
||||
height: opt.height || "100%",
|
||||
width: opt.width || "100%",
|
||||
closeEvent: opt.closeEvent,
|
||||
tabMax: opt.tabMax,
|
||||
};
|
||||
|
||||
if (option.session) {
|
||||
if (sessionStorage.getItem(option.elem + "-pear-tab-page-data") != null) {
|
||||
tabData = JSON.parse(
|
||||
sessionStorage.getItem(option.elem + "-pear-tab-page-data"),
|
||||
);
|
||||
option.data = JSON.parse(
|
||||
sessionStorage.getItem(option.elem + "-pear-tab-page-data"),
|
||||
);
|
||||
tabDataCurrent = sessionStorage.getItem(
|
||||
option.elem + "-pear-tab-page-data-current",
|
||||
);
|
||||
tabData.forEach(function (item, index) {
|
||||
if (item.id == tabDataCurrent) {
|
||||
option.index = index;
|
||||
}
|
||||
});
|
||||
} else {
|
||||
tabData = opt.data;
|
||||
}
|
||||
}
|
||||
|
||||
var lastIndex;
|
||||
var tab = createTab(option);
|
||||
$("#" + option.elem).html(tab);
|
||||
$(".layui-tab[lay-filter='" + option.elem + "'] .layui-tab-prev").click(
|
||||
function () {
|
||||
rollPage("left", option);
|
||||
},
|
||||
);
|
||||
$(".layui-tab[lay-filter='" + option.elem + "'] .layui-tab-next").click(
|
||||
function () {
|
||||
rollPage("right", option);
|
||||
},
|
||||
);
|
||||
element.init();
|
||||
|
||||
$("#" + option.elem).width(opt.width);
|
||||
$("#" + option.elem).height(opt.height);
|
||||
$("#" + option.elem).css({
|
||||
position: "relative",
|
||||
});
|
||||
closeEvent(option);
|
||||
|
||||
option.success(
|
||||
sessionStorage.getItem(option.elem + "-pear-tab-page-data-current"),
|
||||
);
|
||||
|
||||
dropdown.render({
|
||||
elem: `#${option.elem} .layui-icon-down`,
|
||||
trigger: "hover",
|
||||
data: [
|
||||
{
|
||||
title: "关 闭 当 前",
|
||||
id: 1,
|
||||
},
|
||||
{
|
||||
title: "关 闭 其 他",
|
||||
id: 2,
|
||||
},
|
||||
{
|
||||
title: "关 闭 全 部",
|
||||
id: 3,
|
||||
},
|
||||
],
|
||||
click: function (obj) {
|
||||
const id = obj.id;
|
||||
|
||||
if (id === 1) {
|
||||
var currentTab = $(
|
||||
".layui-tab[lay-filter='" +
|
||||
option.elem +
|
||||
"'] .layui-tab-title .layui-this",
|
||||
);
|
||||
if (currentTab.find("span").is(".able-close")) {
|
||||
var currentId = currentTab.attr("lay-id");
|
||||
tabDelete(option.elem, currentId, option.closeEvent, option);
|
||||
} else {
|
||||
layer.msg("当前页面不允许关闭", {
|
||||
icon: 3,
|
||||
time: 1000,
|
||||
});
|
||||
}
|
||||
} else if (id === 2) {
|
||||
var currentId = $(
|
||||
".layui-tab[lay-filter='" +
|
||||
option.elem +
|
||||
"'] .layui-tab-title .layui-this",
|
||||
).attr("lay-id");
|
||||
var tabtitle = $(
|
||||
".layui-tab[lay-filter='" + option.elem + "'] .layui-tab-title li",
|
||||
);
|
||||
$.each(tabtitle, function (i) {
|
||||
if ($(this).attr("lay-id") != currentId) {
|
||||
if ($(this).find("span").is(".able-close")) {
|
||||
tabDelete(
|
||||
option.elem,
|
||||
$(this).attr("lay-id"),
|
||||
option.closeEvent,
|
||||
option,
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
var currentId = $(
|
||||
".layui-tab[lay-filter='" +
|
||||
option.elem +
|
||||
"'] .layui-tab-title .layui-this",
|
||||
).attr("lay-id");
|
||||
var tabtitle = $(
|
||||
".layui-tab[lay-filter='" + option.elem + "'] .layui-tab-title li",
|
||||
);
|
||||
$.each(tabtitle, function (i) {
|
||||
if ($(this).find("span").is(".able-close")) {
|
||||
tabDelete(
|
||||
option.elem,
|
||||
$(this).attr("lay-id"),
|
||||
option.closeEvent,
|
||||
option,
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
$("body .layui-tab[lay-filter='" + option.elem + "'] .layui-tab-title").on(
|
||||
"contextmenu",
|
||||
"li",
|
||||
function (e) {
|
||||
var top = e.clientY;
|
||||
var left = e.clientX;
|
||||
var menuWidth = 100;
|
||||
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>`;
|
||||
|
||||
contextTabDOM = $(this);
|
||||
var isOutsideBounds = left + menuWidth > $(window).width();
|
||||
if (isOutsideBounds) {
|
||||
left = $(window).width() - menuWidth;
|
||||
}
|
||||
|
||||
layer.open({
|
||||
type: 1,
|
||||
title: false,
|
||||
shade: false,
|
||||
skin: "pear-tab-page-menu",
|
||||
closeBtn: false,
|
||||
area: [menuWidth + "px", "108px"],
|
||||
fixed: true,
|
||||
anim: false,
|
||||
isOutAnim: false,
|
||||
offset: [top, left],
|
||||
content: menu,
|
||||
success: function (layero, index) {
|
||||
layer.close(lastIndex);
|
||||
lastIndex = index;
|
||||
menuEvent(option, index);
|
||||
var timer;
|
||||
$(layero).on("mouseout", function () {
|
||||
timer = setTimeout(function () {
|
||||
layer.close(index);
|
||||
}, 30);
|
||||
});
|
||||
|
||||
$(layero).on("mouseover", function () {
|
||||
clearTimeout(timer);
|
||||
});
|
||||
|
||||
$(layero).on("contextmenu", function () {
|
||||
return false;
|
||||
});
|
||||
},
|
||||
});
|
||||
return false;
|
||||
},
|
||||
);
|
||||
|
||||
mousewheelAndTouchmoveHandler(option);
|
||||
return new tabPage(option);
|
||||
};
|
||||
|
||||
tabPage.prototype.click = function (callback) {
|
||||
var option = this.option;
|
||||
var elem = this.option.elem;
|
||||
element.on("tab(" + this.option.elem + ")", function (data) {
|
||||
var id = $("#" + elem + " .layui-tab-title .layui-this").attr("lay-id");
|
||||
sessionStorage.setItem(option.elem + "-pear-tab-page-data-current", id);
|
||||
callback(id);
|
||||
});
|
||||
};
|
||||
|
||||
tabPage.prototype.positionTab = function () {
|
||||
var $tabTitle = $(
|
||||
".layui-tab[lay-filter=" + this.option.elem + "] .layui-tab-title",
|
||||
);
|
||||
var autoLeft = 0;
|
||||
$tabTitle.children("li").each(function () {
|
||||
if ($(this).hasClass("layui-this")) {
|
||||
return false;
|
||||
} else {
|
||||
autoLeft += $(this).outerWidth();
|
||||
}
|
||||
});
|
||||
$tabTitle.animate(
|
||||
{
|
||||
scrollLeft: autoLeft - $tabTitle.width() / 3,
|
||||
},
|
||||
200,
|
||||
);
|
||||
};
|
||||
|
||||
tabPage.prototype.clear = function () {
|
||||
sessionStorage.removeItem(this.option.elem + "-pear-tab-page-data");
|
||||
sessionStorage.removeItem(this.option.elem + "-pear-tab-page-data-current");
|
||||
};
|
||||
|
||||
var index = 0;
|
||||
// 根据过滤 fliter 标识, 重置选项卡标题
|
||||
tabPage.prototype.changeTabTitleById = function (elem, id, title) {
|
||||
var currentTab = $(
|
||||
".layui-tab[lay-filter='" +
|
||||
elem +
|
||||
"'] .layui-tab-title [lay-id='" +
|
||||
id +
|
||||
"'] .title",
|
||||
);
|
||||
currentTab.html(title);
|
||||
};
|
||||
|
||||
// 根据过滤 filter 标识, 删除指定选项卡
|
||||
tabPage.prototype.delTabByElem = function (elem, id, callback) {
|
||||
var currentTab = $(
|
||||
".layui-tab[lay-filter='" +
|
||||
elem +
|
||||
"'] .layui-tab-title [lay-id='" +
|
||||
id +
|
||||
"']",
|
||||
);
|
||||
if (currentTab.find("span").is(".able-close")) {
|
||||
tabDelete(elem, id, callback);
|
||||
}
|
||||
};
|
||||
// 根据过滤 filter 标识, 删除其他选项卡
|
||||
tabPage.prototype.delOtherTabByElem = function (elem, callback) {
|
||||
var currentId = $(
|
||||
".layui-tab[lay-filter='" + elem + "'] .layui-tab-title .layui-this",
|
||||
).attr("lay-id");
|
||||
var tabtitle = $(
|
||||
".layui-tab[lay-filter='" + elem + "'] .layui-tab-title li",
|
||||
);
|
||||
$.each(tabtitle, function (i) {
|
||||
if ($(this).attr("lay-id") != currentId) {
|
||||
if ($(this).find("span").is(".able-close")) {
|
||||
tabDelete(elem, $(this).attr("lay-id"), callback);
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
// 根据过滤 filter 标识, 删除全部选项卡
|
||||
tabPage.prototype.delAllTabByElem = function (elem, callback) {
|
||||
var currentId = $(
|
||||
".layui-tab[lay-filter='" + elem + "'] .layui-tab-title .layui-this",
|
||||
).attr("lay-id");
|
||||
var tabtitle = $(
|
||||
".layui-tab[lay-filter='" + elem + "'] .layui-tab-title li",
|
||||
);
|
||||
$.each(tabtitle, function (i) {
|
||||
if ($(this).find("span").is(".able-close")) {
|
||||
tabDelete(elem, $(this).attr("lay-id"), callback);
|
||||
}
|
||||
});
|
||||
};
|
||||
// 根据过滤 filter 标识, 删除当前选项卡
|
||||
tabPage.prototype.delCurrentTabByElem = function (elem, callback) {
|
||||
var currentTab = $(
|
||||
".layui-tab[lay-filter='" + elem + "'] .layui-tab-title .layui-this",
|
||||
);
|
||||
if (currentTab.find("span").is(".able-close")) {
|
||||
var currentId = currentTab.attr("lay-id");
|
||||
tabDelete(elem, currentId, callback);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @since Pear Admin 4.0
|
||||
*/
|
||||
tabPage.prototype.addTabOnly = function (opt, time) {
|
||||
var title = `<span class="pear-tab-page-active"></span>
|
||||
<span class="${opt.close ? "able-close" : "disable-close"} title">${
|
||||
opt.title
|
||||
}</span>
|
||||
<i class="layui-icon layui-unselect layui-tab-close">ဆ</i>`;
|
||||
|
||||
if (
|
||||
$(
|
||||
".layui-tab[lay-filter='" +
|
||||
this.option.elem +
|
||||
"'] .layui-tab-title li[lay-id]",
|
||||
).length <= 0
|
||||
) {
|
||||
var that = this;
|
||||
|
||||
if (opt.type === "_iframe") {
|
||||
element.tabAdd(this.option.elem, {
|
||||
id: opt.id,
|
||||
title: title,
|
||||
content: `<iframe id="${opt.id}" type="${opt.type}" data-frameid="${opt.id}" scrolling="auto" frameborder="0" src="${opt.url}" style="width:100%;height:100%;" allowfullscreen="true"></iframe>`,
|
||||
});
|
||||
} else {
|
||||
$.ajax({
|
||||
url: opt.url,
|
||||
type: "get",
|
||||
dataType: "html",
|
||||
async: false,
|
||||
success: function (data) {
|
||||
element.tabAdd(that.option.elem, {
|
||||
id: opt.id,
|
||||
title: title,
|
||||
content: `<div id="${opt.id}" type="${opt.type}" data-frameid="${opt.id}" src="${opt.url}">${data}</div>`,
|
||||
});
|
||||
},
|
||||
error: function (xhr, textstatus, thrown) {
|
||||
return layer.msg(
|
||||
"Status:" + xhr.status + "," + xhr.statusText + ",请稍后再试!",
|
||||
);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
tabData.push(opt);
|
||||
sessionStorage.setItem(
|
||||
that.option.elem + "-pear-tab-page-data",
|
||||
JSON.stringify(tabData),
|
||||
);
|
||||
sessionStorage.setItem(
|
||||
that.option.elem + "-pear-tab-page-data-current",
|
||||
opt.id,
|
||||
);
|
||||
} else {
|
||||
var isData = false;
|
||||
$.each(
|
||||
$(
|
||||
".layui-tab[lay-filter='" +
|
||||
this.option.elem +
|
||||
"'] .layui-tab-title li[lay-id]",
|
||||
),
|
||||
function () {
|
||||
if ($(this).attr("lay-id") == opt.id) {
|
||||
isData = true;
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
if (isData == false) {
|
||||
if (this.option.tabMax != false) {
|
||||
if (
|
||||
$(
|
||||
".layui-tab[lay-filter='" +
|
||||
this.option.elem +
|
||||
"'] .layui-tab-title li[lay-id]",
|
||||
).length >= this.option.tabMax
|
||||
) {
|
||||
layer.msg("最多打开" + this.option.tabMax + "个标签页", {
|
||||
icon: 2,
|
||||
time: 1000,
|
||||
shift: 6,
|
||||
});
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
var that = this;
|
||||
if (opt.type === "_iframe") {
|
||||
element.tabAdd(this.option.elem, {
|
||||
id: opt.id,
|
||||
title: title,
|
||||
content: `<iframe id="${opt.id}" type="${opt.type}" data-frameid="${opt.id}" scrolling="auto" frameborder="0" src="${opt.url}" style="width:100%;height:100%;" allowfullscreen="true"></iframe>`,
|
||||
});
|
||||
} else {
|
||||
$.ajax({
|
||||
url: opt.url,
|
||||
type: "get",
|
||||
dataType: "html",
|
||||
async: false,
|
||||
success: function (data) {
|
||||
element.tabAdd(that.option.elem, {
|
||||
id: opt.id,
|
||||
title: title,
|
||||
content: `<div id="${opt.id}" type="${opt.type}" data-frameid="${opt.id}" src="${opt.url}">${data}</div>`,
|
||||
});
|
||||
},
|
||||
error: function (xhr, textstatus, thrown) {
|
||||
return layer.msg(
|
||||
"Status:" +
|
||||
xhr.status +
|
||||
"," +
|
||||
xhr.statusText +
|
||||
",请稍后再试!",
|
||||
);
|
||||
},
|
||||
});
|
||||
}
|
||||
tabData.push(opt);
|
||||
sessionStorage.setItem(
|
||||
that.option.elem + "-pear-tab-page-data",
|
||||
JSON.stringify(tabData),
|
||||
);
|
||||
sessionStorage.setItem(
|
||||
that.option.elem + "-pear-tab-page-data-current",
|
||||
opt.id,
|
||||
);
|
||||
}
|
||||
}
|
||||
element.tabChange(this.option.elem, opt.id);
|
||||
sessionStorage.setItem(
|
||||
this.option.elem + "-pear-tab-page-data-current",
|
||||
opt.id,
|
||||
);
|
||||
};
|
||||
|
||||
// 刷 新 指 定 的 选 项 卡
|
||||
tabPage.prototype.refresh = function (time) {
|
||||
var $iframe = $(
|
||||
".layui-tab[lay-filter='" +
|
||||
this.option.elem +
|
||||
"'] .layui-tab-content .layui-show > *",
|
||||
);
|
||||
var $iframeLoad;
|
||||
|
||||
if (time != false && time != 0) {
|
||||
$iframe
|
||||
.parent()
|
||||
.append(
|
||||
`<div id="pear-tab-page-loading${index}" class="pear-tab-page-loading"><div class="ball-loader"><span></span><span></span><span></span><span></span></div></div>`,
|
||||
);
|
||||
$iframeLoad = $("#" + this.option.elem).find(
|
||||
"#pear-tab-page-loading" + index++,
|
||||
);
|
||||
$iframeLoad.css({
|
||||
display: "block",
|
||||
});
|
||||
}
|
||||
|
||||
if ($iframe.attr("type") === "_iframe") {
|
||||
$iframe.attr("src", $iframe.attr("src"));
|
||||
$iframe.on("load", function () {
|
||||
$iframeLoad.fadeOut(1000, function () {
|
||||
$iframeLoad.remove();
|
||||
});
|
||||
});
|
||||
} else {
|
||||
$.ajax({
|
||||
url: $iframe.attr("src"),
|
||||
type: "get",
|
||||
dataType: "html",
|
||||
success: function (data) {
|
||||
$iframe.html(data);
|
||||
if ($iframeLoad != undefined) {
|
||||
$iframeLoad.fadeOut(1000, function () {
|
||||
$iframeLoad.remove();
|
||||
});
|
||||
}
|
||||
},
|
||||
error: function (xhr) {
|
||||
return layer.msg(
|
||||
"Status:" + xhr.status + "," + xhr.statusText + ",请稍后再试!",
|
||||
);
|
||||
},
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
function tabDelete(elem, id, callback, option) {
|
||||
var tabTitle = $(".layui-tab[lay-filter='" + elem + "']").find(
|
||||
".layui-tab-title",
|
||||
);
|
||||
var removeTab = tabTitle.find("li[lay-id='" + id + "']");
|
||||
var nextNode = removeTab.next("li");
|
||||
if (!removeTab.hasClass("layui-this")) {
|
||||
removeTab.remove();
|
||||
var tabContent = $(".layui-tab[lay-filter='" + elem + "']")
|
||||
.find("*[id='" + id + "']")
|
||||
.parent();
|
||||
tabContent.remove();
|
||||
|
||||
tabData = JSON.parse(
|
||||
sessionStorage.getItem(elem + "-pear-tab-page-data"),
|
||||
);
|
||||
tabDataCurrent = sessionStorage.getItem(
|
||||
elem + "-pear-tab-page-data-current",
|
||||
);
|
||||
tabData = tabData.filter(function (item) {
|
||||
return item.id != id;
|
||||
});
|
||||
sessionStorage.setItem(
|
||||
elem + "-pear-tab-page-data",
|
||||
JSON.stringify(tabData),
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
var currId;
|
||||
if (nextNode.length) {
|
||||
nextNode.addClass("layui-this");
|
||||
currId = nextNode.attr("lay-id");
|
||||
$("#" + elem + " [id='" + currId + "']")
|
||||
.parent()
|
||||
.addClass("layui-show");
|
||||
} else {
|
||||
var prevNode = removeTab.prev("li");
|
||||
prevNode.addClass("layui-this");
|
||||
currId = prevNode.attr("lay-id");
|
||||
$("#" + elem + " [id='" + currId + "']")
|
||||
.parent()
|
||||
.addClass("layui-show");
|
||||
}
|
||||
callback(currId);
|
||||
tabData = JSON.parse(sessionStorage.getItem(elem + "-pear-tab-page-data"));
|
||||
tabDataCurrent = sessionStorage.getItem(
|
||||
elem + "-pear-tab-page-data-current",
|
||||
);
|
||||
tabData = tabData.filter(function (item) {
|
||||
return item.id != id;
|
||||
});
|
||||
sessionStorage.setItem(
|
||||
elem + "-pear-tab-page-data",
|
||||
JSON.stringify(tabData),
|
||||
);
|
||||
sessionStorage.setItem(elem + "-pear-tab-page-data-current", currId);
|
||||
|
||||
removeTab.remove();
|
||||
// 删除 content
|
||||
var tabContent = $(".layui-tab[lay-filter='" + elem + "']")
|
||||
.find("*[id='" + id + "']")
|
||||
.parent();
|
||||
// 删除
|
||||
tabContent.remove();
|
||||
}
|
||||
|
||||
/**
|
||||
* @since Pear Admin 4.0
|
||||
*/
|
||||
function createTab(option) {
|
||||
var type = "";
|
||||
var types = option.type + " ";
|
||||
if (option.roll == true) {
|
||||
type = "layui-tab-roll";
|
||||
}
|
||||
if (option.tool != false) {
|
||||
type = "layui-tab-tool";
|
||||
}
|
||||
if (option.roll == true && option.tool != false) {
|
||||
type = "layui-tab-rollTool";
|
||||
}
|
||||
var tab =
|
||||
'<div class="pear-tab-page ' +
|
||||
types +
|
||||
type +
|
||||
' layui-tab" lay-filter="' +
|
||||
option.elem +
|
||||
'" lay-allowClose="true">';
|
||||
|
||||
var title = '<ul class="layui-tab-title">';
|
||||
var content = '<div class="layui-tab-content">';
|
||||
var control = `<div class="layui-tab-control">
|
||||
<li class="layui-tab-prev layui-icon layui-icon-left"></li>
|
||||
<li class="layui-tab-next layui-icon layui-icon-right"></li>
|
||||
<li class="layui-tab-tool layui-icon layui-icon-down"></li>
|
||||
</div>`;
|
||||
|
||||
// 处 理 选 项 卡 头 部
|
||||
var index = 0;
|
||||
$.each(option.data, function (i, item) {
|
||||
var titleItem = `<li lay-id="${item.id}" class="${
|
||||
option.index == index ? "layui-this" : ""
|
||||
}">
|
||||
<span class="pear-tab-page-active"></span>
|
||||
<span class="${item.close ? "able-close" : "disable-close"} title">
|
||||
${item.title}
|
||||
</span>
|
||||
<i class="layui-icon layui-unselect layui-tab-close">ဆ</i></li>
|
||||
</li>`;
|
||||
|
||||
title += titleItem;
|
||||
|
||||
if (item.type === "_iframe") {
|
||||
content += `<div class="${
|
||||
option.index == index ? "layui-show" : ""
|
||||
} layui-tab-item"><iframe id="${item.id}" type="${
|
||||
item.type
|
||||
}" data-frameid="${item.id}" scrolling="auto" frameborder="0" src="${
|
||||
item.url
|
||||
}" style="width:100%;height:100%;" allowfullscreen="true"></iframe></div>`;
|
||||
} else {
|
||||
$.ajax({
|
||||
url: item.url,
|
||||
type: "get",
|
||||
dataType: "html",
|
||||
async: false,
|
||||
success: function (data) {
|
||||
content += `<div class="${
|
||||
option.index == index ? "layui-show" : ""
|
||||
} layui-tab-item"><div id="${item.id}" type="${
|
||||
item.type
|
||||
}" data-frameid="${item.id}" src="${
|
||||
item.url
|
||||
}">${data}</div></div>`;
|
||||
},
|
||||
error: function (xhr) {
|
||||
return layer.msg(
|
||||
"Status:" + xhr.status + "," + xhr.statusText + ",请稍后再试!",
|
||||
);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
index++;
|
||||
});
|
||||
|
||||
title += "</ul>";
|
||||
content += "</div>";
|
||||
|
||||
tab += title;
|
||||
tab += control;
|
||||
tab += content;
|
||||
tab += "</div>";
|
||||
tab += "";
|
||||
return tab;
|
||||
}
|
||||
|
||||
function rollPage(d, option) {
|
||||
var $tabTitle = $("#" + option.elem + " .layui-tab-title");
|
||||
var left = $tabTitle.scrollLeft();
|
||||
if ("left" === d) {
|
||||
$tabTitle.animate(
|
||||
{
|
||||
scrollLeft: left - 450,
|
||||
},
|
||||
200,
|
||||
);
|
||||
} else {
|
||||
$tabTitle.animate(
|
||||
{
|
||||
scrollLeft: left + 450,
|
||||
},
|
||||
200,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
function closeEvent(option) {
|
||||
$(".layui-tab[lay-filter='" + option.elem + "']").on(
|
||||
"click",
|
||||
".layui-tab-close",
|
||||
function () {
|
||||
var layid = $(this).parent().attr("lay-id");
|
||||
tabDelete(option.elem, layid, option.closeEvent, option);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
function menuEvent(option, index) {
|
||||
$("#" + option.elem + "closeThis").click(function () {
|
||||
var currentTab = contextTabDOM;
|
||||
|
||||
if (currentTab.find("span").is(".able-close")) {
|
||||
var currentId = currentTab.attr("lay-id");
|
||||
tabDelete(option.elem, currentId, option.closeEvent, option);
|
||||
} else {
|
||||
layer.msg("当前页面不允许关闭", {
|
||||
icon: 3,
|
||||
time: 800,
|
||||
});
|
||||
}
|
||||
layer.close(index);
|
||||
});
|
||||
|
||||
$("#" + option.elem + "closeOther").click(function () {
|
||||
var currentId = contextTabDOM.attr("lay-id");
|
||||
var tabtitle = $(
|
||||
".layui-tab[lay-filter='" + option.elem + "'] .layui-tab-title li",
|
||||
);
|
||||
$.each(tabtitle, function (i) {
|
||||
if ($(this).attr("lay-id") != currentId) {
|
||||
if ($(this).find("span").is(".able-close")) {
|
||||
tabDelete(
|
||||
option.elem,
|
||||
$(this).attr("lay-id"),
|
||||
option.closeEvent,
|
||||
option,
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
layer.close(index);
|
||||
});
|
||||
|
||||
$("#" + option.elem + "closeAll").click(function () {
|
||||
var tabtitle = $(
|
||||
".layui-tab[lay-filter='" + option.elem + "'] .layui-tab-title li",
|
||||
);
|
||||
$.each(tabtitle, function (i) {
|
||||
if ($(this).find("span").is(".able-close")) {
|
||||
tabDelete(
|
||||
option.elem,
|
||||
$(this).attr("lay-id"),
|
||||
option.closeEvent,
|
||||
option,
|
||||
);
|
||||
}
|
||||
});
|
||||
layer.close(index);
|
||||
});
|
||||
}
|
||||
|
||||
function mousewheelAndTouchmoveHandler(option) {
|
||||
var $bodyTab = $(
|
||||
"body .layui-tab[lay-filter='" + option.elem + "'] .layui-tab-title",
|
||||
);
|
||||
var $tabTitle = $("#" + option.elem + " .layui-tab-title");
|
||||
var mouseScrollStep = 100;
|
||||
// 鼠标滚轮
|
||||
$bodyTab.on("mousewheel DOMMouseScroll", function (e) {
|
||||
e.originalEvent.preventDefault();
|
||||
var delta =
|
||||
(e.originalEvent.wheelDelta &&
|
||||
(e.originalEvent.wheelDelta > 0 ? "top" : "down")) || // chrome & ie
|
||||
(e.originalEvent.detail &&
|
||||
(e.originalEvent.detail > 0 ? "down" : "top")); // firefox
|
||||
var scrollLeft = $tabTitle.scrollLeft();
|
||||
|
||||
if (delta === "top") {
|
||||
scrollLeft -= mouseScrollStep;
|
||||
} else if (delta === "down") {
|
||||
scrollLeft += mouseScrollStep;
|
||||
}
|
||||
$tabTitle.scrollLeft(scrollLeft);
|
||||
});
|
||||
|
||||
// 触摸移动
|
||||
var touchX = 0;
|
||||
$bodyTab.on("touchstart", function (e) {
|
||||
var touch = e.originalEvent.targetTouches[0];
|
||||
touchX = touch.pageX;
|
||||
});
|
||||
$bodyTab.on("touchmove", function (e) {
|
||||
var event = e.originalEvent;
|
||||
if (event.targetTouches.length > 1) return;
|
||||
event.preventDefault();
|
||||
var touch = event.targetTouches[0];
|
||||
var distanceX = touchX - touch.pageX;
|
||||
var scrollLeft = $tabTitle.scrollLeft();
|
||||
touchX = touch.pageX;
|
||||
$tabTitle.scrollLeft((scrollLeft += distanceX));
|
||||
});
|
||||
}
|
||||
|
||||
exports(MOD_NAME, new tabPage());
|
||||
});
|
||||
@@ -0,0 +1,25 @@
|
||||
layui.define(["jquery", "element"], function (exports) {
|
||||
var $ = layui.jquery;
|
||||
var tools = new (function () {
|
||||
/**
|
||||
* @since 防抖算法
|
||||
*
|
||||
* @param fn 要执行的方法
|
||||
* @param time 防抖时间参数
|
||||
*/
|
||||
this.debounce = function (fn, time) {
|
||||
var timer = null;
|
||||
return function () {
|
||||
var arguments = arguments[0];
|
||||
if (timer) {
|
||||
clearTimeout(timer);
|
||||
}
|
||||
timer = setTimeout(function () {
|
||||
fn(arguments);
|
||||
}, time);
|
||||
};
|
||||
};
|
||||
})();
|
||||
|
||||
exports("tools", tools);
|
||||
});
|
||||
Reference in New Issue
Block a user