feat: 用户维护界面增加授权按钮方法
This commit is contained in:
parent
22b3d760b6
commit
30c4dc9b91
|
@ -61,4 +61,4 @@
|
|||
</ItemTemplate>
|
||||
</AssignModal>
|
||||
|
||||
<Toast @ref="Toast" Id="menu_role_toast"></Toast>
|
||||
<Toast @ref="Toast" Id="menu_assign_toast"></Toast>
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
@inherits UsersBase
|
||||
|
||||
<EditPage Id="user" FixedHeader="@FixedHeader" TItem="Bootstrap.DataAccess.User" SubmitModalTitle="用户编辑窗口" QueryModel="QueryModel" OnQuery="Query" OnAdd="Add" OnDelete="Delete" OnSave="Save" OnResetSearch="ResetSearch">
|
||||
<EditPage @ref="EditPage" Id="user" FixedHeader="@FixedHeader" TItem="Bootstrap.DataAccess.User" SubmitModalTitle="用户编辑窗口" QueryModel="QueryModel" OnQuery="Query" OnAdd="Add" OnDelete="Delete" OnSave="Save" OnResetSearch="ResetSearch">
|
||||
<QueryBody>
|
||||
<LgbInputText ColumnClass="col-sm-auto" @bind-Value="@context.UserName" maxlength="50" />
|
||||
<LgbInputText ColumnClass="col-sm-auto" @bind-Value="@context.DisplayName" maxlength="50" />
|
||||
|
@ -47,3 +47,17 @@
|
|||
</div>
|
||||
</EditTemplate>
|
||||
</EditPage>
|
||||
|
||||
<AssignModal @ref="AssignGroupModal" TItem="Bootstrap.DataAccess.Group" Id="user-group" Title="部门授权窗口" OnSave="SaveGroups">
|
||||
<ItemTemplate>
|
||||
<Checkbox TItem="Bootstrap.DataAccess.Group" Item="@context" Text="@context.GroupName" SetCheckCallback="SetGroupCheck" OnClick="OnGroupClick" />
|
||||
</ItemTemplate>
|
||||
</AssignModal>
|
||||
|
||||
<AssignModal @ref="AssignRoleModal" TItem="Bootstrap.DataAccess.Role" Id="user-role" Title="角色授权窗口" OnSave="SaveRoles">
|
||||
<ItemTemplate>
|
||||
<Checkbox TItem="Bootstrap.DataAccess.Role" Item="@context" Text="@context.RoleName" SetCheckCallback="SetCheck" OnClick="OnClick" />
|
||||
</ItemTemplate>
|
||||
</AssignModal>
|
||||
|
||||
<Toast @ref="Toast" Id="user_assign_toast"></Toast>
|
||||
|
|
|
@ -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
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// 分配部门方法
|
||||
/// 获得/设置 Modal 实例
|
||||
/// </summary>
|
||||
protected AssignModalBase<Group>? AssignGroupModal { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 弹窗分配角色方法
|
||||
/// </summary>
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 分配角色方法
|
||||
/// 保存授权部门方法
|
||||
/// </summary>
|
||||
protected void SaveGroups(IEnumerable<Group> 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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 选择框点击时调用此方法
|
||||
/// </summary>
|
||||
/// <param name="item"></param>
|
||||
/// <param name="check"></param>
|
||||
protected void OnGroupClick(Group item, bool check)
|
||||
{
|
||||
item.Checked = check ? "checked" : "";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置初始化值
|
||||
/// </summary>
|
||||
protected CheckBoxState SetGroupCheck(Group item) => item.Checked == "checked" ? CheckBoxState.Checked : CheckBoxState.UnChecked;
|
||||
|
||||
/// <summary>
|
||||
/// Toast 组件实例
|
||||
/// </summary>
|
||||
protected Toast? Toast { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 显示提示信息
|
||||
/// </summary>
|
||||
/// <param name="title"></param>
|
||||
/// <param name="text"></param>
|
||||
/// <param name="cate"></param>
|
||||
protected void ShowMessage(string title, string text, ToastCategory cate = ToastCategory.Success) => Toast?.ShowMessage(title, text, cate);
|
||||
|
||||
/// <summary>
|
||||
/// 获得/设置 Modal 实例
|
||||
/// </summary>
|
||||
protected AssignModalBase<Role>? AssignRoleModal { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 弹窗分配角色方法
|
||||
/// </summary>
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 保存授权角色方法
|
||||
/// </summary>
|
||||
protected void SaveRoles(IEnumerable<Role> 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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 选择框点击时调用此方法
|
||||
/// </summary>
|
||||
/// <param name="item"></param>
|
||||
/// <param name="check"></param>
|
||||
protected void OnClick(Role item, bool check)
|
||||
{
|
||||
item.Checked = check ? "checked" : "";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置初始化值
|
||||
/// </summary>
|
||||
protected CheckBoxState SetCheck(Role item) => item.Checked == "checked" ? CheckBoxState.Checked : CheckBoxState.UnChecked;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue