Skip to content

Commit 0100b95

Browse files
authored
Merge branch 'main' into feat-treeview-drag
2 parents d1c8dab + 6943615 commit 0100b95

File tree

6 files changed

+50
-19
lines changed

6 files changed

+50
-19
lines changed

src/BootstrapBlazor.Server/Components/Samples/Table/TablesFilter.razor.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,7 @@ private Task<QueryData<Foo>> OnQueryAsync(QueryPageOptions options)
6464
isSorted = true;
6565
}
6666

67-
// 此段代码可不写,组件内部自行处理
68-
if (options.SortName == nameof(Foo.DateTime))
69-
{
70-
items = items.Sort(options.SortList);
71-
isSorted = true;
72-
}
73-
else if (!string.IsNullOrEmpty(options.SortName))
67+
if (!string.IsNullOrEmpty(options.SortName))
7468
{
7569
// 外部未进行排序,内部自动进行排序处理
7670
items = items.Sort(options.SortName, options.SortOrder);

src/BootstrapBlazor.Server/Components/Samples/UploadCards.razor.cs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
// See the LICENSE file in the project root for more information.
44
// Maintainer: Argo Zhang([email protected]) Website: https://www.blazor.zone
55

6-
using Newtonsoft.Json.Linq;
7-
86
namespace BootstrapBlazor.Server.Components.Samples;
97

108
/// <summary>
@@ -50,7 +48,7 @@ private async Task OnCardUpload(UploadFile file)
5048
// 服务器端验证当文件大于 5MB 时提示文件太大信息
5149
if (file.Size > MaxFileLength)
5250
{
53-
await ToastService.Information(Localizer["UploadsFileMsg"], Localizer["UploadsFileError"]);
51+
await ToastService.Information(Localizer["UploadsFileTitle"], Localizer["UploadsFileError"]);
5452
file.Code = 1;
5553
file.Error = Localizer["UploadsFileError"];
5654
}
@@ -59,7 +57,7 @@ private async Task OnCardUpload(UploadFile file)
5957
// 模拟保存成功
6058
await Task.Delay(100);
6159
await SaveToFile(file);
62-
await ToastService.Success(Localizer["UploadsFileMsg"], $"{file.File!.Name} {Localizer["UploadsSuccess"]}");
60+
await ToastService.Success(Localizer["UploadsFileTitle"], $"{file.File!.Name} {Localizer["UploadsSuccess"]}");
6361
}
6462
}
6563
}
@@ -87,10 +85,10 @@ private async Task SaveToFile(UploadFile file)
8785
}
8886
else
8987
{
90-
var errorMessage = $"{Localizer["UploadsSaveFileError"]} {file.OriginFileName}";
88+
var errorMessage = Localizer["UploadsSaveFileError"];
9189
file.Code = 1;
9290
file.Error = errorMessage;
93-
await ToastService.Error(Localizer["UploadFile"], errorMessage);
91+
await ToastService.Error(Localizer["UploadsFileTitle"], errorMessage);
9492
}
9593
}
9694
catch (OperationCanceledException)
@@ -102,7 +100,7 @@ private async Task SaveToFile(UploadFile file)
102100
{
103101
file.Code = 1;
104102
file.Error = Localizer["UploadsWasmError"];
105-
await ToastService.Information(Localizer["UploadsSaveFile"], Localizer["UploadsSaveFileMsg"]);
103+
await ToastService.Error(Localizer["UploadsFileTitle"], Localizer["UploadsWasmError"]);
106104
}
107105
}
108106

@@ -111,9 +109,12 @@ private async Task SaveToFile(UploadFile file)
111109
/// </summary>
112110
public void Dispose()
113111
{
114-
_token?.Cancel();
115-
_token?.Dispose();
116-
_token = null;
112+
if (_token != null)
113+
{
114+
_token.Cancel();
115+
_token.Dispose();
116+
_token = null;
117+
}
117118
GC.SuppressFinalize(this);
118119
}
119120
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the Apache 2.0 License
3+
// See the LICENSE file in the project root for more information.
4+
// Maintainer: Argo Zhang([email protected]) Website: https://www.blazor.zone
5+
6+
using Microsoft.Extensions.FileProviders;
7+
8+
namespace Microsoft.AspNetCore.Builder;
9+
10+
static class WebApplicationExtensions
11+
{
12+
public static void UseUploaderStaticFiles(this WebApplication app)
13+
{
14+
var uploader = Path.Combine(app.Environment.WebRootPath, "images", "uploader");
15+
Directory.CreateDirectory(uploader);
16+
17+
app.UseStaticFiles(new StaticFileOptions
18+
{
19+
FileProvider = new PhysicalFileProvider(uploader),
20+
RequestPath = "/images/uploader"
21+
});
22+
}
23+
}

src/BootstrapBlazor.Server/Locales/en-US.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3398,7 +3398,12 @@
33983398
"UploadFileIconTemplateTitle": "Custom file icon",
33993399
"UploadFileIconTemplateIntro": "By setting the <code>IconTemplate</code> parameter and using the <code>FileIcon</code> component, you can further customize the file icon <a href=\"/file-icon\">[FileIcon example]</a>",
34003400
"UploadBase64Title": "Base64 format",
3401-
"UploadBase64Intro": "By setting the <code>PrevUrl</code> parameter value of the <code>UploadFile</code> instance, use the image content string in the <code>data:image/xxx;base64,XXXXX</code> format as the preview file path"
3401+
"UploadBase64Intro": "By setting the <code>PrevUrl</code> parameter value of the <code>UploadFile</code> instance, use the image content string in the <code>data:image/xxx;base64,XXXXX</code> format as the preview file path",
3402+
"UploadsFileTitle": "Upload",
3403+
"UploadsFileError": "The file is larger than 5M. Please reselect the file to upload.",
3404+
"UploadsSuccess": "File saved successfully",
3405+
"UploadsSaveFileError": "File save failed",
3406+
"UploadsWasmError": "In wasm mode, please call the api to save"
34023407
},
34033408
"BootstrapBlazor.Server.Components.Samples.UploadDrops": {
34043409
"UploadsTitle": "DropUpload",

src/BootstrapBlazor.Server/Locales/zh-CN.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3398,7 +3398,12 @@
33983398
"UploadFileIconTemplateTitle": "自定义文件图标",
33993399
"UploadFileIconTemplateIntro": "通过设置 <code>IconTemplate</code> 参数,使用 <code>FileIcon</code> 组件可以对文件图标进行进一步自定义 <a href=\"/file-icon\">[FileIcon 示例]</a>",
34003400
"UploadBase64Title": "Base64 格式文件",
3401-
"UploadBase64Intro": "通过设置 <code>UploadFile</code> 实例的 <code>PrevUrl</code> 参数值使用 <code>data:image/xxx;base64,XXXXX</code> 格式图片内容字符串作为预览文件路径"
3401+
"UploadBase64Intro": "通过设置 <code>UploadFile</code> 实例的 <code>PrevUrl</code> 参数值使用 <code>data:image/xxx;base64,XXXXX</code> 格式图片内容字符串作为预览文件路径",
3402+
"UploadsFileTitle": "文件上传",
3403+
"UploadsFileError": "文件大于 5M 请重新选择文件上传",
3404+
"UploadsSuccess": "文件保存成功",
3405+
"UploadsSaveFileError": "文件保存失败",
3406+
"UploadsWasmError": "wasm 模式请调用 api 进行保存"
34023407
},
34033408
"BootstrapBlazor.Server.Components.Samples.UploadDrops": {
34043409
"UploadsTitle": "DropUpload 拖拽上传组件",

src/BootstrapBlazor.Server/Program.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@
3535
app.UseExceptionHandler("/Error", createScopeForErrors: true);
3636
}
3737

38+
// 增加上传目录静态资源文件
39+
app.UseUploaderStaticFiles();
40+
3841
app.UseAntiforgery();
3942
app.UseBootstrapBlazor();
4043

0 commit comments

Comments
 (0)