layui.use(['table', 'admin', 'ax', 'func'], function () { var $ = layui.$; var table = layui.table; var $ax = layui.ax; var admin = layui.admin; var func = layui.func; var form = layui.form; /** * 定时任务调度表管理 */ var SysJob = { tableId: "sysJobTable" }; /** * 初始化表格的列 */ SysJob.initColumn = function () { return [[ {type: 'checkbox'}, {field: 'id', hide: true, title: '任务ID'}, {field: 'jobName', sort: true, title: '任务名称'}, // {field: 'jobGroup', sort: true, title: '任务组名'}, {field: 'invokeTarget', sort: true, title: '调用目标字符串'}, {field: 'cronExpression', sort: true, title: 'cron执行表达式'}, // {field: 'misfirePolicy', sort: true, title: '计划执行错误策略'}, // {field: 'concurrent', sort: true, title: '是否并发执行(0允许 1禁止)'}, // {field: 'status', sort: true, title: '状态'}, {field: 'status', sort: true, templet: '#stateTpl', title: '状态'}, {field: 'createBy', sort: true, title: '创建者'}, {field: 'createTime', sort: true, title: '创建时间',width:160}, {field: 'updateBy', sort: true, title: '更新者'}, {field: 'updateTime', sort: true, title: '更新时间',width:160}, {field: 'remark', sort: true, title: '备注信息'}, {align: 'center', toolbar: '#tableBar', title: '操作'} ]]; }; /** * 点击查询按钮 */ SysJob.search = function () { var queryData = {}; queryData['jobName'] = $('#jobName').val(); queryData['status'] = $('#status').val(); table.reload(SysJob.tableId, { where: queryData, page: {curr: 1} }); }; /** * 跳转到添加页面 */ SysJob.jumpAddPage = function () { window.location.href = Feng.ctxPath + '/sysJob/add' }; /** * 跳转到编辑页面 * * @param data 点击按钮时候的行数据 */ SysJob.jumpEditPage = function (data) { window.location.href = Feng.ctxPath + '/sysJob/edit?id=' + data.id }; form.on('switch(status)', function (obj) { var id = obj.elem.value; var checked = obj.elem.checked ? 1 : 0; SysJob.changeStatus(id, checked); }); // 修改状态方法 SysJob.changeStatus = function (id, checked) { var ajax = new $ax(Feng.ctxPath + "/sysJob/editState", function (data) { Feng.success("修改成功!"); }, function (data) { Feng.error("修改失败!" + data.message); }); ajax.set("id", id); ajax.set("status", checked); ajax.start(); }; /** * 导出excel按钮 */ SysJob.exportExcel = function () { var checkRows = table.checkStatus(SysJob.tableId); if (checkRows.data.length === 0) { Feng.error("请选择要导出的数据"); } else { table.exportFile(tableResult.config.id, checkRows.data, 'xls'); } }; /** * 点击删除 * * @param data 点击按钮时候的行数据 */ SysJob.onDeleteItem = function (data) { var operation = function () { var ajax = new $ax(Feng.ctxPath + "/sysJob/delete", function (data) { Feng.success("删除成功!"); table.reload(SysJob.tableId); }, function (data) { Feng.error("删除失败!" + data.responseJSON.message + "!"); }); ajax.set("id", data.id); ajax.start(); }; Feng.confirm("是否删除?", operation); }; // 渲染表格 var tableResult = table.render({ elem: '#' + SysJob.tableId, url: Feng.ctxPath + '/sysJob/list', page: true, height: "full-158", cellMinWidth: 100, cols: SysJob.initColumn() }); // 搜索按钮点击事件 $('#btnSearch').click(function () { SysJob.search(); }); // 添加按钮点击事件 $('#btnAdd').click(function () { SysJob.jumpAddPage(); }); // 导出excel $('#btnExp').click(function () { SysJob.exportExcel(); }); // 工具条点击事件 table.on('tool(' + SysJob.tableId + ')', function (obj) { var data = obj.data; var layEvent = obj.event; if (layEvent === 'edit') { SysJob.jumpEditPage(data); } else if (layEvent === 'delete') { SysJob.onDeleteItem(data); } }); });