SysJobNew.js 8.97 KB
let action = null;

layui.config({
    base: "/js/",
    version: 222
}).use(['system'], function () {
    var form = layui.form,
        $ = layui.jquery,
        system = layui.system,
        u = new system.u(),
        table = layui.table,
        areaName = 'job',
        tableName = 'SysJob';

    action = {
        addOptions: function () {
            var options = {
                fromId: "#modifyForm form",
                url: `/${areaName}/${tableName}/Ins`,
                submit: "submit(fromAdd)"
            }
            return options;
        },

        editOptions: function () {
            var options = {
                fromId: "#modifyForm form",
                url: `/${areaName}/${tableName}/Upd`,
                submit: "submit(fromUpdate)"
            }
            return options;
        },

        deleteOptions: function () {
            var options = {
                url: `/${areaName}/${tableName}/DelByIds`,
                keyId: "id"
            }
            return options;
        },

        exportOptions: function () {
            var options = {
                fromId: "listForm",
                url: `/${areaName}/${tableName}/Export`,
                isDefault: false,
                excelCols: {
                    head: app.data.cols
                }
            }
            return options;
        },

        queryOptions: function () {
            var options = {
                resetFrom: "form[lay-filter=listForm]",
                fromId: "listForm",
                urlExport: `/${areaName}/${tableName}/Export`,
                urlQuery: `/${areaName}/${tableName}/Load`,
                mainTable: app.data.tableIns
            }
            return options;
        },

        uploadOptions: function () {
            var options = {
                url: `/${areaName}/${tableName}/Import`,
                fromFile: "#excelfile",
                content: $("#ImportData")
            }
            return options;
        },

        editBefore: function (data, callBack) {
            form.val("modifyForm", data);
            //callBack是回调函数,如果editBefore有ajax 放在成功之后
            if (callBack != null) callBack();
        },

        addBefore: function (callBack) {
            //callBack是回调函数,如果editBefore有ajax 放在成功之后
            var methodNameData = app.data.selectOption.selectData["methodName"]
            if (methodNameData) {
                form.val("modifyForm", {
                    jobName: methodNameData[0].DictLabel
                });
            }
            if (callBack != null) callBack();
        },
        methodNameFromEvent: function (data) {
            debugger
            form.val("modifyForm", {
                jobName: data.text
            });
        },
        addSaveBefore: function (data, callBack) {
            if (callBack != null) callBack();
        },
        PauseOrResume: function (sysU, toolbarId, obj) {
            var checkStatus = table.checkStatus(toolbarId),
                data = checkStatus.data;
            if (data.length !== 1) {
                layer.alert(sysU.config.titleSelectOne, { icon: u.config.iconoError, shade: 0.4, time: u.config.errorTime });
                return false;
            }
            var ajaxConfig = {
                url: `/job/SysJob/PauseOrResume`,
                type: "post",
                data: { entity: checkStatus.data[0] },
                success: function (result) {
                    if (u.successBefore(result)) return;
                    if (checkStatus.data[0].status == "0") {
                        layer.msg('计划已暂停', { icon: u.config.iconoOk, shade: 0.4, time: u.config.errorTime });
                    }
                    else {
                        layer.msg('计划已启用', { icon: u.config.iconoOk, shade: 0.4, time: u.config.errorTime });
                    }
                    action.actionSuccess(app.data.tableElem)
                }
            };
            u.ajax(ajaxConfig);
        },

        //初始化定时器
        btnInit: function (sysU, toolbarId, obj) {
            layer.confirm(`确定初始化定时器吗?这将删除所有定时器相关记录表,请谨慎操作!`, { icon: 3, title: '提示' }, function () {
                var ajaxConfig = {
                    url: `/job/SysJob/ClearQrtz`,
                    type: "get",
                    success: function (result) {
                        layer.msg(result.Message, { icon: u.config.iconoOk, shade: 0.4, time: u.config.time });
                    }
                };
                sysU.ajax(ajaxConfig);
            });
        },

        //所有动作成功之后
        actionSuccess: (falg) => {
            u.refreshTable(app, u, null, falg);
        }
    }

    var app = {
        data: {
            cols: [[
                { checkbox: true, fixed: true },
                { field: 'id', width: 80, title: 'Id', hide: true, },
                { field: 'jobName', width: 150, title: '任务名称' },
                { field: 'jobGroup', width: 150, hide: true, title: '任务组名' },
                { field: 'methodName', width: 150, title: '任务方法' },
                { field: 'methodParams', width: 150, title: '参数' },
                { field: 'cronExpression', width: 150, title: 'cron执行表达式' },
                { field: 'jobSql', width: 150, title: 'SQL命令' },

                { field: 'lastFireTime', width: 150, title: '上次执行时间' },
                { field: 'nextFireTime', width: 150, title: '下次执行时间' },
                { field: 'misfirePolicy', width: 150, hide: true, title: '错误策略' },
                { field: 'status', width: 150, title: '状态', templet: function (d) { return GetDicLabel('status', 'DictValue', 'DictLabel', d.status) } },
                { field: 'remark', width: 150, hide: true, title: '备注信息' },

                { field: "createTime", width: 150, title: "建立时间" },
                { field: "createBy", width: 150, title: "建立者" },
                { field: "updateTime", width: 150, title: "更新时间" },
                { field: "updateBy", width: 150, title: "更新者" }
            ]],
            tableIns: null,
            tableElem: "mainList",

            selectOption: {
                methodName: {
                    SelType: "FromDict",
                    SelFrom: "jobtype",
                    SelLabel: "DictLabel",
                    SelValue: "DictValue",
                    Dom: [$("select[name='methodName']"), $("select[name='qMethodName']")]
                },
                status: {
                    SelType: "FromDict",
                    SelFrom: "sys_job_status",
                    SelModel: "status",
                    SelLabel: "DictLabel",
                    SelValue: "DictValue",
                    Dom: [$("[name='status']"), $("[name='qStatus']")]
                },
                //返回的数据 用于后续操作
                selectData: {

                }
            },
        },
        methods: {
            initTable: function () {
                let options = {
                    elem: "#" + app.data.tableElem,
                    url: `/${areaName}/${tableName}/Load`,
                    cols: u.columnRecord(app.data.tableElem, app.data.cols),
                    toolbar: '#toolbarTable',
                }
                app.data.tableIns = u.initTable(options);
            },
            initFrom: function () {
                u.initSelect(app.data.selectOption);
            }
        },
        registerEvent: function () {
            var cronExpression = $('.cronExpression')
            cronExpression.on('click', function () {
                u.openPage({
                    type: 2,
                    title: "编辑cron表达式",
                    area: ["900px", "620px"],
                    content: `/job/SysJob/cron`,
                    btn: ['保存', '关闭'],
                    yesBeforeCallBackFn: function (index, layero) {
                        var val = layer.getChildFrame('body', index).find('#cron').val();
                        if (!val) {
                            layer.alert("cron 表达式值不能为空", { icon: u.config.iconoError, shade: 0.4, time: u.config.errorTime });
                            return "-1"
                        }
                        return val;
                    },
                    successCallBackFn: function (layero, index) {
                        var val = $("input[name=cronExpression]").val()
                        layer.getChildFrame('body', index).find('#cron').val(val)
                    },
                    yesCallBackFn: function (result, CallBackFn) {
                        cronExpression.val(result);
                        CallBackFn();
                    },
                })
            });

        },
        init: function () {
            app.methods.initTable();
            app.methods.initFrom();
            app.registerEvent();
        }
    };
    app.init();
});