/// <summary> /// 获取功能菜单适用于Vue Tree树形 /// </summary> /// <returns></returns> public async Task <List <ModuleFunctionOutputDto> > GetAllFunctionTree() { string where = "1=1"; List <ModuleFunctionOutputDto> reslist = new List <ModuleFunctionOutputDto>(); IEnumerable <SystemType> listSystemType = await systemTypeRepository.GetListWhereAsync(where); foreach (SystemType systemType in listSystemType) { ModuleFunctionOutputDto menuTreeTableOutputDto = new ModuleFunctionOutputDto(); menuTreeTableOutputDto.Id = systemType.Id; menuTreeTableOutputDto.FullName = systemType.FullName; menuTreeTableOutputDto.FunctionTag = 0; menuTreeTableOutputDto.IsShow = true; IEnumerable <Menu> elist = await menuRepository.GetListWhereAsync("SystemTypeId='" + systemType.Id + "'"); if (elist.Count() > 0) { List <Menu> list = elist.OrderBy(t => t.SortCode).ToList(); menuTreeTableOutputDto.Children = GetSubMenus(list, "").ToList <ModuleFunctionOutputDto>(); } reslist.Add(menuTreeTableOutputDto); } return(reslist); }
/// <summary> /// 获取子菜单,递归调用 /// </summary> /// <param name="data"></param> /// <param name="parentId">父级Id</param> /// <returns></returns> private List <ModuleFunctionOutputDto> GetSubMenus(List <Menu> data, string parentId) { List <ModuleFunctionOutputDto> list = new List <ModuleFunctionOutputDto>(); var ChilList = data.FindAll(t => t.ParentId == parentId); foreach (Menu entity in ChilList) { ModuleFunctionOutputDto menuTreeTableOutputDto = new ModuleFunctionOutputDto(); menuTreeTableOutputDto.Id = entity.Id; menuTreeTableOutputDto.FullName = entity.FullName; menuTreeTableOutputDto.IsShow = false; if (entity.MenuType == "F") { menuTreeTableOutputDto.FunctionTag = 2; } else { menuTreeTableOutputDto.FunctionTag = 1; } menuTreeTableOutputDto.Children = GetSubMenus(data, entity.Id).MapTo <ModuleFunctionOutputDto>(); list.Add(menuTreeTableOutputDto); } return(list); }