增加功能:菜单维护页面查询区域增加下拉框智能提示 closed #ITDMN

#Issue
https://gitee.com/LongbowEnterprise/dashboard/issues?id=ITDMN
This commit is contained in:
Argo Zhang 2019-03-11 15:45:38 +08:00
parent b20c61bf0e
commit 8d78b115f5
7 changed files with 80 additions and 13 deletions

View File

@ -2,13 +2,14 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Linq;
namespace Bootstrap.Admin.Controllers.Api
{
/// <summary>
/// 数据字典分类
/// </summary>
[Route("api/[controller]")]
[Route("api/[controller]/[action]")]
[ApiController]
public class CategoryController : ControllerBase
{
@ -18,9 +19,29 @@ namespace Bootstrap.Admin.Controllers.Api
/// <returns></returns>
[HttpGet]
[AllowAnonymous]
public IEnumerable<string> Get()
public IEnumerable<string> RetrieveDictCategorys()
{
return DictHelper.RetrieveCategories();
}
/// <summary>
///
/// </summary>
/// <returns></returns>
[HttpGet]
public IEnumerable<string> RetrieveMenus()
{
return MenuHelper.RetrieveAllMenus(User.Identity.Name).OrderBy(m => m.Name).Select(m => m.Name);
}
/// <summary>
///
/// </summary>
/// <returns></returns>
[HttpGet]
public IEnumerable<string> RetrieveParentMenus()
{
return MenuHelper.RetrieveMenus(User.Identity.Name).Where(m => m.Menus.Count() > 0).OrderBy(m => m.Name).Select(m => m.Name);
}
}
}

View File

@ -15,9 +15,11 @@
@section javascript {
<environment include="Development">
<script src="~/lib/nestable2/jquery.nestable.js"></script>
<script src="~/lib/bootstrap-3-typeahead/bootstrap3-typeahead.js"></script>
</environment>
<environment exclude="Development">
<script src="~/lib/nestable2/jquery.nestable.min.js"></script>
<script src="~/lib/bootstrap-3-typeahead/bootstrap3-typeahead.min.js"></script>
</environment>
<script src="~/js/menus.js" asp-append-version="true"></script>
}

View File

@ -613,3 +613,9 @@ pre {
.key {
color: red;
}
.typeahead {
max-height: 300px;
overflow: auto;
padding: 6px 0;
}

View File

@ -28,7 +28,7 @@
// autocomplete
$.bc({
url: "api/Category",
url: "api/Category/RetrieveDictCategorys",
callback: function (result) {
$('#txt_dict_cate').typeahead({
source: result,

View File

@ -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'
});
}
});
});

View File

@ -76,7 +76,8 @@ namespace Bootstrap.DataAccess
/// <summary>
///
/// </summary>
/// <param name="name"></param>
/// <param name="appId"></param>
/// <param name="userName"></param>
/// <param name="activeUrl"></param>
/// <returns></returns>
public static IEnumerable<BootstrapMenu> RetrieveAppMenus(string appId, string userName, string activeUrl)
@ -89,10 +90,8 @@ namespace Bootstrap.DataAccess
/// <summary>
/// 通过当前用户名获得后台菜单,层次化后集合
/// </summary>
/// <param name="db"></param>
/// <param name="userName">当前登陆的用户名</param>
/// <param name="activeUrl">当前访问菜单</param>
/// <param name="connName">连接字符串名称默认为ba</param>
/// <returns></returns>
public static IEnumerable<BootstrapMenu> RetrieveSystemMenus(string userName, string activeUrl = null)
{
@ -105,7 +104,7 @@ namespace Bootstrap.DataAccess
/// </summary>
/// <param name="userName"></param>
/// <returns></returns>
public static IEnumerable<object> RetrieveMenus(string userName)
public static IEnumerable<BootstrapMenu> RetrieveMenus(string userName)
{
var menus = RetrieveAllMenus(userName);
return DbHelper.CascadeMenus(menus);
@ -116,6 +115,6 @@ namespace Bootstrap.DataAccess
/// </summary>
/// <param name="userName"></param>
/// <returns></returns>
private static IEnumerable<BootstrapMenu> RetrieveAllMenus(string userName) => CacheManager.GetOrAdd($"{RetrieveMenusAll}-{userName}", key => DbContextManager.Create<Menu>().RetrieveAllMenus(userName), RetrieveMenusAll);
public static IEnumerable<BootstrapMenu> RetrieveAllMenus(string userName) => CacheManager.GetOrAdd($"{RetrieveMenusAll}-{userName}", key => DbContextManager.Create<Menu>().RetrieveAllMenus(userName), RetrieveMenusAll);
}
}

View File

@ -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<IEnumerable<string>>();
var cates = await Client.GetAsJsonAsync<IEnumerable<string>>("RetrieveDictCategorys");
Assert.NotEmpty(cates);
}
[Fact]
public async void Menus_Ok()
{
var cates = await Client.GetAsJsonAsync<IEnumerable<string>>("RetrieveMenus");
Assert.NotEmpty(cates);
}
[Fact]
public async void ParentMenus_Ok()
{
var cates = await Client.GetAsJsonAsync<IEnumerable<string>>("RetrieveParentMenus");
Assert.NotEmpty(cates);
}
}