Skip to content

Commit ae092a4

Browse files
committed
refactor: 重构代码
1 parent fac8044 commit ae092a4

17 files changed

+382
-278
lines changed

src/BootstrapBlazor/Components/Filters/BoolFilter.razor

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,10 @@
33

44
@if (IsHeaderRow)
55
{
6-
<Select Items="@Items" @bind-Value="@_value"
7-
OnSelectedItemChanged="_ => OnFilterValueChanged()" IsPopover="true"
8-
ShowLabel="false" SkipValidate="true"></Select>
6+
<Select Items="@Items" @bind-Value="@_value" ShowLabel="false" SkipValidate="true"
7+
OnSelectedItemChanged="_ => OnFilterValueChanged()" IsPopover="true"></Select>
98
}
109
else
1110
{
12-
<div class="card filter-item">
13-
<div class="card-header"><span>@Title</span></div>
14-
<div class="card-body">
15-
<Select Items="@Items" @bind-Value="@_value" ShowLabel="false" SkipValidate="true"></Select>
16-
</div>
17-
<div class="card-footer justify-content-end">
18-
<Button Color="Color.None" class="filter-dismiss" OnClick="OnClickReset" Text="@ClearButtonText"></Button>
19-
<Button Color="Color.None" class="filter-dismiss" OnClick="OnClickConfirm" Text="@FilterButtonText"></Button>
20-
</div>
21-
</div>
11+
<Select Items="@Items" @bind-Value="@_value" ShowLabel="false" SkipValidate="true"></Select>
2212
}

src/BootstrapBlazor/Components/Filters/BoolFilter.razor.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
namespace BootstrapBlazor.Components;
77

88
/// <summary>
9-
///
9+
/// BoolFilter component is used for boolean value filtering in table column.
1010
/// </summary>
1111
public partial class BoolFilter
1212
{
1313
/// <summary>
14-
/// 获得/设置 条件候选项 请尽量使用静态数据 避免组件性能损失
14+
/// Gets or sets the filter candidate items. It is recommended to use static data to avoid performance loss.
1515
/// </summary>
1616
[Parameter]
1717
public IEnumerable<SelectedItem>? Items { get; set; }

src/BootstrapBlazor/Components/Filters/DateTimeFilter.razor

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,18 @@
66
<div class="@FilterRowClassString">
77
<DateTimePicker class="is-filter" @bind-Value="_value1" OnValueChanged="_ => OnFilterValueChanged()"
88
ShowLabel="false" SkipValidate="true"></DateTimePicker>
9-
<FilterButton Items="_items" @bind-Value="_action1" OnSelectedItemChanged="_ => OnFilterValueChanged()" OnClearFilter="OnClearFilter" />
9+
<FilterButton Items="Items" @bind-Value="_action1" OnSelectedItemChanged="_ => OnFilterValueChanged()" OnClearFilter="OnClearFilter" />
1010
</div>
1111
}
1212
else
1313
{
14-
<div class="card filter-item">
15-
<div class="card-header"><span>@Title</span></div>
16-
<div class="card-body">
17-
<Select Items="_items" @bind-Value="_action1" ShowLabel="false" SkipValidate="true"></Select>
18-
<DateTimePicker class="is-filter" @bind-Value="_value1" ShowLabel="false" SkipValidate="true"></DateTimePicker>
14+
<Select Items="Items" @bind-Value="_action1" ShowLabel="false" SkipValidate="true"></Select>
15+
<DateTimePicker class="is-filter" @bind-Value="_value1" ShowLabel="false" SkipValidate="true"></DateTimePicker>
1916

20-
@if (Count > 0)
21-
{
22-
<FilterLogicItem @bind-Logic="Logic"></FilterLogicItem>
23-
<Select Items="_items" @bind-Value="_action2" ShowLabel="false" SkipValidate="true"></Select>
24-
<DateTimePicker class="is-filter" @bind-Value="_value2" ShowLabel="false" SkipValidate="true"></DateTimePicker>
25-
}
26-
</div>
27-
<div class="card-footer">
28-
<div class="d-flex flex-fill">
29-
<Button Color="Color.None" OnClick="OnClickPlus" Icon="@PlusIcon" IsDisabled="@(Count == 1)"></Button>
30-
<Button Color="Color.None" OnClick="OnClickMinus" Icon="@MinusIcon" IsDisabled="@(Count == 0)"></Button>
31-
</div>
32-
<Button Color="Color.None" class="filter-dismiss" OnClick="OnClickReset" Text="@ClearButtonText"></Button>
33-
<Button Color="Color.None" class="filter-dismiss" OnClick="OnClickConfirm" Text="@FilterButtonText"></Button>
34-
</div>
35-
</div>
17+
@if (Count > 0)
18+
{
19+
<FilterLogicItem @bind-Logic="Logic"></FilterLogicItem>
20+
<Select Items="Items" @bind-Value="_action2" ShowLabel="false" SkipValidate="true"></Select>
21+
<DateTimePicker class="is-filter" @bind-Value="_value2" ShowLabel="false" SkipValidate="true"></DateTimePicker>
22+
}
3623
}

src/BootstrapBlazor/Components/Filters/DateTimeFilter.razor.cs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,28 @@ public partial class DateTimeFilter
1919
.AddClass("active", TableFilter.HasFilter())
2020
.Build();
2121

22-
private IEnumerable<SelectedItem> _items = [];
22+
/// <summary>
23+
/// Gets or sets the filter candidate items. It is recommended to use static data to avoid performance loss.
24+
/// </summary>
25+
[Parameter]
26+
public IEnumerable<SelectedItem>? Items { get; set; }
2327

2428
/// <summary>
2529
/// <inheritdoc/>
2630
/// </summary>
27-
protected override void OnInitialized()
31+
protected override void OnParametersSet()
2832
{
29-
base.OnInitialized();
33+
base.OnParametersSet();
3034

31-
_items = new SelectedItem[]
32-
{
33-
new("GreaterThanOrEqual", Localizer["GreaterThanOrEqual"].Value),
34-
new("LessThanOrEqual", Localizer["LessThanOrEqual"].Value),
35-
new("GreaterThan", Localizer["GreaterThan"].Value),
36-
new("LessThan", Localizer["LessThan"].Value),
37-
new("Equal", Localizer["Equal"].Value),
38-
new("NotEqual", Localizer["NotEqual"].Value )
39-
};
35+
Items ??=
36+
[
37+
new SelectedItem("GreaterThanOrEqual", Localizer["GreaterThanOrEqual"].Value),
38+
new SelectedItem("LessThanOrEqual", Localizer["LessThanOrEqual"].Value),
39+
new SelectedItem("GreaterThan", Localizer["GreaterThan"].Value),
40+
new SelectedItem("LessThan", Localizer["LessThan"].Value),
41+
new SelectedItem("Equal", Localizer["Equal"].Value),
42+
new SelectedItem("NotEqual", Localizer["NotEqual"].Value)
43+
];
4044
}
4145

4246
private async Task OnClearFilter()

src/BootstrapBlazor/Components/Filters/EnumFilter.razor

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,15 @@
33

44
@if (IsHeaderRow)
55
{
6-
<Select Items="@Items" @bind-Value="@_value" OnSelectedItemChanged="_ => OnFilterValueChanged()" IsPopover="true"
7-
ShowLabel="false" SkipValidate="true"></Select>
6+
<Select Items="@Items" @bind-Value="@_value" ShowLabel="false" SkipValidate="true"
7+
OnSelectedItemChanged="_ => OnFilterValueChanged()" IsPopover="true"></Select>
88
}
99
else
1010
{
11-
<div class="card filter-item">
12-
<div class="card-header"><span>@Title</span></div>
13-
<div class="card-body">
14-
<Select Items="@Items" @bind-Value="@_value" ShowLabel="false" SkipValidate="true"></Select>
15-
@if (Count > 0)
16-
{
17-
<FilterLogicItem @bind-Logic="Logic"></FilterLogicItem>
18-
<Select Items="@Items" @bind-Value="@_value2" ShowLabel="false" SkipValidate="true"></Select>
19-
}
20-
</div>
21-
<div class="card-footer">
22-
<div class="d-flex flex-fill">
23-
<Button Color="Color.None" OnClick="OnClickPlus" Icon="@PlusIcon" IsDisabled="@(Count == 1)"></Button>
24-
<Button Color="Color.None" OnClick="OnClickMinus" Icon="@MinusIcon" IsDisabled="@(Count == 0)"></Button>
25-
</div>
26-
<Button Color="Color.None" class="filter-dismiss" OnClick="OnClickReset" Text="@ClearButtonText"></Button>
27-
<Button Color="Color.None" class="filter-dismiss" OnClick="OnClickConfirm" Text="@FilterButtonText"></Button>
28-
</div>
29-
</div>
11+
<Select Items="@Items" @bind-Value="@_value" ShowLabel="false" SkipValidate="true"></Select>
12+
@if (Count > 0)
13+
{
14+
<FilterLogicItem @bind-Logic="Logic"></FilterLogicItem>
15+
<Select Items="@Items" @bind-Value="@_value2" ShowLabel="false" SkipValidate="true"></Select>
16+
}
3017
}

src/BootstrapBlazor/Components/Filters/EnumFilter.razor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public partial class EnumFilter
2424
public Type? Type { get; set; }
2525

2626
/// <summary>
27-
/// 获得/设置 条件候选项 请尽量使用静态数据 避免组件性能损失
27+
/// Gets or sets the filter candidate items. It is recommended to use static data to avoid performance loss.
2828
/// </summary>
2929
[Parameter]
3030
public IEnumerable<SelectedItem>? Items { get; set; }

src/BootstrapBlazor/Components/Filters/LookupFilter.razor

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,16 @@
33

44
@if (IsHeaderRow)
55
{
6-
<Select Items="@_lookup.Lookup" LookupService="@_lookup.LookupService"
6+
<Select Items="@_lookup.Lookup" ShowLabel="false" SkipValidate="true"
7+
LookupService="@_lookup.LookupService" StringComparison="@_lookup.LookupStringComparison"
78
LookupServiceKey="@_lookup.LookupServiceKey" LookupServiceData="@_lookup.LookupServiceData"
8-
StringComparison="@_lookup.LookupStringComparison"
9-
@bind-Value="@_value" OnSelectedItemChanged="_ => OnFilterValueChanged()"
10-
IsPopover="true" ShowSearch="@_isShowSearch" ShowLabel="false" SkipValidate="true"></Select>
9+
@bind-Value="@_value" ShowSearch="@_isShowSearch"
10+
OnSelectedItemChanged="_ => OnFilterValueChanged()" IsPopover="true"></Select>
1111
}
1212
else
1313
{
14-
<div class="card filter-item">
15-
<div class="card-header"><span>@Title</span></div>
16-
<div class="card-body">
17-
<Select Items="@_lookup.Lookup" LookupService="@_lookup.LookupService"
18-
LookupServiceKey="@_lookup.LookupServiceKey" LookupServiceData="@_lookup.LookupServiceData"
19-
StringComparison="@_lookup.LookupStringComparison"
14+
<Select Items="@_lookup.Lookup" ShowLabel="false" SkipValidate="true"
15+
LookupService="@_lookup.LookupService" StringComparison="@_lookup.LookupStringComparison"
16+
LookupServiceKey="@_lookup.LookupServiceKey" LookupServiceData="@_lookup.LookupServiceData"
2017
@bind-Value="@_value" ShowSearch="@_isShowSearch"></Select>
21-
</div>
22-
<div class="card-footer justify-content-end">
23-
<Button Color="Color.None" class="filter-dismiss" OnClick="OnClickReset" Text="@ClearButtonText"></Button>
24-
<Button Color="Color.None" class="filter-dismiss" OnClick="OnClickConfirm" Text="@FilterButtonText"></Button>
25-
</div>
26-
</div>
2718
}

src/BootstrapBlazor/Components/Filters/MultiFilter.razor

Lines changed: 31 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -8,50 +8,41 @@
88
}
99
else
1010
{
11-
<div class="card filter-item">
12-
<div class="card-header"><span>@Title</span></div>
13-
<div class="card-body">
14-
<div class="bb-multi-filter" id="@Id">
15-
@if (ShowSearch)
16-
{
17-
<BootstrapInput UseInputEvent="true" class="bb-multi-filter-search"
18-
Value="@_searchText" bind-value:event="oninput" IsAutoFocus="true"
19-
PlaceHolder="@SearchPlaceHolderText" IsSelectAllTextOnFocus="true"
20-
OnValueChanged="OnSearchValueChanged" ShowLabel="false" SkipValidate="true"></BootstrapInput>
21-
}
22-
<div class="bb-multi-filter-list">
23-
<div class="bb-multi-filter-header">
24-
<Checkbox Value="GetAllState()" ShowAfterLabel="true" ShowLabel="false" SkipValidate="true"
25-
DisplayText="@SelectAllText" OnStateChanged="@OnStateChanged" State="_selectAllState" />
26-
</div>
27-
<div class="bb-multi-filter-body scroll">
28-
@foreach (var item in GetItems())
29-
{
30-
<div class="bb-multi-filter-body-item">
31-
<Checkbox @bind-Value="@item.Active" ShowAfterLabel="true"
32-
ShowLabel="false" SkipValidate="true" DisplayText="@item.Text" />
33-
</div>
34-
}
35-
</div>
36-
</div>
37-
@if (_source == null)
11+
<div class="bb-multi-filter" id="@Id">
12+
@if (ShowSearch)
13+
{
14+
<BootstrapInput UseInputEvent="true" class="bb-multi-filter-search"
15+
Value="@_searchText" bind-value:event="oninput" IsAutoFocus="true"
16+
PlaceHolder="@SearchPlaceHolderText" IsSelectAllTextOnFocus="true"
17+
OnValueChanged="OnSearchValueChanged" ShowLabel="false" SkipValidate="true"></BootstrapInput>
18+
}
19+
<div class="bb-multi-filter-list">
20+
<div class="bb-multi-filter-header">
21+
<Checkbox Value="GetAllState()" ShowAfterLabel="true" ShowLabel="false" SkipValidate="true"
22+
DisplayText="@SelectAllText" OnStateChanged="@OnStateChanged" State="_selectAllState" />
23+
</div>
24+
<div class="bb-multi-filter-body scroll">
25+
@foreach (var item in GetItems())
3826
{
39-
<div class="bb-multi-filter-loading">
40-
@if (LoadingTemplate != null)
41-
{
42-
@LoadingTemplate
43-
}
44-
else
45-
{
46-
<Spinner Color="Color.Primary" />
47-
}
27+
<div class="bb-multi-filter-body-item">
28+
<Checkbox @bind-Value="@item.Active" ShowAfterLabel="true"
29+
ShowLabel="false" SkipValidate="true" DisplayText="@item.Text" />
4830
</div>
4931
}
5032
</div>
5133
</div>
52-
<div class="card-footer justify-content-end">
53-
<Button Color="Color.None" class="filter-dismiss" OnClick="OnClickReset" Text="@ClearButtonText"></Button>
54-
<Button Color="Color.None" class="filter-dismiss" OnClick="OnClickConfirm" Text="@FilterButtonText"></Button>
55-
</div>
34+
@if (_source == null)
35+
{
36+
<div class="bb-multi-filter-loading">
37+
@if (LoadingTemplate != null)
38+
{
39+
@LoadingTemplate
40+
}
41+
else
42+
{
43+
<Spinner Color="Color.Primary" />
44+
}
45+
</div>
46+
}
5647
</div>
5748
}

src/BootstrapBlazor/Components/Filters/MultiFilter.razor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public partial class MultiFilter
5959
private List<SelectedItem>? _items;
6060

6161
/// <summary>
62-
/// 获得/设置 条件候选项 请尽量使用静态数据 避免组件性能损失
62+
/// Gets or sets the filter candidate items. It is recommended to use static data to avoid performance loss.
6363
/// </summary>
6464
[Parameter]
6565
public IEnumerable<SelectedItem>? Items { get; set; }

src/BootstrapBlazor/Components/Filters/MultipleFilterBase.cs

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -10,59 +10,8 @@ namespace BootstrapBlazor.Components;
1010
/// </summary>
1111
public abstract class MultipleFilterBase : FilterBase
1212
{
13-
[Inject]
14-
[NotNull]
15-
private IIconTheme? IconTheme { get; set; }
16-
17-
/// <summary>
18-
/// 获得/设置 增加过滤条件图标
19-
/// </summary>
20-
[Parameter]
21-
public string? PlusIcon { get; set; }
22-
23-
/// <summary>
24-
/// 获得/设置 减少过滤条件图标
25-
/// </summary>
26-
[Parameter]
27-
public string? MinusIcon { get; set; }
28-
2913
/// <summary>
3014
/// 获得/设置 条件数量
3115
/// </summary>
3216
protected int Count { get; set; }
33-
34-
/// <summary>
35-
/// <inheritdoc/>
36-
/// </summary>
37-
protected override void OnParametersSet()
38-
{
39-
base.OnParametersSet();
40-
41-
PlusIcon ??= IconTheme.GetIconByKey(ComponentIcons.TableFilterPlusIcon);
42-
MinusIcon ??= IconTheme.GetIconByKey(ComponentIcons.TableFilterMinusIcon);
43-
}
44-
45-
/// <summary>
46-
/// 点击增加按钮时回调此方法
47-
/// </summary>
48-
/// <returns></returns>
49-
protected void OnClickPlus()
50-
{
51-
if (Count == 0)
52-
{
53-
Count++;
54-
}
55-
}
56-
57-
/// <summary>
58-
/// 点击减少按钮时回调此方法
59-
/// </summary>
60-
/// <returns></returns>
61-
protected void OnClickMinus()
62-
{
63-
if (Count == 1)
64-
{
65-
Count--;
66-
}
67-
}
6817
}

0 commit comments

Comments
 (0)