コード例 #1
0
        public List <PearMenuViewModel> GetMenu(int userId)
        {
            var sysActionList  = SysActionService.GetPermissionByType(userId, ActionTypeEnum.Menu).OrderBy(x => x.SortCode).ToList();
            var sysActionMenus = dao.GetList(x => true).ToList();

            if (sysActionList == null)
            {
                return(null);
            }
            //actionMenu转PearMenuData
            List <PearMenuViewModel> list = new List <PearMenuViewModel>();
            //返回list
            List <PearMenuViewModel>            pearMenuDatas = new List <PearMenuViewModel>();
            Dictionary <int, PearMenuViewModel> dict          = new Dictionary <int, PearMenuViewModel>();

            foreach (var item in sysActionList)
            {
                PearMenuViewModel pearMenuData = new PearMenuViewModel();
                pearMenuData.Id       = item.Id;
                pearMenuData.Title    = item.Name;
                pearMenuData.Icon     = "layui-icon " + item.SysActionMenu.Icon;
                pearMenuData.Href     = item.SysActionMenu.Url;
                pearMenuData.ParentId = item.ParentId;
                list.Add(pearMenuData);
                dict.Add(item.Id, pearMenuData);
                if (item.ParentId == 0)
                {
                    pearMenuDatas.Add(pearMenuData);
                }
            }
            foreach (var item in list)
            {
                if (item.ParentId != 0 && dict.ContainsKey(item.ParentId))
                {
                    dict[item.ParentId].OpenType = "";
                    dict[item.ParentId].Type     = 0;
                    dict[item.ParentId].Children.Add(item);
                    if (dict[item.Id].Children.Count == 0)
                    {
                        item.Type     = 1;
                        item.OpenType = "_iframe";
                    }
                    else
                    {
                        item.Type = 0;
                    }
                }
            }
            return(pearMenuDatas);
        }
コード例 #2
0
        public List <ButtonViewModel> GetButtonListByUserIdAndMenuId(int userId, string url, PositionEnum position)
        {
            List <ButtonViewModel> buttonViewModels = new List <ButtonViewModel>();
            var sysActionButtons = dao.GetList(x => true).ToList();
            var menu             = SysActionMenuDao.GetList(x => x.Url == url).FirstOrDefault();

            if (menu == null)
            {
                return(buttonViewModels);
            }
            var sysActionList = SysActionService.GetPermissionByType(userId, ActionTypeEnum.Button)
                                .Where(x => x.ParentId == menu.Id && x.SysActionButton.Location == position).OrderBy(x => x.SortCode).ToList();

            foreach (var item in sysActionList)
            {
                ButtonViewModel buttonViewModel = new ButtonViewModel();
                buttonViewModel.FullName   = item.Name;
                buttonViewModel.ButtonCode = item.SysActionButton.ButtonCode;
                buttonViewModel.ClassName  = item.SysActionButton.ButtonClass;
                buttonViewModel.Icon       = item.SysActionButton.ButtonIcon;
                buttonViewModels.Add(buttonViewModel);
            }
            return(buttonViewModels);
        }