日期:2014-06-10  浏览次数:20836 次

从这篇文章,希望您能够了解吉日嘎拉通用权限管理系统菜单项配置、缓存及在前台的展示技巧。

项目中使用了吉日嘎拉的通用权限管理系统,几十个子系统均由该权限管理系统管理。

在系统中配置好相关菜单及非菜单项,配置截图:

菜单权限设置截图

 

 

通过下拉菜单进入其中的一个子系统

 

子系统中的菜单项(菜单项表示该项会在前端需要展示出来,用于用户点击的项目),其中的公开表示所有人均可看到该菜单项目。

 

子系统中的非菜单项(非菜单项表示该项目不需要在前端展示出来,比如有些在页面中的弹出窗口、按钮等项目)

通过单点登录到子系统以后,通过一个服务获取登录用户拥有的全部菜单,在权限基类页实现,所有需要进行权限判断的页面均集成此基类页。

代码实现如下图: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,将非菜单项排除掉即可,这样非菜单项就不会展示出来了,效果如下图:

 

 

使用感受:第一次在子系统开发完成后配置吉日嘎拉通用权限管理菜单项,感觉确实非常强悍,我所使用及想象的权限都已被这个组件包含了,以前从来没有看到对权限有如此深入研究的管理系统,没有对权限走火入魔十余年的研究是做不出这样的系统的,同样感受到程序员要有自己研究的领域,把一件事做好确实不容易,要经得起各种考验,适应各种使用环境,不下功夫,不经磨练是不行的。

目前只是使用这个权限系统进行菜单项的配置,吉日嘎拉权限系统底层是如何实现?如何对几十个子系统进行权限分配而不混乱?如何按角色配置权限?按组织机构配置权限?按个人进行权限配置?多种多样复杂的权限配置如何实现?今后我将在使用过程中不断与大家分享 ~~ ,敬请关注 ~~ ,

好的思想、好的成果能够节省很多资源,欢迎大家分享。