From 8d78b115f5dd7a7dbf0637feb4c76b792861b0d7 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Mon, 11 Mar 2019 15:45:38 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=8A=9F=E8=83=BD=EF=BC=9A?= =?UTF-8?q?=E8=8F=9C=E5=8D=95=E7=BB=B4=E6=8A=A4=E9=A1=B5=E9=9D=A2=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2=E5=8C=BA=E5=9F=9F=E5=A2=9E=E5=8A=A0=E4=B8=8B=E6=8B=89?= =?UTF-8?q?=E6=A1=86=E6=99=BA=E8=83=BD=E6=8F=90=E7=A4=BA=20closed=20#ITDMN?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #Issue https://gitee.com/LongbowEnterprise/dashboard/issues?id=ITDMN --- .../Controllers/Api/CategoryController.cs | 25 +++++++++++++++++-- Bootstrap.Admin/Views/Admin/Menus.cshtml | 2 ++ Bootstrap.Admin/wwwroot/css/site.css | 12 ++++++--- Bootstrap.Admin/wwwroot/js/dicts.js | 2 +- Bootstrap.Admin/wwwroot/js/menus.js | 25 +++++++++++++++++++ Bootstrap.DataAccess/Helper/MenuHelper.cs | 9 +++---- UnitTest/Bootstrap.Admin/Api/CategoryTest.cs | 18 +++++++++++-- 7 files changed, 80 insertions(+), 13 deletions(-) diff --git a/Bootstrap.Admin/Controllers/Api/CategoryController.cs b/Bootstrap.Admin/Controllers/Api/CategoryController.cs index afaf0754..84039e5c 100644 --- a/Bootstrap.Admin/Controllers/Api/CategoryController.cs +++ b/Bootstrap.Admin/Controllers/Api/CategoryController.cs @@ -2,13 +2,14 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using System.Collections.Generic; +using System.Linq; namespace Bootstrap.Admin.Controllers.Api { /// /// 数据字典分类 /// - [Route("api/[controller]")] + [Route("api/[controller]/[action]")] [ApiController] public class CategoryController : ControllerBase { @@ -18,9 +19,29 @@ namespace Bootstrap.Admin.Controllers.Api /// [HttpGet] [AllowAnonymous] - public IEnumerable Get() + public IEnumerable RetrieveDictCategorys() { return DictHelper.RetrieveCategories(); } + + /// + /// + /// + /// + [HttpGet] + public IEnumerable RetrieveMenus() + { + return MenuHelper.RetrieveAllMenus(User.Identity.Name).OrderBy(m => m.Name).Select(m => m.Name); + } + + /// + /// + /// + /// + [HttpGet] + public IEnumerable RetrieveParentMenus() + { + return MenuHelper.RetrieveMenus(User.Identity.Name).Where(m => m.Menus.Count() > 0).OrderBy(m => m.Name).Select(m => m.Name); + } } } diff --git a/Bootstrap.Admin/Views/Admin/Menus.cshtml b/Bootstrap.Admin/Views/Admin/Menus.cshtml index 2bb27feb..7cbdaa97 100644 --- a/Bootstrap.Admin/Views/Admin/Menus.cshtml +++ b/Bootstrap.Admin/Views/Admin/Menus.cshtml @@ -15,9 +15,11 @@ @section javascript { + + } diff --git a/Bootstrap.Admin/wwwroot/css/site.css b/Bootstrap.Admin/wwwroot/css/site.css index 2b52566e..21248ee7 100644 --- a/Bootstrap.Admin/wwwroot/css/site.css +++ b/Bootstrap.Admin/wwwroot/css/site.css @@ -234,9 +234,9 @@ padding: 1px 5px; } - td .btn:not(:first-child) { - margin-left: 5px; - } +td .btn:not(:first-child) { + margin-left: 5px; +} .card-img { max-width: 258px; @@ -613,3 +613,9 @@ pre { .key { color: red; } + +.typeahead { + max-height: 300px; + overflow: auto; + padding: 6px 0; +} diff --git a/Bootstrap.Admin/wwwroot/js/dicts.js b/Bootstrap.Admin/wwwroot/js/dicts.js index 4bb6d8d9..e024b8ff 100644 --- a/Bootstrap.Admin/wwwroot/js/dicts.js +++ b/Bootstrap.Admin/wwwroot/js/dicts.js @@ -28,7 +28,7 @@ // autocomplete $.bc({ - url: "api/Category", + url: "api/Category/RetrieveDictCategorys", callback: function (result) { $('#txt_dict_cate').typeahead({ source: result, diff --git a/Bootstrap.Admin/wwwroot/js/menus.js b/Bootstrap.Admin/wwwroot/js/menus.js index c92b3963..5a75ad9f 100644 --- a/Bootstrap.Admin/wwwroot/js/menus.js +++ b/Bootstrap.Admin/wwwroot/js/menus.js @@ -264,4 +264,29 @@ } } }); + + // autocomplete + $.bc({ + url: "api/Category/RetrieveMenus", + callback: function (result) { + $('#txt_menus_name').typeahead({ + source: result, + showHintOnFocus: 'all', + fitToElement: true, + items: 'all' + }); + } + }); + + $.bc({ + url: "api/Category/RetrieveParentMenus", + callback: function (result) { + $('#txt_parent_menus_name').typeahead({ + source: result, + showHintOnFocus: 'all', + fitToElement: true, + items: 'all' + }); + } + }); }); \ No newline at end of file diff --git a/Bootstrap.DataAccess/Helper/MenuHelper.cs b/Bootstrap.DataAccess/Helper/MenuHelper.cs index 930c2fd2..79d71f08 100644 --- a/Bootstrap.DataAccess/Helper/MenuHelper.cs +++ b/Bootstrap.DataAccess/Helper/MenuHelper.cs @@ -76,7 +76,8 @@ namespace Bootstrap.DataAccess /// /// /// - /// + /// + /// /// /// public static IEnumerable RetrieveAppMenus(string appId, string userName, string activeUrl) @@ -89,10 +90,8 @@ namespace Bootstrap.DataAccess /// /// 通过当前用户名获得后台菜单,层次化后集合 /// - /// /// 当前登陆的用户名 /// 当前访问菜单 - /// 连接字符串名称,默认为ba /// public static IEnumerable RetrieveSystemMenus(string userName, string activeUrl = null) { @@ -105,7 +104,7 @@ namespace Bootstrap.DataAccess /// /// /// - public static IEnumerable RetrieveMenus(string userName) + public static IEnumerable RetrieveMenus(string userName) { var menus = RetrieveAllMenus(userName); return DbHelper.CascadeMenus(menus); @@ -116,6 +115,6 @@ namespace Bootstrap.DataAccess /// /// /// - private static IEnumerable RetrieveAllMenus(string userName) => CacheManager.GetOrAdd($"{RetrieveMenusAll}-{userName}", key => DbContextManager.Create().RetrieveAllMenus(userName), RetrieveMenusAll); + public static IEnumerable RetrieveAllMenus(string userName) => CacheManager.GetOrAdd($"{RetrieveMenusAll}-{userName}", key => DbContextManager.Create().RetrieveAllMenus(userName), RetrieveMenusAll); } } diff --git a/UnitTest/Bootstrap.Admin/Api/CategoryTest.cs b/UnitTest/Bootstrap.Admin/Api/CategoryTest.cs index 4d43bfa5..77690776 100644 --- a/UnitTest/Bootstrap.Admin/Api/CategoryTest.cs +++ b/UnitTest/Bootstrap.Admin/Api/CategoryTest.cs @@ -8,9 +8,23 @@ namespace Bootstrap.Admin.Api public CategoryTest(BAWebHost factory) : base(factory, "api/Category") { } [Fact] - public async void Get_Ok() + public async void DictCategorys_Ok() { - var cates = await Client.GetAsJsonAsync>(); + var cates = await Client.GetAsJsonAsync>("RetrieveDictCategorys"); + Assert.NotEmpty(cates); + } + + [Fact] + public async void Menus_Ok() + { + var cates = await Client.GetAsJsonAsync>("RetrieveMenus"); + Assert.NotEmpty(cates); + } + + [Fact] + public async void ParentMenus_Ok() + { + var cates = await Client.GetAsJsonAsync>("RetrieveParentMenus"); Assert.NotEmpty(cates); } }