diff --git a/src/admin/Bootstrap.Admin/Pages/Views/Admin/Menus.razor b/src/admin/Bootstrap.Admin/Pages/Views/Admin/Menus.razor
index e9f1551e..aaed3f74 100644
--- a/src/admin/Bootstrap.Admin/Pages/Views/Admin/Menus.razor
+++ b/src/admin/Bootstrap.Admin/Pages/Views/Admin/Menus.razor
@@ -61,4 +61,4 @@
-
+
diff --git a/src/admin/Bootstrap.Admin/Pages/Views/Admin/Users.razor b/src/admin/Bootstrap.Admin/Pages/Views/Admin/Users.razor
index 9524b479..79cf1f36 100644
--- a/src/admin/Bootstrap.Admin/Pages/Views/Admin/Users.razor
+++ b/src/admin/Bootstrap.Admin/Pages/Views/Admin/Users.razor
@@ -1,6 +1,6 @@
@inherits UsersBase
-
+
@@ -47,3 +47,17 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/admin/Bootstrap.Admin/Pages/Views/Components/UsersBase.cs b/src/admin/Bootstrap.Admin/Pages/Views/Components/UsersBase.cs
index 814a3088..52f4706b 100644
--- a/src/admin/Bootstrap.Admin/Pages/Views/Components/UsersBase.cs
+++ b/src/admin/Bootstrap.Admin/Pages/Views/Components/UsersBase.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.UserName)) data = data.Where(d => d.UserName.Contains(QueryModel.UserName, StringComparison.OrdinalIgnoreCase));
if (!string.IsNullOrEmpty(QueryModel.DisplayName)) data = data.Where(d => d.DisplayName.Contains(QueryModel.DisplayName, StringComparison.OrdinalIgnoreCase));
if (!string.IsNullOrEmpty(options.SearchText)) data = data.Where(d => d.UserName.Contains(options.SearchText, StringComparison.OrdinalIgnoreCase) || d.DisplayName.Contains(options.SearchText, StringComparison.OrdinalIgnoreCase));
-
+
// sort
data = options.SortName switch
{
@@ -59,19 +60,134 @@ namespace Bootstrap.Admin.Pages.Views.Admin.Components
}
///
- /// 分配部门方法
+ /// 获得/设置 Modal 实例
+ ///
+ protected AssignModalBase? AssignGroupModal { get; set; }
+
+ ///
+ /// 弹窗分配角色方法
///
protected void AssignGroups()
{
-
+ // 菜单对角色授权操作
+ if (EditPage != null)
+ {
+ if (EditPage.SelectedItems.Count() != 1)
+ {
+ ShowMessage("部门授权", "请选择一个用户", ToastCategory.Information);
+ }
+ else
+ {
+ var userId = EditPage.SelectedItems.First().Id;
+ if (!string.IsNullOrEmpty(userId))
+ {
+ var groups = GroupHelper.RetrievesByUserId(userId);
+ AssignGroupModal?.Update(groups);
+ }
+ }
+ }
}
///
- /// 分配角色方法
+ /// 保存授权部门方法
+ ///
+ protected void SaveGroups(IEnumerable groups)
+ {
+ bool ret = false;
+ if (EditPage != null && EditPage.SelectedItems.Any())
+ {
+ var userId = EditPage.SelectedItems.First().Id;
+ var groupIds = groups.Where(r => r.Checked == "checked").Select(r => r.Id ?? "");
+ if (!string.IsNullOrEmpty(userId)) ret = GroupHelper.SaveByUserId(userId, 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;
+
+ ///
+ /// 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 userId = EditPage.SelectedItems.First().Id;
+ if (!string.IsNullOrEmpty(userId))
+ {
+ var roles = RoleHelper.RetrievesByUserId(userId);
+ AssignRoleModal?.Update(roles);
+ }
+ }
+ }
}
+
+ ///
+ /// 保存授权角色方法
+ ///
+ protected void SaveRoles(IEnumerable roles)
+ {
+ bool ret = false;
+ if (EditPage != null && EditPage.SelectedItems.Any())
+ {
+ var userId = EditPage.SelectedItems.First().Id;
+ var roleIds = roles.Where(r => r.Checked == "checked").Select(r => r.Id ?? "");
+ if (!string.IsNullOrEmpty(userId)) ret = RoleHelper.SaveByUserId(userId, 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;
}
}