refactor: 重构 Modal 弹窗逻辑

This commit is contained in:
Argo Zhang 2020-01-23 11:10:49 +08:00
parent 11a121cc63
commit c3cee0dc58
No known key found for this signature in database
GPG Key ID: 152E398953DDF19F
3 changed files with 14 additions and 4 deletions

View File

@ -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);
}
}
/// <summary>
/// OnParametersSet 方法
/// </summary>
protected override void OnParametersSet()
{
if (string.IsNullOrEmpty(Id)) throw new InvalidOperationException("Modal Component Id property must be set");
}
/// <summary>
/// 输出窗口大小样式
/// </summary>

View File

@ -51,7 +51,8 @@ namespace Bootstrap.Admin.Extensions
/// 修复 Modal 组件
/// </summary>
/// <param name="jSRuntime"></param>
public static void InitModal(this IJSRuntime? jSRuntime) => jSRuntime.InvokeVoidAsync("$.initModal");
/// <param name="id"></param>
public static void InitModal(this IJSRuntime? jSRuntime, string id) => jSRuntime.InvokeVoidAsync("$.initModal", id);
/// <summary>
/// 修复 Modal 组件

View File

@ -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'));