6
6
namespace BootstrapBlazor . Components ;
7
7
8
8
/// <summary>
9
- /// Dialog 对话框组件
9
+ /// Dialog component
10
10
/// </summary>
11
11
public partial class Dialog : IDisposable
12
12
{
13
- /// <summary>
14
- /// 获得/设置 Modal 容器组件实例
15
- /// </summary>
16
- [ NotNull ]
17
- private Modal ? ModalContainer { get ; set ; }
18
-
19
- /// <summary>
20
- /// 获得/设置 弹出对话框实例集合
21
- /// </summary>
22
- private Dictionary < Dictionary < string , object > , ( bool IsKeyboard , bool IsBackdrop ) > DialogParameters { get ; } = [ ] ;
23
-
24
- private bool _isKeyboard = false ;
25
-
26
- private bool _isBackdrop = false ;
27
-
28
- private bool _isFade = true ;
29
-
30
- /// <summary>
31
- /// DialogServices 服务实例
32
- /// </summary>
33
13
[ Inject ]
34
14
[ NotNull ]
35
15
private DialogService ? DialogService { get ; set ; }
36
16
37
17
[ NotNull ]
38
- private Func < Task > ? OnShownAsync { get ; set ; }
18
+ private Modal ? _modal = null ;
39
19
40
20
[ NotNull ]
41
- private Func < Task > ? OnCloseAsync { get ; set ; }
21
+ private Func < Task > ? _onShownAsync = null ;
42
22
43
- private Dictionary < string , object > ? CurrentParameter { get ; set ; }
23
+ [ NotNull ]
24
+ private Func < Task > ? _onCloseAsync = null ;
25
+
26
+ private readonly Dictionary < Dictionary < string , object > , ( bool IsKeyboard , bool IsBackdrop ) > DialogParameters = [ ] ;
27
+ private Dictionary < string , object > ? _currentParameter ;
28
+ private bool _isKeyboard = false ;
29
+ private bool _isBackdrop = false ;
30
+ private bool _isFade = true ;
44
31
45
32
/// <summary>
46
- /// OnInitialized 方法
33
+ /// <inheritdoc/>
47
34
/// </summary>
48
35
protected override void OnInitialized ( )
49
36
{
50
37
base . OnInitialized ( ) ;
51
38
52
- // 注册 Dialog 弹窗事件
39
+ // Register Dialog popup event
53
40
DialogService . Register ( this , Show ) ;
54
41
}
55
42
56
43
/// <summary>
57
- /// OnAfterRenderAsync 方法
44
+ /// <inheritdoc/>
58
45
/// </summary>
59
46
/// <param name="firstRender"></param>
60
47
/// <returns></returns>
61
48
protected override async Task OnAfterRenderAsync ( bool firstRender )
62
49
{
63
50
await base . OnAfterRenderAsync ( firstRender ) ;
64
51
65
- if ( CurrentParameter != null )
52
+ if ( _currentParameter != null )
66
53
{
67
- await ModalContainer . Show ( ) ;
54
+ await _modal . Show ( ) ;
68
55
}
69
56
}
70
57
71
58
private async Task Show ( DialogOption option )
72
59
{
73
- OnShownAsync = async ( ) =>
60
+ _onShownAsync = async ( ) =>
74
61
{
75
62
if ( option . OnShownAsync != null )
76
63
{
77
64
await option . OnShownAsync ( ) ;
78
65
}
79
66
} ;
80
67
81
- OnCloseAsync = async ( ) =>
68
+ _onCloseAsync = async ( ) =>
82
69
{
83
- // 回调 OnCloseAsync
70
+ // Callback OnCloseAsync
84
71
if ( option . OnCloseAsync != null )
85
72
{
86
73
await option . OnCloseAsync ( ) ;
87
74
}
88
75
89
- // 移除当前 DialogParameter
90
- if ( CurrentParameter != null )
76
+ // Remove current DialogParameter
77
+ if ( _currentParameter != null )
91
78
{
92
- DialogParameters . Remove ( CurrentParameter ) ;
79
+ DialogParameters . Remove ( _currentParameter ) ;
93
80
94
- // 多弹窗支持
81
+ // Support for multiple dialogs
95
82
var p = DialogParameters . LastOrDefault ( ) ;
96
- CurrentParameter = p . Key ;
83
+ _currentParameter = p . Key ;
97
84
_isKeyboard = p . Value . IsKeyboard ;
98
85
_isBackdrop = p . Value . IsBackdrop ;
99
86
@@ -105,7 +92,7 @@ private async Task Show(DialogOption option)
105
92
_isBackdrop = option . IsBackdrop ;
106
93
_isFade = option . IsFade ;
107
94
108
- option . Modal = ModalContainer ;
95
+ option . Modal = _modal ;
109
96
110
97
var parameters = option . ToAttributes ( ) ;
111
98
var content = option . BodyTemplate ?? option . Component ? . Render ( ) ;
@@ -166,10 +153,10 @@ private async Task Show(DialogOption option)
166
153
}
167
154
}
168
155
169
- // 保存当前 Dialog 参数
170
- CurrentParameter = parameters ;
156
+ // Save current Dialog parameters
157
+ _currentParameter = parameters ;
171
158
172
- // 添加 ModalDialog 到容器中
159
+ // Add ModalDialog to the container
173
160
DialogParameters . Add ( parameters , ( _isKeyboard , _isBackdrop ) ) ;
174
161
await InvokeAsync ( StateHasChanged ) ;
175
162
}
@@ -183,7 +170,7 @@ private static RenderFragment RenderDialog(int index, Dictionary<string, object>
183
170
} ;
184
171
185
172
/// <summary>
186
- /// Dispose 方法
173
+ /// Dispose method
187
174
/// </summary>
188
175
/// <param name="disposing"></param>
189
176
protected virtual void Dispose ( bool disposing )
@@ -195,7 +182,7 @@ protected virtual void Dispose(bool disposing)
195
182
}
196
183
197
184
/// <summary>
198
- /// Dispose 方法
185
+ /// <inheritdoc/>
199
186
/// </summary>
200
187
public void Dispose ( )
201
188
{
0 commit comments