feat: 部门维护增加授权按钮方法
This commit is contained in:
parent
30c4dc9b91
commit
4d83bf470b
|
@ -1,6 +1,6 @@
|
|||
@inherits GroupsBase
|
||||
|
||||
<EditPage Id="group" FixedHeader="@FixedHeader" TItem="Bootstrap.DataAccess.Group" SubmitModalTitle="部门编辑窗口" QueryModel="QueryModel" OnQuery="Query" OnAdd="Add" OnDelete="Delete" OnSave="Save" OnResetSearch="ResetSearch">
|
||||
<EditPage @ref="EditPage" Id="group" FixedHeader="@FixedHeader" TItem="Bootstrap.DataAccess.Group" SubmitModalTitle="部门编辑窗口" QueryModel="QueryModel" OnQuery="Query" OnAdd="Add" OnDelete="Delete" OnSave="Save" OnResetSearch="ResetSearch">
|
||||
<QueryBody>
|
||||
<LgbInputText ColumnClass="col-sm-auto" @bind-Value="@context.GroupName" maxlength="50" />
|
||||
<LgbInputText ColumnClass="col-sm-auto" @bind-Value="@context.Description" maxlength="50" />
|
||||
|
@ -36,3 +36,17 @@
|
|||
</div>
|
||||
</EditTemplate>
|
||||
</EditPage>
|
||||
|
||||
<AssignModal @ref="AssignUserModal" TItem="Bootstrap.DataAccess.User" Id="group-user" Title="用户授权窗口" OnSave="SaveUsers">
|
||||
<ItemTemplate>
|
||||
<Checkbox TItem="Bootstrap.DataAccess.User" Item="@context" Text="@context.DisplayName" SetCheckCallback="SetUserCheck" OnClick="OnUserClick" />
|
||||
</ItemTemplate>
|
||||
</AssignModal>
|
||||
|
||||
<AssignModal @ref="AssignRoleModal" TItem="Bootstrap.DataAccess.Role" Id="group-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="group_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;
|
||||
|
@ -56,19 +57,134 @@ namespace Bootstrap.Admin.Pages.Views.Admin.Components
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// 分配用户方法
|
||||
/// 获得/设置 Modal 实例
|
||||
/// </summary>
|
||||
protected AssignModalBase<User>? AssignUserModal { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 弹窗分配角色方法
|
||||
/// </summary>
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 分配角色方法
|
||||
/// 保存授权部门方法
|
||||
/// </summary>
|
||||
protected void SaveUsers(IEnumerable<User> 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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 选择框点击时调用此方法
|
||||
/// </summary>
|
||||
/// <param name="item"></param>
|
||||
/// <param name="check"></param>
|
||||
protected void OnUserClick(User item, bool check)
|
||||
{
|
||||
item.Checked = check ? "checked" : "";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置初始化值
|
||||
/// </summary>
|
||||
protected CheckBoxState SetUserCheck(User 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 groupId = EditPage.SelectedItems.First().Id;
|
||||
if (!string.IsNullOrEmpty(groupId))
|
||||
{
|
||||
var roles = RoleHelper.RetrievesByGroupId(groupId);
|
||||
AssignRoleModal?.Update(roles);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 保存授权角色方法
|
||||
/// </summary>
|
||||
protected void SaveRoles(IEnumerable<Role> 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);
|
||||
}
|
||||
|
||||
/// <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