我们分享了使用Jquery EasyUI来进行ASP.NET项目的开发的相关方法,每一个模块都有其共用性,细细理解与掌握,我相信使用EasyUI进行开发还是相当方便的,每篇文章,我们力求通俗易懂。

  接下来我分享“模块(菜单)”模块主要的核心代码,“模块(菜单)”管理模块同样使用了EasyUI的TreeGrid控件,对于EasyUI的TreeGrid控件的具体使用方法可以参见上一篇 《使用Jquery+EasyUI 进行框架项目开发案例讲解之三---组织机构源码分享》的说明,或看相关的Easy UI的帮助文件,同时,我们可以看一下如何做模块图标的选择界面,模块(菜单)主界面如下图所示:  

  一、“模块(菜单)”管理主界面UI的ASPX代码如下:

 

[html] view plaincopy在CODE上查看代码片派生到我的代码片
 
  1. <%@ Page Language="C#" MasterPageFile="~/Site.Master"  AutoEventWireup="true" CodeBehind="ModuleAdmin.aspx.cs" Inherits="RDIFramework.WebApp.Modules.ModuleAdmin" %>  
  2.   
  3. <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">  
  4. </asp:Content>  
  5. <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">        
  6.      <div id="toolbar">  
  7.         <%=base.BuildToolBarButtons()%>  
  8.     </div>  
  9.     <table id="navGrid"></table>  
  10.       
  11.     <script type="text/javascript" src="../Scripts/Linqjs/linq.min.js"></script>  
  12.     <script type="text/javascript" src="../Scripts/Linqjs/linq.jquery.js"></script>  
  13.     <script type="text/javascript" src="../Scripts/Business/ModuleAdmin.js?v=5"></script>  
  14. </asp:Content>  

 

 

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

 

[csharp] view plaincopy在CODE上查看代码片派生到我的代码片
 
  1. private bool permissionUserModulePermission = false;  
  2.        private bool permissionRoleModulePermission = false;  
  3.        private bool permissionOrganizeModulePermission = false;  
  4.        private bool permissionModuleConfig = false;  
  5.   
  6.        protected void Page_Load(object sender, EventArgs e)  
  7.        {  
  8.            if (!Page.IsPostBack)  
  9.            {  
  10.                this.GetPermission();  
  11.            }  
  12.        }  
  13.   
  14.        /// <summary>  
  15.        /// 获得页面的权限  
  16.        /// </summary>  
  17.        private void GetPermission()  
  18.        {  
  19.            this.permissionAdd = this.IsAuthorized("ModuleManagement.Add");  
  20.            this.permissionEdit = this.IsAuthorized("ModuleManagement.Edit");  
  21.            this.permissionDelete = this.IsAuthorized("ModuleManagement.Delete");  
  22.            this.permissionExport = this.IsAuthorized("ModuleManagement.Export");  
  23.            //this.permissionAccredit = this.IsAuthorized("UserManagement.Accredit");  
  24.            this.permissionUserModulePermission = this.IsAuthorized("ModuleManagement.UserModulePermission");  
  25.            this.permissionRoleModulePermission = this.IsAuthorized("ModuleManagement.RoleModulePermission");  
  26.            this.permissionOrganizeModulePermission = this.IsAuthorized("ModuleManagement.OrganizeModulePermission") && SystemInfo.EnableOrganizePermission;  
  27.            this.permissionModuleConfig = this.IsAuthorized("ModuleManagement.ModuleConfig");  
  28.        }  
  29.   
  30.        /// <summary>  
  31.        /// 加载工具栏  
  32.        /// </summary>  
  33.        /// <returns>工具栏HTML</returns>  
  34.        public override string BuildToolBarButtons()  
  35.        {  
  36.            StringBuilder sb = new StringBuilder();  
  37.            string linkbtn_template = "<a id=\"a_{0}\" class=\"easyui-linkbutton\" style=\"float:left\"  plain=\"true\" href=\"javascript:;\" icon=\"{1}\"  {2} title=\"{3}\">{4}</a>";  
  38.            sb.Append("<a id=\"a_refresh\" class=\"easyui-linkbutton\" style=\"float:left\"  plain=\"true\" href=\"javascript:;\" icon=\"icon-reload\"  title=\"重新加载\">刷新</a> ");  
  39.            sb.Append("<div class='datagrid-btn-separator'></div> ");  
  40.            sb.Append(string.Format(linkbtn_template, "add", "icon-tab_add", permissionAdd ? "" : "disabled=\"True\"", "新增模块(菜单)", "新增"));  
  41.            sb.Append(string.Format(linkbtn_template, "edit", "icon-tab_edit", permissionEdit ? "" : "disabled=\"True\"", "修改选中的模块(菜单)", "修改"));  
  42.            sb.Append(string.Format(linkbtn_template, "delete", "icon-tab_delete", permissionDelete ? "" : "disabled=\"True\"", "删除选中的模块(菜单)", "删除"));  
  43.            sb.Append("<div class='datagrid-btn-separator'></div> ");  
  44.            //sb.Append(string.Format(linkbtn_template, "move", "icon-shape_move_forwards", permissionMove ? "" : "disabled=\"True\"", "移动选中的模块(菜单)", "移动"));  
  45.            sb.Append(string.Format(linkbtn_template, "export", "icon-tab_go", permissionExport ? "" : "disabled=\"True\"", "导出模块(菜单)数据", "导出"));  
  46.            sb.Append("<div class='datagrid-btn-separator'></div> ");  
  47.            sb.Append(string.Format(linkbtn_template, "setusermodulepermission", "icon-user_key", permissionUserModulePermission ? "" : "disabled=\"True\"", "设置用户的模块(菜单)访问权限", "用户模块权限"));  
  48.            sb.Append(string.Format(linkbtn_template, "setrolemodulepermission", "icon-group_key", permissionRoleModulePermission ? "" : "disabled=\"True\"", "设置角色的模块(菜单)访问权限", "角色模块权限"));  
  49.            sb.Append("<div class='datagrid-btn-separator'></div> ");  
  50.            sb.Append(string.Format(linkbtn_template, "moduleconfig", "icon-table_gear", permissionRoleModulePermission ? "" : "disabled=\"True\"", "设置模块的可用性", "模块配置"));  
  51.            return sb.ToString();  
  52.        }  

 

三、绑定模块主wldmTreeGrid 的JS代码如下:  

 

[javascript] view plaincopy在CODE上查看代码片派生到我的代码片
 
  1. var grid = {  
  2.     databind: function (winsize) {  
  3.         navgrid = $('#navGrid').treegrid({  
  4.             toolbar: '#toolbar',  
  5.             title: '模块(菜单)列表',  
  6.             iconCls: 'icon icon-chart_organisation',  
  7.             width: winsize.width,  
  8.             height: winsize.height,  
  9.             nowrap: false,  
  10.             rownumbers: true,  
  11.             //animate: true,  
  12.             resizable: true,  
  13.             collapsible: false,  
  14.             url: actionUrl,  
  15.             idField: 'Id',  
  16.             treeField: 'FullName',  
  17.             frozenColumns: [[  
  18.                 { title: '模块(菜单)名称', field: 'FullName', width: 200 },  
  19.                 { title: '编码', field: 'Code', width: 130 }  
  20.             ]],  
  21.             columns: [[  
  22.                 { title: 'Id', field: 'Id', hidden: true },  
  23.                 { title: 'ParentId', field: 'ParentId', hidden: true },  
  24.                 { title: '模块分类', field: 'Category', width: 100 },  
  25.                 { title: '图标', field: 'IconCss', width: 130, hidden: true },  
  26.                 { title: 'Web链接地址', field: 'NavigateUrl', width: 200 },  
  27.                 { title: 'WinForm程序集', field: 'AssemblyName', width: 150 },  
  28.                 { title: 'WinForm窗体', field: 'FormName', width: 200 },  
  29.                 {  
  30.                     title: '公共', field: 'IsPublic', width: 50, align: 'center', formatter: function (v, d, i) {  
  31.                         return '<img src="http://images.cnblogs.com/' + (v ? "checkmark.gif" : "checknomark.gif") + '" />';  
  32.                     }  
  33.                 },  
  34.                 { title: '有效', field: 'Enabled', width: 50, align: 'center', formatter: imgcheckbox },                  
  35.                 { title: 'AllowEdit', field: 'AllowEdit', hidden: true },  
  36.                 { title: 'AllowDelete', field: 'AllowDelete', hidden: true },  
  37.                 { title: '排序', field: 'SortCode', width: 80 },  
  38.                 { title: '备注', field: 'Description', width: 500 }  
  39.             ]]  
  40.         });  
  41.     },  
  42.     reload: function () {  
  43.         navgrid.treegrid('reload');  
  44.     },  
  45.     selected: function () {  
  46.         return navgrid.treegrid('getSelected');  
  47.     }  
  48. };  
  49.   
  50. var imgcheckbox = function (cellvalue, options, rowObject) {  
  51.     return cellvalue ? '<img src="/css/icon/ok.png" alt="正常" title="正常" />' : '<img src="/css/icon/stop.png" alt="禁用" title="禁用" />';  
  52. }  

 

四、添加与模块(菜单)主界面  

  代码如下:  

 

[javascript] view plaincopy在CODE上查看代码片派生到我的代码片
 
  1. add: function () {  
  2.         if ($(this).linkbutton('options').disabled == true) {  
  3.             return;  
  4.         }  
  5.         var addDialog = top.$.hDialog({  
  6.             href: formUrl, title: '添加模块(菜单)', iconCls: 'icon-tab_add', width: 490, height: 550,  
  7.             onLoad: function () {  
  8.                 crud.bindCtrl();  
  9.                 crud.bindCategory();  
  10.                 var row = grid.selected();  
  11.                 if (row) {  
  12.                     top.$('#txt_ParentId').combotree('setValue', row.ParentId);  
  13.                 }  
  14.             },  
  15.             submit: function () {  
  16.                 if (top.$('#uiform').validate().form()) {  
  17.                     //var param = createParam('add', '0');  
  18.                     var vcategory = top.$('#txt_Category').combobox('getValue');  
  19.                     var vparentid = top.$('#txt_ParentId').combobox('getValue');  
  20.                     var param = 'action=Add&vcategory=' + vcategory + '&vparentid=' + vparentid + '&' + top.$('#uiform').serialize();  
  21.                     $.ajaxjson(actionUrl, param, function (d) {  
  22.                         if (d.Success) {  
  23.                             msg.ok(d.Message);  
  24.                             addDialog.dialog('close');  
  25.                             grid.reload();  
  26.                         } else {  
  27.                             MessageOrRedirect(d);  
  28.                         }  
  29.                     });  
  30.                 }  
  31.             }  
  32.         });  
  33.     },  
  34.     edit: function () {  
  35.         if ($(this).linkbutton('options').disabled == true) {  
  36.             return;  
  37.         }  
  38.         var row = grid.selected();  
  39.         if (row) {  
  40.             var editDailog = top.$.hDialog({  
  41.                 href: formUrl, title: '修改模块(菜单)', iconCls: 'icon-tab_edit', width: 490, height: 550,  
  42.                 onLoad: function () {  
  43.                     crud.bindCtrl(row.Id);  
  44.                     crud.bindCategory();  
  45.                     top.$('#txt_Code').val(row.Code);  
  46.                     top.$('#txt_FullName').val(row.FullName);  
  47.                     top.$('#txt_Category').combobox('setValue', row.Category);  
  48.                     top.$('#txt_ParentId').combotree('setValue', row.ParentId);  
  49.                     top.$('#txt_NavigateUrl').val(row.NavigateUrl);  
  50.                     top.$('#txt_IconCss').val(row.IconCss);  
  51.                     //top.$('#smallIcon').attr('class', "icon " + row.IconCss);  
  52.                     top.$('#smallIcon').attr('class', row.IconCss);  
  53.                     top.$('#txt_AssemblyName').val(row.AssemblyName);  
  54.                     top.$('#txt_FormName').val(row.FormName);  
  55.                     top.$('#chk_Enabled').attr('checked', row.Enabled == "1");  
  56.                     top.$('#chk_IsPublic').attr('checked', row.IsPublic == "1");  
  57.                     top.$('#chk_Expand').attr('checked', row.Expand == "1");  
  58.                     top.$('#chk_AllowEdit').attr('checked', row.AllowEdit == "1");  
  59.                     top.$('#chk_AllowDelete').attr('checked', row.AllowDelete == "1");  
  60.                     top.$('#txt_Description').val(row.Description);  
  61.                     top.$('#txt_IconUrl').val(row.IconUrl);  
  62.                 },  
  63.                 submit: function () {  
  64.                     if (top.$('#uiform').validate().form()) {  
  65.                         //保存时判断当前节点所选的父节点,不能为当前节点的子节点,这样就乱套了....  
  66.                         var treeParentId = top.$('#txt_ParentId').combotree('tree'); // 得到树对象  
  67.                         var node = treeParentId.tree('getSelected');  
  68.                         if (node) {  
  69.                             var nodeParentId = treeParentId.tree('find', row.Id);  
  70.                             var children = treeParentId.tree('getChildren', nodeParentId.target);  
  71.                             var nodeIds = '';  
  72.                             var isFind = 'false';  
  73.                             for (var index = 0; index < children.length; index++) {  
  74.                                 if (children[index].id == node.id) {  
  75.                                     isFind = 'true';  
  76.                                     break;  
  77.                                 }  
  78.                             }  
  79.   
  80.                             if (isFind == 'true') {  
  81.                                 top.$.messager.alert('温馨提示', '请选择父节点元素!', 'warning');  
  82.                                 return;  
  83.                             }  
  84.                         }  
  85.   
  86.                         var vcategory = top.$('#txt_Category').combobox('getValue');  
  87.                         var vparentid = top.$('#txt_ParentId').combobox('getValue');  
  88.                         var query = 'action=Edit&vcategory=' + vcategory + '&vparentid=' + vparentid + '&KeyId=' + row.Id + '&' + top.$('#uiform').serialize();  
  89.                         $.ajaxjson(actionUrl, query, function (d) {  
  90.                             if (d.Success) {  
  91.                                 msg.ok(d.Message);  
  92.                                 editDailog.dialog('close');  
  93.                                 grid.reload();  
  94.                             } else {  
  95.                                 MessageOrRedirect(d);  
  96.                             }  
  97.                         });  
  98.                     }  
  99.                 }  
  100.             });  
  101.   
  102.   
  103.         } else {  
  104.             msg.warning('请选择要修改菜单!');  
  105.             return false;  
  106.         }  
  107.         return false;  
  108.     }  

 

在模块(菜单)编辑与新增界面上,我们可以设置模块的图标,设置模块图标如下图所示:

  这个是如何实现的呢?

  首先准备图标的基页面,截取部分格式如下,保存为一个html文件,如:iconlist.htm:  

 

[html] view plaincopy在CODE上查看代码片派生到我的代码片
 
  1. <ul id="iconlist" style="margin:0px;padding:0px; list-style-type:none;">  
  2. <li title="/css/icon/accept.png"><span class="icon icon-accept"</span></li>  
  3. <li title="/css/icon/add.png"><span class="icon icon-add"</span></li>  
  4. <li title="/css/icon/advancedsettings.png"><span class="icon icon-advancedsettings"</span></li>  
  5. <li title="/css/icon/advancedsettings2.png"><span class="icon icon-advancedsettings2"</span></li>  
  6. <li title="/css/icon/anchor.png"><span class="icon icon-anchor"</span></li>  
  7. <li title="/css/icon/application.png"><span class="icon icon-application"</span></li>  
  8. <li title="/css/icon/application_delete.png"><span class="icon icon-application_delete"</span></li>  
  9. <li title="/css/icon/application_double.png"><span class="icon icon-application_double"</span></li>  
  10. <li title="/css/icon/application_edit.png"><span class="icon icon-application_edit"</span></li>  
  11. <li title="/css/icon/application_error.png"><span class="icon icon-application_error"</span></li>  
  12. <li title="/css/icon/application_form.png"><span class="icon icon-application_form"</span></li>  
  13. <li title="/css/icon/application_form_add.png"><span class="icon icon-application_form_add"</span></li>  
  14. <li title="/css/icon/application_form_delete.png"><span class="icon icon-application_form_delete"</span></li>  
  15. <li title="/css/icon/application_form_edit.png"><span class="icon icon-application_form_edit"</span></li>  
  16. <li title="/css/icon/application_form_magnify.png"><span class="icon icon-application_form_magnify"</span></li>  
  17. <li title="/css/icon/application_get.png"><span class="icon icon-application_get"</span></li>  
  18. <li title="/css/icon/application_go.png"><span class="icon icon-application_go"</span></li>  
  19. <li title="/css/icon/application_home.png"><span class="icon icon-application_home"</span></li>  
  20. <li title="/css/icon/application_key.png"><span class="icon icon-application_key"</span></li>  
  21. <li title="/css/icon/application_lightning.png"><span class="icon icon-application_lightning"</span></li>  
  22. <ul>  

 

然后在我们的js中调用这个html做相应的处理即可了,js部分代码为:

 

[javascript] view plaincopy在CODE上查看代码片派生到我的代码片
 
  1. var showIcon = function () {  
  2.     top.$('#selecticon').click(function () {  
  3.         var iconDialog = top.$.hDialog({  
  4.             iconCls: 'icon-application_view_icons',  
  5.             href: '/css/iconlist.htm?v=' + Math.random(),  
  6.             title: '选取图标', width: 800, height: 600, showBtns: false,  
  7.             onLoad: function () {  
  8.                 top.$('#iconlist li').attr('style', 'float:left;border:1px solid #fff;margin:2px;width:16px;cursor:pointer').click(function () {  
  9.                     //var iconCls = top.$(this).find('span').attr('class').replace('icon ', '');  
  10.                     var iconCls = top.$(this).find('span').attr('class');  
  11.                     top.$('#txt_IconCss').val(iconCls);  
  12.                     top.$('#txt_IconUrl').val(top.$(this).attr('title'));  
  13.                     //top.$('#smallIcon').attr('class', "icon " + iconCls);  
  14.                     top.$('#smallIcon').attr('class', iconCls);  
  15.   
  16.                     iconDialog.dialog('close');  
  17.                 }).hover(function () {  
  18.                     top.$(this).css({ 'border': '1px solid red' });  
  19.                 }, function () {  
  20.                     top.$(this).css({ 'border': '1px solid #fff' });  
  21.                 });  
  22.             }  
  23.         });  
  24.     });  
  25. };  

 

五、用户模块(菜单)权限批量设置

  用户模块(菜单)权限功能项用于设置那些用户可以访问那些模块,那些用户不能访问那些模块。用户模块(菜单)权限设置如下图用户模块(菜单)权限集中设置。左侧列出框架的所有有效用户,右侧为模块(菜单)项,选中相应的模块后保存,即可为当前选中用户授予模块的访问权限。

  js代码如下: 

 

[javascript] view plaincopy在CODE上查看代码片派生到我的代码片
 
  1. userModulePermissionBatchSet: function () { //用户模块(菜单)权限批量设置  
  2.         if ($(this).linkbutton('options').disabled == true) {  
  3.             return;  
  4.         }  
  5.         var userGrid;  
  6.         var curUserModuleIds = []; //当前所选用户所拥有的模块ID  
  7.         var setDialog = top.$.hDialog({  
  8.             title: '用户模块(菜单)权限批量设置',  
  9.             width: 670, height: 600, iconCls: 'icon-user_key', //cache: false,  
  10.             href: "Modules/html/PermissionBacthSetForm.htm?n=" + Math.random(),  
  11.             onLoad: function () {  
  12.                 using('panel', function () {  
  13.                     top.$('#panelTarget').panel({ title: '模块(菜单)', iconCls: 'icon-org', height: $(window).height() - 3 });  
  14.                 });  
  15.   
  16.                 userGrid = top.$('#leftnav').datagrid({  
  17.                     title: '所有用户',  
  18.                     url: 'Modules/handler/UserAdminHandler.ashx',  
  19.                     nowrap: false, //折行  
  20.                     //fit: true,  
  21.                     rownumbers: true, //行号  
  22.                     striped: true, //隔行变色  
  23.                     idField: 'Id', //主键  
  24.                     singleSelect: true, //单选  
  25.                     frozenColumns: [[]],  
  26.                     columns: [[  
  27.                         { title: '登录名', field: 'UserName', width: 120, align: 'left' },  
  28.                         { title: '用户名', field: 'RealName', width: 150, align: 'left' }  
  29.                     ]],  
  30.                     onLoadSuccess: function (data) {  
  31.                         top.$('#rightnav').tree({  
  32.                             cascadeCheck: false, //联动选中节点  
  33.                             checkbox: true,  
  34.                             lines: true,  
  35.                             url: 'Modules/handler/ModuleAdminHandler.ashx?action=GetModuleTree',  
  36.                             onSelect: function (node) {  
  37.                                 top.$('#rightnav').tree('getChildren', node.target);  
  38.                             }  
  39.                         });  
  40.                         top.$('#leftnav').datagrid('selectRow', 0);  
  41.                     },  
  42.                     onSelect: function (rowIndex, rowData) {  
  43.                         curUserModuleIds = [];  
  44.                         var query = 'action=GetModuleByUserId&userid=' + rowData.Id;  
  45.                         $.ajaxtext('handler/PermissionHandler.ashx', query, function (data) {  
  46.                             var moduelTree = top.$('#rightnav');  
  47.                             moduelTree.tree('uncheckedAll');  
  48.                             if (data == '' || data.toString() == '[object XMLDocument]') {  
  49.                                 return;  
  50.                             }  
  51.                             curUserModuleIds = data.split(',');  
  52.                             for (var i = 0; i < curUserModuleIds.length; i++) {  
  53.                                 var node = moduelTree.tree('find', curUserModuleIds[i]);  
  54.                                 if (node)  
  55.                                     moduelTree.tree("check", node.target);  
  56.                             }  
  57.                         });  
  58.                     }  
  59.                 });  
  60.             },  
  61.             submit: function () {  
  62.                 var allSelectModuledIds = permissionMgr.getUserSelectedModule().split(',');  
  63.                 var grantModuleIds = '';  
  64.                 var revokeModuleIds = '';  
  65.                 var flagRevoke = 0;  
  66.                 var flagGrant = 0;  
  67.                 while (flagRevoke < curUserModuleIds.length) {  
  68.                     if ($.inArray(curUserModuleIds[flagRevoke], allSelectModuledIds) == -1) {  
  69.                         revokeModuleIds += curUserModuleIds[flagRevoke] + ','; //得到收回的权限列表  
  70.                     }  
  71.                     ++flagRevoke;  
  72.                 }  
  73.   
  74.                 while (flagGrant < allSelectModuledIds.length) {  
  75.                     if ($.inArray(allSelectModuledIds[flagGrant], curUserModuleIds) == -1) {  
  76.                         grantModuleIds += allSelectModuledIds[flagGrant] + ','; //得到授予的权限列表  
  77.                     }  
  78.                     ++flagGrant;  
  79.                 }  
  80.   
  81.                 var query = 'action=SetUserModulePermission&userid=' + top.$('#leftnav').datagrid('getSelected').Id + '&grantIds=' + grantModuleIds + "&revokeIds=" + revokeModuleIds;  
  82.                 $.ajaxjson('handler/PermissionHandler.ashx', query, function (d) {  
  83.                     if (d.Data > 0) {  
  84.                         msg.ok('设置成功!');  
  85.                     }  
  86.                     else {  
  87.                         alert(d.Message);  
  88.                     }  
  89.                 });  
  90.             }  
  91.         });  
  92.     }  

 

六、角色模块(菜单)权限批量设置

   角色模块(菜单)操作权限用于设置那些角色拥有那些操作(功能)权限,那些角色不拥有那些操作(功能)权限。如下图所示,左侧列出框架的所有有效角色,右侧为相应的模块(菜单),选中相应的模块(菜单)后保存,即可为当前选中角色授予相应的模块(菜单)可访问的控制。

  js部分代码如下:  

 

[javascript] view plaincopy在CODE上查看代码片派生到我的代码片
 
  1. roleModulePermissionBatchSet: function () { //角色模块(菜单)权限批量设置  
  2.         if ($(this).linkbutton('options').disabled == true) {  
  3.             return;  
  4.         }  
  5.         var roleGrid;  
  6.         var curRoleModuleIds = []; //当前所选角色所拥有的模块ID  
  7.         var setDialog = top.$.hDialog({  
  8.             title: '角色模块(菜单)权限批量设置',  
  9.             width: 670, height: 600, iconCls: 'icon-group_key', //cache: false,  
  10.             href: "Modules/html/PermissionBacthSetForm.htm?n=" + Math.random(),  
  11.             onLoad: function () {  
  12.                 using('panel', function () {  
  13.                     top.$('#panelTarget').panel({ title: '模块(菜单)', iconCls: 'icon-org', height: $(window).height() - 3 });  
  14.                 });  
  15.                 roleGrid = top.$('#leftnav').datagrid({  
  16.                     title: '所有角色',  
  17.                     url: 'Modules/handler/RoleAdminHandler.ashx?action=getrolelist',  
  18.                     nowrap: false, //折行  
  19.                     //fit: true,  
  20.                     rownumbers: true, //行号  
  21.                     striped: true, //隔行变色  
  22.                     idField: 'Id', //主键  
  23.                     singleSelect: true, //单选  
  24.                     frozenColumns: [[]],  
  25.                     columns: [[  
  26.                         { title: '角色编码', field: 'Code', width: 120, align: 'left' },  
  27.                         { title: '角色名称', field: 'RealName', width: 150, align: 'left' }  
  28.                     ]],  
  29.                     onLoadSuccess: function (data) {  
  30.                         top.$('#rightnav').tree({  
  31.                             cascadeCheck: false, //联动选中节点  
  32.                             checkbox: true,  
  33.                             lines: true,  
  34.                             url: 'Modules/handler/ModuleAdminHandler.ashx?action=GetModuleTree',  
  35.                             onSelect: function (node) {  
  36.                                 top.$('#rightnav').tree('getChildren', node.target);  
  37.                             }  
  38.                         });  
  39.                         top.$('#leftnav').datagrid('selectRow', 0);  
  40.                     },  
  41.                     onSelect: function (rowIndex, rowData) {  
  42.                         curRoleModuleIds = [];  
  43.                         var query = 'action=GetModuleByRoleId&roleid=' + rowData.Id;  
  44.                         $.ajaxtext('handler/PermissionHandler.ashx', query, function (data) {  
  45.                             var moduelTree = top.$('#rightnav');  
  46.                             moduelTree.tree('uncheckedAll');  
  47.                             if (data == '' || data.toString() == '[object XMLDocument]') {  
  48.                                 return;  
  49.                             }  
  50.                             curRoleModuleIds = data.split(',');  
  51.                             for (var i = 0; i < curRoleModuleIds.length; i++) {  
  52.                                 var node = moduelTree.tree('find', curRoleModuleIds[i]);  
  53.                                 if (node)  
  54.                                     moduelTree.tree("check", node.target);  
  55.                             }  
  56.                         });  
  57.                     }  
  58.                 });  
  59.             },  
  60.             submit: function () {  
  61.                 var allSelectModuledIds = permissionMgr.getUserSelectedModule().split(',');  
  62.                 var grantModuleIds = '';  
  63.                 var revokeModuleIds = '';  
  64.                 var flagRevoke = 0;  
  65.                 var flagGrant = 0;  
  66.                 while (flagRevoke < curRoleModuleIds.length) {  
  67.                     if ($.inArray(curRoleModuleIds[flagRevoke], allSelectModuledIds) == -1) {  
  68.                         revokeModuleIds += curRoleModuleIds[flagRevoke] + ','; //得到收回的权限列表  
  69.                     }  
  70.                     ++flagRevoke;  
  71.                 }  
  72.   
  73.                 while (flagGrant < allSelectModuledIds.length) {  
  74.                     if ($.inArray(allSelectModuledIds[flagGrant], curRoleModuleIds) == -1) {  
  75.                         grantModuleIds += allSelectModuledIds[flagGrant] + ','; //得到授予的权限列表  
  76.                     }  
  77.                     ++flagGrant;  
  78.                 }  
  79.                 var query = 'action=SetRoleModulePermission&roleid=' + top.$('#leftnav').datagrid('getSelected').Id + '&grantIds=' + grantModuleIds + "&revokeIds=" + revokeModuleIds;  
  80.                 $.ajaxjson('handler/PermissionHandler.ashx', query, function (d) {  
  81.                     if (d.Data > 0) {  
  82.                         msg.ok('设置成功!');  
  83.                     }  
  84.                     else {  
  85.                         alert(d.Message);  
  86.                     }  
  87.                 });  
  88.             }  
  89.         });  
  90.     }  

 

 

相关资源分享 

1、基于.NET的快速信息化系统开发整合框架 —RDIFramework.NET—系统目录

2、Jquery EasyUI官方网站

3、Jquery学习官方网站

 4、Jquery EasyUI本地实例文件(如果嫌官网速度过慢,可以下载这个看)

5、Jquery权威指南下载

6、Jquery权威指南源代码下载

7、Jquery EasyUI 1.3中文.chm文件下载

8、JavaScript权威指南(第六版)中文版(强烈推荐)在线观看

posted on 2015-08-13 10:52  三人之行,必有我师  阅读(423)  评论(0编辑  收藏  举报