From 49cdbbb3f78c46cb83241d6744346a0dd73b3461 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Sun, 19 Jan 2020 22:25:22 +0800 Subject: [PATCH 1/4] =?UTF-8?q?feat:=20Blazor=20=E6=A8=A1=E5=BC=8F?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=8F=9C=E5=8D=95=E7=BB=B4=E6=8A=A4=E7=BD=91?= =?UTF-8?q?=E9=A1=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Extensions/DisplayNamesExtensions.cs | 11 ++ .../Bootstrap.Admin/Pages/Admin/Menus.razor | 60 ++++++- .../Pages/Components/MenusBase.cs | 146 ++++++++++++++++++ 3 files changed, 212 insertions(+), 5 deletions(-) create mode 100644 src/admin/Bootstrap.Admin/Pages/Components/MenusBase.cs diff --git a/src/admin/Bootstrap.Admin/Extensions/DisplayNamesExtensions.cs b/src/admin/Bootstrap.Admin/Extensions/DisplayNamesExtensions.cs index ba419bdca..9eab8d6dd 100644 --- a/src/admin/Bootstrap.Admin/Extensions/DisplayNamesExtensions.cs +++ b/src/admin/Bootstrap.Admin/Extensions/DisplayNamesExtensions.cs @@ -32,6 +32,17 @@ namespace Microsoft.AspNetCore.Builder _displayNameCache.TryAdd((typeof(Group), nameof(Group.GroupCode)), "部门编码"); _displayNameCache.TryAdd((typeof(Group), nameof(Group.GroupName)), "部门名称"); _displayNameCache.TryAdd((typeof(Group), nameof(Group.Description)), "部门描述"); + + _displayNameCache.TryAdd((typeof(BootstrapMenu), nameof(BootstrapMenu.Name)), "菜单名称"); + _displayNameCache.TryAdd((typeof(BootstrapMenu), nameof(BootstrapMenu.ParentName)), "父级菜单"); + _displayNameCache.TryAdd((typeof(BootstrapMenu), nameof(BootstrapMenu.Order)), "菜单序号"); + _displayNameCache.TryAdd((typeof(BootstrapMenu), nameof(BootstrapMenu.Icon)), "菜单图标"); + _displayNameCache.TryAdd((typeof(BootstrapMenu), nameof(BootstrapMenu.Url)), "菜单路径"); + _displayNameCache.TryAdd((typeof(BootstrapMenu), nameof(BootstrapMenu.Category)), "菜单类别"); + _displayNameCache.TryAdd((typeof(BootstrapMenu), nameof(BootstrapMenu.Target)), "目标"); + _displayNameCache.TryAdd((typeof(BootstrapMenu), nameof(BootstrapMenu.IsResource)), "菜单类型"); + _displayNameCache.TryAdd((typeof(BootstrapMenu), nameof(BootstrapMenu.Application)), "所属应用"); + return services; } diff --git a/src/admin/Bootstrap.Admin/Pages/Admin/Menus.razor b/src/admin/Bootstrap.Admin/Pages/Admin/Menus.razor index fecf0af70..338d63e7f 100644 --- a/src/admin/Bootstrap.Admin/Pages/Admin/Menus.razor +++ b/src/admin/Bootstrap.Admin/Pages/Admin/Menus.razor @@ -1,6 +1,56 @@ - -

Menus

+@inherits MenusBase -@code { - -} + + + + + + + + + + + + diff --git a/src/admin/Bootstrap.Admin/Pages/Components/MenusBase.cs b/src/admin/Bootstrap.Admin/Pages/Components/MenusBase.cs new file mode 100644 index 000000000..f5b834ef9 --- /dev/null +++ b/src/admin/Bootstrap.Admin/Pages/Components/MenusBase.cs @@ -0,0 +1,146 @@ +using Bootstrap.Admin.Components; +using Bootstrap.DataAccess; +using Bootstrap.Security; +using Microsoft.AspNetCore.Components; +using Microsoft.AspNetCore.Components.Authorization; +using System; +using System.Collections.Generic; +using System.Linq; + +namespace Bootstrap.Pages.Admin.Components +{ + /// + /// 菜单维护组件 + /// + public class MenusBase : QueryPageBase + { + /// + /// 获得 授权服务 + /// + [Inject] + protected AuthenticationStateProvider? AuthenticationStateProvider { get; set; } + + /// + /// 获得/设置 菜单类别 + /// + protected List QueryCategory { get; set; } = new List(new SelectedItem[] { + new SelectedItem() { Text = "全部", Value = "-1", Active = true }, + new SelectedItem() { Text = "系统菜单", Value = "0" }, + new SelectedItem() { Text = "外部菜单", Value = "1" } + }); + + /// + /// 获得/设置 菜单类型 + /// + protected List QueryResource { get; set; } = new List(new SelectedItem[] { + new SelectedItem() { Text = "全部", Value = "-1", Active = true }, + new SelectedItem() { Text = "菜单", Value = "0" }, + new SelectedItem() { Text = "资源", Value = "1" }, + new SelectedItem() { Text = "按钮", Value = "2" } + }); + + /// + /// 获得/设置 所属应用 + /// + protected List QueryApp { get; set; } = new List(new SelectedItem[] { + new SelectedItem() { Text = "全部", Value = "-1", Active = true } + }); + + + /// + /// 获得/设置 菜单类别 + /// + protected List DefineCategory { get; set; } = new List(new SelectedItem[] { + new SelectedItem() { Text = "系统菜单", Value = "0" }, + new SelectedItem() { Text = "外部菜单", Value = "1" } + }); + + /// + /// 获得/设置 菜单类型 + /// + protected List DefineResource { get; set; } = new List(new SelectedItem[] { + new SelectedItem() { Text = "菜单", Value = "0" }, + new SelectedItem() { Text = "资源", Value = "1" }, + new SelectedItem() { Text = "按钮", Value = "2" } + }); + + /// + /// 获得/设置 所属应用 + /// + protected List DefineApp { get; set; } = new List(); + + /// + /// 获得/设置 所属应用 + /// + protected List DefineTarget { get; set; } = new List() { + new SelectedItem() { Text = "本窗口", Value = "_self" }, + new SelectedItem() { Text = "新窗口", Value = "_blank" }, + new SelectedItem() { Text = "父级窗口", Value = "_parent" }, + new SelectedItem() { Text = "顶级窗口", Value = "_top" } + }; + + /// + /// 获得/设置 用户登录名 + /// + protected string? UserName { get; set; } + + /// + /// OnInitializedAsync 方法 + /// + /// + protected override async System.Threading.Tasks.Task OnInitializedAsync() + { + if (AuthenticationStateProvider != null) + { + var state = await AuthenticationStateProvider.GetAuthenticationStateAsync(); + UserName = state?.User.Identity.Name; + } + } + + /// + /// OnParametersSet 方法 + /// + /// + protected override void OnParametersSet() + { + QueryApp.AddRange(DictHelper.RetrieveApps().Select(app => new SelectedItem() { Text = app.Value, Value = app.Key })); + DefineApp.AddRange(DictHelper.RetrieveApps().Select(app => new SelectedItem() { Text = app.Value, Value = app.Key })); + } + + /// + /// 查询方法 + /// + /// 页码 + /// 每页显示数据条目数量 + protected override QueryData Query(int pageIndex, int pageItems) + { + var data = MenuHelper.RetrieveMenusByUserName(UserName); + if (!string.IsNullOrEmpty(QueryModel.Name)) data = data.Where(d => d.Name.Contains(QueryModel.Name, StringComparison.OrdinalIgnoreCase)); + if (!string.IsNullOrEmpty(QueryModel.ParentName)) data = data.Where(d => d.ParentName.Contains(QueryModel.ParentName, StringComparison.OrdinalIgnoreCase)); + if (!string.IsNullOrEmpty(QueryModel.Category)) data = data.Where(d => d.Category == QueryModel.Category); + if (QueryModel.IsResource != -1) data = data.Where(d => d.IsResource == QueryModel.IsResource); + if (!string.IsNullOrEmpty(QueryModel.Application)) data = data.Where(d => d.Application.Equals(QueryModel.Application, StringComparison.OrdinalIgnoreCase)); + var totalCount = data.Count(); + var items = data.Skip((pageIndex - 1) * pageItems).Take(pageItems); + return new QueryData() { Items = items, TotalCount = totalCount, PageIndex = pageIndex, PageItems = pageItems }; + } + + /// + /// 保存方法 + /// + protected override bool Save(BootstrapMenu item) => MenuHelper.Save(item); + + /// + /// 删除方法 + /// + protected override bool Delete(IEnumerable items) => MenuHelper.Delete(items.Select(item => item.Id ?? "")); + + /// + /// 分配角色方法 + /// + protected void AssignRoles() + { + + } + } +} -- Gitee From 5b3fea70eb5e86e7449c7df2384bed13bc967472 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Mon, 20 Jan 2020 10:37:27 +0800 Subject: [PATCH 2/4] =?UTF-8?q?feat:=20Blazor=20=E4=B8=8B=E6=8B=89?= =?UTF-8?q?=E6=A1=86=E7=BB=84=E4=BB=B6=E6=94=AF=E6=8C=81=20Disabled=20?= =?UTF-8?q?=E5=B1=9E=E6=80=A7=20=E9=BB=98=E8=AE=A4=E4=B8=BA=20false?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #Comment comment #BUGID #Issue close link fix https://gitee.com/LongbowEnterprise/dashboard/issues?id=BUGID # 样式 : feat(location): 接入登录API # # 登录功能与服务器对接 # ():