diff --git a/lib/layui/lay/okmodules/okLayer.js b/lib/layui/lay/okmodules/okLayer.js new file mode 100644 index 0000000..bdb5236 --- /dev/null +++ b/lib/layui/lay/okmodules/okLayer.js @@ -0,0 +1,120 @@ +"use strict"; +layui.define(["layer"], function (exports) { + var okLayer = { + /** + * confirm()函数二次封装 + * @param content + * @param yesFunction + */ + confirm: function (content, yesFunction) { + var options = {skin: okLayer.skinChoose(), icon: 3, title: "提示", anim: okLayer.animChoose()}; + layer.confirm(content, options, yesFunction); + }, + /** + * open()函数二次封装,支持在table页面和普通页面打开 + * @param title + * @param content + * @param width + * @param height + * @param successFunction + * @param endFunction + */ + open: function (title, content, width, height, successFunction, endFunction) { + layer.open({ + title: title, + type: 2, + maxmin: true, + shade: 0.5, + anim: okLayer.animChoose(), + area: [width, height], + content: content, + zIndex: layer.zIndex, + skin: okLayer.skinChoose(), + success: successFunction, + end: endFunction + }); + }, + /** + * msg()函数二次封装 + */ + msg: { + // msg弹窗默认消失时间 + time: 1000, + // 绿色勾 + greenTick: function (content, callbackFunction) { + var options = {icon: 1, time: okLayer.msg.time, anim: okLayer.animChoose()}; + layer.msg(content, options, callbackFunction); + }, + // 红色叉 + redCross: function (content, callbackFunction) { + var options = {icon: 2, time: okLayer.msg.time, anim: okLayer.animChoose()}; + layer.msg(content, options, callbackFunction); + }, + // 黄色问号 + yellowQuestion: function (content, callbackFunction) { + var options = {icon: 3, time: okLayer.msg.time, anim: okLayer.animChoose()}; + layer.msg(content, options, callbackFunction); + }, + // 灰色锁 + grayLock: function (content, callbackFunction) { + var options = {icon: 4, time: okLayer.msg.time, anim: okLayer.animChoose()}; + layer.msg(content, options, callbackFunction); + }, + // 红色哭脸 + redCry: function (content, callbackFunction) { + var options = {icon: 5, time: okLayer.msg.time, anim: okLayer.animChoose()}; + layer.msg(content, options, callbackFunction); + }, + // 绿色笑脸 + greenLaugh: function (content, callbackFunction) { + var options = {icon: 6, time: okLayer.msg.time, anim: okLayer.animChoose()}; + layer.msg(content, options, callbackFunction); + }, + // 黄色感叹号 + yellowSigh: function (content, callbackFunction) { + var options = {icon: 7, time: okLayer.msg.time, anim: okLayer.animChoose()}; + layer.msg(content, options, callbackFunction); + } + }, + /** + * 皮肤选择 + * @returns {string} + */ + skinChoose: function () { + var storage = window.localStorage; + var skin = storage.getItem("skin"); + if (skin == 1) { + // 灰白色 + return ""; + } else if (skin == 2) { + // 墨绿色 + return "layui-layer-molv"; + } else if (skin == 3) { + // 蓝色 + return "layui-layer-lan"; + } else if (!skin || skin == 4) { + // 随机颜色 + var skinArray = ["", "layui-layer-molv", "layui-layer-lan"]; + return skinArray[Math.floor(Math.random() * skinArray.length)]; + } + }, + /** + * 动画选择 + * @returns {number} + */ + animChoose: function () { + var storage = window.localStorage; + var anim = storage.getItem("anim"); + var animArray = ["0", "1", "2", "3", "4", "5", "6"]; + if (animArray.indexOf(anim) > -1) { + // 用户选择的动画 + return anim; + } else if (!anim || anim == 7) { + // 随机动画 + return Math.floor(Math.random() * animArray.length); + } + } + } + + exports("okLayer", okLayer); +}); diff --git a/lib/layui/lay/okmodules/okUtils.js b/lib/layui/lay/okmodules/okUtils.js index f0e25ed..640e31c 100644 --- a/lib/layui/lay/okmodules/okUtils.js +++ b/lib/layui/lay/okmodules/okUtils.js @@ -1,31 +1,129 @@ -layui.define(["jquery"], function (exprots) { - var $ = layui.jquery; - var okUtils = { - getBodyWidth: function () { - return document.body.scrollWidth;//body的总宽度 - }, - echartsResize: function (elemnt) { - /* - * 主要用于对echart视图自动适应宽度 - * eg: - * var mapTree = echarts.init($("#mapOne")[0], "mytheme"); - * var mapTree2 = echarts.init($("#mapOne")[0], "mytheme"); - * resize(mapTree,mapTree2); - * */ - /*console.log(arguments[0]); - console.log(elemnt);*/ - elemnt = elemnt || []; - - window.addEventListener("resize", function () { - var isResize = localStorage.getItem("isResize"); - if(isResize != 'false'){ - for (var i = 0; i < elemnt.length; i++) { - elemnt[i].resize(); - } +"use strict"; +layui.define(["layer"], function(exprots) { + var $ = layui.jquery; + var okUtils = { + // 是否前后端分离 + isFrontendBackendSeparate: false, + // 服务器地址 + baseUrl: "http://localhost:8080", + /** + * 获取body的总宽度 + */ + getBodyWidth: function() { + return document.body.scrollWidth; + }, + /** + * 主要用于对echart视图自动适应宽度 + */ + echartsResize: function(elemnt) { + elemnt = elemnt || []; + window.addEventListener("resize", function() { + var isResize = localStorage.getItem("isResize"); + if (isResize != 'false') { + for (var i = 0; i < elemnt.length; i++) { + elemnt[i].resize(); + } + } + }); + }, + /** + * ajax()函数二次封装 + * @param url + * @param type + * @param param + * @returns {*|*|*} + */ + ajax: function (url, type, param) { + var deferred = $.Deferred(); + var loadIndex; + $.ajax({ + url: okUtils.isFrontendBackendSeparate ? okUtils.baseUrl + url : url, + type: type || "get", + data: param || {}, + dataType: "json", + beforeSend: function () { + loadIndex = layer.load(0, {shade: false}); + }, + success: function (data) { + if (data.status == 1000) { + // 业务正常 + deferred.resolve(data.data) + } else { + // 业务异常 + layer.msg(data.msg, {icon: 7, time: 2000}); + deferred.reject("okUtils.ajax warn: " + data.msg); + } + }, + complete: function () { + layer.close(loadIndex); + }, + error: function () { + layer.close(loadIndex); + layer.msg("服务器错误", {icon: 2, time: 2000}); + deferred.reject("okUtils.ajax error: 服务器错误"); + } + }); + return deferred.promise(); + }, + table: { + /** + * 主要用于针对表格批量操作操作之前的检查 + * @param table + * @returns {string} + */ + batchCheck: function (table) { + var checkStatus = table.checkStatus("tableId"); + var rows = checkStatus.data.length; + if (rows > 0) { + var idsStr = ""; + for (var i = 0; i < checkStatus.data.length; i++) { + idsStr += checkStatus.data[i].id + ","; + } + return idsStr; + } else { + layer.msg("未选择有效数据", {offset: "t", anim: 6}); + } + }, + /** + * 在表格页面操作成功后弹窗提示 + * @param content + */ + successMsg: function (content) { + layer.msg(content, {icon: 1, time: 1000}, function () { + // 刷新当前页table数据 + $(".layui-laypage-btn")[0].click(); + }); } - }); - } - }; - exprots("okUtils", okUtils); + }, + mockApi: { + login: "https://easy-mock.com/mock/5d0ce725424f15399a6c2068/okadmin/login", + menu: { + list: "https://easy-mock.com/mock/5d0ce725424f15399a6c2068/okadmin/menu/list" + }, + user: { + list: "https://easy-mock.com/mock/5d0ce725424f15399a6c2068/okadmin/user/list", + batchNormal: "https://easy-mock.com/mock/5d0ce725424f15399a6c2068/okadmin/user/batchNormal", + batchStop: "https://easy-mock.com/mock/5d0ce725424f15399a6c2068/okadmin/user/batchStop", + batchDel: "https://easy-mock.com/mock/5d0ce725424f15399a6c2068/okadmin/user/batchDel", + add: "https://easy-mock.com/mock/5d0ce725424f15399a6c2068/okadmin/user/add", + edit: "https://easy-mock.com/mock/5d0ce725424f15399a6c2068/okadmin/user/edit" + }, + role: { + list: "https://easy-mock.com/mock/5d0ce725424f15399a6c2068/okadmin/role/list" + }, + permission: { + list: "https://easy-mock.com/mock/5d0ce725424f15399a6c2068/okadmin/permission/list" + }, + article: { + list: "https://easy-mock.com/mock/5d0ce725424f15399a6c2068/okadmin/article/list" + }, + log: { + list: "https://easy-mock.com/mock/5d0ce725424f15399a6c2068/okadmin/log/list" + }, + message: { + list: "https://easy-mock.com/mock/5d0ce725424f15399a6c2068/okadmin/message/list" + } + } + }; + exprots("okUtils", okUtils); }); - diff --git a/lib/layui/layui.js b/lib/layui/layui.js index ee2b22e..1ea6f97 100644 --- a/lib/layui/layui.js +++ b/lib/layui/layui.js @@ -33,6 +33,7 @@ if (!Object.assign) { "qrcode": "okmodules/qrcode", "jQqrcode": "okmodules/jQqrcode", "okAddlink": "okmodules/okAddlink", + "okLayer": "okmodules/okLayer", }; var modulePath=Object.assign({ layer: "modules/layer", diff --git a/pages/member/user-add.html b/pages/member/user-add.html index bf477c1..fd58886 100644 --- a/pages/member/user-add.html +++ b/pages/member/user-add.html @@ -105,30 +105,30 @@ diff --git a/pages/member/user-edit.html b/pages/member/user-edit.html index 57ced47..a657bd1 100644 --- a/pages/member/user-edit.html +++ b/pages/member/user-edit.html @@ -21,7 +21,7 @@ -
+
@@ -105,26 +105,34 @@