程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> C# >> C#入門知識 >> 通用權限管理系統菜單展示的一個技巧

通用權限管理系統菜單展示的一個技巧

編輯:C#入門知識

從這篇文章,希望您能夠了解吉日嘎拉通用權限管理系統菜單項配置、緩存及在前台的展示技巧。

項目中使用了吉日嘎拉的通用權限管理系統,幾十個子系統均由該權限管理系統管理。

在系統中配置好相關菜單及非菜單項,配置截圖:

菜單權限設置截圖

 

 

通過下拉菜單進入其中的一個子系統

 

子系統中的菜單項(菜單項表示該項會在前端需要展示出來,用於用戶點擊的項目),其中的公開表示所有人均可看到該菜單項目。

 

子系統中的非菜單項(非菜單項表示該項目不需要在前端展示出來,比如有些在頁面中的彈出窗口、按鈕等項目)

通過單點登錄到子系統以後,通過一個服務獲取登錄用戶擁有的全部菜單,在權限基類頁實現,所有需要進行權限判斷的頁面均集成此基類頁。

代碼實現如下圖:AuthBasePage.cs基類頁,可參考編寫基類頁

    public class AuthBasePage : BasePage
    {
        /// <summary>
        /// 所有的權限菜單:包含菜單項、非菜單項(如程序中的彈出頁、按鈕等)
        /// </summary>
        protected string menuHtml = string.Empty;
        /// <summary>
        /// 獲取所有菜單的方法 用緩存
         /// 通過userInfo.OpenId來更新緩存  每次進入會重新獲取一次菜單,
        /// </summary>
        /// <param name="userInfo"></param>
        /// <returns></returns>
        private string GetmenuHtml(BaseUserInfo userInfo, bool refreshFlag = false)
        {
            string cacheKey = "menuHtml_" + userInfo.OpenId;
            if (refreshFlag)
            {
                HttpContext.Current.Cache.Remove(cacheKey);
            }
            if (HttpContext.Current.Cache[cacheKey] == null)
            {
                lock (this)
                {
                    if (HttpContext.Current.Cache[cacheKey] == null)
                    {
                         PermissionServiceSoapClient service = new PermissionServiceSoapClient();
                        string systemCode = ZTOTransferFees.Foundation.ConfigHelper.GetConfigString("SystemCode");
                        menuHtml = service.GetPermissionListByUser(systemCode, userInfo.Id);
                        menuHtml = menuHtml.Replace("Id", "id").Replace("FullName", "name").Replace("NavigateUrl", "tabUrl").Replace("Parentid", "parentId").Replace(
                                      "ImagUrl", "icon").Replace("\"Expand\":1", "open:true");
                        HttpContext.Current.Cache.Add(cacheKey, menuHtml, null, DateTime.Now.AddMinutes(120), Cache.NoSlidingExpiration, CacheItemPriority.NotRemovable, null);
                    }
                }
            }
            return HttpContext.Current.Cache[cacheKey] as string;
        }

        protected override void OnInit(EventArgs e)
        {
            //判斷是否得到身份認證 未認證或超時時彈出登錄窗口而非跳轉到登錄頁
            if (null == HttpContext.Current.User.Identity || !HttpContext.Current.User.Identity.IsAuthenticated)
            {
                Response.Write("<script type=\"text/javascript\">");
                Response.Write("var topWin = (function (p, c) {while (p != c) {c = p;p = p.parent}return c;})(window.parent, window);");
                Response.Write("try{ topWin.openLoginWindow();}catch(e){window.location='/Login.aspx'}");
                Response.Write("</script>");
                Response.End();
            }
            HttpCookie authCookie = Context.Request.Cookies[FormsAuthentication.FormsCookieName];
            FormsAuthenticationTicket authTicket = FormsAuthentication.Decrypt(authCookie.Value);
            userData = authTicket.UserData;
            JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer();
            userInfo = javaScriptSerializer.Deserialize<BaseUserInfo>(userData);
            userInfo.ServiceUserName = BaseSystemInfo.ServiceUserName;
            userInfo.ServicePassword = BaseSystemInfo.ServicePassword;
            //獲得全部菜單項、非菜單項的字符串(json)字符串
            menuHtml = GetmenuHtml(userInfo);
           //正在訪問的頁面,通過判斷該頁面是否在menuHtml中來進行權限判斷,按鈕等也一樣
            string curUrl = HttpContext.Current.Request.FilePath;
            if (!menuHtml.Contains(curUrl))
            {
	//權限管理員的聯系方式
               string authManagerInfo = ZTOTransferFees.Foundation.ConfigHelper.GetConfigString("authManagerInfo");
               HttpContext.Current.Items["ErrorMessage"] = "對不起,您沒有權限訪問頁面:" + curUrl + "<br/>如有疑問,請與權限分配人聯系<br/>" + authManagerInfo;
               HttpContext.Current.Server.Transfer("~/Prompt/ShowNoRigh.aspx");
           }
            base.OnInit(e);
        }

 

在上面我們可以看到,通過服務已經獲取了該用戶所擁有的所有菜單及非菜單項目 menuHtml,menuHtml代碼如下,是一個Json數組, 菜單項太多,折疊起來了。

1 [ 2 { 3 "id": 1000005, 4 "parentId": null, 5 "Code": "991810201", 6 "name": "報價維護", 7 "CategoryCode": null, 8 "ImageIndex": null, 9 "SelectedImageIndex": null, 10 "tabUrl": null, 11 "icon": "/system/libs/js/tree/ztree/img/diy/1_close.png", 12 "Target": "fraContent", 13 "FormName": null, 14 "AssemblyName": null, 15 "PermissionScopeTables": null, 16 "SortCode": 1000005, 17 "Enabled": 1, 18 "DeletionStateCode": 0, 19 "IsMenu": 1, 20 "IsPublic": 1, 21 "IsVisible": 1, 22 "IsScope": 0, 23 "LastCall": null, 24 "Expand": 0, 25 "AllowEdit": 1, 26 "AllowDelete": 1, 27 "Description": null, 28 "CreateOn": "/Date(1400819927000)/", 29 "CreateUserid": "102383", 30 "CreateBy": "宋彪", 31 "ModifiedOn": "/Date(1400830672000)/", 32 "ModifiedUserid": "102383", 33 "ModifiedBy": "宋彪" 34 }, 35 { 36 "id": 1000006, 37 "parentId": 1000005, 38 "Code": "99181020101", 39 "name": "報價查詢", 40 "CategoryCode": null, 41 "ImageIndex": null, 42 "SelectedImageIndex": null, 43 "tabUrl": "/BaoJiaChaXun.aspx", 44 "icon": "/system/skin/titlebar_arrow.gif", 45 "Target": "fraContent", 46 "FormName": null, 47 "AssemblyName": null, 48 "PermissionScopeTables": null, 49 "SortCode": 1000006, 50 "Enabled": 1, 51 "DeletionStateCode": 0, 52 "IsMenu": 1, 53 "IsPublic": 1, 54 "IsVisible": 1, 55 "IsScope": 0, 56 "LastCall": null, 57 "Expand": 0, 58 "AllowEdit": 1, 59 "AllowDelete": 1, 60 "Description": null, 61 "CreateOn": "/Date(1400819973000)/", 62 "CreateUserid": "102383", 63 "CreateBy": "宋彪", 64 "ModifiedOn": "/Date(1400828358000)/", 65 "ModifiedUserid": "102383", 66 "ModifiedBy": "宋彪" 67 }, 68 { 69 "id": 1000008, 70 "parentId": null, 71 "Code": "991810202", 72 "name": "報價審核", 73 "CategoryCode": null, 74 "ImageIndex": null, 75 "SelectedImageIndex": null, 76 "tabUrl": null, 77 "icon": "/system/libs/js/tree/ztree/img/diy/2.png", 78 "Target": "fraContent", 79 "FormName": null, 80 "AssemblyName": null, 81 "PermissionScopeTables": null, 82 "SortCode": 1000008, 83 "Enabled": 1, 84 "DeletionStateCode": 0, 85 "IsMenu": 1, 86 "IsPublic": 1, 87 "IsVisible": 1, 88 "IsScope": 0, 89 "LastCall": null, 90 "Expand": 0, 91 "AllowEdit": 1, 92 "AllowDelete": 1, 93 "Description": null, 94 "CreateOn": "/Date(1400820277000)/", 95 "CreateUserid": "102383", 96 "CreateBy": "宋彪", 97 "ModifiedOn": "/Date(1400828373000)/", 98 "ModifiedUserid": "102383", 99 "ModifiedBy": "宋彪" 100 }, 101 { 102 "id": 1000010, 103 "parentId": 1000008, 104 "Code": "99181020202", 105 "name": "訪客信息", 106 "CategoryCode": null, 107 "ImageIndex": null, 108 "SelectedImageIndex": null, 109 "tabUrl": "/SysInfo/OnLineUser.aspx", 110 "icon": "/system/skin/titlebar_arrow.gif", 111 "Target": "fraContent", 112 "FormName": null, 113 "AssemblyName": null, 114 "PermissionScopeTables": null, 115 "SortCode": 1000010, 116 "Enabled": 1, 117 "DeletionStateCode": 0, 118 "IsMenu": 1, 119 "IsPublic": 1, 120 "IsVisible": 1, 121 "IsScope": 0, 122 "LastCall": null, 123 "Expand": 0, 124 "AllowEdit": 1, 125 "AllowDelete": 1, 126 "Description": null, 127 "CreateOn": "/Date(1400820486000)/", 128 "CreateUserid": "102383", 129 "CreateBy": "宋彪", 130 "ModifiedOn": "/Date(1400828383000)/", 131 "ModifiedUserid": "102383", 132 "ModifiedBy": "宋彪" 133 }, 134 { 135 "id": 1000012, 136 "parentId": null, 137 "Code": "9918102001", 138 "name": "左側導航頁面", 139 "CategoryCode": null, 140 "ImageIndex": null, 141 "SelectedImageIndex": null, 142 "tabUrl": "/FrameLeft.aspx", 143 "icon": null, 144 "Target": "fraContent", 145 "FormName": null, 146 "AssemblyName": null, 147 "PermissionScopeTables": null, 148 "SortCode": 1000012, 149 "Enabled": 1, 150 "DeletionStateCode": 0, 151 "IsMenu": 0, 152 "IsPublic": 1, 153 "IsVisible": 1, 154 "IsScope": 0, 155 "LastCall": null, 156 "Expand": 0, 157 "AllowEdit": 1, 158 "AllowDelete": 1, 159 "Description": null, 160 "CreateOn": "/Date(1400828603000)/", 161 "CreateUserid": "102383", 162 "CreateBy": "宋彪", 163 "ModifiedOn": "/Date(1400831720000)/", 164 "ModifiedUserid": "102383", 165 "ModifiedBy": "宋彪" 166 }, 167 { 168 "id": 1000013, 169 "parentId": null, 170 "Code": "Logout", 171 "name": "退出系統", 172 "CategoryCode": null, 173 "ImageIndex": null, 174 "SelectedImageIndex": null, 175 "tabUrl": "/Logout.aspx", 176 "icon": null, 177 "Target": "fraContent", 178 "FormName": null, 179 "AssemblyName": null, 180 "PermissionScopeTables": null, 181 "SortCode": 1000013, 182 "Enabled": 1, 183 "DeletionStateCode": 0, 184 "IsMenu": 0, 185 "IsPublic": 1, 186 "IsVisible": 1, 187 "IsScope": 0, 188 "LastCall": null, 189 "Expand": 0, 190 "AllowEdit": 1, 191 "AllowDelete": 1, 192 "Description": null, 193 "CreateOn": "/Date(1400828694000)/", 194 "CreateUserid": "102383", 195 "CreateBy": "宋彪", 196 "ModifiedOn": "/Date(1400833385000)/", 197 "ModifiedUserid": "102383", 198 "ModifiedBy": "宋彪" 199 }, 200 { 201 "id": 1000014, 202 "parentId": null, 203 "Code": "Main", 204 "name": "框架主頁面", 205 "CategoryCode": null, 206 "ImageIndex": null, 207 "SelectedImageIndex": null, 208 "tabUrl": "/Main.aspx", 209 "icon": null, 210 "Target": "fraContent", 211 "FormName": null, 212 "AssemblyName": null, 213 "PermissionScopeTables": null, 214 "SortCode": 1000014, 215 "Enabled": 1, 216 "DeletionStateCode": 0, 217 "IsMenu": 0, 218 "IsPublic": 1, 219 "IsVisible": 1, 220 "IsScope": 0, 221 "LastCall": null, 222 "Expand": 0, 223 "AllowEdit": 1, 224 "AllowDelete": 1, 225 "Description": null, 226 "CreateOn": "/Date(1400828790000)/", 227 "CreateUserid": "102383", 228 "CreateBy": "宋彪", 229 "ModifiedOn": "/Date(1400831595000)/", 230 "ModifiedUserid": "102383", 231 "ModifiedBy": "宋彪" 232 }, 233 { 234 "id": 1000015, 235 "parentId": null, 236 "Code": "ReadMe", 237 "name": "中轉費使用說明文檔", 238 "CategoryCode": null, 239 "ImageIndex": null, 240 "SelectedImageIndex": null, 241 "tabUrl": "/ReadMe.aspx", 242 "icon": null, 243 "Target": "fraContent", 244 "FormName": null, 245 "AssemblyName": null, 246 "PermissionScopeTables": null, 247 "SortCode": 1000015, 248 "Enabled": 1, 249 "DeletionStateCode": 0, 250 "IsMenu": 0, 251 "IsPublic": 1, 252 "IsVisible": 1, 253 "IsScope": 0, 254 "LastCall": null, 255 "Expand": 0, 256 "AllowEdit": 1, 257 "AllowDelete": 1, 258 "Description": null, 259 "CreateOn": "/Date(1400828829000)/", 260 "CreateUserid": "102383", 261 "CreateBy": "宋彪", 262 "ModifiedOn": "/Date(1400832451000)/", 263 "ModifiedUserid": "102383", 264 "ModifiedBy": "宋彪" 265 }, 266 { 267 "id": 1000018, 268 "parentId": 1000016, 269 "Code": "DialogLogin", 270 "name": "DialogLogin", 271 "CategoryCode": null, 272 "ImageIndex": null, 273 "SelectedImageIndex": null, 274 "tabUrl": "/PageUtils/DialogLogin.aspx", 275 "icon": null, 276 "Target": "fraContent", 277 "FormName": null, 278 "AssemblyName": null, 279 "PermissionScopeTables": null, 280 "SortCode": 1000018, 281 "Enabled": 1, 282 "DeletionStateCode": 0, 283 "IsMenu": 0, 284 "IsPublic": 1, 285 "IsVisible": 1, 286 "IsScope": 0, 287 "LastCall": null, 288 "Expand": 0, 289 "AllowEdit": 1, 290 "AllowDelete": 1, 291 "Description": null, 292 "CreateOn": "/Date(1400829312000)/", 293 "CreateUserid": "102383", 294 "CreateBy": "宋彪", 295 "ModifiedOn": "/Date(1400838755000)/", 296 "ModifiedUserid": "102383", 297 "ModifiedBy": "宋彪" 298 }, 299 { 300 "id": 1000019, 301 "parentId": 1000016, 302 "Code": "QuoteExpression", 303 "name": "QuoteExpression", 304 "CategoryCode": null, 305 "ImageIndex": null, 306 "SelectedImageIndex": null, 307 "tabUrl": "/PageUtils/QuoteExpression.aspx", 308 "icon": null, 309 "Target": "fraContent", 310 "FormName": null, 311 "AssemblyName": null, 312 "PermissionScopeTables": null, 313 "SortCode": 1000019, 314 "Enabled": 1, 315 "DeletionStateCode": 0, 316 "IsMenu": 0, 317 "IsPublic": 1, 318 "IsVisible": 1, 319 "IsScope": 0, 320 "LastCall": null, 321 "Expand": 0, 322 "AllowEdit": 1, 323 "AllowDelete": 1, 324 "Description": null, 325 "CreateOn": "/Date(1400829348000)/", 326 "CreateUserid": "102383", 327 "CreateBy": "宋彪", 328 "ModifiedOn": "/Date(1400838755000)/", 329 "ModifiedUserid": "102383", 330 "ModifiedBy": "宋彪" 331 }, 332 { 333 "id": 1000020, 334 "parentId": 1000016, 335 "Code": "QuotePrice", 336 "name": "QuotePrice", 337 "CategoryCode": null, 338 "ImageIndex": null, 339 "SelectedImageIndex": null, 340 "tabUrl": "/PageUtils/QuotePrice.aspx", 341 "icon": null, 342 "Target": "fraContent", 343 "FormName": null, 344 "AssemblyName": null, 345 "PermissionScopeTables": null, 346 "SortCode": 1000020, 347 "Enabled": 1, 348 "DeletionStateCode": 0, 349 "IsMenu": 0, 350 "IsPublic": 1, 351 "IsVisible": 1, 352 "IsScope": 0, 353 "LastCall": null, 354 "Expand": 0, 355 "AllowEdit": 1, 356 "AllowDelete": 1, 357 "Description": null, 358 "CreateOn": "/Date(1400829379000)/", 359 "CreateUserid": "102383", 360 "CreateBy": "宋彪", 361 "ModifiedOn": "/Date(1400838755000)/", 362 "ModifiedUserid": "102383", 363 "ModifiedBy": "宋彪" 364 }, 365 { 366 "id": 1000021, 367 "parentId": 1000016, 368 "Code": "RegionScan", 369 "name": "RegionScan", 370 "CategoryCode": null, 371 "ImageIndex": null, 372 "SelectedImageIndex": null, 373 "tabUrl": "/PageUtils/RegionScan.aspx", 374 "icon": null, 375 "Target": "fraContent", 376 "FormName": null, 377 "AssemblyName": null, 378 "PermissionScopeTables": null, 379 "SortCode": 1000021, 380 "Enabled": 1, 381 "DeletionStateCode": 0, 382 "IsMenu": 0, 383 "IsPublic": 1, 384 "IsVisible": 1, 385 "IsScope": 0, 386 "LastCall": null, 387 "Expand": 0, 388 "AllowEdit": 1, 389 "AllowDelete": 1, 390 "Description": null, 391 "CreateOn": "/Date(1400829412000)/", 392 "CreateUserid": "102383", 393 "CreateBy": "宋彪", 394 "ModifiedOn": "/Date(1400838755000)/", 395 "ModifiedUserid": "102383", 396 "ModifiedBy": "宋彪" 397 }, 398 { 399 "id": 1000022, 400 "parentId": 1000016, 401 "Code": "RegionSite", 402 "name": "RegionSite", 403 "CategoryCode": null, 404 "ImageIndex": null, 405 "SelectedImageIndex": null, 406 "tabUrl": "/PageUtils/RegionSite.aspx", 407 "icon": null, 408 "Target": "fraContent", 409 "FormName": null, 410 "AssemblyName": null, 411 "PermissionScopeTables": null, 412 "SortCode": 1000022, 413 "Enabled": 1, 414 "DeletionStateCode": 0, 415 "IsMenu": 0, 416 "IsPublic": 1, 417 "IsVisible": 1, 418 "IsScope": 0, 419 "LastCall": null, 420 "Expand": 0, 421 "AllowEdit": 1, 422 "AllowDelete": 1, 423 "Description": null, 424 "CreateOn": "/Date(1400829439000)/", 425 "CreateUserid": "102383", 426 "CreateBy": "宋彪", 427 "ModifiedOn": "/Date(1400838755000)/", 428 "ModifiedUserid": "102383", 429 "ModifiedBy": "宋彪" 430 }, 431 { 432 "id": 1000023, 433 "parentId": 1000016, 434 "Code": "Screen", 435 "name": "Screen", 436 "CategoryCode": null, 437 "ImageIndex": null, 438 "SelectedImageIndex": null, 439 "tabUrl": "/PageUtils/Screen.aspx", 440 "icon": null, 441 "Target": "fraContent", 442 "FormName": null, 443 "AssemblyName": null, 444 "PermissionScopeTables": null, 445 "SortCode": 1000023, 446 "Enabled": 1, 447 "DeletionStateCode": 0, 448 "IsMenu": 0, 449 "IsPublic": 1, 450 "IsVisible": 1, 451 "IsScope": 0, 452 "LastCall": null, 453 "Expand": 0, 454 "AllowEdit": 1, 455 "AllowDelete": 1, 456 "Description": null, 457 "CreateOn": "/Date(1400829468000)/", 458 "CreateUserid": "102383", 459 "CreateBy": "宋彪", 460 "ModifiedOn": "/Date(1400838755000)/", 461 "ModifiedUserid": "102383", 462 "ModifiedBy": "宋彪" 463 }, 464 { 465 "id": 1000024, 466 "parentId": 1000016, 467 "Code": "ZtoOrganize", 468 "name": "ZtoOrganize", 469 "CategoryCode": null, 470 "ImageIndex": null, 471 "SelectedImageIndex": null, 472 "tabUrl": "/PageUtils/ZtoOrganize.aspx", 473 "icon": null, 474 "Target": "fraContent", 475 "FormName": null, 476 "AssemblyName": null, 477 "PermissionScopeTables": null, 478 "SortCode": 1000024, 479 "Enabled": 1, 480 "DeletionStateCode": 0, 481 "IsMenu": 0, 482 "IsPublic": 1, 483 "IsVisible": 1, 484 "IsScope": 0, 485 "LastCall": null, 486 "Expand": 0, 487 "AllowEdit": 1, 488 "AllowDelete": 1, 489 "Description": null, 490 "CreateOn": "/Date(1400829495000)/", 491 "CreateUserid": "102383", 492 "CreateBy": "宋彪", 493 "ModifiedOn": "/Date(1400838755000)/", 494 "ModifiedUserid": "102383", 495 "ModifiedBy": "宋彪" 496 }, 497 { 498 "id": 1000026, 499 "parentId": 1000025, 500 "Code": "CacheManager", 501 "name": "CacheManager", 502 "CategoryCode": null, 503 "ImageIndex": null, 504 "SelectedImageIndex": null, 505 "tabUrl": "/SysInfo/CacheManager.aspx", 506 "icon": null, 507 "Target": "fraContent", 508 "FormName": null, 509 "AssemblyName": null, 510 "PermissionScopeTables": null, 511 "SortCode": 1000026, 512 "Enabled": 1, 513 "DeletionStateCode": 0, 514 "IsMenu": 0, 515 "IsPublic": 1, 516 "IsVisible": 1, 517 "IsScope": 0, 518 "LastCall": null, 519 "Expand": 0, 520 "AllowEdit": 1, 521 "AllowDelete": 1, 522 "Description": null, 523 "CreateOn": "/Date(1400829582000)/", 524 "CreateUserid": "102383", 525 "CreateBy": "宋彪", 526 "ModifiedOn": "/Date(1400837347000)/", 527 "ModifiedUserid": "102383", 528 "ModifiedBy": "宋彪" 529 }, 530 { 531 "id": 1000027, 532 "parentId": 1000025, 533 "Code": "OnlineTalk", 534 "name": "OnlineTalk", 535 "CategoryCode": null, 536 "ImageIndex": null, 537 "SelectedImageIndex": null, 538 "tabUrl": "/SysInfo/OnlineTalk.aspx", 539 "icon": null, 540 "Target": "fraContent", 541 "FormName": null, 542 "AssemblyName": null, 543 "PermissionScopeTables": null, 544 "SortCode": 1000027, 545 "Enabled": 1, 546 "DeletionStateCode": 0, 547 "IsMenu": 0, 548 "IsPublic": 1, 549 "IsVisible": 1, 550 "IsScope": 0, 551 "LastCall": null, 552 "Expand": 0, 553 "AllowEdit": 1, 554 "AllowDelete": 1, 555 "Description": null, 556 "CreateOn": "/Date(1400829605000)/", 557 "CreateUserid": "102383", 558 "CreateBy": "宋彪", 559 "ModifiedOn": "/Date(1400837347000)/", 560 "ModifiedUserid": "102383", 561 "ModifiedBy": "宋彪" 562 }, 563 { 564 "id": 1000028, 565 "parentId": 1000025, 566 "Code": "OnLineUser", 567 "name": "OnLineUser", 568 "CategoryCode": null, 569 "ImageIndex": null, 570 "SelectedImageIndex": null, 571 "tabUrl": "/SysInfo/OnLineUser.aspx", 572 "icon": null, 573 "Target": "fraContent", 574 "FormName": null, 575 "AssemblyName": null, 576 "PermissionScopeTables": null, 577 "SortCode": 1000028, 578 "Enabled": 1, 579 "DeletionStateCode": 0, 580 "IsMenu": 0, 581 "IsPublic": 1, 582 "IsVisible": 1, 583 "IsScope": 0, 584 "LastCall": null, 585 "Expand": 0, 586 "AllowEdit": 1, 587 "AllowDelete": 1, 588 "Description": null, 589 "CreateOn": "/Date(1400829629000)/", 590 "CreateUserid": "102383", 591 "CreateBy": "宋彪", 592 "ModifiedOn": "/Date(1400837347000)/", 593 "ModifiedUserid": "102383", 594 "ModifiedBy": "宋彪" 595 }, 596 { 597 "id": 1000029, 598 "parentId": 1000025, 599 "Code": "OnLineUserList", 600 "name": "OnLineUserList", 601 "CategoryCode": null, 602 "ImageIndex": null, 603 "SelectedImageIndex": null, 604 "tabUrl": "/SysInfo/OnLineUserList.aspx", 605 "icon": null, 606 "Target": "fraContent", 607 "FormName": null, 608 "AssemblyName": null, 609 "PermissionScopeTables": null, 610 "SortCode": 1000029, 611 "Enabled": 1, 612 "DeletionStateCode": 0, 613 "IsMenu": 0, 614 "IsPublic": 1, 615 "IsVisible": 1, 616 "IsScope": 0, 617 "LastCall": null, 618 "Expand": 0, 619 "AllowEdit": 1, 620 "AllowDelete": 1, 621 "Description": null, 622 "CreateOn": "/Date(1400829677000)/", 623 "CreateUserid": "102383", 624 "CreateBy": "宋彪", 625 "ModifiedOn": "/Date(1400837347000)/", 626 "ModifiedUserid": "102383", 627 "ModifiedBy": "宋彪" 628 }, 629 { 630 "id": 1000030, 631 "parentId": 1000025, 632 "Code": "SetParameter", 633 "name": "SetParameter", 634 "CategoryCode": null, 635 "ImageIndex": null, 636 "SelectedImageIndex": null, 637 "tabUrl": "/SysInfo/SetParameter.aspx", 638 "icon": null, 639 "Target": "fraContent", 640 "FormName": null, 641 "AssemblyName": null, 642 "PermissionScopeTables": null, 643 "SortCode": 1000030, 644 "Enabled": 1, 645 "DeletionStateCode": 0, 646 "IsMenu": 0, 647 "IsPublic": 1, 648 "IsVisible": 1, 649 "IsScope": 0, 650 "LastCall": null, 651 "Expand": 0, 652 "AllowEdit": 1, 653 "AllowDelete": 1, 654 "Description": null, 655 "CreateOn": "/Date(1400829704000)/", 656 "CreateUserid": "102383", 657 "CreateBy": "宋彪", 658 "ModifiedOn": "/Date(1400837347000)/", 659 "ModifiedUserid": "102383", 660 "ModifiedBy": "宋彪" 661 }, 662 { 663 "id": 1000032, 664 "parentId": 1000031, 665 "Code": "BaojiaSiteList", 666 "name": "BaojiaSiteList", 667 "CategoryCode": null, 668 "ImageIndex": null, 669 "SelectedImageIndex": null, 670 "tabUrl": "/Ajax/BaojiaSiteList.aspx", 671 "icon": null, 672 "Target": "fraContent", 673 "FormName": null, 674 "AssemblyName": null, 675 "PermissionScopeTables": null, 676 "SortCode": 1000032, 677 "Enabled": 1, 678 "DeletionStateCode": 0, 679 "IsMenu": 0, 680 "IsPublic": 1, 681 "IsVisible": 1, 682 "IsScope": 0, 683 "LastCall": null, 684 "Expand": 0, 685 "AllowEdit": 1, 686 "AllowDelete": 1, 687 "Description": null, 688 "CreateOn": "/Date(1400829803000)/", 689 "CreateUserid": "102383", 690 "CreateBy": "宋彪", 691 "ModifiedOn": "/Date(1400837269000)/", 692 "ModifiedUserid": "102383", 693 "ModifiedBy": "宋彪" 694 }, 695 { 696 "id": 1000033, 697 "parentId": 1000031, 698 "Code": "CommonDistrict", 699 "name": "CommonDistrict", 700 "CategoryCode": null, 701 "ImageIndex": null, 702 "SelectedImageIndex": null, 703 "tabUrl": "/Ajax/CommonDistrict.aspx", 704 "icon": null, 705 "Target": "fraContent", 706 "FormName": null, 707 "AssemblyName": null, 708 "PermissionScopeTables": null, 709 "SortCode": 1000033, 710 "Enabled": 1, 711 "DeletionStateCode": 0, 712 "IsMenu": 0, 713 "IsPublic": 1, 714 "IsVisible": 1, 715 "IsScope": 0, 716 "LastCall": null, 717 "Expand": 0, 718 "AllowEdit": 1, 719 "AllowDelete": 1, 720 "Description": null, 721 "CreateOn": "/Date(1400829850000)/", 722 "CreateUserid": "102383", 723 "CreateBy": "宋彪", 724 "ModifiedOn": "/Date(1400837269000)/", 725 "ModifiedUserid": "102383", 726 "ModifiedBy": "宋彪" 727 }, 728 { 729 "id": 1000034, 730 "parentId": 1000031, 731 "Code": "GetScanSiteByPager", 732 "name": "GetScanSiteByPager", 733 "CategoryCode": null, 734 "ImageIndex": null, 735 "SelectedImageIndex": null, 736 "tabUrl": "/Ajax/GetScanSiteByPager.aspx", 737 "icon": null, 738 "Target": "fraContent", 739 "FormName": null, 740 "AssemblyName": null, 741 "PermissionScopeTables": null, 742 "SortCode": 1000034, 743 "Enabled": 1, 744 "DeletionStateCode": 0, 745 "IsMenu": 0, 746 "IsPublic": 1, 747 "IsVisible": 1, 748 "IsScope": 0, 749 "LastCall": null, 750 "Expand": 0, 751 "AllowEdit": 1, 752 "AllowDelete": 1, 753 "Description": null, 754 "CreateOn": "/Date(1400829872000)/", 755 "CreateUserid": "102383", 756 "CreateBy": "宋彪", 757 "ModifiedOn": "/Date(1400837269000)/", 758 "ModifiedUserid": "102383", 759 "ModifiedBy": "宋彪" 760 }, 761 { 762 "id": 1000035, 763 "parentId": 1000031, 764 "Code": "ItemsZto", 765 "name": "ItemsZto", 766 "CategoryCode": null, 767 "ImageIndex": null, 768 "SelectedImageIndex": null, 769 "tabUrl": "/Ajax/ItemsZto.aspx", 770 "icon": null, 771 "Target": "fraContent", 772 "FormName": null, 773 "AssemblyName": null, 774 "PermissionScopeTables": null, 775 "SortCode": 1000035, 776 "Enabled": 1, 777 "DeletionStateCode": 0, 778 "IsMenu": 0, 779 "IsPublic": 1, 780 "IsVisible": 1, 781 "IsScope": 0, 782 "LastCall": null, 783 "Expand": 0, 784 "AllowEdit": 1, 785 "AllowDelete": 1, 786 "Description": null, 787 "CreateOn": "/Date(1400829891000)/", 788 "CreateUserid": "102383", 789 "CreateBy": "宋彪", 790 "ModifiedOn": "/Date(1400837269000)/", 791 "ModifiedUserid": "102383", 792 "ModifiedBy": "宋彪" 793 }, 794 { 795 "id": 1000036, 796 "parentId": 1000031, 797 "Code": "QuoteArea", 798 "name": "QuoteArea", 799 "CategoryCode": null, 800 "ImageIndex": null, 801 "SelectedImageIndex": null, 802 "tabUrl": "/Ajax/QuoteArea.aspx", 803 "icon": null, 804 "Target": "fraContent", 805 "FormName": null, 806 "AssemblyName": null, 807 "PermissionScopeTables": null, 808 "SortCode": 1000036, 809 "Enabled": 1, 810 "DeletionStateCode": 0, 811 "IsMenu": 0, 812 "IsPublic": 1, 813 "IsVisible": 1, 814 "IsScope": 0, 815 "LastCall": null, 816 "Expand": 0, 817 "AllowEdit": 1, 818 "AllowDelete": 1, 819 "Description": null, 820 "CreateOn": "/Date(1400829911000)/", 821 "CreateUserid": "102383", 822 "CreateBy": "宋彪", 823 "ModifiedOn": "/Date(1400837269000)/", 824 "ModifiedUserid": "102383", 825 "ModifiedBy": "宋彪" 826 }, 827 { 828 "id": 1000037, 829 "parentId": 1000031, 830 "Code": "Site", 831 "name": "Site", 832 "CategoryCode": null, 833 "ImageIndex": null, 834 "SelectedImageIndex": null, 835 "tabUrl": "/Ajax/Site.aspx", 836 "icon": null, 837 "Target": "fraContent", 838 "FormName": null, 839 "AssemblyName": null, 840 "PermissionScopeTables": null, 841 "SortCode": 1000037, 842 "Enabled": 1, 843 "DeletionStateCode": 0, 844 "IsMenu": 0, 845 "IsPublic": 1, 846 "IsVisible": 1, 847 "IsScope": 0, 848 "LastCall": null, 849 "Expand": 0, 850 "AllowEdit": 1, 851 "AllowDelete": 1, 852 "Description": null, 853 "CreateOn": "/Date(1400829932000)/", 854 "CreateUserid": "102383", 855 "CreateBy": "宋彪", 856 "ModifiedOn": "/Date(1400837269000)/", 857 "ModifiedUserid": "102383", 858 "ModifiedBy": "宋彪" 859 }, 860 { 861 "id": 1000038, 862 "parentId": 1000031, 863 "Code": "SiteAutoComplete", 864 "name": "SiteAutoComplete", 865 "CategoryCode": null, 866 "ImageIndex": null, 867 "SelectedImageIndex": null, 868 "tabUrl": "/Ajax/SiteAutoComplete.aspx", 869 "icon": null, 870 "Target": "fraContent", 871 "FormName": null, 872 "AssemblyName": null, 873 "PermissionScopeTables": null, 874 "SortCode": 1000038, 875 "Enabled": 1, 876 "DeletionStateCode": 0, 877 "IsMenu": 0, 878 "IsPublic": 1, 879 "IsVisible": 1, 880 "IsScope": 0, 881 "LastCall": null, 882 "Expand": 0, 883 "AllowEdit": 1, 884 "AllowDelete": 1, 885 "Description": null, 886 "CreateOn": "/Date(1400829950000)/", 887 "CreateUserid": "102383", 888 "CreateBy": "宋彪", 889 "ModifiedOn": "/Date(1400837269000)/", 890 "ModifiedUserid": "102383", 891 "ModifiedBy": "宋彪" 892 }, 893 { 894 "id": 1000039, 895 "parentId": 1000031, 896 "Code": "User", 897 "name": "User", 898 "CategoryCode": null, 899 "ImageIndex": null, 900 "SelectedImageIndex": null, 901 "tabUrl": "/Ajax/User.aspx", 902 "icon": null, 903 "Target": "fraContent", 904 "FormName": null, 905 "AssemblyName": null, 906 "PermissionScopeTables": null, 907 "SortCode": 1000039, 908 "Enabled": 1, 909 "DeletionStateCode": 0, 910 "IsMenu": 0, 911 "IsPublic": 1, 912 "IsVisible": 1, 913 "IsScope": 0, 914 "LastCall": null, 915 "Expand": 0, 916 "AllowEdit": 1, 917 "AllowDelete": 1, 918 "Description": null, 919 "CreateOn": "/Date(1400829970000)/", 920 "CreateUserid": "102383", 921 "CreateBy": "宋彪", 922 "ModifiedOn": "/Date(1400837269000)/", 923 "ModifiedUserid": "102383", 924 "ModifiedBy": "宋彪" 925 }, 926 { 927 "id": 1000040, 928 "parentId": null, 929 "Code": "OpenRight", 930 "name": "右側TAB容器頁面", 931 "CategoryCode": null, 932 "ImageIndex": null, 933 "SelectedImageIndex": null, 934 "tabUrl": "/OpenRight.aspx", 935 "icon": null, 936 "Target": "fraContent", 937 "FormName": null, 938 "AssemblyName": null, 939 "PermissionScopeTables": null, 940 "SortCode": 1000040, 941 "Enabled": 1, 942 "DeletionStateCode": 0, 943 "IsMenu": 0, 944 "IsPublic": 1, 945 "IsVisible": 1, 946 "IsScope": 0, 947 "LastCall": null, 948 "Expand": 0, 949 "AllowEdit": 1, 950 "AllowDelete": 1, 951 "Description": null, 952 "CreateOn": "/Date(1400832606000)/", 953 "CreateUserid": "102383", 954 "CreateBy": "宋彪", 955 "ModifiedOn": "/Date(1400833155000)/", 956 "ModifiedUserid": "102383", 957 "ModifiedBy": "宋彪" 958 } 959 ] View Code

 

 現在我們需要在用戶登錄以後在前端將其展示出來,這裡我使用了ztree樹形菜單展示控件,關鍵代碼如下圖,

            var zNodes = <%=menuHtml%>;//看上面獲取的數據

            function initTreeMenu(b) {
                if (b) {
                    var a = b.treeNodes;
                    if (a) {
                        $.fn.zTree.init($("#treeDemo"), setting, a)
                    }
                }
            };

 由於menuHtml中包含了非菜單項目,導致非菜單項也在ztree中展示出來,如下圖:

 

這樣就不好了,如何處理這種情況呢?我想使用通用權限管理系統的都會遇到這個情況,大家都會有不同的處理方式,

如果您使用的也是ztree菜單展示控件,可參考一下我的處理方式,Js代碼如下

            function filter(childNodes) {
                var newNodes=new Array();
                for (var i = 0, l = childNodes.length; i < l; i++) {
                    if (childNodes[i].IsMenu) {
                        newNodes.push(childNodes[i]);
                    }
                };
                return newNodes;
            };
            var zNodes = <%=menuHtml%>;
            zNodes=filter(zNodes);
            function initTreeMenu(b) {
                if (b) {
                    var a = b.treeNodes;
                    if (a) {
                        $.fn.zTree.init($("#treeDemo"), setting, a)
                    }
                }
            };

 另外,如果您的菜單項是通過異步方式獲取的,ztree中也有一個可以過濾菜單項的方法:

        var setting = {
            async: {
                enable: true,
                dataType: 'JSON',
                dataName: 'treeNodes',
                url: "/Ajax/GetMenu.aspx",
                //傳回的數據格式不是ztree所需要的格式的時候,可以對數據進行轉化。正常情況下不需要實現dataFilter
                dataFilter: filter
            },
	}

function filter(treeId, parentNode, childNodes) {
                var newNodes=new Array();
                for (var i = 0, l = childNodes.length; i < l; i++) {
                    if (childNodes[i].IsMenu) {
                        newNodes.push(childNodes[i]);
                    }
                };
                return newNodes;
        };

 

可以看到,使用了一個過濾方法filter,將非菜單項排除掉即可,這樣非菜單項就不會展示出來了,效果如下圖:

 

 

使用感受:第一次在子系統開發完成後配置吉日嘎拉通用權限管理菜單項,感覺確實非常強悍,我所使用及想象的權限都已被這個組件包含了,以前從來沒有看到對權限有如此深入研究的管理系統,沒有對權限走火入魔十余年的研究是做不出這樣的系統的,同樣感受到程序員要有自己研究的領域,把一件事做好確實不容易,要經得起各種考驗,適應各種使用環境,不下功夫,不經磨練是不行的。

目前只是使用這個權限系統進行菜單項的配置,吉日嘎拉權限系統底層是如何實現?如何對幾十個子系統進行權限分配而不混亂?如何按角色配置權限?按組織機構配置權限?按個人進行權限配置?多種多樣復雜的權限配置如何實現?今後我將在使用過程中不斷與大家分享 ~~ ,敬請關注 ~~ ,

好的思想、好的成果能夠節省很多資源,歡迎大家分享。

 

 

 

 

 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved