完善工具类

v1.0
bobi 2019-05-14 08:59:49 +08:00
parent 241a271283
commit 384c5d9e4f
3 changed files with 46 additions and 45 deletions

View File

@ -5,34 +5,6 @@ layui.define(["layer"], function (exports) {
skinStyle: 3,
// 控制了msg() confirm() open()方法的弹窗动画
animStyle: 2,
/**
* 主要用于针对表格批量操作操作之前的检查
* @param table
* @returns {string}
*/
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});
}
},
/**
* 在表格页面操作成功后弹窗提示
* @param content
*/
tableOperationSuccessMsg: function (content) {
layer.msg(content, {icon: 1, time: 1000}, function () {
// 刷新当前table数据
$(".layui-laypage-btn")[0].click();
});
},
/**
* confirm()函数二次封装
* @param content
@ -50,7 +22,7 @@ layui.define(["layer"], function (exports) {
* @param height
* @param isRefreshTable
*/
open: function (title, content, width, height, isRefreshTable) {
open: function (title, content, width, height, callbackFunction) {
layer.open({
title: title,
type: 2,
@ -62,12 +34,7 @@ layui.define(["layer"], function (exports) {
content: content,
zIndex: layer.zIndex,
skin: okLayer.skinChoose(),
end: function () {
if (isRefreshTable) {
// 刷新当前table数据
$(".layui-laypage-btn")[0].click();
}
}
end: callbackFunction
});
},
/**

View File

@ -41,7 +41,37 @@ layui.define("layer", function (exports) {
}
});
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
*/
operationSuccessMsg: function (content) {
layer.msg(content, {icon: 1, time: 1000}, function () {
// 刷新当前table数据
$(".layui-laypage-btn")[0].click();
});
},
}
}
exports("okUtils", okUtils);

View File

@ -108,12 +108,14 @@
var data = obj.data;
var layEvent = obj.event;
if (layEvent === "edit") {
okLayer.open("编辑用户", "user-edit.html", "90%", "90%", true)
okLayer.open("编辑用户", "user-edit.html", "90%", "90%", function () {
$(".layui-laypage-btn")[0].click();
})
} else if (layEvent === "del") {
okLayer.confirm("确定要删除吗?", function () {
okUtils.ajax("/user/batchDel", "post", {idsStr: data.id}).done(function (response) {
console.log(response)
okLayer.tableOperationMsg("删除成功");
okUtils.table.operationSuccessMsg("删除成功");
}).fail(function (error) {
console.log(error)
});
@ -124,13 +126,13 @@
$("#batchEnabled").click(function () {
okLayer.confirm("确定要批量启用吗?", function (index) {
layer.close(index);
var idsStr = okLayer.tableCheck(table);
var idsStr = okUtils.table.batchCheck(table);
console.log("idsStr-->" + idsStr)
// ajax请求后台api
if (idsStr) {
okUtils.ajax("/user/batchNormal", "post", {idsStr: idsStr}).done(function (response) {
console.log(response)
okLayer.tableOperationSuccessMsg("批量启用成功");
okUtils.table.operationSuccessMsg("批量启用成功");
}).fail(function (error) {
console.log(error)
});
@ -141,11 +143,11 @@
$("#batchDisabled").click(function () {
okLayer.confirm("确定要批量停用吗?", function (index) {
layer.close(index);
var idsStr = okLayer.tableCheck(table);
var idsStr = okUtils.table.batchCheck(table);
if (idsStr) {
okUtils.ajax("/user/batchStop", "post", {idsStr: idsStr}).done(function (response) {
console.log(response)
okLayer.tableOperationSuccessMsg("批量停用成功");
okUtils.table.operationSuccessMsg("批量停用成功");
}).fail(function (error) {
console.log(error)
});
@ -156,11 +158,11 @@
$("#batchDel").click(function () {
okLayer.confirm("确定要批量删除吗?", function (index) {
layer.close(index);
var idsStr = okLayer.tableCheck(table);
var idsStr = okUtils.table.batchCheck(table);
if (idsStr) {
okUtils.ajax("/user/batchDel", "post", {idsStr: idsStr}).done(function (response) {
console.log(response)
okLayer.tableOperationSuccessMsg("批量删除成功");
okUtils.table.operationSuccessMsg("批量删除成功");
}).fail(function (error) {
console.log(error)
});
@ -169,7 +171,9 @@
})
$("#addUser").click(function () {
okLayer.open("添加用户", "user-add.html", "90%", "90%", true)
okLayer.open("添加用户", "user-add.html", "90%", "90%", function () {
$(".layui-laypage-btn")[0].click();
})
})
})
</script>