From 4d83bf470b9aab811b26b6f1a60807be4dc17afd Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Thu, 6 Feb 2020 13:20:14 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E9=83=A8=E9=97=A8=E7=BB=B4=E6=8A=A4?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=8E=88=E6=9D=83=E6=8C=89=E9=92=AE=E6=96=B9?= =?UTF-8?q?=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Pages/Views/Admin/Groups.razor | 16 ++- .../Pages/Views/Components/GroupsBase.cs | 126 +++++++++++++++++- 2 files changed, 136 insertions(+), 6 deletions(-) diff --git a/src/admin/Bootstrap.Admin/Pages/Views/Admin/Groups.razor b/src/admin/Bootstrap.Admin/Pages/Views/Admin/Groups.razor index 161e532a..c4d15289 100644 --- a/src/admin/Bootstrap.Admin/Pages/Views/Admin/Groups.razor +++ b/src/admin/Bootstrap.Admin/Pages/Views/Admin/Groups.razor @@ -1,6 +1,6 @@ @inherits GroupsBase - + @@ -36,3 +36,17 @@ + + + + + + + + + + + + + + diff --git a/src/admin/Bootstrap.Admin/Pages/Views/Components/GroupsBase.cs b/src/admin/Bootstrap.Admin/Pages/Views/Components/GroupsBase.cs index e92d7ccb..c43f0e31 100644 --- a/src/admin/Bootstrap.Admin/Pages/Views/Components/GroupsBase.cs +++ b/src/admin/Bootstrap.Admin/Pages/Views/Components/GroupsBase.cs @@ -1,4 +1,5 @@ using Bootstrap.Admin.Pages.Components; +using Bootstrap.Admin.Pages.Shared; using Bootstrap.DataAccess; using System; using System.Collections.Generic; @@ -21,7 +22,7 @@ namespace Bootstrap.Admin.Pages.Views.Admin.Components if (!string.IsNullOrEmpty(QueryModel.GroupName)) data = data.Where(d => d.GroupName.Contains(QueryModel.GroupName, StringComparison.OrdinalIgnoreCase)); if (!string.IsNullOrEmpty(QueryModel.Description)) data = data.Where(d => d.Description != null && d.Description.Contains(QueryModel.Description, StringComparison.OrdinalIgnoreCase)); if (!string.IsNullOrEmpty(options.SearchText)) data = data.Where(d => d.GroupName.Contains(options.SearchText, StringComparison.OrdinalIgnoreCase) || (d.Description ?? "").Contains(options.SearchText, StringComparison.OrdinalIgnoreCase)); - + // sort data = options.SortName switch { @@ -56,19 +57,134 @@ namespace Bootstrap.Admin.Pages.Views.Admin.Components } /// - /// 分配用户方法 + /// 获得/设置 Modal 实例 + /// + protected AssignModalBase? AssignUserModal { get; set; } + + /// + /// 弹窗分配角色方法 /// protected void AssignUsers() { - + // 菜单对角色授权操作 + if (EditPage != null) + { + if (EditPage.SelectedItems.Count() != 1) + { + ShowMessage("用户授权", "请选择一个部门", ToastCategory.Information); + } + else + { + var groupId = EditPage.SelectedItems.First().Id; + if (!string.IsNullOrEmpty(groupId)) + { + var users = UserHelper.RetrievesByGroupId(groupId); + AssignUserModal?.Update(users); + } + } + } } /// - /// 分配角色方法 + /// 保存授权部门方法 + /// + protected void SaveUsers(IEnumerable users) + { + bool ret = false; + if (EditPage != null && EditPage.SelectedItems.Any()) + { + var groupId = EditPage.SelectedItems.First().Id; + var userIds = users.Where(r => r.Checked == "checked").Select(r => r.Id ?? ""); + if (!string.IsNullOrEmpty(groupId)) ret = UserHelper.SaveByGroupId(groupId, userIds); + } + ShowMessage("用户授权", ret ? "保存成功" : "保存失败", ret ? ToastCategory.Success : ToastCategory.Error); + } + + /// + /// 选择框点击时调用此方法 + /// + /// + /// + protected void OnUserClick(User item, bool check) + { + item.Checked = check ? "checked" : ""; + } + + /// + /// 设置初始化值 + /// + protected CheckBoxState SetUserCheck(User item) => item.Checked == "checked" ? CheckBoxState.Checked : CheckBoxState.UnChecked; + + /// + /// Toast 组件实例 + /// + protected Toast? Toast { get; set; } + + /// + /// 显示提示信息 + /// + /// + /// + /// + protected void ShowMessage(string title, string text, ToastCategory cate = ToastCategory.Success) => Toast?.ShowMessage(title, text, cate); + + /// + /// 获得/设置 Modal 实例 + /// + protected AssignModalBase? AssignRoleModal { get; set; } + + /// + /// 弹窗分配角色方法 /// protected void AssignRoles() { - + // 菜单对角色授权操作 + if (EditPage != null) + { + if (EditPage.SelectedItems.Count() != 1) + { + ShowMessage("角色授权", "请选择一个部门", ToastCategory.Information); + } + else + { + var groupId = EditPage.SelectedItems.First().Id; + if (!string.IsNullOrEmpty(groupId)) + { + var roles = RoleHelper.RetrievesByGroupId(groupId); + AssignRoleModal?.Update(roles); + } + } + } } + + /// + /// 保存授权角色方法 + /// + protected void SaveRoles(IEnumerable roles) + { + bool ret = false; + if (EditPage != null && EditPage.SelectedItems.Any()) + { + var groupId = EditPage.SelectedItems.First().Id; + var roleIds = roles.Where(r => r.Checked == "checked").Select(r => r.Id ?? ""); + if (!string.IsNullOrEmpty(groupId)) ret = RoleHelper.SaveByGroupId(groupId, roleIds); + } + ShowMessage("角色授权", ret ? "保存成功" : "保存失败", ret ? ToastCategory.Success : ToastCategory.Error); + } + + /// + /// 选择框点击时调用此方法 + /// + /// + /// + protected void OnClick(Role item, bool check) + { + item.Checked = check ? "checked" : ""; + } + + /// + /// 设置初始化值 + /// + protected CheckBoxState SetCheck(Role item) => item.Checked == "checked" ? CheckBoxState.Checked : CheckBoxState.UnChecked; } }