From 24a00f083012028c82f88ae7661387505837affe Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Tue, 14 Oct 2025 17:26:26 +0800 Subject: [PATCH 01/17] =?UTF-8?q?refactor:=20=E7=A7=BB=E9=99=A4=20JSObject?= =?UTF-8?q?Reference=20=E5=88=9D=E5=A7=8B=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BootstrapBlazor.Region/Components/SelectRegion.razor | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/BootstrapBlazor.Region/Components/SelectRegion.razor b/src/components/BootstrapBlazor.Region/Components/SelectRegion.razor index 69b3c48d..e6759b13 100644 --- a/src/components/BootstrapBlazor.Region/Components/SelectRegion.razor +++ b/src/components/BootstrapBlazor.Region/Components/SelectRegion.razor @@ -1,6 +1,6 @@ @namespace BootstrapBlazor.Components @inherits PopoverSelectBase -@attribute [JSModuleAutoLoader("./_content/BootstrapBlazor.Region/Components/SelectRegion.razor.js", JSObjectReference = true)] +@attribute [JSModuleAutoLoader("./_content/BootstrapBlazor.Region/Components/SelectRegion.razor.js")] @if (IsShowLabel) { From b131e1dedffa720b6fba373ecc9235ee84c8d804 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Wed, 15 Oct 2025 08:35:57 +0800 Subject: [PATCH 02/17] =?UTF-8?q?chore:=20=E5=A2=9E=E5=8A=A0=20SelectCity?= =?UTF-8?q?=20=E7=BB=84=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Components/SelectCity.razor | 30 ++++++ .../Components/SelectCity.razor.cs | 32 ++++++ .../Components/SelectCity.razor.css | 40 ++++++++ .../Components/SelectRegion.razor | 2 +- .../Components/SelectRegion.razor.cs | 67 +------------ .../Components/SelectRegion.razor.css | 18 ++-- .../Components/SelectRegionBase.cs | 98 +++++++++++++++++++ 7 files changed, 211 insertions(+), 76 deletions(-) create mode 100644 src/components/BootstrapBlazor.Region/Components/SelectCity.razor create mode 100644 src/components/BootstrapBlazor.Region/Components/SelectCity.razor.cs create mode 100644 src/components/BootstrapBlazor.Region/Components/SelectCity.razor.css create mode 100644 src/components/BootstrapBlazor.Region/Components/SelectRegionBase.cs diff --git a/src/components/BootstrapBlazor.Region/Components/SelectCity.razor b/src/components/BootstrapBlazor.Region/Components/SelectCity.razor new file mode 100644 index 00000000..8b71678a --- /dev/null +++ b/src/components/BootstrapBlazor.Region/Components/SelectCity.razor @@ -0,0 +1,30 @@ +@namespace BootstrapBlazor.Components +@inherits SelectRegionBase +@attribute [JSModuleAutoLoader("./_content/BootstrapBlazor.Region/Components/SelectRegion.razor.js")] + +@if (IsShowLabel) +{ + +} +
+ + @if (!IsDisabled) + { + + } + +
diff --git a/src/components/BootstrapBlazor.Region/Components/SelectCity.razor.cs b/src/components/BootstrapBlazor.Region/Components/SelectCity.razor.cs new file mode 100644 index 00000000..5b393473 --- /dev/null +++ b/src/components/BootstrapBlazor.Region/Components/SelectCity.razor.cs @@ -0,0 +1,32 @@ +// Copyright (c) BootstrapBlazor & Argo Zhang (argo@live.ca). All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +// Website: https://www.blazor.zone or https://argozhang.github.io/ + +namespace BootstrapBlazor.Components; + +/// +/// SelectCity 组件 +/// +public partial class SelectCity +{ + private string? InputId => $"{Id}_input"; + + private string? ClassString => CssBuilder.Default("select bb-region") + .AddClass("disabled", IsDisabled) + .AddClassFromAttributes(AdditionalAttributes) + .Build(); + + private async Task OnClearValue() + { + CurrentValue = ""; + + if (OnClearAsync != null) + { + await OnClearAsync(); + } + } + + private HashSet GetProvinces() => RegionService.GetProvinces(); + + private HashSet GetCities(string proviceName) => RegionService.GetCities(proviceName); +} diff --git a/src/components/BootstrapBlazor.Region/Components/SelectCity.razor.css b/src/components/BootstrapBlazor.Region/Components/SelectCity.razor.css new file mode 100644 index 00000000..421642f4 --- /dev/null +++ b/src/components/BootstrapBlazor.Region/Components/SelectCity.razor.css @@ -0,0 +1,40 @@ +.dropdown-menu { + --bs-dropdown-padding-y: .5rem; + --bs-dropdown-padding-x: .5rem; + max-width: 400px; + max-height: 400px; + overflow-y: auto; +} + + .dropdown-menu ul { + margin: 0; + padding: 0; + display: flex; + flex-wrap: wrap; + gap: 5px; + } + + .dropdown-menu li { + list-style: none; + transition: background-color .3s linear, color .3s linear; + cursor: pointer; + padding: 3px 12px; + border-radius: var(--bs-border-radius); + color: #777; + } + + + .dropdown-menu li.active { + background-color: #e3e3e3; + color: #000; + } + + .dropdown-menu li:hover { + background-color: #e3e3e3; + color: #000; + } + +.bb-region-city-item { + padding: 3px 12px; + color: #ddd; +} diff --git a/src/components/BootstrapBlazor.Region/Components/SelectRegion.razor b/src/components/BootstrapBlazor.Region/Components/SelectRegion.razor index e6759b13..fba41d09 100644 --- a/src/components/BootstrapBlazor.Region/Components/SelectRegion.razor +++ b/src/components/BootstrapBlazor.Region/Components/SelectRegion.razor @@ -1,5 +1,5 @@ @namespace BootstrapBlazor.Components -@inherits PopoverSelectBase +@inherits SelectRegionBase @attribute [JSModuleAutoLoader("./_content/BootstrapBlazor.Region/Components/SelectRegion.razor.js")] @if (IsShowLabel) diff --git a/src/components/BootstrapBlazor.Region/Components/SelectRegion.razor.cs b/src/components/BootstrapBlazor.Region/Components/SelectRegion.razor.cs index 274f9d68..40340d9f 100644 --- a/src/components/BootstrapBlazor.Region/Components/SelectRegion.razor.cs +++ b/src/components/BootstrapBlazor.Region/Components/SelectRegion.razor.cs @@ -11,75 +11,13 @@ namespace BootstrapBlazor.Components; /// public partial class SelectRegion { - /// - /// Gets or sets the placeholder text. - /// - [Parameter] - public string? PlaceHolder { get; set; } - - /// - /// Gets or sets the color. The default is (no color). - /// - [Parameter] - public Color Color { get; set; } - - /// - /// Gets or sets the dropdown icon. The default is "fa-solid fa-angle-up". - /// - [Parameter] - [NotNull] - public string? DropdownIcon { get; set; } - - /// - /// Gets or sets the callback method when the clear button is clicked. Default is null. - /// - [Parameter] - public Func? OnClearAsync { get; set; } - - /// - /// Gets or sets the right-side clear icon. Default is fa-solid fa-angle-up. - /// - [Parameter] - [NotNull] - public string? ClearIcon { get; set; } - - /// - /// Gets or sets the service instance. - /// - [Inject] - [NotNull] - private IIconTheme? IconTheme { get; set; } - - [Inject] - [NotNull] - private IRegionService? RegionService { get; set; } + private string? InputId => $"{Id}_input"; private string? ClassString => CssBuilder.Default("select bb-region") .AddClass("disabled", IsDisabled) .AddClassFromAttributes(AdditionalAttributes) .Build(); - private string? InputId => $"{Id}_input"; - - private string? InputClassString => CssBuilder.Default("form-select form-control") - .AddClass($"border-{Color.ToDescriptionString()}", Color != Color.None && !IsDisabled && !IsValid.HasValue) - .AddClass($"border-success", IsValid.HasValue && IsValid.Value) - .AddClass($"border-danger", IsValid.HasValue && !IsValid.Value) - .AddClass(CssClass).AddClass(ValidCss) - .Build(); - - private string? AppendClassString => CssBuilder.Default("form-select-append") - .AddClass($"text-{Color.ToDescriptionString()}", Color != Color.None && !IsDisabled && !IsValid.HasValue) - .AddClass($"text-success", IsValid.HasValue && IsValid.Value) - .AddClass($"text-danger", IsValid.HasValue && !IsValid.Value) - .Build(); - - private string? ClearClassString => CssBuilder.Default("clear-icon") - .AddClass($"text-{Color.ToDescriptionString()}", Color != Color.None) - .AddClass($"text-success", IsValid.HasValue && IsValid.Value) - .AddClass($"text-danger", IsValid.HasValue && !IsValid.Value) - .Build(); - private string? GetHeaderActiveClass(RegionViewMode type) => _currentViewMode == type ? "active" : null; private string? GetBodyActiveClass(RegionViewMode type) => CssBuilder.Default("bb-region-body-item") @@ -111,9 +49,6 @@ protected override void OnParametersSet() { base.OnParametersSet(); - DropdownIcon ??= IconTheme.GetIconByKey(ComponentIcons.SelectDropdownIcon); - ClearIcon ??= IconTheme.GetIconByKey(ComponentIcons.SelectClearIcon); - ResetValue(); } diff --git a/src/components/BootstrapBlazor.Region/Components/SelectRegion.razor.css b/src/components/BootstrapBlazor.Region/Components/SelectRegion.razor.css index ef0b2dea..8ccd3596 100644 --- a/src/components/BootstrapBlazor.Region/Components/SelectRegion.razor.css +++ b/src/components/BootstrapBlazor.Region/Components/SelectRegion.razor.css @@ -6,19 +6,19 @@ display: none; } -.popover-region .dropdown-menu { +.dropdown-menu { --bs-dropdown-padding-y: 0; } -.popover-region ul { - margin: 0; - padding: 0; -} + .dropdown-menu ul { + margin: 0; + padding: 0; + } -.popover-region li { - list-style: none; - transition: background-color .3s linear, color .3s linear; -} + .dropdown-menu li { + list-style: none; + transition: background-color .3s linear, color .3s linear; + } .bb-region-header { width: 400px; diff --git a/src/components/BootstrapBlazor.Region/Components/SelectRegionBase.cs b/src/components/BootstrapBlazor.Region/Components/SelectRegionBase.cs new file mode 100644 index 00000000..c6cf9e69 --- /dev/null +++ b/src/components/BootstrapBlazor.Region/Components/SelectRegionBase.cs @@ -0,0 +1,98 @@ +// Copyright (c) BootstrapBlazor & Argo Zhang (argo@live.ca). All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +// Website: https://www.blazor.zone or https://argozhang.github.io/ + +using Microsoft.AspNetCore.Components; + +namespace BootstrapBlazor.Components; + +/// +/// SelectRegion 组件基类 +/// +public abstract class SelectRegionBase : PopoverSelectBase +{ + /// + /// Gets or sets the placeholder text. + /// + [Parameter] + public string? PlaceHolder { get; set; } + + /// + /// Gets or sets the color. The default is (no color). + /// + [Parameter] + public Color Color { get; set; } + + /// + /// Gets or sets the dropdown icon. The default is "fa-solid fa-angle-up". + /// + [Parameter] + [NotNull] + public string? DropdownIcon { get; set; } + + /// + /// Gets or sets the callback method when the clear button is clicked. Default is null. + /// + [Parameter] + public Func? OnClearAsync { get; set; } + + /// + /// Gets or sets the right-side clear icon. Default is fa-solid fa-angle-up. + /// + [Parameter] + [NotNull] + public string? ClearIcon { get; set; } + + /// + /// Gets or sets the service instance. + /// + [Inject] + [NotNull] + protected IIconTheme? IconTheme { get; set; } + + /// + /// service instance + /// + [Inject] + [NotNull] + protected IRegionService? RegionService { get; set; } + + /// + /// 文本框样式 + /// + protected string? InputClassString => CssBuilder.Default("form-select form-control") + .AddClass($"border-{Color.ToDescriptionString()}", Color != Color.None && !IsDisabled && !IsValid.HasValue) + .AddClass($"border-success", IsValid.HasValue && IsValid.Value) + .AddClass($"border-danger", IsValid.HasValue && !IsValid.Value) + .AddClass(CssClass).AddClass(ValidCss) + .Build(); + + /// + /// 下拉框按钮样式 + /// + protected string? AppendClassString => CssBuilder.Default("form-select-append") + .AddClass($"text-{Color.ToDescriptionString()}", Color != Color.None && !IsDisabled && !IsValid.HasValue) + .AddClass($"text-success", IsValid.HasValue && IsValid.Value) + .AddClass($"text-danger", IsValid.HasValue && !IsValid.Value) + .Build(); + + /// + /// 清空按钮样式 + /// + protected string? ClearClassString => CssBuilder.Default("clear-icon") + .AddClass($"text-{Color.ToDescriptionString()}", Color != Color.None) + .AddClass($"text-success", IsValid.HasValue && IsValid.Value) + .AddClass($"text-danger", IsValid.HasValue && !IsValid.Value) + .Build(); + + /// + /// + /// + protected override void OnParametersSet() + { + base.OnParametersSet(); + + DropdownIcon ??= IconTheme.GetIconByKey(ComponentIcons.SelectDropdownIcon); + ClearIcon ??= IconTheme.GetIconByKey(ComponentIcons.SelectClearIcon); + } +} From 662fd9feb7e3a9b9084eb387f59fc13763c989a7 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Wed, 15 Oct 2025 09:02:47 +0800 Subject: [PATCH 03/17] =?UTF-8?q?refactor:=20=E6=9B=B4=E6=96=B0=E7=BB=86?= =?UTF-8?q?=E8=8A=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Components/SelectRegion.razor.cs | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/components/BootstrapBlazor.Region/Components/SelectRegion.razor.cs b/src/components/BootstrapBlazor.Region/Components/SelectRegion.razor.cs index 40340d9f..de778f56 100644 --- a/src/components/BootstrapBlazor.Region/Components/SelectRegion.razor.cs +++ b/src/components/BootstrapBlazor.Region/Components/SelectRegion.razor.cs @@ -2,8 +2,6 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Website: https://www.blazor.zone or https://argozhang.github.io/ -using Microsoft.AspNetCore.Components; - namespace BootstrapBlazor.Components; /// @@ -112,11 +110,11 @@ private void ResetValue() private async Task OnClearValue() { - _provinceValue = ""; - _cityValue = ""; + _provinceValue = null; + _cityValue = null; _countyValue = new(); - _detailValue = ""; - CurrentValue = ""; + _detailValue = null; + CurrentValue = null; _currentViewMode = RegionViewMode.Province; @@ -161,6 +159,9 @@ private HashSet GetDetails() private void OnClickProvince(string value) { _provinceValue = value; + _cityValue = null; + _countyValue = new(); + _detailValue = null; _currentViewMode = RegionViewMode.City; CurrentValue = _provinceValue; @@ -169,6 +170,8 @@ private void OnClickProvince(string value) private void OnClickCity(string value) { _cityValue = value; + _countyValue = new(); + _detailValue = null; _currentViewMode = RegionViewMode.County; CurrentValue = $"{_provinceValue}-{_cityValue}"; @@ -177,6 +180,7 @@ private void OnClickCity(string value) private void OnClickCounty(CountyItem item) { _countyValue = item; + _detailValue = null; _currentViewMode = RegionViewMode.Detail; CurrentValue = $"{_provinceValue}-{_cityValue}-{_countyValue.Name}"; @@ -194,22 +198,16 @@ private async Task OnClickDetail(string value) private void OnSwitchProvinceView() { _currentViewMode = RegionViewMode.Province; - _cityValue = ""; - _countyValue = new(); - _detailValue = ""; } private void OnSwitchCityView() { _currentViewMode = RegionViewMode.City; - _countyValue = new(); - _detailValue = ""; } private void OnSwitchCountyView() { _currentViewMode = RegionViewMode.County; - _detailValue = ""; } private void OnSwitchDetailView() From ea460419ab3541504b2f2421a181c3842970ccf5 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Wed, 15 Oct 2025 09:04:20 +0800 Subject: [PATCH 04/17] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E8=84=9A?= =?UTF-8?q?=E6=9C=AC=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BootstrapBlazor.Region/Components/SelectRegion.razor.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/BootstrapBlazor.Region/Components/SelectRegion.razor.js b/src/components/BootstrapBlazor.Region/Components/SelectRegion.razor.js index ed5603a1..245d12fc 100644 --- a/src/components/BootstrapBlazor.Region/Components/SelectRegion.razor.js +++ b/src/components/BootstrapBlazor.Region/Components/SelectRegion.razor.js @@ -25,6 +25,6 @@ export function dispose(id) { const { popover } = region; if (popover) { - Popover.dispose(select.popover); + Popover.dispose(popover); } } From f75ae546c0d924eccd26f9b32cb5833529908706 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Wed, 15 Oct 2025 09:45:34 +0800 Subject: [PATCH 05/17] =?UTF-8?q?feat:=20=E5=AE=9E=E7=8E=B0=E5=9F=8E?= =?UTF-8?q?=E5=B8=82=E6=8E=92=E5=88=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Components/SelectCity.razor | 18 +++--- .../Components/SelectCity.razor.cs | 62 ++++++++++++++++++- .../Components/SelectCity.razor.css | 11 +++- 3 files changed, 79 insertions(+), 12 deletions(-) diff --git a/src/components/BootstrapBlazor.Region/Components/SelectCity.razor b/src/components/BootstrapBlazor.Region/Components/SelectCity.razor index 8b71678a..d5e25302 100644 --- a/src/components/BootstrapBlazor.Region/Components/SelectCity.razor +++ b/src/components/BootstrapBlazor.Region/Components/SelectCity.razor @@ -16,15 +16,17 @@ } diff --git a/src/components/BootstrapBlazor.Region/Components/SelectCity.razor.cs b/src/components/BootstrapBlazor.Region/Components/SelectCity.razor.cs index 5b393473..ad91c082 100644 --- a/src/components/BootstrapBlazor.Region/Components/SelectCity.razor.cs +++ b/src/components/BootstrapBlazor.Region/Components/SelectCity.razor.cs @@ -26,7 +26,65 @@ private async Task OnClearValue() } } - private HashSet GetProvinces() => RegionService.GetProvinces(); + private static HashSet GetProvinces() + { + return + [ + "直辖市", + "河北省", + "山西省", + "辽宁省", + "吉林省", + "黑龙江省", + "江苏省", + "浙江省", + "安徽省", + "福建省", + "江西省", + "山东省", + "河南省", + "湖北省", + "湖南省", + "广东省", + "海南省", + "四川省", + "贵州省", + "云南省", + "陕西省", + "甘肃省", + "青海省", + "内蒙古自治区", + "广西壮族自治区", + "西藏自治区", + "宁夏回族自治区", + "新疆维吾尔自治区", + "台湾省", + "特别行政区" + ]; + } + + private HashSet GetCities(string proviceName) + { + if (proviceName == "直辖市") + { + return + [ + "北京市", + "天津市", + "上海市", + "重庆市" + ]; + } - private HashSet GetCities(string proviceName) => RegionService.GetCities(proviceName); + if (proviceName == "特别行政区") + { + return + [ + "香港特别行政区", + "澳门特别行政区" + ]; + } + + return RegionService.GetCities(proviceName); + } } diff --git a/src/components/BootstrapBlazor.Region/Components/SelectCity.razor.css b/src/components/BootstrapBlazor.Region/Components/SelectCity.razor.css index 421642f4..f66329e9 100644 --- a/src/components/BootstrapBlazor.Region/Components/SelectCity.razor.css +++ b/src/components/BootstrapBlazor.Region/Components/SelectCity.razor.css @@ -34,7 +34,14 @@ color: #000; } -.bb-region-city-item { +.bb-region-city-item:not(:last-child) { + margin-bottom: 3px; + padding-bottom: 3px; + border-bottom: 1px solid var(--bs-border-color); +} + +.bb-region-city-title { padding: 3px 12px; - color: #ddd; + color: #000; + font-weight: bold; } From 01bc34a49d8638f8a81ec9194143fc1d14b5d76d Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Wed, 15 Oct 2025 09:55:12 +0800 Subject: [PATCH 06/17] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E9=80=89?= =?UTF-8?q?=E6=8B=A9=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Components/SelectCity.razor | 2 +- .../Components/SelectCity.razor.cs | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/components/BootstrapBlazor.Region/Components/SelectCity.razor b/src/components/BootstrapBlazor.Region/Components/SelectCity.razor index d5e25302..51c6bf88 100644 --- a/src/components/BootstrapBlazor.Region/Components/SelectCity.razor +++ b/src/components/BootstrapBlazor.Region/Components/SelectCity.razor @@ -23,7 +23,7 @@
    @foreach (var city in GetCities(item)) { -
  • @city
  • +
  • @city
  • }
diff --git a/src/components/BootstrapBlazor.Region/Components/SelectCity.razor.cs b/src/components/BootstrapBlazor.Region/Components/SelectCity.razor.cs index ad91c082..9eb2e378 100644 --- a/src/components/BootstrapBlazor.Region/Components/SelectCity.razor.cs +++ b/src/components/BootstrapBlazor.Region/Components/SelectCity.razor.cs @@ -16,6 +16,10 @@ public partial class SelectCity .AddClassFromAttributes(AdditionalAttributes) .Build(); + private readonly HashSet _values = []; + + private string? GetActiveClass(string item) => _values.Contains(item) ? "active" : null; + private async Task OnClearValue() { CurrentValue = ""; @@ -26,6 +30,19 @@ private async Task OnClearValue() } } + private void OnSelectCity(string item) + { + if (_values.Contains(item)) + { + _values.Remove(item); + } + else + { + _values.Add(item); + } + CurrentValue = string.Join(",", _values); + } + private static HashSet GetProvinces() { return From edf553d2b34a080cfdc2342132a418a2cd625efc Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Wed, 15 Oct 2025 10:13:31 +0800 Subject: [PATCH 07/17] =?UTF-8?q?refactor:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BootstrapBlazor.Region/Components/SelectCity.razor.cs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/components/BootstrapBlazor.Region/Components/SelectCity.razor.cs b/src/components/BootstrapBlazor.Region/Components/SelectCity.razor.cs index 9eb2e378..b5247467 100644 --- a/src/components/BootstrapBlazor.Region/Components/SelectCity.razor.cs +++ b/src/components/BootstrapBlazor.Region/Components/SelectCity.razor.cs @@ -32,11 +32,7 @@ private async Task OnClearValue() private void OnSelectCity(string item) { - if (_values.Contains(item)) - { - _values.Remove(item); - } - else + if (!_values.Remove(item)) { _values.Add(item); } From 9f2e0d9d45e4102b8450e0f640317f9214205fc3 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Wed, 15 Oct 2025 10:13:38 +0800 Subject: [PATCH 08/17] =?UTF-8?q?refactor:=20=E6=9B=B4=E6=96=B0=E6=A0=B7?= =?UTF-8?q?=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BootstrapBlazor.Region/Components/SelectCity.razor.css | 1 + 1 file changed, 1 insertion(+) diff --git a/src/components/BootstrapBlazor.Region/Components/SelectCity.razor.css b/src/components/BootstrapBlazor.Region/Components/SelectCity.razor.css index f66329e9..5172ba53 100644 --- a/src/components/BootstrapBlazor.Region/Components/SelectCity.razor.css +++ b/src/components/BootstrapBlazor.Region/Components/SelectCity.razor.css @@ -44,4 +44,5 @@ padding: 3px 12px; color: #000; font-weight: bold; + cursor: pointer; } From 8d746e9dde47219ddb601a3cc7bc6cc3b0c7204c Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Wed, 15 Oct 2025 10:38:17 +0800 Subject: [PATCH 09/17] =?UTF-8?q?chore:=20=E5=A2=9E=E5=8A=A0=E5=85=A8?= =?UTF-8?q?=E5=B1=80=E5=91=BD=E5=90=8D=E7=A9=BA=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BootstrapBlazor.Region/BootstrapBlazor.Region.csproj | 1 + 1 file changed, 1 insertion(+) diff --git a/src/components/BootstrapBlazor.Region/BootstrapBlazor.Region.csproj b/src/components/BootstrapBlazor.Region/BootstrapBlazor.Region.csproj index 9279e3a0..664f20b8 100644 --- a/src/components/BootstrapBlazor.Region/BootstrapBlazor.Region.csproj +++ b/src/components/BootstrapBlazor.Region/BootstrapBlazor.Region.csproj @@ -22,6 +22,7 @@ + From 5263751bf444970d0b9f7708a243230408575be8 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Wed, 15 Oct 2025 10:38:37 +0800 Subject: [PATCH 10/17] =?UTF-8?q?refactor:=20=E5=A2=9E=E5=8A=A0=E5=A4=9A?= =?UTF-8?q?=E9=80=89=E5=8F=82=E6=95=B0=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Components/SelectCity.razor.cs | 10 ++++++++++ .../Components/SelectRegionBase.cs | 2 -- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/components/BootstrapBlazor.Region/Components/SelectCity.razor.cs b/src/components/BootstrapBlazor.Region/Components/SelectCity.razor.cs index b5247467..f9bc0bf9 100644 --- a/src/components/BootstrapBlazor.Region/Components/SelectCity.razor.cs +++ b/src/components/BootstrapBlazor.Region/Components/SelectCity.razor.cs @@ -9,6 +9,12 @@ namespace BootstrapBlazor.Components; ///
public partial class SelectCity { + /// + /// 获得/设置 是否可多选 默认 false 单选 + /// + [Parameter] + public bool IsMultiple { get; set; } + private string? InputId => $"{Id}_input"; private string? ClassString => CssBuilder.Default("select bb-region") @@ -32,6 +38,10 @@ private async Task OnClearValue() private void OnSelectCity(string item) { + if(IsMultiple) + { + + } if (!_values.Remove(item)) { _values.Add(item); diff --git a/src/components/BootstrapBlazor.Region/Components/SelectRegionBase.cs b/src/components/BootstrapBlazor.Region/Components/SelectRegionBase.cs index c6cf9e69..3aa2f320 100644 --- a/src/components/BootstrapBlazor.Region/Components/SelectRegionBase.cs +++ b/src/components/BootstrapBlazor.Region/Components/SelectRegionBase.cs @@ -2,8 +2,6 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Website: https://www.blazor.zone or https://argozhang.github.io/ -using Microsoft.AspNetCore.Components; - namespace BootstrapBlazor.Components; /// From 9611c54722ddffec0b691f48b2a3d64d9dfb1250 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Wed, 15 Oct 2025 11:06:05 +0800 Subject: [PATCH 11/17] =?UTF-8?q?refactor:=20=E5=A2=9E=E5=8A=A0=E6=B8=85?= =?UTF-8?q?=E7=A9=BA=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Components/SelectCity.razor.cs | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/components/BootstrapBlazor.Region/Components/SelectCity.razor.cs b/src/components/BootstrapBlazor.Region/Components/SelectCity.razor.cs index f9bc0bf9..c880d99c 100644 --- a/src/components/BootstrapBlazor.Region/Components/SelectCity.razor.cs +++ b/src/components/BootstrapBlazor.Region/Components/SelectCity.razor.cs @@ -28,6 +28,10 @@ public partial class SelectCity private async Task OnClearValue() { + if (IsMultiple) + { + _values.Clear(); + } CurrentValue = ""; if (OnClearAsync != null) @@ -38,15 +42,18 @@ private async Task OnClearValue() private void OnSelectCity(string item) { - if(IsMultiple) + if (IsMultiple) { - + if (!_values.Remove(item)) + { + _values.Add(item); + } + CurrentValue = string.Join(",", _values); } - if (!_values.Remove(item)) + else { - _values.Add(item); + CurrentValue = item; } - CurrentValue = string.Join(",", _values); } private static HashSet GetProvinces() @@ -86,9 +93,9 @@ private static HashSet GetProvinces() ]; } - private HashSet GetCities(string proviceName) + private HashSet GetCities(string provinceName) { - if (proviceName == "直辖市") + if (provinceName == "直辖市") { return [ @@ -99,7 +106,7 @@ private HashSet GetCities(string proviceName) ]; } - if (proviceName == "特别行政区") + if (provinceName == "特别行政区") { return [ @@ -108,6 +115,6 @@ private HashSet GetCities(string proviceName) ]; } - return RegionService.GetCities(proviceName); + return RegionService.GetCities(provinceName); } } From 46907b746fd8c5916ba416f97336800361eecbec Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Wed, 15 Oct 2025 11:20:00 +0800 Subject: [PATCH 12/17] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E8=A1=A8?= =?UTF-8?q?=E5=A4=B4=E6=8C=89=E9=92=AE=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Components/SelectCity.razor | 2 +- .../Components/SelectCity.razor.cs | 45 ++++++++++++++----- 2 files changed, 34 insertions(+), 13 deletions(-) diff --git a/src/components/BootstrapBlazor.Region/Components/SelectCity.razor b/src/components/BootstrapBlazor.Region/Components/SelectCity.razor index 51c6bf88..31c3f8c8 100644 --- a/src/components/BootstrapBlazor.Region/Components/SelectCity.razor +++ b/src/components/BootstrapBlazor.Region/Components/SelectCity.razor @@ -19,7 +19,7 @@ @foreach (var item in GetProvinces()) {
-
@item
+
@item
    @foreach (var city in GetCities(item)) { diff --git a/src/components/BootstrapBlazor.Region/Components/SelectCity.razor.cs b/src/components/BootstrapBlazor.Region/Components/SelectCity.razor.cs index c880d99c..64b4b9e3 100644 --- a/src/components/BootstrapBlazor.Region/Components/SelectCity.razor.cs +++ b/src/components/BootstrapBlazor.Region/Components/SelectCity.razor.cs @@ -40,6 +40,33 @@ private async Task OnClearValue() } } + private void OnSelectProvince(string province) + { + if (IsMultiple) + { + HashSet cities = []; + if (province == "直辖市") + { + cities = Municipalities; + } + else if (province == "特别行政区") + { + cities = SpecialAdministrativeRegions; + } + else + { + cities = GetCities(province); + } + foreach (var city in cities) + { + if (!_values.Remove(city)) + { + _values.Add(city); + } + } + } + } + private void OnSelectCity(string item) { if (IsMultiple) @@ -93,26 +120,20 @@ private static HashSet GetProvinces() ]; } + private static readonly HashSet Municipalities = ["北京市", "天津市", "上海市", "重庆市"]; + + private static readonly HashSet SpecialAdministrativeRegions = ["香港特别行政区", "澳门特别行政区"]; + private HashSet GetCities(string provinceName) { if (provinceName == "直辖市") { - return - [ - "北京市", - "天津市", - "上海市", - "重庆市" - ]; + return Municipalities; } if (provinceName == "特别行政区") { - return - [ - "香港特别行政区", - "澳门特别行政区" - ]; + return SpecialAdministrativeRegions; } return RegionService.GetCities(provinceName); From 8b68c94b67d051d7e944dcd9d65a3d298a1dca32 Mon Sep 17 00:00:00 2001 From: Argo Date: Wed, 15 Oct 2025 11:39:12 +0800 Subject: [PATCH 13/17] =?UTF-8?q?refactor:=20=E6=9B=B4=E6=96=B0=E6=A0=B7?= =?UTF-8?q?=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Components/SelectRegion.razor.css | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/components/BootstrapBlazor.Region/Components/SelectRegion.razor.css b/src/components/BootstrapBlazor.Region/Components/SelectRegion.razor.css index 8ccd3596..978fceb8 100644 --- a/src/components/BootstrapBlazor.Region/Components/SelectRegion.razor.css +++ b/src/components/BootstrapBlazor.Region/Components/SelectRegion.razor.css @@ -71,12 +71,12 @@ color: #777; } - .bb-region-body ul li.active { - background-color: #e3e3e3; + .bb-region-body ul li:hover { + background-color: #e9ecef; color: #000; } - .bb-region-body ul li:hover { + .bb-region-body ul li.active { background-color: #e3e3e3; color: #000; } From c33b2489f789d6145e9ef86d13ff637bbf7429bd Mon Sep 17 00:00:00 2001 From: Argo Date: Wed, 15 Oct 2025 11:39:19 +0800 Subject: [PATCH 14/17] =?UTF-8?q?feat:=20=E6=9B=B4=E6=96=B0=E6=A0=B7?= =?UTF-8?q?=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BootstrapBlazor.Region/Components/SelectCity.razor.cs | 1 + .../BootstrapBlazor.Region/Components/SelectCity.razor.css | 7 +++---- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/components/BootstrapBlazor.Region/Components/SelectCity.razor.cs b/src/components/BootstrapBlazor.Region/Components/SelectCity.razor.cs index 64b4b9e3..f05638ab 100644 --- a/src/components/BootstrapBlazor.Region/Components/SelectCity.razor.cs +++ b/src/components/BootstrapBlazor.Region/Components/SelectCity.razor.cs @@ -64,6 +64,7 @@ private void OnSelectProvince(string province) _values.Add(city); } } + CurrentValue = string.Join(",", _values); } } diff --git a/src/components/BootstrapBlazor.Region/Components/SelectCity.razor.css b/src/components/BootstrapBlazor.Region/Components/SelectCity.razor.css index 5172ba53..cedd5848 100644 --- a/src/components/BootstrapBlazor.Region/Components/SelectCity.razor.css +++ b/src/components/BootstrapBlazor.Region/Components/SelectCity.razor.css @@ -23,13 +23,12 @@ color: #777; } - - .dropdown-menu li.active { - background-color: #e3e3e3; + .dropdown-menu li:hover { + background-color: #e9ecef; color: #000; } - .dropdown-menu li:hover { + .dropdown-menu li.active { background-color: #e3e3e3; color: #000; } From fb093919c2c4cbf8a1be8b80bf6ca2b8209a4c9b Mon Sep 17 00:00:00 2001 From: Argo Date: Wed, 15 Oct 2025 11:49:01 +0800 Subject: [PATCH 15/17] =?UTF-8?q?refactor:=20=E5=A2=9E=E5=8A=A0=E6=A0=B7?= =?UTF-8?q?=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Components/SelectCity.razor.cs | 4 ++-- .../Components/SelectCity.razor.css | 10 +++++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/components/BootstrapBlazor.Region/Components/SelectCity.razor.cs b/src/components/BootstrapBlazor.Region/Components/SelectCity.razor.cs index f05638ab..df1afaee 100644 --- a/src/components/BootstrapBlazor.Region/Components/SelectCity.razor.cs +++ b/src/components/BootstrapBlazor.Region/Components/SelectCity.razor.cs @@ -17,14 +17,14 @@ public partial class SelectCity private string? InputId => $"{Id}_input"; - private string? ClassString => CssBuilder.Default("select bb-region") + private string? ClassString => CssBuilder.Default("select bb-city") .AddClass("disabled", IsDisabled) .AddClassFromAttributes(AdditionalAttributes) .Build(); private readonly HashSet _values = []; - private string? GetActiveClass(string item) => _values.Contains(item) ? "active" : null; + private string? GetActiveClass(string item) => _values.Contains(item) || CurrentValue == item ? "active" : null; private async Task OnClearValue() { diff --git a/src/components/BootstrapBlazor.Region/Components/SelectCity.razor.css b/src/components/BootstrapBlazor.Region/Components/SelectCity.razor.css index cedd5848..9b99033f 100644 --- a/src/components/BootstrapBlazor.Region/Components/SelectCity.razor.css +++ b/src/components/BootstrapBlazor.Region/Components/SelectCity.razor.css @@ -1,4 +1,12 @@ -.dropdown-menu { +.bb-city { + position: relative; +} + + .bb-city:not(.disabled):hover .form-select-append { + display: none; + } + +.dropdown-menu { --bs-dropdown-padding-y: .5rem; --bs-dropdown-padding-x: .5rem; max-width: 400px; From 2634802b18075d2d886a026d82b40ed07c0f3066 Mon Sep 17 00:00:00 2001 From: Argo Date: Wed, 15 Oct 2025 11:58:07 +0800 Subject: [PATCH 16/17] chore: bump version 9.0.1 --- .../BootstrapBlazor.Region/BootstrapBlazor.Region.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/BootstrapBlazor.Region/BootstrapBlazor.Region.csproj b/src/components/BootstrapBlazor.Region/BootstrapBlazor.Region.csproj index 664f20b8..b8ef9ff5 100644 --- a/src/components/BootstrapBlazor.Region/BootstrapBlazor.Region.csproj +++ b/src/components/BootstrapBlazor.Region/BootstrapBlazor.Region.csproj @@ -1,7 +1,7 @@  - 9.0.0 + 9.0.1 From 359adf52f8b8af5cbe1e84ad1d4d3d59a48a3a11 Mon Sep 17 00:00:00 2001 From: Argo Date: Wed, 15 Oct 2025 12:04:40 +0800 Subject: [PATCH 17/17] =?UTF-8?q?refactor:=20=E7=A7=BB=E9=99=A4=E8=B5=8B?= =?UTF-8?q?=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BootstrapBlazor.Region/Components/SelectCity.razor.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/BootstrapBlazor.Region/Components/SelectCity.razor.cs b/src/components/BootstrapBlazor.Region/Components/SelectCity.razor.cs index df1afaee..c4287977 100644 --- a/src/components/BootstrapBlazor.Region/Components/SelectCity.razor.cs +++ b/src/components/BootstrapBlazor.Region/Components/SelectCity.razor.cs @@ -44,7 +44,7 @@ private void OnSelectProvince(string province) { if (IsMultiple) { - HashSet cities = []; + HashSet cities; if (province == "直辖市") { cities = Municipalities;