feat: 角色维护页面增加授权按钮方法

This commit is contained in:
Argo Zhang 2020-02-06 13:20:33 +08:00
parent 4d83bf470b
commit 7ef09fae6c
No known key found for this signature in database
GPG Key ID: 152E398953DDF19F
2 changed files with 207 additions and 15 deletions

View File

@ -1,6 +1,6 @@
@inherits RolesBase
<EditPage Id="role" FixedHeader="@FixedHeader" TItem="Bootstrap.DataAccess.Role" SubmitModalTitle="角色编辑窗口" QueryModel="QueryModel" OnQuery="Query" OnAdd="Add" OnDelete="Delete" OnSave="Save" OnResetSearch="ResetSearch">
<EditPage @ref="EditPage" Id="role" FixedHeader="@FixedHeader" TItem="Bootstrap.DataAccess.Role" SubmitModalTitle="角色编辑窗口" QueryModel="QueryModel" OnQuery="Query" OnAdd="Add" OnDelete="Delete" OnSave="Save" OnResetSearch="ResetSearch">
<QueryBody>
<LgbInputText ColumnClass="col-sm-auto" @bind-Value="@context.RoleName" maxlength="50" />
<LgbInputText ColumnClass="col-sm-auto" @bind-Value="@context.Description" maxlength="50" />
@ -37,3 +37,23 @@
</div>
</EditTemplate>
</EditPage>
<AssignModal @ref="AssignUserModal" TItem="Bootstrap.DataAccess.User" Id="role-user" Title="用户授权窗口" OnSave="SaveUsers">
<ItemTemplate>
<Checkbox TItem="Bootstrap.DataAccess.User" Item="@context" Text="@context.DisplayName" SetCheckCallback="SetUserCheck" OnClick="OnUserClick" />
</ItemTemplate>
</AssignModal>
<AssignModal @ref="AssignGroupModal" TItem="Bootstrap.DataAccess.Group" Id="role-group" Title="部门授权窗口" OnSave="SaveGroups">
<ItemTemplate>
<Checkbox TItem="Bootstrap.DataAccess.Group" Item="@context" Text="@context.GroupName" SetCheckCallback="SetGroupCheck" OnClick="OnGroupClick" />
</ItemTemplate>
</AssignModal>
<AssignModal @ref="AssignAppModal" TItem="Bootstrap.DataAccess.App" Id="role-app" Title="应用授权窗口" OnSave="SaveApps">
<ItemTemplate>
<Checkbox TItem="Bootstrap.DataAccess.App" Item="@context" Text="@context.AppName" SetCheckCallback="SetAppCheck" OnClick="OnAppClick" />
</ItemTemplate>
</AssignModal>
<Toast @ref="Toast" Id="role_assign_toast"></Toast>

View File

@ -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
}
/// <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 roleId = EditPage.SelectedItems.First().Id;
if (!string.IsNullOrEmpty(roleId))
{
var users = UserHelper.RetrievesByRoleId(roleId);
AssignUserModal?.Update(users);
}
}
}
}
/// <summary>
/// 分配部门方法
/// 保存授权部门方法
/// </summary>
protected void SaveUsers(IEnumerable<User> 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);
}
/// <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<Group>? AssignGroupModal { get; set; }
/// <summary>
/// 弹窗分配角色方法
/// </summary>
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);
}
}
}
}
/// <summary>
/// 分配菜单方法
/// 保存授权部门方法
/// </summary>
protected void SaveGroups(IEnumerable<Group> 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);
}
/// <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>
/// 获得/设置 Modal 实例
/// </summary>
protected AssignModalBase<DataAccess.App>? AssignAppModal { get; set; }
/// <summary>
/// 弹窗分配角色方法
/// </summary>
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);
}
}
}
}
/// <summary>
/// 保存授权部门方法
/// </summary>
protected void SaveApps(IEnumerable<DataAccess.App> 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);
}
/// <summary>
/// 选择框点击时调用此方法
/// </summary>
/// <param name="item"></param>
/// <param name="check"></param>
protected void OnAppClick(DataAccess.App item, bool check)
{
item.Checked = check ? "checked" : "";
}
/// <summary>
/// 设置初始化值
/// </summary>
protected CheckBoxState SetAppCheck(DataAccess.App item) => item.Checked == "checked" ? CheckBoxState.Checked : CheckBoxState.UnChecked;
/// <summary>
/// 获得/设置 Modal 实例
/// </summary>
protected AssignModalBase<Menu>? AssignMenuModal { get; set; }
/// <summary>
/// 弹窗分配菜单方法
/// </summary>
protected void AssignMenus()
{
}
/// <summary>
/// 分配应用方法
/// </summary>
protected void AssignApps()
{
}
}
}