From 12fbba285c4336914c9346adcea88cb976499ef7 Mon Sep 17 00:00:00 2001 From: Argo-AsicoTech Date: Mon, 2 Dec 2024 10:12:40 +0800 Subject: [PATCH 01/26] =?UTF-8?q?refactor:=20=E7=B2=BE=E7=AE=80=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/BootstrapBlazor.Server/Services/ClearUploadFilesService.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/BootstrapBlazor.Server/Services/ClearUploadFilesService.cs b/src/BootstrapBlazor.Server/Services/ClearUploadFilesService.cs index c134e2bf0cb..93e52a7f02a 100644 --- a/src/BootstrapBlazor.Server/Services/ClearUploadFilesService.cs +++ b/src/BootstrapBlazor.Server/Services/ClearUploadFilesService.cs @@ -37,8 +37,7 @@ protected override Task ExecuteAsync(CancellationToken stoppingToken) { TaskServicesManager.GetOrAdd("Clear Upload Files", (provider, token) => { - var webSiteUrl = $"images{Path.DirectorySeparatorChar}uploader{Path.DirectorySeparatorChar}"; - var filePath = Path.Combine(_env.WebRootPath, webSiteUrl); + var filePath = Path.Combine(_env.WebRootPath, "images", "uploader"); if (Directory.Exists(filePath)) { Directory.EnumerateFiles(filePath).Take(10).ToList().ForEach(file => DeleteFile(file, token)); From afa9d8fa8645f39aeff2a2339f8c9b241a686a9e Mon Sep 17 00:00:00 2001 From: Argo-AsicoTech Date: Mon, 2 Dec 2024 11:15:03 +0800 Subject: [PATCH 02/26] =?UTF-8?q?refactor:=20=E6=9B=B4=E6=96=B0=E8=84=9A?= =?UTF-8?q?=E6=9C=AC=E8=B7=AF=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/BootstrapBlazor.Shared/Components/Components/Header.razor | 2 +- src/BootstrapBlazor.Shared/Components/Components/Pre.razor | 2 +- .../Components/Components/ThemeChooser.razor | 2 +- .../Components/Components/UpdateIntro.razor | 2 +- .../Components/Components/VideoDemo.razor | 2 +- .../Components/Components/WebSiteModuleComponentBase.cs | 2 +- src/BootstrapBlazor.Shared/Components/Components/Wwads.razor | 2 +- src/BootstrapBlazor.Shared/Components/Layout/NavMenu.razor | 2 +- .../Components/Layout/TutorialsNavMenu.razor | 2 +- src/BootstrapBlazor.Shared/Components/Pages/Chats.razor | 2 +- .../Components/Samples/Charts/Line.razor.cs | 2 +- .../Components/Samples/Icons/AntDesignIconList.razor.cs | 2 +- .../Components/Samples/Icons/ElementIconList.razor.cs | 2 +- .../Components/Samples/Icons/FAIconList.razor.cs | 2 +- .../Components/Samples/Icons/IconParkList.razor.cs | 2 +- .../Components/Samples/Table/TablesSelection.razor.cs | 2 +- src/BootstrapBlazor.Shared/Components/Samples/Topologies.razor | 2 +- 17 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/BootstrapBlazor.Shared/Components/Components/Header.razor b/src/BootstrapBlazor.Shared/Components/Components/Header.razor index 9c3514da9de..62db13d1842 100644 --- a/src/BootstrapBlazor.Shared/Components/Components/Header.razor +++ b/src/BootstrapBlazor.Shared/Components/Components/Header.razor @@ -1,5 +1,5 @@ @inherits WebSiteModuleComponentBase -@attribute [JSModuleAutoLoader("../_content/BootstrapBlazor.Shared/Components/Components/Header.razor.js")] +@attribute [JSModuleAutoLoader("Components/Header.razor.js")]
- +
@Localizer["MenusClickShrinkMenuTitle"]
diff --git a/src/BootstrapBlazor.Shared/Components/Samples/MouseFollowers.razor b/src/BootstrapBlazor.Shared/Components/Samples/MouseFollowers.razor index 897a4f05f23..b9cf90eb353 100644 --- a/src/BootstrapBlazor.Shared/Components/Samples/MouseFollowers.razor +++ b/src/BootstrapBlazor.Shared/Components/Samples/MouseFollowers.razor @@ -1,6 +1,7 @@ @page "/mouse-follower" +@inject IOptionsMonitor WebsiteOption -
+ + -

@Localizer["MouseFollowersTitle"]

+

@Localizer["MouseFollowersTitle"]

-

@Localizer["MouseFollowersDescription"]

+

@Localizer["MouseFollowersDescription"]

- + - - -
- - + + +
+ + - - -
- - + + +
+ + - - -
- - + + +
+ + - - -
- - + + +
+ + - - -
- - + + +
+ + - -
+ diff --git a/src/BootstrapBlazor.Shared/Components/Samples/Notifications.razor.cs b/src/BootstrapBlazor.Shared/Components/Samples/Notifications.razor.cs index 0800f2fee60..e664420b742 100644 --- a/src/BootstrapBlazor.Shared/Components/Samples/Notifications.razor.cs +++ b/src/BootstrapBlazor.Shared/Components/Samples/Notifications.razor.cs @@ -3,6 +3,8 @@ // See the LICENSE file in the project root for more information. // Maintainer: Argo Zhang(argo@live.ca) Website: https://www.blazor.zone +using Microsoft.Extensions.Options; + namespace BootstrapBlazor.Shared.Components.Samples; ///
@@ -14,15 +16,16 @@ public partial class Notifications [NotNull] private NotificationService? BrowserNotification { get; set; } + [Inject, NotNull] + private IOptionsMonitor? WebSiteOptions { get; set; } + [NotNull] private ConsoleLogger? Logger { get; set; } private bool Permission { get; set; } - private NotificationItem Model { get; set; } = new() - { - Icon = "./_content/BootstrapBlazor.Shared/images/Argo-C.png" - }; + [NotNull] + private NotificationItem? Model { get; set; } /// /// @@ -30,9 +33,14 @@ public partial class Notifications protected override void OnInitialized() { base.OnInitialized(); - Model.Title ??= Localizer["NotificationsNormalTitleSampleText"]; - Model.Message ??= Localizer["NotificationsNormalMessageSampleText"]; - Model.OnClick = OnClickNotificationCallback; + + Model = new() + { + Icon = $"{WebSiteOptions.CurrentValue.AssetRootPath}images/Argo-C.png", + Title = Localizer["NotificationsNormalTitleSampleText"], + Message = Localizer["NotificationsNormalMessageSampleText"], + OnClick = OnClickNotificationCallback + }; } /// diff --git a/src/BootstrapBlazor.Shared/Components/Samples/SelectObjects.razor.cs b/src/BootstrapBlazor.Shared/Components/Samples/SelectObjects.razor.cs index abb7a74510f..74ed73a5302 100644 --- a/src/BootstrapBlazor.Shared/Components/Samples/SelectObjects.razor.cs +++ b/src/BootstrapBlazor.Shared/Components/Samples/SelectObjects.razor.cs @@ -3,6 +3,8 @@ // See the LICENSE file in the project root for more information. // Maintainer: Argo Zhang(argo@live.ca) Website: https://www.blazor.zone +using Microsoft.Extensions.Options; + namespace BootstrapBlazor.Shared.Components.Samples; /// @@ -10,6 +12,9 @@ namespace BootstrapBlazor.Shared.Components.Samples; /// public partial class SelectObjects { + [Inject, NotNull] + private IOptionsMonitor? WebSiteOptions { get; set; } + [NotNull] private IEnumerable? Products { get; set; } @@ -30,7 +35,7 @@ protected override void OnInitialized() Products = Enumerable.Range(1, 8).Select(i => new ListViews.Product() { - ImageUrl = $"./_content/BootstrapBlazor.Shared/images/Pic{i}.jpg", + ImageUrl = $"{WebSiteOptions.CurrentValue.AssetRootPath}images/Pic{i}.jpg", Description = $"Pic{i}.jpg", Category = $"Group{(i % 4) + 1}" }); diff --git a/src/BootstrapBlazor.Shared/Components/Samples/Tutorials/Admin.razor b/src/BootstrapBlazor.Shared/Components/Samples/Tutorials/Admin.razor index b8a528dad4b..688068e1c8b 100644 --- a/src/BootstrapBlazor.Shared/Components/Samples/Tutorials/Admin.razor +++ b/src/BootstrapBlazor.Shared/Components/Samples/Tutorials/Admin.razor @@ -1,4 +1,5 @@ @page "/tutorials/admin" +@inject IOptionsMonitor WebsiteOption

后台权限管理演示系统

@@ -8,7 +9,7 @@
BootstrapBlazor 组件库实现
- +
@@ -18,7 +19,7 @@
MVC & Blazor 混合实现
- +
diff --git a/src/BootstrapBlazor.Shared/Components/Samples/Tutorials/LoginAndRegister/Template3.razor b/src/BootstrapBlazor.Shared/Components/Samples/Tutorials/LoginAndRegister/Template3.razor index 9a8985f5655..99d69538fb5 100644 --- a/src/BootstrapBlazor.Shared/Components/Samples/Tutorials/LoginAndRegister/Template3.razor +++ b/src/BootstrapBlazor.Shared/Components/Samples/Tutorials/LoginAndRegister/Template3.razor @@ -1,9 +1,10 @@ @page "/tutorials/template3" @layout TutorialsLoginLayout +@inject IOptionsMonitor WebsiteOption
public sealed partial class Uploads { + [Inject, NotNull] + private IOptionsMonitor? WebSiteOptions { get; set; } + [NotNull] private ConsoleLogger? Logger1 { get; set; } @@ -28,7 +32,7 @@ public sealed partial class Uploads private Person Foo2 { get; set; } = new Person(); - private List PreviewFileList { get; } = new(new[] { new UploadFile { PrevUrl = "./_content/BootstrapBlazor.Shared/images/Argo.png" } }); + private List PreviewFileList { get; } = []; private CancellationTokenSource? ReadAvatarToken { get; set; } @@ -51,6 +55,19 @@ public sealed partial class Uploads new UploadFile { FileName = "Test", PrevUrl = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACoAAAAkCAYAAAD/yagrAAAE60lEQVR4AWJwL/AB9GIWvI0jURz/L1NomZmZP8p9kWNmhnIbKPdomZmZGcJgO7QsWMbce55Yl11t47FbVdKTYpjOr/+H4y4Z/MpYeJVV8KVvokFRylq9osKfVtGQ/NHyPl2CbNVGwau2oOlmgUDJtDJGzxtvvIA3vRH+7IgeA0VtYhQBtKPlToFgC6RY58aggfwLNKhr0Zry2NnPrpIM2YGW2+UBG1IEmdGVJEVXE+hQXt8joKhLjdGVZHd7TSD9DHmT3J1dheroSF4fhnvUVQwbZx9UOnHSzQjkTN0tIG+8hFdbxet4PQOG4WqJwN1hFVb+xUBmCblxvxRkIE+Q+Yf0T31NSrp4/RV4FhHgoSTchQRZBK4D1+Fe2q2g8CYXU6buQyNDaiZKZhn0IYXHVwbkRQydHyawOAGGisa/o3DvI/jF3QKKiuAy+LKs5CvaXMLdeXb35wbkKTjmReDZHysCBosWJqN7r0jZ/VfgXtIlUNQnVpK7D4nNJSC5BHGi1d108Ppr8MxlF0cJqBSyFJaUfUnvHLyO4cttgaI+NhGB7HE0MaSUks/gU5vwe1gv5tfhmUmAhxME8jbIUtiEDus+fhmDJlgCRY0ylZRZhybKWtNinmYlH9NvL5puO3m9UHOkgzb3xuF5HCkDyhYiSwrYVfQPTpYChTc+E35tG9VJBjGFFNmtVlNMDnjzbx0EBpKq1eTeh2awbArBRuHadBWu6WVB4U/NITfuobYoCZl7QL//wDtr+nTmsgzQh2Kwgtz7QAZWFeGw/RI8s94Kigp1PvzZg2i9x11FDtKn/oZCoZdZxhaAXmG4/ohJKHudLE1Gyu66DOfs10BRR5CU3TKQIrtzj9BAkF991dsMslTZEClLsI+jFmANZYFAdAJl9QG03jWH9GrcFh9QTP4Of6GfJGSpsv1J2aoEKRuWCANNJNqOFAaPAW36rVRMCjVf6ZCtqYF2p6Asxg5mWK6tQamY9RCs8z1wF+FxTR5UqYT/3GC7oCkMHcjxKguq6cnl+Egf2whip3C9Yu56jk+GXXOtv1XIa8L1f3AFkHe9az83AmNanwV/bhfa5JKJ3n1slCUL8dk7CNfvVFMfySRThoxbK7fh18tTZXI2QeySLk88IRGsbHkqQj6wUJ72G5CloCXKZrdbLPgVMgVfQMq5m97bfQWOOeVbaK02nSA2ofn2y662UJE47horLZTe38oDjdxQUhmawocxa0OJ5hXjnZE4w1y0uc/iULKGfk+xNuZxI/BnjhFs+THPq4phmTsbeYPXRjFsJJ+NSMlnInHkxrwzGDjR3uBcG1/B/b/TwZkhubb6tP2oVfTAD2G4kw9vYiA2h+zy4GwYxd7S4qGOgd6oqVn6re1DTXiO4e4wPF+yQlF4ZCBfheSPIjJn+ciS/w93qjA6aZYqeQ5D3dTqvuE6GZNTkov5vqsYvLh7j8u1sWWkLIdBQR+q+XdtaKGhJCWBDpkwgSw9gRpKyoNKw6rjCLCDP4yVflSgWFwt3C0HSUo2BTFYX28fVAaWPpDx7wtwjOSSUszawnUT0KTudlfrFQwZ3WNf867CNZQhk/C8kIFUhJLt/O3Jzn62IYNwrUvA8zws4W61CGlDSfugXMz5pJgiSFYyXMYiRXdH4GmyqaR9UHLxzxG41KAwpZxRPN4kRf85Z5I4MvYfFUFGfemJG40AAAAASUVORK5CYII=" }, ]; + /// + /// + /// + protected override void OnInitialized() + { + base.OnInitialized(); + + PreviewFileList.AddRange(new[] + { + new UploadFile { PrevUrl = $"{WebSiteOptions.CurrentValue.AssetRootPath}images/Argo.png" } + }); + } + private Task OnFileChange(UploadFile file) { // 未真正保存文件 @@ -95,12 +112,12 @@ private async Task OnClickToUploadNoUploadList(UploadFile file) private async Task SaveToFile(UploadFile file) { // Server Side 使用 - // Web Assembly 模式下必须使用 webapi 方式去保存文件到服务器或者数据库中 + // Web Assembly 模式下必须使用 WebApi 方式去保存文件到服务器或者数据库中 // 生成写入文件名称 var ret = false; - if (!string.IsNullOrEmpty(SiteOptions.CurrentValue.WebRootPath)) + if (!string.IsNullOrEmpty(WebSiteOptions.CurrentValue.WebRootPath)) { - var uploaderFolder = Path.Combine(SiteOptions.CurrentValue.WebRootPath, $"images{Path.DirectorySeparatorChar}uploader"); + var uploaderFolder = Path.Combine(WebSiteOptions.CurrentValue.WebRootPath, $"images{Path.DirectorySeparatorChar}uploader"); file.FileName = $"{Path.GetFileNameWithoutExtension(file.OriginFileName)}-{DateTimeOffset.Now:yyyyMMddHHmmss}{Path.GetExtension(file.OriginFileName)}"; var fileName = Path.Combine(uploaderFolder, file.FileName); @@ -110,7 +127,7 @@ private async Task SaveToFile(UploadFile file) if (ret) { // 保存成功 - file.PrevUrl = $"./_content/BootstrapBlazor.Shared/images/uploader/{file.FileName}"; + file.PrevUrl = $"{WebSiteOptions.CurrentValue.AssetRootPath}images/uploader/{file.FileName}"; } else { diff --git a/src/BootstrapBlazor.Shared/Components/Samples/WinBoxes.razor b/src/BootstrapBlazor.Shared/Components/Samples/WinBoxes.razor index 06d273eb5a5..3bbf3de6f99 100644 --- a/src/BootstrapBlazor.Shared/Components/Samples/WinBoxes.razor +++ b/src/BootstrapBlazor.Shared/Components/Samples/WinBoxes.razor @@ -1,6 +1,7 @@ @page "/win-box" @inject IStringLocalizer Localizer @inject IStringLocalizer LocalizerFoo +@inject IOptionsMonitor WebsiteOption

@Localizer["WinBoxTitle"]

@Localizer["WinBoxDescription"]

@@ -56,7 +57,7 @@ private WinBoxService? WinBoxService { get; set; }

通过 WinBoxOption 参数 Icon 设置

-
new WinBoxOption() { Icon = "./_content/BootstrapBlazor.Shared/images/Argo-C.png" }
+
new WinBoxOption() { Icon = "@WebsiteOption.CurrentValue.GetAssetUrl("images/Argo-C.png")" }

通过服务方法 WinBoxService 实例方法

[Inject]
@@ -66,7 +67,7 @@ private WinBoxService? WinBoxService { get; set; }
 private async Task SetIcon()
 {
     // 提前保持弹窗 WinBoxOption 实例
-    option.Icon = "./_content/BootstrapBlazor.Shared/images/Argo-C.png";
+    option.Icon = "@WebsiteOption.CurrentValue.GetAssetUrl("images/Argo-C.png")";
     await WinBoxService.setIcon(option.Id);
 }
diff --git a/src/BootstrapBlazor.Shared/Data/WebsiteOptions.cs b/src/BootstrapBlazor.Shared/Data/WebsiteOptions.cs index ea60acee543..3fe2b71d040 100644 --- a/src/BootstrapBlazor.Shared/Data/WebsiteOptions.cs +++ b/src/BootstrapBlazor.Shared/Data/WebsiteOptions.cs @@ -88,10 +88,10 @@ public class WebsiteOptions public string? ContentRootPath { get; set; } /// - /// 获得/设置 资源文件根目录 + /// 获得/设置 资源文件根目录 默认值为 "./_content/BootstrapBlazor.Shared/" /// [NotNull] - public string? AssetRootPath { get; set; } + public string? AssetRootPath { get; set; } = "./_content/BootstrapBlazor.Shared/"; /// /// 获得/设置 脚本根路径 @@ -165,4 +165,11 @@ private IConfiguration GetConfiguration(string jsonFileName) .AddJsonStream(res) .Build(); } + + /// + /// 拼接静态资源文件路径 + /// + /// + /// + public string? GetAssetUrl(string url) => $"{AssetRootPath}{url}"; } From bd81b454e4bdb0113416f3a0fe3f4b4dbb2b8fdc Mon Sep 17 00:00:00 2001 From: Argo-AsicoTech Date: Mon, 2 Dec 2024 13:19:47 +0800 Subject: [PATCH 09/26] =?UTF-8?q?refactor:=20=E6=9B=B4=E6=AD=A3=E8=84=9A?= =?UTF-8?q?=E6=9C=AC=E8=B5=84=E6=BA=90=E8=B7=AF=E5=BE=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Components/Samples/Tutorials/DrawingApp.razor | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/BootstrapBlazor.Shared/Components/Samples/Tutorials/DrawingApp.razor b/src/BootstrapBlazor.Shared/Components/Samples/Tutorials/DrawingApp.razor index 94874259839..0209a418626 100644 --- a/src/BootstrapBlazor.Shared/Components/Samples/Tutorials/DrawingApp.razor +++ b/src/BootstrapBlazor.Shared/Components/Samples/Tutorials/DrawingApp.razor @@ -1,8 +1,8 @@ @page "/tutorials/drawing" @inject MessageService MessageService @inject DownloadService DownloadService -@inherits BootstrapModuleComponentBase -@attribute [JSModuleAutoLoader("../../_content/BootstrapBlazor.Shared/Components/Samples/Tutorials/DrawingApp.razor.js")] +@inherits WebSiteModuleComponentBase +@attribute [JSModuleAutoLoader("Samples/Tutorials/DrawingApp.razor.js")]
From dfb21f98f50893a6255158566da4a6c8bbec7a92 Mon Sep 17 00:00:00 2001 From: Argo-AsicoTech Date: Mon, 2 Dec 2024 13:37:44 +0800 Subject: [PATCH 10/26] =?UTF-8?q?refactor:=20=E6=9B=B4=E6=96=B0=E5=A4=B4?= =?UTF-8?q?=E5=83=8F=E8=B7=AF=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Components/Pages/Localization.razor | 2 +- .../Components/Samples/AutoFills.razor | 9 +++++---- .../Components/Samples/InputGroups.razor | 3 ++- .../Components/Samples/SelectTables.razor | 3 ++- .../Components/Samples/Selects.razor | 3 ++- .../Components/Samples/Table/TablesColumn.razor | 2 +- .../Components/Samples/Table/TablesExcel.razor | 3 ++- src/BootstrapBlazor.Shared/Data/Foo.cs | 8 -------- src/BootstrapBlazor.Shared/Data/WebsiteOptions.cs | 7 +++++++ src/BootstrapBlazor.Shared/Locales/en-US.json | 3 +-- src/BootstrapBlazor.Shared/Locales/zh-CN.json | 3 +-- 11 files changed, 24 insertions(+), 22 deletions(-) diff --git a/src/BootstrapBlazor.Shared/Components/Pages/Localization.razor b/src/BootstrapBlazor.Shared/Components/Pages/Localization.razor index 8c5a857b0d6..f395c7f3f35 100644 --- a/src/BootstrapBlazor.Shared/Components/Pages/Localization.razor +++ b/src/BootstrapBlazor.Shared/Components/Pages/Localization.razor @@ -9,7 +9,7 @@
@Localizer["T1"] @Localizer["T2"]
-
@Localizer["T3"] wasm @Localizer["T4"] en@Localizer["T5"]
+
@Localizer["T3"] wasm @Localizer["T4"] en
@((MarkupString)Localizer["LocalizationFileDesc"].Value)
diff --git a/src/BootstrapBlazor.Shared/Components/Samples/AutoFills.razor b/src/BootstrapBlazor.Shared/Components/Samples/AutoFills.razor index 8fe89f96a1b..41487ad5d9b 100644 --- a/src/BootstrapBlazor.Shared/Components/Samples/AutoFills.razor +++ b/src/BootstrapBlazor.Shared/Components/Samples/AutoFills.razor @@ -1,5 +1,6 @@ @page "/auto-fill" @inject IStringLocalizer Localizer +@inject IOptionsMonitor WebsiteOption

@Localizer["Title"]

@Localizer["Description"]

@@ -13,7 +14,7 @@ - + @@ -33,7 +34,7 @@