Skip to content

Commit

Permalink
refactor: per-page 模式更新到 net9
Browse files Browse the repository at this point in the history
  • Loading branch information
ArgoZhang committed Nov 10, 2024
1 parent a8ab802 commit fce907e
Show file tree
Hide file tree
Showing 16 changed files with 68 additions and 397 deletions.
10 changes: 5 additions & 5 deletions src/Auto-Per/BootstrapBlazorApp.Client/Data/Foo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public class Foo
[Required(ErrorMessage = "请选择一种{0}")]
[Display(Name = "爱好")]
[AutoGenerateColumn(Order = 70)]
public IEnumerable<string> Hobby { get; set; } = new List<string>();
public IEnumerable<string> Hobby { get; set; } = [];

private static readonly Random random = new();

Expand All @@ -91,7 +91,7 @@ public class Foo
Address = localizer["Foo.Address", $"{random.Next(1000, 2000)}"],
Count = random.Next(1, 100),
Complete = random.Next(1, 100) > 50,
Education = random.Next(1, 100) > 50 ? EnumEducation.Primary : EnumEducation.Middel
Education = random.Next(1, 100) > 50 ? EnumEducation.Primary : EnumEducation.Middle
};

/// <summary>
Expand All @@ -106,14 +106,14 @@ public class Foo
Address = localizer["Foo.Address", $"{random.Next(1000, 2000)}"],
Count = random.Next(1, 100),
Complete = random.Next(1, 100) > 50,
Education = random.Next(1, 100) > 50 ? EnumEducation.Primary : EnumEducation.Middel
Education = random.Next(1, 100) > 50 ? EnumEducation.Primary : EnumEducation.Middle
}).ToList();

/// <summary>
///
/// </summary>
/// <returns></returns>
public static IEnumerable<SelectedItem> GenerateHobbys(IStringLocalizer<Foo> localizer) => localizer["Hobbys"].Value.Split(",").Select(i => new SelectedItem(i, i)).ToList();
public static IEnumerable<SelectedItem> GenerateHobbies(IStringLocalizer<Foo> localizer) => localizer["Hobbies"].Value.Split(",").Select(i => new SelectedItem(i, i)).ToList();
}

/// <summary>
Expand All @@ -131,5 +131,5 @@ public enum EnumEducation
///
/// </summary>
[Display(Name = "中学")]
Middel
Middle
}
4 changes: 2 additions & 2 deletions src/Auto-Per/BootstrapBlazorApp.Client/Locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"Education.Required": "{0} is required.",
"Hobby.Required": "{0} is required.",
"Name.PlaceHolder": "required",
"Hobbys": "Swimming,Climb,Shoot,Chess",
"Hobbies": "Swimming,Climb,Shoot,Chess",
"Foo.Name": "Zhangsan {0}",
"Foo.Address": "Lane {0} of Jinshajiang Road, Putuo District, Shanghai",
"Foo.Address2": "Earth, China, Lane {0} of Jinshajiang Road, Putuo District, Shanghai. Here is an example of super long cell",
Expand All @@ -21,6 +21,6 @@
"BootstrapBlazorApp.Client.Data.EnumEducation": {
"PlaceHolder": "Click to select ...",
"Primary": "Primary",
"Middel": "Middel"
"Middle": "Middle"
}
}
4 changes: 2 additions & 2 deletions src/Auto-Per/BootstrapBlazorApp.Client/Locales/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"Education.Required": "{0}是必选项",
"Hobby.Required": "请选择一种{0}",
"Name.PlaceHolder": "不可为空",
"Hobbys": "游泳,登山,打球,下棋",
"Hobbies": "游泳,登山,打球,下棋",
"Foo.Name": "张三 {0}",
"Foo.Address": "上海市普陀区金沙江路 {0} 弄",
"Foo.Address2": "地球、中国、上海市普陀区金沙江路 {0} 弄 这里是超长单元格示例",
Expand All @@ -21,6 +21,6 @@
"BootstrapBlazorApp.Client.Data.EnumEducation": {
"PlaceHolder": "请选择 ...",
"Primary": "小学",
"Middel": "中学"
"Middle": "中学"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
ShowSkeleton="true" ShowToolbar="true" ShowSearch="true" ShowExtendButtons="true"
OnQueryAsync="OnQueryAsync" OnSaveAsync="OnSaveAsync" OnDeleteAsync="OnDeleteAsync">
<TableColumns>
<TableColumn @bind-Field="@context.Hobby" Items="GetHobbys(context)" />
<TableColumn @bind-Field="@context.Hobby" Items="GetHobbies(context)" />
</TableColumns>
</Table>
</BootstrapBlazorRoot>
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public partial class TableDemo

private readonly ConcurrentDictionary<Foo, IEnumerable<SelectedItem>> _cache = new();

private IEnumerable<SelectedItem> GetHobbys(Foo item) => _cache.GetOrAdd(item, f => Foo.GenerateHobbys(Localizer));
private IEnumerable<SelectedItem> GetHobbies(Foo item) => _cache.GetOrAdd(item, f => Foo.GenerateHobbies(Localizer));

private static IEnumerable<int> PageItemsSource => new int[] { 20, 40 };

Expand Down Expand Up @@ -105,7 +105,6 @@ private Task<bool> OnDeleteAsync(IEnumerable<Foo> foos)
{
Items.Remove(foo);
}

return Task.FromResult(true);
}
}
4 changes: 2 additions & 2 deletions src/Auto-Per/BootstrapBlazorApp/BootstrapBlazorApp.csproj
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\BootstrapBlazorApp.Client\BootstrapBlazorApp.Client.csproj" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="8.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="9.0.0-rc.2.24474.3" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<Layout ShowGotoTop="true" ShowFooter="@ShowFooter" SideWidth="0"
IsPage="true" IsFullSide="@IsFullSide" IsFixedHeader="@IsFixedHeader" IsFixedFooter="@IsFixedFooter"
class="@Theme">
Menus="@Menus" class="@Theme">
<Header>
<span class="ms-3 flex-sm-fill d-none d-sm-block">Bootstrap of Blazor</span>
<div class="flex-fill d-sm-none">
Expand All @@ -19,12 +19,11 @@
</Header>
<Side>
<div class="layout-banner">
<img class="layout-logo" src="favicon.png" />
<img class="layout-logo" src="../images/logo.png" />
<div class="layout-title">
<span>后台管理</span>
</div>
</div>
<Sidebar></Sidebar>
</Side>
<Main>
<CascadingValue Value="this" IsFixed="true">
Expand All @@ -36,9 +35,6 @@
<a class="page-layout-demo-footer-link" href="https://gitee.com/LongbowEnterprise/BootstrapAdmin" target="_blank">Bootstrap Admin</a>
</div>
</Footer>
<NotFound>
<p>Sorry, there's nothing at this address.</p>
</NotFound>
</Layout>

<div id="blazor-error-ui">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
namespace BootstrapBlazorApp.Components.Layout;
using BootstrapBlazor.Components;
using Microsoft.AspNetCore.Components.Routing;

namespace BootstrapBlazorApp.Components.Layout;

public partial class MainLayout
{
Expand All @@ -11,4 +14,31 @@ public partial class MainLayout
private bool IsFullSide { get; set; } = true;

private bool ShowFooter { get; set; } = true;

private List<MenuItem>? Menus { get; set; }

/// <summary>
/// <inheritdoc/>
/// </summary>
protected override void OnInitialized()
{
base.OnInitialized();

Menus = GetIconSideMenuItems();
}

private static List<MenuItem> GetIconSideMenuItems()
{
var menus = new List<MenuItem>
{
new() { Text = "返回组件库", Icon = "fa-solid fa-fw fa-home", Url = "https://www.blazor.zone/components" },
new() { Text = "Index", Icon = "fa-solid fa-fw fa-flag", Url = "/" , Match = NavLinkMatch.All},
new() { Text = "Counter", Icon = "fa-solid fa-fw fa-check-square", Url = "/counter" },
new() { Text = "Weather", Icon = "fa-solid fa-fw fa-database", Url = "/weather" },
new() { Text = "Table", Icon = "fa-solid fa-fw fa-table", Url = "/table" },
new() { Text = "花名册", Icon = "fa-solid fa-fw fa-users", Url = "/users" }
};

return menus;
}
}
36 changes: 0 additions & 36 deletions src/Auto-Per/BootstrapBlazorApp/Components/Layout/Sidebar.razor

This file was deleted.

26 changes: 13 additions & 13 deletions src/Auto-Per/BootstrapBlazorApp/Components/Layout/Widget.razor
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</div>
<div class="ms-2">
<div class="d-flex position-relative">
<h4>Argo Zhang</h4>
<div class="flex-fill">Argo Zhang</div>
<small><i class="fa fa-clock-o"></i> @(4 + index) mins</small>
</div>
<div class="text-truncate">Why not buy a new awesome theme?</div>
Expand Down Expand Up @@ -47,24 +47,24 @@
</HeaderTemplate>
<BodyTemplate>
<a href="#" class="dropdown-item" @onclick:preventDefault>
<h3 class="position-relative">
Design some buttons
<small class="pull-right">20%</small>
</h3>
<div class="d-flex">
<div class="flex-fill pe-5">Design some buttons</div>
<small>20%</small>
</div>
<Progress IsAnimated="true" IsStriped="true" Value="20" Color="Color.Primary"></Progress>
</a>
<a href="#" class="dropdown-item" @onclick:preventDefault>
<h3 class="position-relative">
Create a nice theme
<small class="pull-right">40%</small>
</h3>
<div class="d-flex">
<div class="flex-fill pe-5">Create a nice theme</div>
<small>40%</small>
</div>
<Progress Value="40" Color="Color.Success"></Progress>
</a>
<a href="#" class="dropdown-item" @onclick:preventDefault>
<h3 class="position-relative">
Some task I need to do
<small class="pull-right">60%</small>
</h3>
<div class="d-flex">
<div class="flex-fill pe-5">Some task I need to do</div>
<small>60%</small>
</div>
<Progress Value="60" Color="Color.Danger"></Progress>
</a>
</BodyTemplate>
Expand Down

This file was deleted.

Loading

0 comments on commit fce907e

Please sign in to comment.