sysrole.js 4.14 KB

let action = null;
let app = null;
layui.config({
    base: "/js/",
    version: 44
}).use(['ztree','droptree','system'], function () {
    var form = layui.form,
        $ = layui.jquery,
        system = layui.system,
        u = new system.u(),
        layuimini = layui,
        areaName = "",
        tableName = "SysRole";

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

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

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

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

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

        uploadOptions: function () {
            var options = {
                url: `/${tableName}/Import`
            }
            return options;
        },

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

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

        //所有动作成功之后
        actionSuccess: (falg, toolbarId) => {

        }
    }

    app = {
        data: {
            cols: [[
                { checkbox: true, fixed: true },
                { field: "Id", width: 80, hide: true, title: "Id" },
                { field: "RoleName", width: 250, sort: true, fixed: false, hide: false, title: "角色名", noExel: true },
                { field: "Remark", width: 150, title: "备注" },

                { field: 'Created', width: 150, title: '创建时间' },
                { field: "CreatedBy", width: 150,  title: "创建人" },
                { field: "Updated", width: 150,  title: "更新时间" },
                { field: "UpdatedBy", width: 150,  title: "更新人" }
            ]],
            urlTable: `/${tableName}/Load`,
            tableIns: null,
            tableElem: "mainList"
        },
        methods: {
            initTable: function (options) {
                var config = {};
                if (options != undefined) $.extend(config, options);
                let opt = {
                    cols: u.columnRecord(app.data.tableElem, app.data.cols),
                    elem: "#" + app.data.tableElem,
                    url: app.data.urlTable,
                    toolbar: '#toolbarTable',
                    where: config,
                    menuModule: tableName
                }
                app.data.tableIns = u.initTable(opt);
            },
            initTree: function () {
                layuimini.droptree('/SysPermission/GetAllPermission', "#MenuAuthority", "#MenuAuthoritys");
            }
        },
        registerEvent: function () {

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