public async Task <IActionResult> Index() { // bool b = await _redisCache.SetAsync<string>("TwBusWeb", "测试2222"); string strApiUrl = ApiServerAddr + @"/api/v1/manage/querymenu"; SearchMenuParamsDto paramsDto = new SearchMenuParamsDto(); paramsDto.parentId = 0; paramsDto.lstRoleId = UserInfo.lstRoleID; string strJson = JsonHelper.SerializeObject(paramsDto); HttpContent content = new StringContent(strJson); string strRes = await ApiHelp.ApiPostWithTokenAsync(strApiUrl, content, AccessToken); List <MenuDto> lstMenu = new List <MenuDto>(); if (strRes.Contains("网络错误") == false) { lstMenu = JsonHelper.Deserialize <List <MenuDto> >(strRes); } return(View(lstMenu)); }
/// <summary> /// 根据父ID获取菜单列表SelectList /// </summary> /// <param name="menulSelectList"></param> /// <param name="parentID"></param> public void GetMenuList(List <SelectListItem> menulSelectList, int parentID) { IList <MenuDto> list = new List <MenuDto>(); try { string strApiUrl = ApiServerAddr + @"/api/v1/manage/querymenu"; SearchMenuParamsDto paramsDto = new SearchMenuParamsDto(); paramsDto.parentId = parentID; string strJson = JsonHelper.SerializeObject(paramsDto); HttpContent content = new StringContent(strJson); string strRes = ApiHelp.ApiPostWithTokenAsync(strApiUrl, content, AccessToken).Result; if (strRes.Contains("网络错误") == false) { list = JsonHelper.Deserialize <List <MenuDto> >(strRes); } } catch { throw; } foreach (var item in list) { SelectListItem selectitem = new SelectListItem(); string name = item.Name; string id = item.id.ToString(); if (item.Class_layer == parentID) { menulSelectList.Add(new SelectListItem { Text = name, Value = id }); } else { name = "├ " + name; name = Utils.StringOfChar(item.Class_layer - 1, " ") + name; menulSelectList.Add(new SelectListItem { Text = name, Value = id }); } } }
public async Task <string> GetMenuGetListHaveSort([FromBody] SearchMenuParamsDto dto) { try { var list = await _menuRepository.GetListHaveSortAsync(dto.parentId, dto.IsShowHide, dto.lstRoleId); var dtos = AutoMapper.Mapper.Map <List <MenuDto> >(list); return(Common.JsonHelper.SerializeObject(dtos)); } catch (Exception ex) { log.Error("GetMenuGetListHaveSort方法错误", ex); throw; } }
private async Task <List <MenuDto> > GetMenuAsync(UserViewModel user) { string strToken = HttpContext.Session.GetString("token"); if (string.IsNullOrEmpty(strToken)) { //获取访问token AccessTokenModel tokenModel = await ApiHelp.GetAccessTokenAsync(user.JobNumber, user.Pwd, ApiServerAddr); HttpContext.Session.SetString("token", tokenModel.access_token); strToken = tokenModel.access_token; } string strApiUrl = ApiServerAddr + @"/api/v1/manage/querymenu"; SearchMenuParamsDto paramsDto = new SearchMenuParamsDto(); paramsDto.parentId = 0; paramsDto.lstRoleId = user.lstRoleID; string strJson = JsonHelper.SerializeObject(paramsDto); HttpContent content = new StringContent(strJson); string strRes = await ApiHelp.ApiPostWithTokenAsync(strApiUrl, content, strToken); List <MenuDto> lstMenu = new List <MenuDto>(); if (strRes.Contains("网络错误") == false) { lstMenu = JsonHelper.Deserialize <List <MenuDto> >(strRes); } return(lstMenu); //return Task.FromResult(_menuService.MenuGetListHaveSort(0, true, rolelist).Where(c => c.IsLock == 0).ToList()); }