Skip to content

Commit 3d39e2c

Browse files
authored
feat(SelectRegion): update switch board logic (#600)
* refactor: 移除 JSObjectReference 初始化 * refactor: 更新细节 * fix: 修复脚本错误 * chore: 增加全局命名空间 * refactor: 更新样式
1 parent 96d557b commit 3d39e2c

5 files changed

Lines changed: 16 additions & 17 deletions

File tree

src/components/BootstrapBlazor.Region/BootstrapBlazor.Region.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
</ItemGroup>
2323

2424
<ItemGroup>
25+
<Using Include="Microsoft.AspNetCore.Components" />
2526
<Using Include="Microsoft.JSInterop" />
2627
</ItemGroup>
2728

src/components/BootstrapBlazor.Region/Components/SelectRegion.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
@namespace BootstrapBlazor.Components
22
@inherits PopoverSelectBase<string>
3-
@attribute [JSModuleAutoLoader("./_content/BootstrapBlazor.Region/Components/SelectRegion.razor.js", JSObjectReference = true)]
3+
@attribute [JSModuleAutoLoader("./_content/BootstrapBlazor.Region/Components/SelectRegion.razor.js")]
44

55
@if (IsShowLabel)
66
{

src/components/BootstrapBlazor.Region/Components/SelectRegion.razor.cs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33
// Website: https://www.blazor.zone or https://argozhang.github.io/
44

5-
using Microsoft.AspNetCore.Components;
6-
75
namespace BootstrapBlazor.Components;
86

97
/// <summary>
@@ -177,11 +175,11 @@ private void ResetValue()
177175

178176
private async Task OnClearValue()
179177
{
180-
_provinceValue = "";
181-
_cityValue = "";
178+
_provinceValue = null;
179+
_cityValue = null;
182180
_countyValue = new();
183-
_detailValue = "";
184-
CurrentValue = "";
181+
_detailValue = null;
182+
CurrentValue = null;
185183

186184
_currentViewMode = RegionViewMode.Province;
187185

@@ -226,6 +224,9 @@ private HashSet<string> GetDetails()
226224
private void OnClickProvince(string value)
227225
{
228226
_provinceValue = value;
227+
_cityValue = null;
228+
_countyValue = new();
229+
_detailValue = null;
229230
_currentViewMode = RegionViewMode.City;
230231

231232
CurrentValue = _provinceValue;
@@ -234,6 +235,8 @@ private void OnClickProvince(string value)
234235
private void OnClickCity(string value)
235236
{
236237
_cityValue = value;
238+
_countyValue = new();
239+
_detailValue = null;
237240
_currentViewMode = RegionViewMode.County;
238241

239242
CurrentValue = $"{_provinceValue}-{_cityValue}";
@@ -242,6 +245,7 @@ private void OnClickCity(string value)
242245
private void OnClickCounty(CountyItem item)
243246
{
244247
_countyValue = item;
248+
_detailValue = null;
245249
_currentViewMode = RegionViewMode.Detail;
246250

247251
CurrentValue = $"{_provinceValue}-{_cityValue}-{_countyValue.Name}";
@@ -259,22 +263,16 @@ private async Task OnClickDetail(string value)
259263
private void OnSwitchProvinceView()
260264
{
261265
_currentViewMode = RegionViewMode.Province;
262-
_cityValue = "";
263-
_countyValue = new();
264-
_detailValue = "";
265266
}
266267

267268
private void OnSwitchCityView()
268269
{
269270
_currentViewMode = RegionViewMode.City;
270-
_countyValue = new();
271-
_detailValue = "";
272271
}
273272

274273
private void OnSwitchCountyView()
275274
{
276275
_currentViewMode = RegionViewMode.County;
277-
_detailValue = "";
278276
}
279277

280278
private void OnSwitchDetailView()

src/components/BootstrapBlazor.Region/Components/SelectRegion.razor.css

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,12 @@
7171
color: #777;
7272
}
7373

74-
.bb-region-body ul li.active {
75-
background-color: #e3e3e3;
74+
.bb-region-body ul li:hover {
75+
background-color: #e9ecef;
7676
color: #000;
7777
}
7878

79-
.bb-region-body ul li:hover {
79+
.bb-region-body ul li.active {
8080
background-color: #e3e3e3;
8181
color: #000;
8282
}

src/components/BootstrapBlazor.Region/Components/SelectRegion.razor.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@ export function dispose(id) {
2525

2626
const { popover } = region;
2727
if (popover) {
28-
Popover.dispose(select.popover);
28+
Popover.dispose(popover);
2929
}
3030
}

0 commit comments

Comments
 (0)