diff --git a/src/admin/Bootstrap.Admin/Pages/Views/Admin/Roles.razor b/src/admin/Bootstrap.Admin/Pages/Views/Admin/Roles.razor index 04c606c8..cf9699a0 100644 --- a/src/admin/Bootstrap.Admin/Pages/Views/Admin/Roles.razor +++ b/src/admin/Bootstrap.Admin/Pages/Views/Admin/Roles.razor @@ -1,6 +1,6 @@ @inherits RolesBase - + @@ -37,3 +37,23 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/src/admin/Bootstrap.Admin/Pages/Views/Components/RolesBase.cs b/src/admin/Bootstrap.Admin/Pages/Views/Components/RolesBase.cs index 6d6d687e..537ba7a0 100644 --- a/src/admin/Bootstrap.Admin/Pages/Views/Components/RolesBase.cs +++ b/src/admin/Bootstrap.Admin/Pages/Views/Components/RolesBase.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.RoleName)) data = data.Where(d => d.RoleName.Contains(QueryModel.RoleName, 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.RoleName.Contains(options.SearchText, StringComparison.OrdinalIgnoreCase) || d.Description.Contains(options.SearchText, StringComparison.OrdinalIgnoreCase)); - + // sort data = options.SortName switch { @@ -55,35 +56,206 @@ 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 roleId = EditPage.SelectedItems.First().Id; + if (!string.IsNullOrEmpty(roleId)) + { + var users = UserHelper.RetrievesByRoleId(roleId); + AssignUserModal?.Update(users); + } + } + } } /// - /// 分配部门方法 + /// 保存授权部门方法 + /// + protected void SaveUsers(IEnumerable users) + { + bool ret = false; + if (EditPage != null && EditPage.SelectedItems.Any()) + { + var roleId = EditPage.SelectedItems.First().Id; + var userIds = users.Where(r => r.Checked == "checked").Select(r => r.Id ?? ""); + if (!string.IsNullOrEmpty(roleId)) ret = UserHelper.SaveByRoleId(roleId, 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? AssignGroupModal { get; set; } + + /// + /// 弹窗分配角色方法 /// protected void AssignGroups() { - + // 菜单对角色授权操作 + if (EditPage != null) + { + if (EditPage.SelectedItems.Count() != 1) + { + ShowMessage("部门授权", "请选择一个角色", ToastCategory.Information); + } + else + { + var roleId = EditPage.SelectedItems.First().Id; + if (!string.IsNullOrEmpty(roleId)) + { + var groups = GroupHelper.RetrievesByRoleId(roleId); + AssignGroupModal?.Update(groups); + } + } + } } /// - /// 分配菜单方法 + /// 保存授权部门方法 + /// + protected void SaveGroups(IEnumerable groups) + { + bool ret = false; + if (EditPage != null && EditPage.SelectedItems.Any()) + { + var roleId = EditPage.SelectedItems.First().Id; + var groupIds = groups.Where(r => r.Checked == "checked").Select(r => r.Id ?? ""); + if (!string.IsNullOrEmpty(roleId)) ret = GroupHelper.SaveByRoleId(roleId, groupIds); + } + ShowMessage("部门授权", ret ? "保存成功" : "保存失败", ret ? ToastCategory.Success : ToastCategory.Error); + } + + /// + /// 选择框点击时调用此方法 + /// + /// + /// + protected void OnGroupClick(Group item, bool check) + { + item.Checked = check ? "checked" : ""; + } + + /// + /// 设置初始化值 + /// + protected CheckBoxState SetGroupCheck(Group item) => item.Checked == "checked" ? CheckBoxState.Checked : CheckBoxState.UnChecked; + + /// + /// 获得/设置 Modal 实例 + /// + protected AssignModalBase? AssignAppModal { get; set; } + + /// + /// 弹窗分配角色方法 + /// + protected void AssignApps() + { + // 菜单对角色授权操作 + if (EditPage != null) + { + if (EditPage.SelectedItems.Count() != 1) + { + ShowMessage("应用程序授权", "请选择一个角色", ToastCategory.Information); + } + else + { + var roleId = EditPage.SelectedItems.First().Id; + if (!string.IsNullOrEmpty(roleId)) + { + var apps = AppHelper.RetrievesByRoleId(roleId); + AssignAppModal?.Update(apps); + } + } + } + } + + /// + /// 保存授权部门方法 + /// + protected void SaveApps(IEnumerable apps) + { + bool ret = false; + if (EditPage != null && EditPage.SelectedItems.Any()) + { + var roleId = EditPage.SelectedItems.First().Id; + var appIds = apps.Where(r => r.Checked == "checked").Select(r => r.Id ?? ""); + if (!string.IsNullOrEmpty(roleId)) ret = AppHelper.SaveByRoleId(roleId, appIds); + } + ShowMessage("应用程序授权", ret ? "保存成功" : "保存失败", ret ? ToastCategory.Success : ToastCategory.Error); + } + + /// + /// 选择框点击时调用此方法 + /// + /// + /// + protected void OnAppClick(DataAccess.App item, bool check) + { + item.Checked = check ? "checked" : ""; + } + + /// + /// 设置初始化值 + /// + protected CheckBoxState SetAppCheck(DataAccess.App item) => item.Checked == "checked" ? CheckBoxState.Checked : CheckBoxState.UnChecked; + + /// + /// 获得/设置 Modal 实例 + /// + protected AssignModalBase? AssignMenuModal { get; set; } + + /// + /// 弹窗分配菜单方法 /// protected void AssignMenus() { } - - /// - /// 分配应用方法 - /// - protected void AssignApps() - { - - } } }