diff --git a/src/admin/Bootstrap.Admin/Pages/Components/TableBase.cs b/src/admin/Bootstrap.Admin/Pages/Components/TableBase.cs index 1f8110dd..0070f332 100644 --- a/src/admin/Bootstrap.Admin/Pages/Components/TableBase.cs +++ b/src/admin/Bootstrap.Admin/Pages/Components/TableBase.cs @@ -358,18 +358,13 @@ namespace Bootstrap.Admin.Pages.Components EditModal?.Toggle(); } - /// - /// Toast 组件实例 - /// - protected Toast? Toast { get; set; } - /// /// 显示提示信息 /// /// /// /// - protected void ShowMessage(string title, string text, ToastCategory cate = ToastCategory.Success) => Toast?.ShowMessage(title, text, cate); + protected void ShowMessage(string title, string text, ToastCategory cate = ToastCategory.Success) => JSRuntime?.ShowToast(title, text, cate); /// /// 编辑按钮方法 diff --git a/src/admin/Bootstrap.Admin/Pages/Components/ToastBase.cs b/src/admin/Bootstrap.Admin/Pages/Components/ToastBase.cs deleted file mode 100644 index e137fb2e..00000000 --- a/src/admin/Bootstrap.Admin/Pages/Components/ToastBase.cs +++ /dev/null @@ -1,133 +0,0 @@ -using Microsoft.AspNetCore.Components; -using Microsoft.JSInterop; -using System; - -namespace Bootstrap.Admin.Pages.Components -{ - /// - /// Toast 组件基类 - /// - public class ToastBase : ComponentBase - { - /// - /// IJSRuntime 实例 - /// - [Inject] - protected IJSRuntime? JSRuntime { get; set; } - - /// - /// 是否自动隐藏 默认为 true - /// - [Parameter] - public bool AutoHide { get; set; } = true; - - /// - /// 自动隐藏延时 默认为 1500 毫秒 - /// - [Parameter] - public int Interval { get; set; } = 2000; - - /// - /// 组件显示位置 - /// - [Parameter] - public Placement Placement { get; set; } - - /// - /// Toast 类型 - /// - [Parameter] - public ToastCategory Category { get; set; } - - /// - /// 组件标题文本 - /// - [Parameter] - public string Title { get; set; } = "BootstrapAdmin Blazor"; - - /// - /// 消息正文 - /// - [Parameter] - public string Text { get; set; } = "Toast 消息正文内容-未设置"; - - /// - /// 获得/设置 组件 ID - /// - [Parameter] - public string Id { get; set; } = ""; - - /// - /// 控件呈现后回调方法 - /// - /// - protected override void OnAfterRender(bool firstRender) - { - if (_show) - { - _show = false; - Show(); - } - } - - /// - /// OnParametersSet 方法 - /// - protected override void OnParametersSet() - { - if (string.IsNullOrEmpty(Id)) throw new InvalidOperationException("Toast component must have Id property"); - } - - /// - /// 显示 Toast 提示框方法 - /// - protected void Show() - { - JSRuntime.ShowToast(Id); - } - - private bool _show; - /// - /// 显示 Toast 提示框方法 - /// - public void ShowMessage(string title, string text, ToastCategory category = ToastCategory.Success) - { - Title = title; - Text = text; - Category = category; - _show = true; - StateHasChanged(); - } - - /// - /// 呈现不同类别方法 - /// - /// - protected string RenderCategory() - { - var ret = ""; - switch (Category) - { - case ToastCategory.Error: - ret = "fa fa-times-circle text-danger"; - break; - case ToastCategory.Information: - ret = "fa fa-exclamation-triangle text-info"; - break; - case ToastCategory.Success: - ret = "fa fa-check-circle text-success"; - break; - } - return ret; - } - - /// - /// 呈现动画方法 - /// - /// - protected string RenderAnimation() - { - return AutoHide ? $"transition: width {(Interval * 1.0 - 200) / 1000}s linear;" : ""; - } - } -} diff --git a/src/admin/Bootstrap.Admin/Pages/Components/ToastCategory.cs b/src/admin/Bootstrap.Admin/Pages/Components/ToastCategory.cs index 85543d91..15eafa42 100644 --- a/src/admin/Bootstrap.Admin/Pages/Components/ToastCategory.cs +++ b/src/admin/Bootstrap.Admin/Pages/Components/ToastCategory.cs @@ -9,10 +9,12 @@ /// 成功 /// Success, + /// /// 提示信息 /// Information, + /// /// 错误信息 /// diff --git a/src/admin/Bootstrap.Admin/Pages/Extensions/DisplayNamesExtensions.cs b/src/admin/Bootstrap.Admin/Pages/Extensions/DisplayNamesExtensions.cs index 3c1d5dc4..5d0975d1 100644 --- a/src/admin/Bootstrap.Admin/Pages/Extensions/DisplayNamesExtensions.cs +++ b/src/admin/Bootstrap.Admin/Pages/Extensions/DisplayNamesExtensions.cs @@ -2,11 +2,10 @@ using Bootstrap.Security; using Longbow.Cache; using Longbow.Web; -using Microsoft.Extensions.DependencyInjection; using System; using System.Collections.Concurrent; -namespace Microsoft.AspNetCore.Builder +namespace Microsoft.Extensions.DependencyInjection { /// /// 显示名称扩展方法类 diff --git a/src/admin/Bootstrap.Admin/Pages/Extensions/FieldIdentifierExtensions.cs b/src/admin/Bootstrap.Admin/Pages/Extensions/FieldIdentifierExtensions.cs index 07380c51..c9804dda 100644 --- a/src/admin/Bootstrap.Admin/Pages/Extensions/FieldIdentifierExtensions.cs +++ b/src/admin/Bootstrap.Admin/Pages/Extensions/FieldIdentifierExtensions.cs @@ -1,5 +1,5 @@ using Bootstrap.Admin.Pages.Components; -using Microsoft.AspNetCore.Builder; +using Microsoft.Extensions.DependencyInjection; using System.ComponentModel; namespace Microsoft.AspNetCore.Components.Forms diff --git a/src/admin/Bootstrap.Admin/Pages/Extensions/JSRuntimeExtensions.cs b/src/admin/Bootstrap.Admin/Pages/Extensions/JSRuntimeExtensions.cs index e2230f6a..7268c133 100644 --- a/src/admin/Bootstrap.Admin/Pages/Extensions/JSRuntimeExtensions.cs +++ b/src/admin/Bootstrap.Admin/Pages/Extensions/JSRuntimeExtensions.cs @@ -1,4 +1,5 @@ using System.Threading.Tasks; +using Bootstrap.Admin.Pages.Components; namespace Microsoft.JSInterop { @@ -57,8 +58,10 @@ namespace Microsoft.JSInterop /// 弹出 Toast 组件 /// /// - /// - public static void ShowToast(this IJSRuntime? jSRuntime, string id) => jSRuntime.InvokeVoidAsync("$.showToast", id); + /// + /// + /// + public static void ShowToast(this IJSRuntime? jSRuntime, string title, string message, ToastCategory cate) => jSRuntime.InvokeVoidAsync("$.showToast", title, message, cate.ToString()); /// /// 弹出 Tooltip 组件 diff --git a/src/admin/Bootstrap.Admin/Pages/Shared/Table.razor b/src/admin/Bootstrap.Admin/Pages/Shared/Table.razor index b25c9e9b..6854d1a4 100644 --- a/src/admin/Bootstrap.Admin/Pages/Shared/Table.razor +++ b/src/admin/Bootstrap.Admin/Pages/Shared/Table.razor @@ -228,5 +228,3 @@ } - - diff --git a/src/admin/Bootstrap.Admin/Pages/Shared/Toast.razor b/src/admin/Bootstrap.Admin/Pages/Shared/Toast.razor deleted file mode 100644 index 8244cb46..00000000 --- a/src/admin/Bootstrap.Admin/Pages/Shared/Toast.razor +++ /dev/null @@ -1,19 +0,0 @@ -@inherits ToastBase - - - -@code { - -} diff --git a/src/admin/Bootstrap.Admin/Pages/Views/Admin/Groups.razor b/src/admin/Bootstrap.Admin/Pages/Views/Admin/Groups.razor index d0624597..3c60faa2 100644 --- a/src/admin/Bootstrap.Admin/Pages/Views/Admin/Groups.razor +++ b/src/admin/Bootstrap.Admin/Pages/Views/Admin/Groups.razor @@ -48,5 +48,3 @@ - - diff --git a/src/admin/Bootstrap.Admin/Pages/Views/Admin/Menus.razor b/src/admin/Bootstrap.Admin/Pages/Views/Admin/Menus.razor index aaed3f74..1fbe353e 100644 --- a/src/admin/Bootstrap.Admin/Pages/Views/Admin/Menus.razor +++ b/src/admin/Bootstrap.Admin/Pages/Views/Admin/Menus.razor @@ -60,5 +60,3 @@ - - diff --git a/src/admin/Bootstrap.Admin/Pages/Views/Admin/Profiles.razor b/src/admin/Bootstrap.Admin/Pages/Views/Admin/Profiles.razor index 7c058543..2b261a5c 100644 --- a/src/admin/Bootstrap.Admin/Pages/Views/Admin/Profiles.razor +++ b/src/admin/Bootstrap.Admin/Pages/Views/Admin/Profiles.razor @@ -111,4 +111,3 @@ - diff --git a/src/admin/Bootstrap.Admin/Pages/Views/Admin/Roles.razor b/src/admin/Bootstrap.Admin/Pages/Views/Admin/Roles.razor index 2da3364c..fb819b1d 100644 --- a/src/admin/Bootstrap.Admin/Pages/Views/Admin/Roles.razor +++ b/src/admin/Bootstrap.Admin/Pages/Views/Admin/Roles.razor @@ -55,5 +55,3 @@ - - diff --git a/src/admin/Bootstrap.Admin/Pages/Views/Admin/Settings.razor b/src/admin/Bootstrap.Admin/Pages/Views/Admin/Settings.razor index 0741b7a9..e4eea25e 100644 --- a/src/admin/Bootstrap.Admin/Pages/Views/Admin/Settings.razor +++ b/src/admin/Bootstrap.Admin/Pages/Views/Admin/Settings.razor @@ -306,4 +306,3 @@ - diff --git a/src/admin/Bootstrap.Admin/Pages/Views/Admin/Users.razor b/src/admin/Bootstrap.Admin/Pages/Views/Admin/Users.razor index 79cf1f36..8e71680d 100644 --- a/src/admin/Bootstrap.Admin/Pages/Views/Admin/Users.razor +++ b/src/admin/Bootstrap.Admin/Pages/Views/Admin/Users.razor @@ -59,5 +59,3 @@ - - diff --git a/src/admin/Bootstrap.Admin/Pages/Views/Components/GroupsBase.cs b/src/admin/Bootstrap.Admin/Pages/Views/Components/GroupsBase.cs index c43f0e31..8ecfc6a2 100644 --- a/src/admin/Bootstrap.Admin/Pages/Views/Components/GroupsBase.cs +++ b/src/admin/Bootstrap.Admin/Pages/Views/Components/GroupsBase.cs @@ -1,6 +1,7 @@ using Bootstrap.Admin.Pages.Components; -using Bootstrap.Admin.Pages.Shared; using Bootstrap.DataAccess; +using Microsoft.AspNetCore.Components; +using Microsoft.JSInterop; using System; using System.Collections.Generic; using System.Linq; @@ -116,9 +117,10 @@ namespace Bootstrap.Admin.Pages.Views.Admin.Components protected CheckBoxState SetUserCheck(User item) => item.Checked == "checked" ? CheckBoxState.Checked : CheckBoxState.UnChecked; /// - /// Toast 组件实例 + /// IJSRuntime 接口实例 /// - protected Toast? Toast { get; set; } + [Inject] + protected IJSRuntime? JSRuntime { get; set; } /// /// 显示提示信息 @@ -126,7 +128,7 @@ namespace Bootstrap.Admin.Pages.Views.Admin.Components /// /// /// - protected void ShowMessage(string title, string text, ToastCategory cate = ToastCategory.Success) => Toast?.ShowMessage(title, text, cate); + protected void ShowMessage(string title, string text, ToastCategory cate = ToastCategory.Success) => JSRuntime?.ShowToast(title, text, cate); /// /// 获得/设置 Modal 实例 diff --git a/src/admin/Bootstrap.Admin/Pages/Views/Components/MenusBase.cs b/src/admin/Bootstrap.Admin/Pages/Views/Components/MenusBase.cs index 46485017..9823986e 100644 --- a/src/admin/Bootstrap.Admin/Pages/Views/Components/MenusBase.cs +++ b/src/admin/Bootstrap.Admin/Pages/Views/Components/MenusBase.cs @@ -1,9 +1,9 @@ using Bootstrap.Admin.Pages.Components; -using Bootstrap.Admin.Pages.Shared; using Bootstrap.DataAccess; using Bootstrap.Security; using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components.Authorization; +using Microsoft.JSInterop; using System; using System.Collections.Generic; using System.Linq; @@ -228,9 +228,10 @@ namespace Bootstrap.Admin.Pages.Views.Admin.Components protected CheckBoxState SetCheck(Role item) => item.Checked == "checked" ? CheckBoxState.Checked : CheckBoxState.UnChecked; /// - /// Toast 组件实例 + /// IJSRuntime 接口实例 /// - protected Toast? Toast { get; set; } + [Inject] + protected IJSRuntime? JSRuntime { get; set; } /// /// 显示提示信息 @@ -238,6 +239,6 @@ namespace Bootstrap.Admin.Pages.Views.Admin.Components /// /// /// - protected void ShowMessage(string title, string text, ToastCategory cate = ToastCategory.Success) => Toast?.ShowMessage(title, text, cate); + protected void ShowMessage(string title, string text, ToastCategory cate = ToastCategory.Success) => JSRuntime?.ShowToast(title, text, cate); } } diff --git a/src/admin/Bootstrap.Admin/Pages/Views/Components/ProfilesBase.cs b/src/admin/Bootstrap.Admin/Pages/Views/Components/ProfilesBase.cs index 65bf42d2..6049c704 100644 --- a/src/admin/Bootstrap.Admin/Pages/Views/Components/ProfilesBase.cs +++ b/src/admin/Bootstrap.Admin/Pages/Views/Components/ProfilesBase.cs @@ -5,6 +5,7 @@ using Bootstrap.DataAccess; using Bootstrap.Security; using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components.Forms; +using Microsoft.JSInterop; using System.Collections.Generic; using System.ComponentModel; using System.Linq; @@ -49,9 +50,10 @@ namespace Bootstrap.Admin.Pages.Views.Admin.Components public string DisplayName { get; set; } = ""; /// - /// Toast 组件实例 + /// IJSRuntime 接口实例 /// - protected Toast? Toast { get; set; } + [Inject] + protected IJSRuntime? JSRuntime { get; set; } /// /// 获得/设置 选中的样式项 @@ -78,7 +80,7 @@ namespace Bootstrap.Admin.Pages.Views.Admin.Components /// /// /// - protected void ShowMessage(string text, bool ret = true) => Toast?.ShowMessage("个人中心", text, ret ? ToastCategory.Success : ToastCategory.Error); + protected void ShowMessage(string text, bool ret = true) => JSRuntime?.ShowToast("个人中心", text, ret ? ToastCategory.Success : ToastCategory.Error); /// /// 组件初始化方法 diff --git a/src/admin/Bootstrap.Admin/Pages/Views/Components/RolesBase.cs b/src/admin/Bootstrap.Admin/Pages/Views/Components/RolesBase.cs index 537ba7a0..9d628837 100644 --- a/src/admin/Bootstrap.Admin/Pages/Views/Components/RolesBase.cs +++ b/src/admin/Bootstrap.Admin/Pages/Views/Components/RolesBase.cs @@ -1,6 +1,8 @@ using Bootstrap.Admin.Pages.Components; using Bootstrap.Admin.Pages.Shared; using Bootstrap.DataAccess; +using Microsoft.AspNetCore.Components; +using Microsoft.JSInterop; using System; using System.Collections.Generic; using System.Linq; @@ -115,9 +117,10 @@ namespace Bootstrap.Admin.Pages.Views.Admin.Components protected CheckBoxState SetUserCheck(User item) => item.Checked == "checked" ? CheckBoxState.Checked : CheckBoxState.UnChecked; /// - /// Toast 组件实例 + /// IJSRuntime 接口实例 /// - protected Toast? Toast { get; set; } + [Inject] + protected IJSRuntime? JSRuntime { get; set; } /// /// 显示提示信息 @@ -125,7 +128,7 @@ namespace Bootstrap.Admin.Pages.Views.Admin.Components /// /// /// - protected void ShowMessage(string title, string text, ToastCategory cate = ToastCategory.Success) => Toast?.ShowMessage(title, text, cate); + protected void ShowMessage(string title, string text, ToastCategory cate = ToastCategory.Success) => JSRuntime?.ShowToast(title, text, cate); /// /// 获得/设置 Modal 实例 diff --git a/src/admin/Bootstrap.Admin/Pages/Views/Components/SettingsBase.cs b/src/admin/Bootstrap.Admin/Pages/Views/Components/SettingsBase.cs index 6be76587..80ef28ee 100644 --- a/src/admin/Bootstrap.Admin/Pages/Views/Components/SettingsBase.cs +++ b/src/admin/Bootstrap.Admin/Pages/Views/Components/SettingsBase.cs @@ -37,9 +37,10 @@ namespace Bootstrap.Admin.Pages.Views.Admin.Components public DefaultLayout? RootLayout { get; protected set; } /// - /// Toast 组件实例 + /// IJSRuntime 接口实例 /// - protected Toast? Toast { get; set; } + [Inject] + protected IJSRuntime? JSRuntime { get; set; } /// /// NavigationManager 实例 @@ -52,7 +53,7 @@ namespace Bootstrap.Admin.Pages.Views.Admin.Components /// /// /// - protected void ShowMessage(string text, bool ret = true) => Toast?.ShowMessage("网站设置", ret ? $"{text}成功" : $"{text}失败", ret ? ToastCategory.Success : ToastCategory.Error); + protected void ShowMessage(string text, bool ret = true) => JSRuntime?.ShowToast("网站设置", ret ? $"{text}成功" : $"{text}失败", ret ? ToastCategory.Success : ToastCategory.Error); /// /// 设置参数方法 diff --git a/src/admin/Bootstrap.Admin/Pages/Views/Components/UsersBase.cs b/src/admin/Bootstrap.Admin/Pages/Views/Components/UsersBase.cs index 52f4706b..195afea1 100644 --- a/src/admin/Bootstrap.Admin/Pages/Views/Components/UsersBase.cs +++ b/src/admin/Bootstrap.Admin/Pages/Views/Components/UsersBase.cs @@ -1,6 +1,7 @@ using Bootstrap.Admin.Pages.Components; -using Bootstrap.Admin.Pages.Shared; using Bootstrap.DataAccess; +using Microsoft.AspNetCore.Components; +using Microsoft.JSInterop; using System; using System.Collections.Generic; using System.Linq; @@ -119,9 +120,10 @@ namespace Bootstrap.Admin.Pages.Views.Admin.Components protected CheckBoxState SetGroupCheck(Group item) => item.Checked == "checked" ? CheckBoxState.Checked : CheckBoxState.UnChecked; /// - /// Toast 组件实例 + /// IJSRuntime 接口实例 /// - protected Toast? Toast { get; set; } + [Inject] + protected IJSRuntime? JSRuntime { get; set; } /// /// 显示提示信息 @@ -129,7 +131,7 @@ namespace Bootstrap.Admin.Pages.Views.Admin.Components /// /// /// - protected void ShowMessage(string title, string text, ToastCategory cate = ToastCategory.Success) => Toast?.ShowMessage(title, text, cate); + protected void ShowMessage(string title, string text, ToastCategory cate = ToastCategory.Success) => JSRuntime?.ShowToast(title, text, cate); /// /// 获得/设置 Modal 实例 diff --git a/src/admin/Bootstrap.Admin/wwwroot/css/blazor.css b/src/admin/Bootstrap.Admin/wwwroot/css/blazor.css index c704ca08..04f404ca 100644 --- a/src/admin/Bootstrap.Admin/wwwroot/css/blazor.css +++ b/src/admin/Bootstrap.Admin/wwwroot/css/blazor.css @@ -131,14 +131,14 @@ nav .dropdown .nav-link-close.dropdown-toggle:after { clear: both; } - .bootstrap-table .fixed-table-toolbar .columns-right { - margin-left: 5px; - } + .bootstrap-table .fixed-table-toolbar .columns-right { + margin-left: 5px; + } .bootstrap-table .table-fixed { height: 388px; overflow: hidden; - } + } .bootstrap-table .table-fixed-header { overflow: hidden; @@ -160,27 +160,27 @@ nav .dropdown .nav-link-close.dropdown-toggle:after { border-bottom: 1px solid #dee2e6; } -.bootstrap-table .datetime { - min-width: 170px; -} - -.bootstrap-table .sortable { - padding-right: 30px; - cursor: pointer; -} - - .bootstrap-table .sortable span { - display: inline-block; - width: 100%; + .bootstrap-table .datetime { + min-width: 170px; } - .bootstrap-table .sortable i { - margin-left: 8px; + .bootstrap-table .sortable { + padding-right: 30px; + cursor: pointer; } - .bootstrap-table .sortable .fa-sort { - color: #dee2e6; - } + .bootstrap-table .sortable span { + display: inline-block; + width: 100%; + } + + .bootstrap-table .sortable i { + margin-left: 8px; + } + + .bootstrap-table .sortable .fa-sort { + color: #dee2e6; + } .table-wrapper { border-radius: 4px; @@ -234,7 +234,11 @@ nav .dropdown .nav-link-close.dropdown-toggle:after { } .toast.show { - z-index: 1080; + z-index: 1030; + } + + .toast:not(:last-child) { + margin-bottom: 0; } .toast-top { @@ -303,6 +307,7 @@ nav .dropdown .nav-link-close.dropdown-toggle:after { -ms-filter: progid:DXImageTransform.Microsoft.Alpha(Opacity=40); filter: alpha(opacity=40); width: 0; + transition: all 4s linear; } .showing .toast-progress, .show .toast-progress { diff --git a/src/admin/Bootstrap.Admin/wwwroot/js/ba.blazor.js b/src/admin/Bootstrap.Admin/wwwroot/js/ba.blazor.js index 62e4085c..b416d09a 100644 --- a/src/admin/Bootstrap.Admin/wwwroot/js/ba.blazor.js +++ b/src/admin/Bootstrap.Admin/wwwroot/js/ba.blazor.js @@ -111,8 +111,49 @@ toggleModal: function (modalId) { $(modalId).modal('toggle'); }, - showToast: function (id) { - $('#' + id).toast('show'); + showToast: function (title, message, cate) { + var cateToCss = function (c) { + var ret = ""; + switch (c) { + case "Success": + ret = "fa fa-check-circle text-success"; + break; + case "Information": + ret = "fa fa-exclamation-triangle text-info"; + break; + case "Error": + default: + ret = "fa fa-times-circle text-danger"; + break; + } + return ret; + } + var toastTemplate = ''; + + // 利用 js 生成一个临时 toast 弹窗后自我销毁 + var $toast = $(toastTemplate).appendTo('body'); + var handler = window.setTimeout(function () { + window.clearTimeout(handler); + $toast.toast('show'); + }, 200); + + var handlerDismiss = window.setTimeout(function () { + window.clearTimeout(handlerDismiss); + //$toast.remove(); + + // 回调重新排列方法 + }, 4400); }, tooltip: function (id, method) { var $ele = $(id);