自动化立体仓库 - WMS系统
lty
8 天以前 539a56279625242c497b4b4093f2defbb9d80334
src/main/webapp/static/js/role/role.js
@@ -1,6 +1,21 @@
var pageCurr;
var roleId;
var powerTreeData;
function getCols() {
    var t = typeof I18n !== 'undefined' ? I18n.t : function(k) { return k; };
    return [[
        {type: 'checkbox', fixed: 'left'}
        ,{field: 'id', title: 'ID', sort: true,align: 'center', fixed: 'left', width: 80}
        ,{field: 'code', align: 'center',title: t('role_code')}
        ,{field: 'name', align: 'center',title: t('role_name')}
        ,{field: 'leader$', align: 'center',title: t('leader')}
        // ,{field: 'level$', align: 'center',title: '角色等级'}
        ,{fixed: 'right', title: t('operation'), align: 'center', toolbar: '#operate', width:150}
    ]];
}
$(function (){
    $.ajax({
        url: baseUrl+"/power/list/auth",
@@ -25,48 +40,74 @@
    var layDate = layui.laydate;
    var form = layui.form;
    // 数据渲染
    tableIns = table.render({
        elem: '#role',
        headers: {token: localStorage.getItem('token')},
        url: baseUrl+'/role/list/auth',
        page: true,
        limit: 16,
        limits: [16, 30, 50, 100, 200, 500],
        toolbar: '#toolbar',
        cellMinWidth: 50,
        cols: [[
            {type: 'checkbox', fixed: 'left'}
            ,{field: 'id', title: 'ID', sort: true,align: 'center', fixed: 'left', width: 80}
            ,{field: 'code', align: 'center',title: '编码'}
            ,{field: 'name', align: 'center',title: '名称'}
            ,{field: 'leader$', align: 'center',title: '上级'}
            // ,{field: 'level$', align: 'center',title: '角色等级'}
    // Local translation helper
    var t = typeof I18n !== 'undefined' ? I18n.t : function(k) { return k; };
            ,{fixed: 'right', title:'操作', align: 'center', toolbar: '#operate', width:150}
        ]],
        request: {
            pageName: 'curr',
            pageSize: 'limit'
        },
        parseData: function (res) {
            return {
                'code': res.code,
                'msg': res.msg,
                'count': res.data.total,
                'data': res.data.records
    form.verify({
        required: function (value) {
            if (!value || $.trim(value) === '') {
                return typeof I18n !== 'undefined'
                    ? I18n.t('form_required')
                    : '必填项不能为空';
            }
        },
        response: {
            statusCode: 200
        },
        done: function(res, curr, count) {
            if (res.code === 403) {
                top.location.href = baseUrl+"/";
            }
            pageCurr=curr;
            limit();
        }
    });
    // 数据渲染
    var initTable = function() {
        tableIns = table.render({
            elem: '#role',
            headers: {token: localStorage.getItem('token')},
            url: baseUrl+'/role/list/auth',
            page: true,
            limit: 16,
            limits: [16, 30, 50, 100, 200, 500],
            toolbar: '#toolbar',
            cellMinWidth: 50,
            cols: getCols(),
            request: {
                pageName: 'curr',
                pageSize: 'limit'
            },
            parseData: function (res) {
                return {
                    'code': res.code,
                    'msg': res.msg,
                    'count': res.data.total,
                    'data': res.data.records
                }
            },
            response: {
                statusCode: 200
            },
            done: function(res, curr, count) {
                if (res.code === 403) {
                    top.location.href = baseUrl+"/";
                }
                pageCurr=curr;
                limit();
                if (typeof I18n !== 'undefined') {
                    I18n.updateLayuiPagination();
                } else {
                    $(document).one('i18n:ready', function() {
                        I18n.updateLayuiPagination();
                    });
                }
            }
        });
    }
    if (typeof I18n !== 'undefined' && I18n.isReady()) {
        initTable();
    } else {
        $(document).one('i18n:ready', initTable);
    }
    // Listen for language change
    $(document).on('i18n:languageChanged', function() {
        tableIns.reload({
            cols: getCols()
        });
    });
    // 监听排序事件
@@ -99,12 +140,13 @@
            case 'addData':
                layer.open({
                    type: 2,
                    title: '新增',
                    title: t('add'),
                    maxmin: true,
                    area: [top.detailWidth, top.detailHeight],
                    shadeClose: false,
                    content: 'role_detail.html',
                    success: function(layero, index){
                        if (typeof I18n !== 'undefined') I18n.updatePage(layero);
                       clearFormVal(layer.getChildFrame('#detail', index));
                        layer.iframeAuto(index);layer.style(index, {top: (($(window).height()-layer.getChildFrame('#data-detail', index).height())/3)+"px"});
                    }
@@ -125,9 +167,9 @@
                    ids.push(track.id);
                });
                if (ids.length === 0){
                    layer.msg('请选择数据');
                    layer.msg(t('please_select_data'));
                } else {
                    layer.confirm('确定删除'+(ids.length===1?'此':ids.length)+'条数据吗', function(){
                    layer.confirm(t('confirm_delete_prefix')+(ids.length===1?t('this'):ids.length)+t('confirm_delete_suffix'), function(){
                        $.ajax({
                            url: baseUrl+"/role/delete/auth",
                            headers: {'token': localStorage.getItem('token')},
@@ -149,7 +191,7 @@
                }
                break;
            case 'exportData':
                layer.confirm('确定导出Excel吗', {shadeClose: true}, function(){
                layer.confirm(t('confirm_export_excel'), {shadeClose: true}, function(){
                    var titles=[];
                    var fields=[];
                    obj.config.cols[0].map(function (col) {
@@ -197,12 +239,13 @@
            case 'detail':
                layer.open({
                    type: 2,
                    title: '详情',
                    title: t('detail'),
                    maxmin: true,
                    area: [top.detailWidth, top.detailHeight],
                    shadeClose: false,
                    content: 'role_detail.html',
                    success: function(layero, index){
                        if (typeof I18n !== 'undefined') I18n.updatePage(layero);
                        setFormVal(layer.getChildFrame('#detail', index), data, true);
                        top.convertDisabled(layer.getChildFrame('#data-detail :input', index), true);
                        layer.getChildFrame('#data-detail-submit,#prompt', index).hide();
@@ -215,12 +258,13 @@
            case 'edit':
                layer.open({
                    type: 2,
                    title: '修改',
                    title: t('modify'),
                    maxmin: true,
                    area: [top.detailWidth, top.detailHeight],
                    shadeClose: false,
                    content: 'role_detail.html',
                    success: function(layero, index){
                        if (typeof I18n !== 'undefined') I18n.updatePage(layero);
                        setFormVal(layer.getChildFrame('#detail', index), data, false);
                        top.convertDisabled(layer.getChildFrame('#data-detail :input', index), false);
                        layer.iframeAuto(index);layer.style(index, {top: (($(window).height()-layer.getChildFrame('#data-detail', index).height())/3)+"px"});
@@ -231,16 +275,17 @@
            case 'leader':
                var param = top.reObject(data).leader;
                if (param === undefined) {
                    layer.msg("无数据");
                    layer.msg(t('no_data'));
                } else {
                   layer.open({
                       type: 2,
                       title: '详情',
                       title: t('detail'),
                       maxmin: true,
                       area: [top.detailHeight, top.detailWidth],
                       shadeClose: false,
                       content: '../role/role_detail.html',
                       success: function(layero, index){
                           if (typeof I18n !== 'undefined') I18n.updatePage(layero);
                           $.ajax({
                               url: baseUrl+"/role/"+ param +"/auth",
                               headers: {'token': localStorage.getItem('token')},
@@ -267,12 +312,13 @@
                roleId = data.id;
                layer.open({
                    type: 2,
                    title: data.name + ' 权限分配',
                    title: data.name + ' ' + t('permission_assignment'),
                    maxmin: true,
                    area: [top.detailWidth/2, '85%'],
                    shadeClose: false,
                    content: 'role_power_detail.html',
                    success: function(layero, index){
                        if (typeof I18n !== 'undefined') I18n.updatePage(layero);
                    }
                });
                break;