feat: 菜单维护页面增加保存提示信息
This commit is contained in:
parent
7ea6d0a4e1
commit
22b3d760b6
|
@ -1,4 +1,3 @@
|
||||||
using Bootstrap.Admin.Pages.Shared;
|
|
||||||
using Microsoft.AspNetCore.Components;
|
using Microsoft.AspNetCore.Components;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
@ -48,24 +47,11 @@ namespace Bootstrap.Admin.Pages.Components
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public IEnumerable<TItem> Items { get; set; } = new TItem[0];
|
public IEnumerable<TItem> Items { get; set; } = new TItem[0];
|
||||||
|
|
||||||
/// <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>
|
/// <summary>
|
||||||
/// 获得/设置 保存回调事件
|
/// 获得/设置 保存回调事件
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Parameter]
|
[Parameter]
|
||||||
public Func<IEnumerable<TItem>, bool>? OnSave { get; set; }
|
public Action<IEnumerable<TItem>>? OnSave { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// OnAfterRender 方法
|
/// OnAfterRender 方法
|
||||||
|
@ -95,9 +81,8 @@ namespace Bootstrap.Admin.Pages.Components
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected void Save()
|
protected void Save()
|
||||||
{
|
{
|
||||||
bool ret = OnSave?.Invoke(Items) ?? false;
|
OnSave?.Invoke(Items);
|
||||||
Modal?.Toggle();
|
Modal?.Toggle();
|
||||||
ShowMessage(Title, ret ? "保存成功" : "保存失败", ret ? ToastCategory.Success : ToastCategory.Error);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool show;
|
private bool show;
|
||||||
|
|
|
@ -25,5 +25,3 @@
|
||||||
</button>
|
</button>
|
||||||
</ModalFooter>
|
</ModalFooter>
|
||||||
</Modal>
|
</Modal>
|
||||||
|
|
||||||
<Toast @ref="Toast" Id="@($"{Id}_toast")"></Toast>
|
|
||||||
|
|
|
@ -60,3 +60,5 @@
|
||||||
<Checkbox TItem="Bootstrap.DataAccess.Role" Item="@context" Text="@context.RoleName" SetCheckCallback="SetCheck" OnClick="OnClick" />
|
<Checkbox TItem="Bootstrap.DataAccess.Role" Item="@context" Text="@context.RoleName" SetCheckCallback="SetCheck" OnClick="OnClick" />
|
||||||
</ItemTemplate>
|
</ItemTemplate>
|
||||||
</AssignModal>
|
</AssignModal>
|
||||||
|
|
||||||
|
<Toast @ref="Toast" Id="menu_role_toast"></Toast>
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
using Bootstrap.Admin.Pages.Components;
|
using Bootstrap.Admin.Pages.Components;
|
||||||
|
using Bootstrap.Admin.Pages.Shared;
|
||||||
using Bootstrap.DataAccess;
|
using Bootstrap.DataAccess;
|
||||||
using Bootstrap.Security;
|
using Bootstrap.Security;
|
||||||
using Microsoft.AspNetCore.Components;
|
using Microsoft.AspNetCore.Components;
|
||||||
|
@ -178,7 +179,13 @@ namespace Bootstrap.Admin.Pages.Views.Admin.Components
|
||||||
protected void AssignRoles()
|
protected void AssignRoles()
|
||||||
{
|
{
|
||||||
// 菜单对角色授权操作
|
// 菜单对角色授权操作
|
||||||
if (EditPage != null && EditPage.SelectedItems.Any())
|
if (EditPage != null)
|
||||||
|
{
|
||||||
|
if (EditPage.SelectedItems.Count() != 1)
|
||||||
|
{
|
||||||
|
ShowMessage("角色授权", "请选择一个菜单", ToastCategory.Information);
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
var menuId = EditPage.SelectedItems.First().Id;
|
var menuId = EditPage.SelectedItems.First().Id;
|
||||||
if (!string.IsNullOrEmpty(menuId))
|
if (!string.IsNullOrEmpty(menuId))
|
||||||
|
@ -188,11 +195,12 @@ namespace Bootstrap.Admin.Pages.Views.Admin.Components
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 保存授权角色方法
|
/// 保存授权角色方法
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected bool SaveRoles(IEnumerable<Role> roles)
|
protected void SaveRoles(IEnumerable<Role> roles)
|
||||||
{
|
{
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
if (EditPage != null && EditPage.SelectedItems.Any())
|
if (EditPage != null && EditPage.SelectedItems.Any())
|
||||||
|
@ -201,7 +209,7 @@ namespace Bootstrap.Admin.Pages.Views.Admin.Components
|
||||||
var roleIds = roles.Where(r => r.Checked == "checked").Select(r => r.Id ?? "");
|
var roleIds = roles.Where(r => r.Checked == "checked").Select(r => r.Id ?? "");
|
||||||
if (!string.IsNullOrEmpty(menuId)) ret = RoleHelper.SavaByMenuId(menuId, roleIds);
|
if (!string.IsNullOrEmpty(menuId)) ret = RoleHelper.SavaByMenuId(menuId, roleIds);
|
||||||
}
|
}
|
||||||
return ret;
|
ShowMessage("角色授权", ret ? "保存成功" : "保存失败", ret ? ToastCategory.Success : ToastCategory.Error);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -218,5 +226,18 @@ namespace Bootstrap.Admin.Pages.Views.Admin.Components
|
||||||
/// 设置初始化值
|
/// 设置初始化值
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected CheckBoxState SetCheck(Role item) => item.Checked == "checked" ? CheckBoxState.Checked : CheckBoxState.UnChecked;
|
protected CheckBoxState SetCheck(Role 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue