|
87 | 87 | var commentAttribute = p.GetCustomAttribute(typeof(CommentAttribute)) as CommentAttribute; |
88 | 88 | var title = commentAttribute?.Comment ?? p.Name; |
89 | 89 | return |
90 | | - $" <div style=\"width:140px\" class=\"mr-2\">\n" + |
91 | | - $" <MudTextField T=\"string\" @bind-Value=\"searchObject.Search{p.Name}\" \n" + |
92 | | - $" Margin=\"Margin.Dense\" Label=\"{title}\" Variant=\"Variant.Outlined\" \n" + |
93 | | - $" Clearable Class=\"search-com\"></MudTextField>\n" + |
94 | | - $" </div>"; |
| 90 | + $" <MudTextField T=\"string\" @bind-Value=\"searchObject.Search{p.Name}\" \n" + |
| 91 | + $" Margin=\"Margin.Dense\" Label=\"{title}\" Variant=\"Variant.Outlined\" \n" + |
| 92 | + $" Clearable Class=\"mt-2\"></MudTextField>\n"; |
95 | 93 | })); |
96 | 94 |
|
97 | 95 | var searchProperties = string.Join("\n", properties |
| 96 | + .Where(p => p.PropertyType == typeof(string)) |
98 | 97 | .Select(p => |
99 | 98 | { |
100 | 99 | var typeName = GetCSharpTypeName(p.PropertyType); |
|
126 | 125 | var commentAttribute = p.GetCustomAttribute(typeof(CommentAttribute)) as CommentAttribute; |
127 | 126 | var title = commentAttribute?.Comment ?? p.Name; |
128 | 127 | return |
129 | | - $" <MudTextField T=\"{GetCSharpTypeName(p.PropertyType)}\" @bind-Value=\"editModel.{p.Name}\"\n " + |
130 | | - $" Label=\"{title}\" Variant=\"Variant.Outlined\" For=\"()=>editModel.{p.Name}\"/>"; |
| 128 | + $" <MudTextField T=\"{GetCSharpTypeName(p.PropertyType)}\" @bind-Value=\"editModel.{p.Name}\" Class=\"mb-2\"\n " + |
| 129 | + $" Label=\"{title}\" Variant=\"Variant.Outlined\" For=\"()=>editModel.{p.Name}\" Margin=\"Margin.Dense\" Clearable/>"; |
131 | 130 | })); |
132 | 131 |
|
133 | 132 | var setEditModelProperties = string.Join(",\n", properties |
|
148 | 147 | @using BlazorAdmin.Data.Entities |
149 | 148 | @using static BlazorAdmin.Component.Pages.PagePagination |
150 | 149 | @using BlazorAdmin.Component.Dialogs |
| 150 | +@using BlazorAdmin.Core.Helper |
151 | 151 |
|
152 | 152 | @using {selectedEntity.Namespace} |
153 | 153 |
|
154 | 154 | <PageHeader Title=""{entityName}管理""> |
155 | | -{searchFields} |
156 | | - <MudIconButton Size=""MudBlazor.Size.Medium"" |
157 | | - Icon=""@Icons.Material.Filled.Search"" Color=""Color.Primary"" Class=""mr-2"" |
158 | | - OnClick=""()=> dataGrid.ReloadServerData()"" Variant=""Variant.Outlined""/> |
| 155 | + @if (_notEmptyCount > 0) |
| 156 | + {{ |
| 157 | + <MudBadge Content=""@_notEmptyCount"" Overlap=""true"" Color=""Color.Primary"" Bordered=""true"" Class=""mr-3""> |
| 158 | + <MudIconButton Size=""MudBlazor.Size.Medium"" Icon=""@Icons.Material.Filled.Search"" |
| 159 | + OnClick=""ShowSearchDialog"" |
| 160 | + Variant=""Variant.Outlined"" Color=""Color.Primary"" Class=""""></MudIconButton > |
| 161 | + </MudBadge> |
| 162 | + }} |
| 163 | + else |
| 164 | + {{ |
| 165 | + <MudIconButton Size=""MudBlazor.Size.Medium"" Icon =""@Icons.Material.Filled.Search"" |
| 166 | + OnClick=""ShowSearchDialog"" |
| 167 | + Variant=""Variant.Outlined"" Color=""Color.Primary"" Class=""mr-3"" ></MudIconButton > |
| 168 | + }} |
| 169 | + <MudTooltip Text=""刷新"" Color=""Color.Primary"" > |
| 170 | + <MudIconButton Size=""MudBlazor.Size.Medium"" Icon = ""@Icons.Material.Filled.Refresh"" OnClick=""Refresh"" |
| 171 | + Variant=""Variant.Outlined"" Color=""Color.Primary"" Class=""mr-3""></MudIconButton > |
| 172 | + </MudTooltip> |
159 | 173 | <MudTooltip Text=""重置搜索"" Color = ""Color.Primary"" > |
160 | | - <MudIconButton Size=""MudBlazor.Size.Medium"" Icon = ""@Icons.Material.Filled.SearchOff"" Class=""mr-2"" |
161 | | - OnClick=""SearchReset"" Variant = ""Variant.Outlined"" Color = ""Color.Primary"" ></MudIconButton > |
| 174 | + <MudIconButton Size=""MudBlazor.Size.Medium"" Icon=""@Icons.Material.Filled.SearchOff"" |
| 175 | + OnClick=""SearchReset"" Variant=""Variant.Outlined"" Color=""Color.Primary"" Class=""mr-3""></MudIconButton > |
162 | 176 | </MudTooltip> |
163 | 177 | <MudIconButton Size=""MudBlazor.Size.Medium"" Icon =""@Icons.Material.Filled.Add"" OnClick=""AddClick"" |
164 | 178 | Variant=""Variant.Outlined"" Color=""Color.Primary"" > |
|
219 | 233 | </DialogContent> |
220 | 234 | </MudDialog> |
221 | 235 |
|
| 236 | +<MudDialog @bind-Visible=""_searchDialogVisible"" Options=""_searchDialogOptions"" > |
| 237 | + <DialogContent> |
| 238 | + <div style=""width:400px;overflow:hidden;""> |
| 239 | + <MudText Typo=""Typo.h6"" Class=""my-4"">搜索</MudText> |
| 240 | +{searchFields} |
| 241 | + </div> |
| 242 | + </DialogContent> |
| 243 | + <DialogActions> |
| 244 | + <MudButton Variant=""Variant.Filled"" Color=""Color.Primary"" OnClick=""Search"">搜索</MudButton> |
| 245 | + </DialogActions> |
| 246 | +</MudDialog> |
| 247 | +
|
222 | 248 | @code {{ |
223 | 249 |
|
224 | 250 | private MudDataGrid<TableModel> dataGrid = null!; |
|
228 | 254 | private bool _dialogVisible = false; |
229 | 255 | private EditViewModel editModel {{ get; set; }} = new(); |
230 | 256 |
|
| 257 | + private bool _searchDialogVisible = false; |
| 258 | + private int _notEmptyCount = 0; |
| 259 | + private DialogOptions _searchDialogOptions = new() |
| 260 | + {{ |
| 261 | + MaxWidth = MaxWidth.Large, |
| 262 | + NoHeader = true, |
| 263 | + }}; |
| 264 | +
|
231 | 265 | protected override async Task OnInitializedAsync() |
232 | 266 | {{ |
233 | 267 | await base.OnInitializedAsync(); |
|
270 | 304 | Items = TableData |
271 | 305 | }}; |
272 | 306 | }} |
| 307 | + |
| 308 | + private void ShowSearchDialog() |
| 309 | + {{ |
| 310 | + _searchDialogVisible = true; |
| 311 | + StateHasChanged(); |
| 312 | + }} |
| 313 | +
|
| 314 | + private async Task Search() |
| 315 | + {{ |
| 316 | + _searchDialogVisible = false; |
| 317 | + _notEmptyCount = ReflectionHelper.GetNonNullPropertyCount(searchObject); |
| 318 | + await dataGrid.ReloadServerData(); |
| 319 | + }} |
| 320 | + |
| 321 | + private void Refresh() |
| 322 | + {{ |
| 323 | + dataGrid.ReloadServerData(); |
| 324 | + }} |
273 | 325 |
|
274 | 326 | private void SearchReset() |
275 | 327 | {{ |
| 328 | + _notEmptyCount = 0; |
276 | 329 | searchObject = new(); |
277 | 330 | searchObject.Page = 1; |
278 | 331 | dataGrid.ReloadServerData(); |
|
0 commit comments