예제 #1
0
        /// <summary>
        /// 加载菜单
        /// </summary>
        public async Task LoadModules()
        {
            try
            {
                ModuleComponent loader = new ModuleComponent();
                _IModule = await loader.GetModules();

                foreach (var m in _IModule)
                {
                    //寻找模块对应的组
                    var mg = ModuleGroups.FirstOrDefault(t => t.MenuType.Equals(m.ModuleType));
                    if (mg != null)
                    {
                        MenuGroupModel groupModel = new MenuGroupModel();
                        groupModel.MenuCode  = m.Code;
                        groupModel.MenuName  = m.Name;
                        groupModel.MenuType  = m.ModuleType;
                        groupModel.AuthValue = m.Autority;
                        mg.Nodes.Add(groupModel);
                        #region 添加功能按钮

                        var authItemList = _TreeList.Where(t => t.MenuCode.Equals(m.Code)).ToList();

                        foreach (var a in authItemList)
                        {
                            groupModel.Nodes.Add(new MenuGroupModel()
                            {
                                MenuName  = a.AuthorityName,
                                MenuCode  = a.MenuCode,
                                AuthValue = a.AuthorityValue,
                            });
                        }

                        #endregion
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
예제 #2
0
        /// <summary>
        /// 加载模块-根据权限
        /// </summary>
        public async void LoadModules()
        {
            try
            {
                ModuleComponent loader = new ModuleComponent();
                _IModule = await Task.Run(() => loader.GetModules());

                if (_IModule == null)
                {
                    return;
                }
                foreach (var m in _IModule)
                {
                    if (!loader.ModuleVerify(m))
                    {
                        continue;
                    }

                    var mg = ModuleGroups.FirstOrDefault(t => t.ModuleType.Equals(m.ModuleType)); //寻找模块对应的组
                    if (mg != null)
                    {
                        if (mg.Modules == null)
                        {
                            mg.Modules = new ObservableCollection <Module>();
                        }
                        int?   auth = Loginer.LoginerUser.IsAdmin == true ? m.Autority : loader.UserAuthority.Authorities;
                        Module md   = new Module(m.Name, m.Remark, auth, m.ModuleNameSpace, m.ICON);
                        mg.Modules.Add(md);
                        Modules.Add(md);
                    }
                }
                GC.Collect();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }