LoadExecute.js

//是否可编辑
var IsEdit = true;

//$("#MenuNav a").hide();

var UserJurisdictionV;
LoadPageJurisdiction();

//获取用户角色页面权限
function GetUserRolePageJurisdiction() {

    if (window.location.pathname.indexOf("TipsPage") > 0) {
        return;
    }

    //alert(1);
    //PathName: window.location.pathname 
    $.post("/UserList/GetUserJurisdictionV", {}, function (data) {
        //alert(2);
        //window.top.location.href = "/Administration/TipsPage/Index";
        //console.log(data);
        //console.log(!objValidate.NotNull(data));
        //if (!objValidate.NotNull(data)) {

        //    //window.top.location.href = "/Administration/TipsPage/Index";
        //    return;
        //}

        //if (!objValidate.NotNull(data.Jurisdiction)) {

        //    //window.top.location.href = "/Administration/TipsPage/Index";
        //    return;
        //}

        //var JsonData = $.parseJSON(data);

        //add,edit,delete,view,upload,download"



        var data = data.data;
        UserJurisdictionV = data;

        objSessionStorage.SetJsonData("UserJurisdictionV", UserJurisdictionV);

        LoadPageJurisdiction();

    });


}


function LoadPageJurisdiction() {

    //console.log(UserJurisdictionV);
    UserJurisdictionV = objSessionStorage.GetJsonData("UserJurisdictionV");

    if (!objValidate.NotNull(UserJurisdictionV)) {
        GetUserRolePageJurisdiction();
        return;
    }

    var data = UserJurisdictionV;

    //菜单权限
    for (var i = 0; i < data.length; i++) {

        //console.log(data[i].PathName);
        if (data[i].PathName.indexOf("IPList") != -1 && data[i].Operations.indexOf("View") != -1) {
            $(".View-IPList").css("display", "inline-block");
        }

        if (data[i].PathName == "/SegmentList/index" && data[i].Operations.indexOf("View") != -1) {
            $(".View-SegmentList").css("display", "inline-block");
        }

        if (data[i].PathName == "/PurposeList/index" && data[i].Operations.indexOf("View") != -1) {
            $(".View-PurposeList").css("display", "inline-block");
        }

        if (data[i].PathName == "/UserList/index" && data[i].Operations.indexOf("View") != -1) {
            $(".View-UserList").css("display", "inline-block");
        }

        if (data[i].PathName == "/GroupList/index" && data[i].Operations.indexOf("View") != -1) {
            $(".View-GroupList").css("display", "inline-block");
        }

        if (data[i].PathName == "/Enumeration/index" && data[i].Operations.indexOf("View") != -1) {
            $(".View-Enumeration").css("display", "inline-block");
        }

        if (data[i].PathName == "/SystemLog/index" && data[i].Operations.indexOf("View") != -1) {
            $(".View-SystemLog").css("display", "inline-block");
        }
    }


    data = data.find((item) => item.PathName == window.location.pathname);


    if (!objValidate.NotNull(data) && window.location.pathname != "/Login/Welcome") {

        layer.alert("无权限查看此页面", {
            icon: 2,
            shadeClose: true,
            title: '提示'
        }, function () {
            window.location.href = "/Login/Welcome";
        });

    } else {
        return false;
    }

    //以下为功能权限
    if (data.Operations.indexOf("View") == -1) {
        $(".View").hide();
    }

    if (data.Operations.indexOf("Add") == -1) {
        //$(".Add").hide();
        $(".Add").prop("disabled", "disabled").addClass("layui-btn-disabled");
    }
    if (data.Operations.indexOf("Edit") == -1) {
        //$(".Edit").hide();
        $(".Edit").prop("disabled", "disabled").addClass("layui-btn-disabled");
        IsEdit = false;
    }
    if (data.Operations.indexOf("Delete") == -1) {
        //$(".Delete").hide();
        $(".Delete").prop("disabled", "disabled").addClass("layui-btn-disabled");
    }

    //if (data.Operations.indexOf("upload") == -1) {
    //    //$(".upload").hide();
    //    $(".upload").prop("disabled", "disabled").addClass("layui-btn-disabled");
    //}
    //if (data.Operations.indexOf("download") == -1) {
    //    //$(".download").hide();
    //    $(".download").prop("disabled", "disabled").addClass("layui-btn-disabled");
    //}


}

//主要是数据表格渲染完成后执行  表格中的操作权限控制
function LoadFunJurisdiction() {

    UserJurisdictionV = objSessionStorage.GetJsonData("UserJurisdictionV");

    var data = UserJurisdictionV;

    //console.log(window.location.pathname);
    //console.log(data);

    data = data.find((item) => item.PathName == window.location.pathname);

    if (!objValidate.NotNull(data)) {

        return;
    }
    //console.log(data);
    //以下为功能权限
    if (data.Operations.indexOf("View") == -1) {
        $(".View").hide();
    }

    if (data.Operations.indexOf("Add") == -1) {
        //$(".Add").hide();
        $(".Add").prop("disabled", "disabled").addClass("layui-btn-disabled");
    }
    if (data.Operations.indexOf("Edit") == -1) {
        //$(".Edit").hide();
        $(".Edit").prop("disabled", "disabled").addClass("layui-btn-disabled");
        IsEdit = false;
    }
    if (data.Operations.indexOf("Delete") == -1) {
        //$(".Delete").hide();
        $(".Delete").prop("disabled", "disabled").addClass("layui-btn-disabled");
    }

}

 

posted @ 2023-05-04 14:26  妖狐鬼魅  阅读(12)  评论(0编辑  收藏  举报