使用Jquery+EasyUI 进行框架项目开发案例讲解之三---角色管理源码分享


使用Jquery+EasyUI 进行框架项目开发案例讲解之三

角色管理源码分享 

    在上两篇文章

   《使用Jquery+EasyUI进行框架项目开发案例讲解之一---员工管理源码分享》 

  《使用Jquery+EasyUI 进行框架项目开发案例讲解之二---用户管理源码分享》

  我们分享了使用Jquery EasyUI来进行UI布局等开发的相关方法,也许你在使用EasyUI的过程过更熟练,有更方便快捷的技巧,我强烈建议你可以分享出来,大家共同进步、共同学习,谢谢!

  接下来我分享“角色管理”模块主要的核心代码,角色管理主界面如下图所示:

  首先是角色管理的UI界面aspx代码如下: 

<%@ Page Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="RoleAdmin.aspx.cs" Inherits="RDIFramework.WebApp.Modules.RoleAdmin" %>

<script src="../Scripts/jquery-checkbox.js" type="text/javascript"></script>
<script src="../Scripts/jQuery.Select.js" type="text/javascript"></script>
<script src="../Scripts/jquery.easyListSplitter.js" type="text/javascript"></script>
<script src="../Scripts/Business/RoleAdmin.js" type="text/javascript"></script>



<%=base.BuildToolBarButtons() %>   角色分类:    查询
<script type="text/javascript"> $(document).ready(function () { // 浏览器的高度和div的高度 var height = $(window).height(); var divHeight = $("#scolldiv").height(); //获取div对象 var divh = $("#scolldiv").get(0); //div高度大于屏幕高度把屏幕高度赋给div,并出现滚动条 if (divHeight > height - 40) { divh.style.height = height - 40; divh.style.overflow = "auto"; } $('#txtCategory').combobox({ url: 'handler/DataItemAdminHandler.ashx?action=GetCategory&categorycode=RoleCategory', method: 'get', valueField: 'ItemValue', textField: 'ItemName', editable: false, panelHeight: 'auto' }); }); </script>
 

  绑定当前登录用户所拥有的功能按钮列表代码如下:  

/// 
/// 获得页面的权限
/// 
private void GetPermission()
{           
    this.permissionAdd = this.IsAuthorized("RoleManagement.Add");
    this.permissionEdit = this.IsAuthorized("RoleManagement.Edit");
    this.permissionExport = this.IsAuthorized("RoleManagement.Export");
    this.permissionDelete = this.IsAuthorized("RoleManagement.Delete");
    this.permissionRoleUser = this.IsAuthorized("RoleManagement.RoleUser");
}

/// 
/// 加载工具栏
/// 
/// 工具栏HTML
public override string BuildToolBarButtons()
{
    StringBuilder sb = new StringBuilder();
    string linkbtn_template = "{4}";
    sb.Append("刷新 ");
    sb.Append("
"); sb.Append(string.Format(linkbtn_template, "add", "icon-group-add", permissionAdd ? "" : "disabled=\"True\"", "新增角色", "新增")); sb.Append(string.Format(linkbtn_template, "edit", "icon-group_edit", permissionEdit ? "" : "disabled=\"True\"", "修改选中角色", "修改")); sb.Append(string.Format(linkbtn_template, "del", "icon-group_delete", permissionDelete ? "" : "disabled=\"True\"", "删除选中角色", "删除")); sb.Append("
"); sb.Append(string.Format(linkbtn_template, "roleuser", "icon-group_link", permissionRoleUser ? "" : "disabled=\"True\"", "设置当前角色拥有的用户", "用户")); return sb.ToString(); } private void InitGrid() { this.DTRole = base.GetRoleScope(this.PermissionItemCode); this.gvRoleList.DataSource = this.DTRole; this.gvRoleList.DataBind(); } 

  核心业务逻辑完整JS代码如下: 

$(function () {
    addRole();
    editRole();
    delRole();

    $('#a_edit').click(function () {
        if ($(this).linkbutton('options').disabled == true) {
            return;
        }
        var i = $('table').data('tr_index');
        if (i > -1)
            $('.grid2 tr').eq(i).find("a[rel='edit']").click();
        else
            top.$('#notity').jnotifyAddMessage({ text: '请选择要编辑的数据.', permanent: false, type: 'warning' });
    });

    $('#a_del').click(function () {
        if ($(this).linkbutton('options').disabled == true) {
            return;
        }
        var i = $('table').data('tr_index');
        if (i > -1)
            $('.grid2 tr').eq(i).find("a[rel='delete']").click();
        else
            top.$('#notity').jnotifyAddMessage({ text: '请选择要删除的数据.', permanent: false, type: 'warning' });
    });

    $('#a_roleuser').click(function () {
        if ($(this).linkbutton('options').disabled == true) {
            return;
        }
        var i = $('table').data('tr_index');
        if (i > -1)
            $('.grid2 tr').eq(i).find("a[rel='setuser']").click();
        else
            top.$('#notity').jnotifyAddMessage({ text: '请选择要添加用户的角色.', permanent: false, type: 'warning' });
    });

    $('#a_refresh').click(function () {
        window.location = 'RoleAdmin.aspx';
    });

    using('linkbutton', function () {
        $('#a_roleuser').linkbutton({ text: "成员" });
    });

    accreditUsers(); //授权角色包含的用户
    searchUser();

    $('#txtCategory').combobox({
        onChange: function (newValue, oldValue) {
            $("#hidrolecategory").val(newValue) 
        }
    })
});

function scripthtmlStr() {
    var html = '
' html += '角色编号:
'; html += '角色名称:
'; html += '角色分类:
'; html += '有效性:  注:选中则启用该角色。
'; html += '角色描述: