Beispiel #1
0
        public IEnumerable <TreeDataView> GetMenuButtonTree()
        {
            var menuButtons = _platformDomain.MenuButtonSet;

            var tree  = GetModuleAndMenuTree();
            var mmtor = tree.GetEnumerator();

            AddMenuButton(mmtor);
            return(tree);

            void AddMenuButton(IEnumerator <TreeDataView> menuEmumertor)
            {
                while (menuEmumertor.MoveNext())
                {
                    TreeDataView curr = menuEmumertor.Current;
                    if (curr.Children.Any())
                    {
                        AddMenuButton(curr.Children.GetEnumerator());
                    }
                    if (curr.Data.IsMenu)
                    {
                        var children = AddOperNode(curr);
                        if (children.Any())
                        {
                            curr.Children = children.ToList();
                        }
                    }
                }
            }

            IEnumerable <TreeDataView> AddOperNode(TreeDataView menuNode)
            {
                var    opers   = typeof(OperEnum).EnumItems(_multiLangService);
                string menuUid = menuNode.Id;

                if (!_applicationContext.IsAdministrator)
                {
                    //权限中获取
                    var roleButtons = _rbacService.GetRoleButtonList(_applicationContext.CurrentRoleUid);
                    if (roleButtons.Any())
                    {
                        var rbtns = roleButtons.Where(r => r.MenuUid == menuUid);
                        foreach (var btn in rbtns.Where(b => b.ButtonType == FapMenuButtonType.Grid || b.ButtonType == FapMenuButtonType.Tree))
                        {
                            var button = menuButtons.FirstOrDefault(b => b.MenuUid == btn.MenuUid && b.ButtonID == btn.ButtonId);
                            if (button != null)
                            {
                                string langkey = $"{menuUid}_{button.ButtonID}";
                                button.Description = _multiLangService.GetMultiLangValue(MultiLanguageOriginEnum.ButtonTag, langkey);
                                TreeDataView toper = new TreeDataView()
                                {
                                    Id   = button.Fid,
                                    Data = new { IsBtn = false, IsMenu = false },
                                    Pid  = menuNode.Id,
                                    Text = button.Description,
                                    Icon = btn.ButtonType == FapMenuButtonType.Grid ? "fa fa-table" : "fa fa-code-fork"
                                };

                                foreach (var oper in btn.ButtonValue.SplitComma())
                                {
                                    OperEnum     operEnum = (OperEnum)oper.ToInt();
                                    TreeDataView tcol     = new TreeDataView();
                                    tcol.Id   = $"{menuNode.Id}|{button.ButtonType}|{ button.ButtonID }|{oper}";
                                    tcol.Data = new { IsBtn = true, IsMenu = false };
                                    tcol.Pid  = toper.Id;
                                    tcol.Text = operEnum.Description();
                                    tcol.Icon = GetOperIcon(operEnum);
                                    toper.Children.Add(tcol);
                                }
                                yield return(toper);
                            }
                        }
                        var buttons = rbtns.Where(b => b.ButtonType == FapMenuButtonType.Link || b.ButtonType == FapMenuButtonType.Button);
                        foreach (var btn in buttons)
                        {
                            var          button = menuButtons.FirstOrDefault(b => b.MenuUid == btn.MenuUid && b.ButtonID == btn.ButtonId);
                            TreeDataView toper  = new TreeDataView()
                            {
                                Id   = $"{menuNode.Id}|button|{ button.ButtonID }|1",
                                Icon = "fa  fa-bolt",
                                Data = new { IsBtn = true, IsMenu = false },
                                Pid  = menuNode.Id,
                                Text = button.Description,
                            };
                            yield return(toper);
                        }
                    }
                }
                else
                {
                    if (menuButtons.TryGetValue(menuUid, out IEnumerable <FapMenuButton> buttons))
                    {
                        foreach (var button in buttons)
                        {
                            string langkey = $"{menuUid}_{button.ButtonID}";
                            button.Description = _multiLangService.GetMultiLangValue(MultiLanguageOriginEnum.ButtonTag, langkey);
                            TreeDataView toper = new TreeDataView()
                            {
                                Id   = button.Fid,
                                Data = new { IsBtn = false, IsMenu = false },
                                Pid  = menuNode.Id,
                                Text = button.Description
                            };
                            if (button.ButtonType == FapMenuButtonType.Grid)
                            {
                                toper.Icon = " fa fa-table";
                                foreach (var oper in opers)
                                {
                                    TreeDataView tcol = new TreeDataView();
                                    tcol.Id   = $"{menuNode.Id}|{button.ButtonType}|{ button.ButtonID }|{oper.Key}";
                                    tcol.Data = new { IsBtn = true, IsMenu = false };
                                    tcol.Pid  = toper.Id;
                                    tcol.Text = oper.Description;
                                    tcol.Icon = GetOperIcon(oper.Value.ParseEnum <OperEnum>());
                                    toper.Children.Add(tcol);
                                }
                            }
                            else if (button.ButtonType == FapMenuButtonType.Tree)
                            {
                                toper.Icon = " fa fa-code-fork";
                                foreach (var oper in opers)
                                {
                                    if (oper.Key == (int)OperEnum.Add ||
                                        oper.Key == (int)OperEnum.Update ||
                                        oper.Key == (int)OperEnum.Delete ||
                                        oper.Key == (int)OperEnum.Refresh)
                                    {
                                        TreeDataView tcol = new TreeDataView();
                                        tcol.Id   = $"{menuNode.Id}|{button.ButtonType}|{ button.ButtonID }|{oper.Key}";
                                        tcol.Data = new { IsBtn = true, IsMenu = false };
                                        tcol.Pid  = toper.Id;
                                        tcol.Text = oper.Description;
                                        tcol.Icon = GetOperIcon(oper.Value.ParseEnum <OperEnum>());
                                        toper.Children.Add(tcol);
                                    }
                                }
                            }
                            else if (button.ButtonType == FapMenuButtonType.Link || button.ButtonType == FapMenuButtonType.Button)
                            {
                                toper.Id   = $"{menuNode.Id}|button|{ button.ButtonID }|1";
                                toper.Icon = "fa  fa-bolt";
                                toper.Data = new { IsBtn = true, IsMenu = false };
                            }
                            yield return(toper);
                        }
                    }
                }
            }
        }