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