Skip to content

Commit 96d557b

Browse files
authored
feat(SelectRegion): add SelectRegion component (#598)
* chore: 增加数据资源 * chore: 增加 Region 包 * feat: 增加组件脚本 * feat: 增加 IRegionSerivce 服务 * refactor: 属性排序 * refactor: 移动位置 * feat: 增加 IRegionService 方法实现类 * feat: 实现明细逻辑 * refactor: 使用哈希集合 * refactor: 增加 Region 组件 * test: 增加单元测试 * chore: 增加项目到解决方案 * feat: 实现卡片式切换逻辑 * refactor: 增加直辖市数据 * feat: 支持双向绑定 * refactor: 增加禁用逻辑 * refactor: 移除 Disabled 状态判断 * feat: 增加特别行政区 * refactor: 更改为 SelectRegion 组件 * chore: 更改依赖 * refactor: 增加 ResetValue 逻辑 * refactor: 更改服务为 HashSet 返回值 * refactor: 更新内部逻辑
1 parent 52b6b81 commit 96d557b

3,223 files changed

Lines changed: 7580 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

BootstrapBlazor.Extensions.slnx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
<Project Path="src/components/BootstrapBlazor.PdfViewer/BootstrapBlazor.PdfViewer.csproj" />
6262
<Project Path="src/components/BootstrapBlazor.Player/BootstrapBlazor.Player.csproj" />
6363
<Project Path="src/components/BootstrapBlazor.RDKit/BootstrapBlazor.RDKit.csproj" />
64+
<Project Path="src/components/BootstrapBlazor.Region/BootstrapBlazor.Region.csproj" Id="f4e0b11d-f630-4e34-9dca-e9c6b6b60cee" />
6465
<Project Path="src/components/BootstrapBlazor.SignaturePad/BootstrapBlazor.SignaturePad.csproj" />
6566
<Project Path="src/components/BootstrapBlazor.SmilesDrawer/BootstrapBlazor.SmilesDrawer.csproj" />
6667
<Project Path="src/components/BootstrapBlazor.Sortable/BootstrapBlazor.Sortable.csproj" />
@@ -106,6 +107,7 @@
106107
<Project Path="test/UnitTestHoliday/UnitTestHoliday.csproj" />
107108
<Project Path="test/UnitTestOpcDa/UnitTestOpcDa.csproj" />
108109
<Project Path="test/UnitTestOpcUa/UnitTestOpcUa.csproj" />
110+
<Project Path="test/UnitTestRegion/UnitTestRegion.csproj" Id="37e8696e-3ae5-468f-b6d9-0a8eb4e81876" />
109111
<Project Path="test/UnitTestSvgIcon/UnitTestSvgIcon.csproj" />
110112
</Folder>
111113
</Solution>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Razor">
2+
3+
<PropertyGroup>
4+
<Version>9.0.0</Version>
5+
</PropertyGroup>
6+
7+
<PropertyGroup>
8+
<PackageTags>Bootstrap Blazor WebAssembly wasm UI Components Province City Region</PackageTags>
9+
<Description>Bootstrap UI components extensions of Region Select</Description>
10+
</PropertyGroup>
11+
12+
<ItemGroup>
13+
<Content Remove="Data\**\*.json" />
14+
</ItemGroup>
15+
16+
<ItemGroup>
17+
<EmbeddedResource Include="Data\**\*.json" />
18+
</ItemGroup>
19+
20+
<ItemGroup>
21+
<PackageReference Include="BootstrapBlazor" Version="9.11.0" />
22+
</ItemGroup>
23+
24+
<ItemGroup>
25+
<Using Include="Microsoft.JSInterop" />
26+
</ItemGroup>
27+
28+
</Project>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright (c) BootstrapBlazor & Argo Zhang (argo@live.ca). All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
// Website: https://www.blazor.zone or https://argozhang.github.io/
4+
5+
namespace BootstrapBlazor.Components;
6+
7+
/// <summary>
8+
/// Region 视图模式
9+
/// </summary>
10+
internal enum RegionViewMode
11+
{
12+
/// <summary>
13+
/// 省模式
14+
/// </summary>
15+
Province = 0,
16+
17+
/// <summary>
18+
/// 城市模式
19+
/// </summary>
20+
City = 1,
21+
22+
/// <summary>
23+
/// 区县模式
24+
/// </summary>
25+
County = 2,
26+
27+
/// <summary>
28+
/// 乡镇街道模式
29+
/// </summary>
30+
Detail = 3
31+
}
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
@namespace BootstrapBlazor.Components
2+
@inherits PopoverSelectBase<string>
3+
@attribute [JSModuleAutoLoader("./_content/BootstrapBlazor.Region/Components/SelectRegion.razor.js", JSObjectReference = true)]
4+
5+
@if (IsShowLabel)
6+
{
7+
<BootstrapLabel required="@Required" for="@InputId" ShowLabelTooltip="ShowLabelTooltip" Value="@DisplayText" />
8+
}
9+
<div @attributes="AdditionalAttributes" id="@Id" class="@ClassString">
10+
<div class="dropdown-toggle" data-bs-toggle="bb.dropdown" data-bs-placement="@PlacementString" data-bs-offset="@OffsetString" data-bs-custom-class="@CustomClassString">
11+
<input type="text" id="@InputId" disabled="@Disabled" readonly placeholder="@PlaceHolder" class="@InputClassString" value="@CurrentValueAsString" />
12+
<span class="@AppendClassString"><i class="@DropdownIcon"></i></span>
13+
</div>
14+
@if (!IsDisabled)
15+
{
16+
<span class="@ClearClassString" @onclick="OnClearValue"><i class="@ClearIcon"></i></span>
17+
}
18+
<div class="dropdown-menu">
19+
<div class="bb-region-header">
20+
<ul>
21+
<li class="@GetHeaderActiveClass(RegionViewMode.Province)" @onclick="@OnSwitchProvinceView">省/直辖市</li>
22+
<li class="@GetHeaderActiveClass(RegionViewMode.City)" @onclick="@OnSwitchCityView">市</li>
23+
<li class="@GetHeaderActiveClass(RegionViewMode.County)" @onclick="@OnSwitchCountyView">区/县</li>
24+
<li class="@GetHeaderActiveClass(RegionViewMode.Detail)" @onclick="@OnSwitchDetailView">乡/镇/街道</li>
25+
</ul>
26+
</div>
27+
<div class="bb-region-body">
28+
<div class="@GetBodyActiveClass(RegionViewMode.Province)">
29+
@RenderProvinces()
30+
</div>
31+
<div class="@GetBodyActiveClass(RegionViewMode.City)">
32+
@RenderCities()
33+
</div>
34+
<div class="@GetBodyActiveClass(RegionViewMode.County)">
35+
@RenderCounties()
36+
</div>
37+
<div class="@GetBodyActiveClass(RegionViewMode.Detail)">
38+
@RenderDetails()
39+
</div>
40+
</div>
41+
</div>
42+
</div>
43+
44+
@code {
45+
RenderFragment RenderProvinces() =>
46+
@<ul>
47+
@foreach(var item in GetProvinces())
48+
{
49+
<li class="@GetProvinceActiveClass(item)" @onclick="() => OnClickProvince(item)">@item</li>
50+
}
51+
</ul>;
52+
53+
RenderFragment RenderCities() =>
54+
@<ul class="bb-region-province">
55+
@{
56+
var items = GetCities();
57+
}
58+
@if (items.Count == 0)
59+
{
60+
<li>无匹配项目</li>
61+
}
62+
else
63+
{
64+
foreach(var item in items)
65+
{
66+
<li class="@GetCityActiveClass(item)" @onclick="() => OnClickCity(item)">@item</li>
67+
}
68+
}
69+
</ul>;
70+
71+
RenderFragment RenderCounties() =>
72+
@<ul class="bb-region-province">
73+
@{
74+
var items = GetCounties();
75+
}
76+
@if (items.Count == 0)
77+
{
78+
<li>无匹配项目</li>
79+
}
80+
else
81+
{
82+
@foreach(var item in items)
83+
{
84+
<li class="@GetCountyActiveClass(item)" @onclick="() => OnClickCounty(item)">@item.Name</li>
85+
}
86+
}
87+
</ul>;
88+
89+
RenderFragment RenderDetails() =>
90+
@<ul class="bb-region-province">
91+
@{
92+
var items = GetDetails();
93+
}
94+
@if (items.Count == 0)
95+
{
96+
<li>无匹配项目</li>
97+
}
98+
else
99+
{
100+
@foreach(var item in items)
101+
{
102+
<li class="@GetDetailActiveClass(item)" @onclick="() => OnClickDetail(item)">@item</li>
103+
}
104+
}
105+
</ul>;
106+
}

0 commit comments

Comments
 (0)