add:okUtils.html

master
bobi 2019-10-27 23:10:20 +08:00
parent 33d2f7c8e4
commit 2de88e9c7d
6 changed files with 132 additions and 48 deletions

View File

@ -4,7 +4,7 @@
### QQ群交流 ### QQ群交流
964222534 833539807
### 技术栈 ### 技术栈

View File

@ -161,12 +161,12 @@
"icon": "", "icon": "",
"spread": false "spread": false
}, },
{ {
"title": "帖子列表", "title": "帖子列表",
"href": "pages/often/bbs.html", "href": "pages/often/bbs.html",
"icon": "", "icon": "",
"spread": false "spread": false
} }
] ]
}, },
{ {
@ -382,6 +382,12 @@
"href": "pages/help/nav_parameter.html", "href": "pages/help/nav_parameter.html",
"icon": "", "icon": "",
"spread": false "spread": false
},
{
"title": "okUtils",
"href": "pages/help/okUtils.html",
"icon": "",
"spread": false
} }
] ]
}, },

View File

@ -8,9 +8,12 @@ layui.use(["element", "layer", "okUtils", "okTab", "okLayer"], function () {
var okLayer = layui.okLayer; var okLayer = layui.okLayer;
var okTab = layui.okTab({ var okTab = layui.okTab({
// 菜单请求路径
url: "data/navs.json", url: "data/navs.json",
openTabNum: 30, // 允许同时选项卡的个数 // 允许同时选项卡的个数
parseData: function (data) { // 如果返回的结果和navs.json中的数据结构一致可省略这个方法 openTabNum: 30,
// 如果返回的结果和navs.json中的数据结构一致可省略这个方法
parseData: function (data) {
return data; return data;
} }
}); });
@ -25,45 +28,38 @@ layui.use(["element", "layer", "okUtils", "okTab", "okLayer"], function () {
/** /**
* 添加新窗口 * 添加新窗口
*/ */
$("body").on("click", "#navBar .layui-nav-item a,#userInfo a", function () { $("body").on("click", "#navBar .layui-nav-item a, #userInfo a", function () {
// 如果不存在子级 // 如果不存在子级
if ($(this).siblings().length == 0) { if ($(this).siblings().length == 0) {
okTab.tabAdd($(this)); okTab.tabAdd($(this));
} }
// 关闭其他展开的二级标签 // 关闭其他展开的二级标签
$(this).parent("li").siblings().removeClass("layui-nav-itemed"); $(this).parent("li").siblings().removeClass("layui-nav-itemed");
if (!$(this).attr('lay-id')) { if (!$(this).attr("lay-id")) {
var topLevelEle = $(this).parents("li.layui-nav-item"); var topLevelEle = $(this).parents("li.layui-nav-item");
var childs = $("#navBar > li > dl.layui-nav-child").not(topLevelEle.children("dl.layui-nav-child")); var childs = $("#navBar > li > dl.layui-nav-child").not(topLevelEle.children("dl.layui-nav-child"));
childs.removeAttr('style'); childs.removeAttr("style");
} }
}); });
/** /**
* 左侧菜单展开动画 * 左侧菜单展开动画
*/ */
$("#navBar").on('click', '.layui-nav-item a', function () { $("#navBar").on("click", ".layui-nav-item a", function () {
if (!$(this).attr('lay-id')) { if (!$(this).attr("lay-id")) {
var superEle = $(this).parent(); var superEle = $(this).parent();
var ele = $(this).next('.layui-nav-child'); var ele = $(this).next('.layui-nav-child');
var height = ele.height(); var height = ele.height();
ele.css({'display': 'block'}); ele.css({"display": "block"});
// 是否是展开状态
if (superEle.is('.layui-nav-itemed')) {//是否是展开状态 if (superEle.is(".layui-nav-itemed")) {
ele.height(0); ele.height(0);
ele.animate({ ele.animate({height: height + "px"}, function () {
height: height + 'px' ele.css({height: "auto"});
}, function () {
ele.css({
height: "auto"
});
//ele.removeAttr('style');
}); });
} else { } else {
ele.animate({ ele.animate({height: 0}, function () {
height: 0 ele.removeAttr("style");
}, function () {
ele.removeAttr('style');
}); });
} }
} }
@ -74,7 +70,7 @@ layui.use(["element", "layer", "okUtils", "okTab", "okLayer"], function () {
*/ */
$(".ok-menu").click(function () { $(".ok-menu").click(function () {
$(".layui-layout-admin").toggleClass("ok-left-hide"); $(".layui-layout-admin").toggleClass("ok-left-hide");
$(this).find('i').toggleClass("ok-menu-hide"); $(this).find("i").toggleClass("ok-menu-hide");
localStorage.setItem("isResize", false); localStorage.setItem("isResize", false);
setTimeout(function () { setTimeout(function () {
localStorage.setItem("isResize", true); localStorage.setItem("isResize", true);
@ -84,7 +80,7 @@ layui.use(["element", "layer", "okUtils", "okTab", "okLayer"], function () {
/** /**
* 移动端的处理事件 * 移动端的处理事件
*/ */
$("body").on("click", ".layui-layout-admin .ok-left a[data-url],.ok-make", function () { $("body").on("click", ".layui-layout-admin .ok-left a[data-url], .ok-make", function () {
if ($(".layui-layout-admin").hasClass("ok-left-hide")) { if ($(".layui-layout-admin").hasClass("ok-left-hide")) {
$(".layui-layout-admin").removeClass("ok-left-hide"); $(".layui-layout-admin").removeClass("ok-left-hide");
$(".ok-menu").find('i').removeClass("ok-menu-hide"); $(".ok-menu").find('i').removeClass("ok-menu-hide");
@ -111,7 +107,7 @@ layui.use(["element", "layer", "okUtils", "okTab", "okLayer"], function () {
* 关闭tab页 * 关闭tab页
*/ */
$("body").on("click", "#tabAction a", function () { $("body").on("click", "#tabAction a", function () {
var num = $(this).attr('data-num'); var num = $(this).attr("data-num");
okTab.tabClose(num); okTab.tabClose(num);
}); });
@ -121,7 +117,7 @@ layui.use(["element", "layer", "okUtils", "okTab", "okLayer"], function () {
$("body").on("keydown", function (event) { $("body").on("keydown", function (event) {
event = event || window.event || arguments.callee.caller.arguments[0]; event = event || window.event || arguments.callee.caller.arguments[0];
// 按 Esc // 按 Esc
if (event && event.keyCode == 27) { if (event && event.keyCode === 27) {
console.log("Esc"); console.log("Esc");
$("#fullScreen").children("i").eq(0).removeClass("okicon-screen-restore"); $("#fullScreen").children("i").eq(0).removeClass("okicon-screen-restore");
} }
@ -341,16 +337,16 @@ layui.use(["element", "layer", "okUtils", "okTab", "okLayer"], function () {
}); });
}); });
console.log(" _ _ _ \n" + console.log(" __ .___ .__ \n" +
" | | | | (_) \n" + " ____ | | __ _____ __| _/_____ |__| ____ \n" +
" ___ | | _ _____ _____ __| |____ _ ____ \n" + " / _ \\| |/ / ______ \\__ \\ / __ |/ \\| |/ \\ \n" +
" / _ \\| |_/ |_____|____ |/ _ | \\| | _ \\ \n" + "( <_> ) < /_____/ / __ \\_/ /_/ | Y Y \\ | | \\\n" +
"| |_| | _ ( / ___ ( (_| | | | | | | | |\n" + " \\____/|__|_ \\ (____ /\\____ |__|_| /__|___| /\n" +
" \\___/|_| \\_) \\_____|\\____|_|_|_|_|_| |_|\n" + " \\/ \\/ \\/ \\/ \\/\n" +
" \n" + "" +
"版本v2.0\n" + "版本v2.0\n" +
"作者bobi\n" + "作者bobi\n" +
"邮箱bobi1234@foxmail.com\n" + "邮箱bobi1234@foxmail.com\n" +
"企鹅964222534\n" + "企鹅833539807\n" +
"描述:一个很赞的,扁平化风格的,响应式布局的后台管理模版,旨为后端程序员减压!"); "描述:一个很赞的,扁平化风格的,响应式布局的后台管理模版,旨为后端程序员减压!");
}); });

View File

@ -34,17 +34,17 @@ layui.define(["layer"], function (exprots) {
* ajax()函数二次封装 * ajax()函数二次封装
* @param url * @param url
* @param type * @param type
* @param param * @param params
* @param load * @param load
* @returns {*|never|{always, promise, state, then}} * @returns {*|never|{always, promise, state, then}}
*/ */
ajax: function (url, type, param, load) { ajax: function (url, type, params, load) {
var deferred = $.Deferred(); var deferred = $.Deferred();
var loadIndex; var loadIndex;
$.ajax({ $.ajax({
url: okUtils.isFrontendBackendSeparate ? okUtils.baseUrl + url : url, url: okUtils.isFrontendBackendSeparate ? okUtils.baseUrl + url : url,
type: type || "get", type: type || "get",
data: param || {}, data: params || {},
dataType: "json", dataType: "json",
beforeSend: function () { beforeSend: function () {
if (load) { if (load) {

82
pages/help/okUtils.html Normal file
View File

@ -0,0 +1,82 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>okUtils</title>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<link rel="stylesheet" href="../../lib/layui/css/layui.css">
<style>
.ok-body {
padding: 20px;
}
</style>
</head>
<body>
<div class="ok-body">
<blockquote class="layui-elem-quote">
<p>主要讲述如何okUtils封装的工具类使用方法。</p>
</blockquote>
<!--1、okUtils.ajax-->
<blockquote class="layui-elem-quote layui-quote-nm">
okUtils.ajax(url, type, params, load);
</blockquote>
<pre>
okUtils.ajax("/permission/tree", "get", null, true).done(function (response) {
console.log(response);
}).fail(function (error) {
console.log(error);
});
</pre>
<table class="layui-table">
<colgroup>
<col>
<col>
<col>
</colgroup>
<thead>
<tr>
<th>参数</th>
<th>类型</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>url</td>
<td>String</td>
<td>请求路径</td>
</tr>
<tr>
<td>type</td>
<td>String</td>
<td>请求类型</td>
</tr>
<tr>
<td>params</td>
<td>String</td>
<td>请求参数</td>
</tr>
<tr>
<td>load</td>
<td>Boolean</td>
<td>是否显示loading</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>
<script src="../../lib/layui/layui.js"></script>
<script type="text/javascript">
layui.use(["util", "code"], function () {
let util = layui.util;
let code = layui.code;
util.fixbar({});
code({
elem: 'pre',
title: "代码示例"
});
});
</script>

View File

@ -53,7 +53,7 @@
laydate.render({elem: '#endTime', type: "datetime"}); laydate.render({elem: '#endTime', type: "datetime"});
function initPermissionTree() { function initPermissionTree() {
okUtils.ajax("/permission/tree", "get", null).done(function (response) { okUtils.ajax("/permission/tree", "get", null, true).done(function (response) {
tree.render({ tree.render({
elem: '#permissionTree', elem: '#permissionTree',
data: response.data, data: response.data,