ok-admin/lib/layui_plugins/okLayer/okLayer.js

150 lines
5.4 KiB
JavaScript
Raw Normal View History

2019-05-12 08:15:57 +00:00
layui.define(["layer"], function (exports) {
2019-05-12 11:09:10 +00:00
var $ = layui.jquery;
2019-05-12 08:15:57 +00:00
var okLayer = {
2019-05-13 15:41:06 +00:00
// 控制了msg() confirm() open()方法的弹窗皮肤
skinStyle: 3,
// 控制了msg() confirm() open()方法的弹窗动画
2019-05-12 11:43:52 +00:00
animStyle: 2,
2019-05-13 15:41:06 +00:00
/**
* 主要用于针对表格批量操作操作之前的检查
* @param table
* @returns {string}
*/
2019-05-12 08:57:14 +00:00
tableCheck: 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});
}
},
2019-05-13 15:41:06 +00:00
/**
* 在表格页面操作成功后弹窗提示
* @param content
*/
tableOperationSuccessMsg: function (content) {
2019-05-12 11:09:10 +00:00
layer.msg(content, {icon: 1, time: 1000}, function () {
2019-05-13 15:41:06 +00:00
// 刷新当前table数据
2019-05-12 11:09:10 +00:00
$(".layui-laypage-btn")[0].click();
});
2019-05-12 11:22:05 +00:00
},
2019-05-13 15:41:06 +00:00
/**
* confirm()函数二次封装
* @param content
* @param yesFunction
*/
2019-05-12 11:43:52 +00:00
confirm: function (content, yesFunction) {
var options = {skin: okLayer.skinChoose(), icon: 2, title: "提示", anim: okLayer.animChoose()};
layer.confirm(content, options, yesFunction);
},
2019-05-13 15:41:06 +00:00
/**
* open()函数二次封装,支持在table页面和普通页面打开
* @param title
* @param content
* @param width
* @param height
* @param isRefreshTable
*/
2019-05-13 00:45:45 +00:00
open: function (title, content, width, height, isRefreshTable) {
2019-05-12 11:22:05 +00:00
layer.open({
title: title,
type: 2,
shade: false,
maxmin: true,
shade: 0.5,
2019-05-12 11:43:52 +00:00
anim: okLayer.animChoose(),
2019-05-12 11:22:05 +00:00
area: [width, height],
content: content,
zIndex: layer.zIndex,
2019-05-12 11:43:52 +00:00
skin: okLayer.skinChoose(),
2019-05-12 11:22:05 +00:00
end: function () {
2019-05-13 15:41:06 +00:00
if (isRefreshTable) {
$(".layui-laypage-btn")[0].click();
}
2019-05-12 11:22:05 +00:00
}
});
2019-05-12 11:43:52 +00:00
},
2019-05-13 15:41:06 +00:00
/**
* msg()函数二次封装
*/
msg: {
// msg弹窗默认消失时间
time: 1000,
// 绿色勾
greenTick: function (content, time, callbackFunction) {
var options = {icon: 1, time: okLayer.msg.timeCompute(time), anim: okLayer.animChoose()};
layer.msg(content, options, callbackFunction);
},
// 红色叉
redCross: function (content, callbackFunction) {
var options = {icon: 2, time: okLayer.msg.timeCompute(time), anim: okLayer.animChoose()};
layer.msg(content, options, callbackFunction);
},
// 黄色问号
yellowQuestion: function (content, callbackFunction) {
var options = {icon: 3, time: okLayer.msg.timeCompute(time), anim: okLayer.animChoose()};
layer.msg(content, options, callbackFunction);
},
// 灰色锁
grayLock: function (content, callbackFunction) {
var options = {icon: 4, time: okLayer.msg.timeCompute(time), anim: okLayer.animChoose()};
layer.msg(content, options, callbackFunction);
},
// 红色哭脸
redCry: function (content, callbackFunction) {
var options = {icon: 5, time: okLayer.msg.timeCompute(time), anim: okLayer.animChoose()};
layer.msg(content, options, callbackFunction);
},
// 绿色笑脸
greenLaugh: function (content, callbackFunction) {
var options = {icon: 6, time: okLayer.msg.timeCompute(time), anim: okLayer.animChoose()};
layer.msg(content, options, callbackFunction);
},
// 黄色感叹号
yellowSigh: function (content, callbackFunction) {
var options = {icon: 7, time: okLayer.msg.timeCompute(time), anim: okLayer.animChoose()};
layer.msg(content, options, callbackFunction);
},
timeCompute: function (time) {
return time ? time : okLayer.msg.time;
}
},
/**
* 皮肤选择
* @returns {string}
*/
2019-05-12 11:43:52 +00:00
skinChoose: function () {
if (okLayer.skinStyle == 1) {
2019-05-13 15:41:06 +00:00
// 默认皮肤
return "";
2019-05-12 11:43:52 +00:00
} else if (okLayer.skinStyle == 2) {
2019-05-13 15:41:06 +00:00
// 墨绿色
2019-05-12 11:43:52 +00:00
return "layui-layer-molv";
2019-05-13 15:41:06 +00:00
} else if (okLayer.skinStyle == 3) {
// 蓝色
return "layui-layer-lan";
2019-05-12 11:43:52 +00:00
}
},
2019-05-13 15:41:06 +00:00
/**
* 动画选择
* @returns {number}
*/
2019-05-12 11:43:52 +00:00
animChoose: function () {
if (okLayer.animStyle == 1) {
2019-05-13 15:41:06 +00:00
// 默认动画
2019-05-12 11:43:52 +00:00
return 0;
} else if (okLayer.animStyle == 2) {
2019-05-13 15:41:06 +00:00
// 随机动画
2019-05-12 11:43:52 +00:00
return Math.floor(Math.random() * 7);
}
2019-05-12 08:15:57 +00:00
}
}
exports("okLayer", okLayer);
});