From c3cee0dc584ed2b22b2e23a793aba1b44ec853f0 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Thu, 23 Jan 2020 11:10:49 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E9=87=8D=E6=9E=84=20Modal=20?= =?UTF-8?q?=E5=BC=B9=E7=AA=97=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/admin/Bootstrap.Admin/Components/ModalBase.cs | 11 ++++++++++- .../Bootstrap.Admin/Extensions/JSRuntimeExtensions.cs | 3 ++- src/admin/Bootstrap.Admin/wwwroot/js/ba.blazor.js | 4 ++-- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/admin/Bootstrap.Admin/Components/ModalBase.cs b/src/admin/Bootstrap.Admin/Components/ModalBase.cs index e7cdf8c3..a887d8bd 100644 --- a/src/admin/Bootstrap.Admin/Components/ModalBase.cs +++ b/src/admin/Bootstrap.Admin/Components/ModalBase.cs @@ -1,6 +1,7 @@ using Bootstrap.Admin.Extensions; using Microsoft.AspNetCore.Components; using Microsoft.JSInterop; +using System; namespace Bootstrap.Admin.Components { @@ -71,10 +72,18 @@ namespace Bootstrap.Admin.Components { if (firstRender) { - JSRuntime.InitModal(); + JSRuntime.InitModal(Id); } } + /// + /// OnParametersSet 方法 + /// + protected override void OnParametersSet() + { + if (string.IsNullOrEmpty(Id)) throw new InvalidOperationException("Modal Component Id property must be set"); + } + /// /// 输出窗口大小样式 /// diff --git a/src/admin/Bootstrap.Admin/Extensions/JSRuntimeExtensions.cs b/src/admin/Bootstrap.Admin/Extensions/JSRuntimeExtensions.cs index 0da63861..938ad6b0 100644 --- a/src/admin/Bootstrap.Admin/Extensions/JSRuntimeExtensions.cs +++ b/src/admin/Bootstrap.Admin/Extensions/JSRuntimeExtensions.cs @@ -51,7 +51,8 @@ namespace Bootstrap.Admin.Extensions /// 修复 Modal 组件 /// /// - public static void InitModal(this IJSRuntime? jSRuntime) => jSRuntime.InvokeVoidAsync("$.initModal"); + /// + public static void InitModal(this IJSRuntime? jSRuntime, string id) => jSRuntime.InvokeVoidAsync("$.initModal", id); /// /// 修复 Modal 组件 diff --git a/src/admin/Bootstrap.Admin/wwwroot/js/ba.blazor.js b/src/admin/Bootstrap.Admin/wwwroot/js/ba.blazor.js index 042ef339..0570e256 100644 --- a/src/admin/Bootstrap.Admin/wwwroot/js/ba.blazor.js +++ b/src/admin/Bootstrap.Admin/wwwroot/js/ba.blazor.js @@ -108,8 +108,8 @@ $('[data-toggle="tooltip"]').tooltip(); $('.sidebar').addNiceScroll().autoScrollSidebar(); }, - initModal: function () { - $('.modal').appendTo($('body')); + initModal: function (id) { + $('#' + id).appendTo($('body')); }, initToast: function (id) { $('#' + id).appendTo($('body'));