-
-
Notifications
You must be signed in to change notification settings - Fork 7
feat(SelectCity): add SelectCity component #602
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
24a00f0
refactor: 移除 JSObjectReference 初始化
ArgoZhang b131e1d
chore: 增加 SelectCity 组件
ArgoZhang 662fd9f
refactor: 更新细节
ArgoZhang ea46041
fix: 修复脚本错误
ArgoZhang f75ae54
feat: 实现城市排列
ArgoZhang 01bc34a
feat: 增加选择逻辑
ArgoZhang edf553d
refactor: 优化代码
ArgoZhang 9f2e0d9
refactor: 更新样式
ArgoZhang 8d746e9
chore: 增加全局命名空间
ArgoZhang 5263751
refactor: 增加多选参数支持
ArgoZhang 9611c54
refactor: 增加清空逻辑
ArgoZhang 46907b7
feat: 增加表头按钮逻辑
ArgoZhang 8b68c94
refactor: 更新样式
ArgoZhang c33b248
feat: 更新样式
ArgoZhang fb09391
refactor: 增加样式
ArgoZhang 113a320
Merge branch 'master' into feat-region
ArgoZhang 2634802
chore: bump version 9.0.1
ArgoZhang 359adf5
refactor: 移除赋值
ArgoZhang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
src/components/BootstrapBlazor.Region/BootstrapBlazor.Region.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
src/components/BootstrapBlazor.Region/Components/SelectCity.razor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| @namespace BootstrapBlazor.Components | ||
| @inherits SelectRegionBase | ||
| @attribute [JSModuleAutoLoader("./_content/BootstrapBlazor.Region/Components/SelectRegion.razor.js")] | ||
|
|
||
| @if (IsShowLabel) | ||
| { | ||
| <BootstrapLabel required="@Required" for="@InputId" ShowLabelTooltip="ShowLabelTooltip" Value="@DisplayText" /> | ||
| } | ||
| <div @attributes="AdditionalAttributes" id="@Id" class="@ClassString"> | ||
| <div class="dropdown-toggle" data-bs-toggle="bb.dropdown" data-bs-placement="@PlacementString" data-bs-offset="@OffsetString" data-bs-custom-class="@CustomClassString"> | ||
| <input type="text" id="@InputId" disabled="@Disabled" readonly placeholder="@PlaceHolder" class="@InputClassString" value="@CurrentValueAsString" /> | ||
| <span class="@AppendClassString"><i class="@DropdownIcon"></i></span> | ||
| </div> | ||
| @if (!IsDisabled) | ||
| { | ||
| <span class="@ClearClassString" @onclick="OnClearValue"><i class="@ClearIcon"></i></span> | ||
| } | ||
| <div class="dropdown-menu"> | ||
| @foreach (var item in GetProvinces()) | ||
| { | ||
| <div class="bb-region-city-item"> | ||
| <div class="bb-region-city-title" @onclick="() => OnSelectProvince(item)">@item</div> | ||
| <ul> | ||
| @foreach (var city in GetCities(item)) | ||
| { | ||
| <li class="@GetActiveClass(city)" @onclick="() => OnSelectCity(city)">@city</li> | ||
| } | ||
| </ul> | ||
| </div> | ||
| } | ||
| </div> | ||
| </div> | ||
142 changes: 142 additions & 0 deletions
142
src/components/BootstrapBlazor.Region/Components/SelectCity.razor.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,142 @@ | ||
| // 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; | ||
|
|
||
| /// <summary> | ||
| /// SelectCity 组件 | ||
| /// </summary> | ||
| public partial class SelectCity | ||
| { | ||
| /// <summary> | ||
| /// 获得/设置 是否可多选 默认 false 单选 | ||
| /// </summary> | ||
| [Parameter] | ||
| public bool IsMultiple { get; set; } | ||
|
|
||
| private string? InputId => $"{Id}_input"; | ||
|
|
||
| private string? ClassString => CssBuilder.Default("select bb-city") | ||
| .AddClass("disabled", IsDisabled) | ||
| .AddClassFromAttributes(AdditionalAttributes) | ||
| .Build(); | ||
|
|
||
| private readonly HashSet<string> _values = []; | ||
|
|
||
| private string? GetActiveClass(string item) => _values.Contains(item) || CurrentValue == item ? "active" : null; | ||
|
|
||
| private async Task OnClearValue() | ||
| { | ||
| if (IsMultiple) | ||
| { | ||
| _values.Clear(); | ||
| } | ||
| CurrentValue = ""; | ||
|
|
||
| if (OnClearAsync != null) | ||
| { | ||
| await OnClearAsync(); | ||
| } | ||
| } | ||
|
|
||
| private void OnSelectProvince(string province) | ||
| { | ||
| if (IsMultiple) | ||
| { | ||
| HashSet<string> cities; | ||
| if (province == "直辖市") | ||
| { | ||
| cities = Municipalities; | ||
| } | ||
| else if (province == "特别行政区") | ||
|
ArgoZhang marked this conversation as resolved.
|
||
| { | ||
| cities = SpecialAdministrativeRegions; | ||
| } | ||
| else | ||
| { | ||
| cities = GetCities(province); | ||
| } | ||
| foreach (var city in cities) | ||
| { | ||
| if (!_values.Remove(city)) | ||
| { | ||
| _values.Add(city); | ||
| } | ||
| } | ||
| CurrentValue = string.Join(",", _values); | ||
| } | ||
| } | ||
|
|
||
| private void OnSelectCity(string item) | ||
| { | ||
| if (IsMultiple) | ||
| { | ||
| if (!_values.Remove(item)) | ||
| { | ||
| _values.Add(item); | ||
| } | ||
| CurrentValue = string.Join(",", _values); | ||
| } | ||
| else | ||
| { | ||
| CurrentValue = item; | ||
| } | ||
| } | ||
|
|
||
| private static HashSet<string> GetProvinces() | ||
|
ArgoZhang marked this conversation as resolved.
|
||
| { | ||
| return | ||
| [ | ||
| "直辖市", | ||
| "河北省", | ||
| "山西省", | ||
| "辽宁省", | ||
| "吉林省", | ||
| "黑龙江省", | ||
| "江苏省", | ||
| "浙江省", | ||
| "安徽省", | ||
| "福建省", | ||
| "江西省", | ||
| "山东省", | ||
| "河南省", | ||
| "湖北省", | ||
| "湖南省", | ||
| "广东省", | ||
| "海南省", | ||
| "四川省", | ||
| "贵州省", | ||
| "云南省", | ||
| "陕西省", | ||
| "甘肃省", | ||
| "青海省", | ||
| "内蒙古自治区", | ||
| "广西壮族自治区", | ||
| "西藏自治区", | ||
| "宁夏回族自治区", | ||
| "新疆维吾尔自治区", | ||
| "台湾省", | ||
| "特别行政区" | ||
| ]; | ||
| } | ||
|
|
||
| private static readonly HashSet<string> Municipalities = ["北京市", "天津市", "上海市", "重庆市"]; | ||
|
|
||
| private static readonly HashSet<string> SpecialAdministrativeRegions = ["香港特别行政区", "澳门特别行政区"]; | ||
|
|
||
| private HashSet<string> GetCities(string provinceName) | ||
| { | ||
| if (provinceName == "直辖市") | ||
| { | ||
| return Municipalities; | ||
| } | ||
|
|
||
| if (provinceName == "特别行政区") | ||
| { | ||
| return SpecialAdministrativeRegions; | ||
|
ArgoZhang marked this conversation as resolved.
|
||
| } | ||
|
|
||
| return RegionService.GetCities(provinceName); | ||
| } | ||
| } | ||
55 changes: 55 additions & 0 deletions
55
src/components/BootstrapBlazor.Region/Components/SelectCity.razor.css
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| .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; | ||
| 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:hover { | ||
| background-color: #e9ecef; | ||
| color: #000; | ||
| } | ||
|
|
||
| .dropdown-menu li.active { | ||
| background-color: #e3e3e3; | ||
| color: #000; | ||
| } | ||
|
|
||
| .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: #000; | ||
| font-weight: bold; | ||
| cursor: pointer; | ||
| } |
2 changes: 1 addition & 1 deletion
2
src/components/BootstrapBlazor.Region/Components/SelectRegion.razor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.