Skip to content

Commit 096d197

Browse files
committed
Merge branch 'feat-pdf'
2 parents 6f78e01 + 8b47783 commit 096d197

34 files changed

Lines changed: 371 additions & 198 deletions

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,3 +381,6 @@ src/**/wwwroot/**/uploader
381381
**/BootstrapBlazor/wwwroot/css/sweetalert2.css
382382
**/BootstrapBlazor/wwwroot/css/motronic.min.css
383383
**/BootstrapBlazor/wwwroot/css/nano.min.css
384+
385+
# Bootstrap
386+
**/BootstrapBlazor/wwwroot/js/bootstrap.blazor.bundle.min.js

src/BootstrapBlazor.Server/Components/Samples/ImageViewers.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@
116116
Name="PreviewList">
117117
<div class="images img-ph mt-3">
118118
<div class="images-item">
119-
<ImageViewer Url="@WebsiteOption.CurrentValue.GetAssetUrl("images/bird.jpeg")" PreviewList="PreviewList" />
119+
<ImageViewer Url="@WebsiteOption.CurrentValue.GetAssetUrl("images/bird.jpeg")" PreviewList="PreviewList" ZoomSpeed="0.5" />
120120
</div>
121121
</div>
122122
</DemoBlock>

src/BootstrapBlazor.Server/Components/Samples/SelectGenerics.razor

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,8 @@
428428
<section ignore>@((MarkupString)Localizer["SelectsGenericDesc"].Value)</section>
429429
<div class="row">
430430
<div class="col-12 col-sm-6">
431-
<SelectGeneric Items="_genericItems" @bind-Value="_selectedFoo" IsEditable="true"></SelectGeneric>
431+
<SelectGeneric Items="_genericItems" @bind-Value="_selectedFoo"
432+
IsEditable="true" TextConvertToValueCallback="TextConvertToValueCallback"></SelectGeneric>
432433
</div>
433434
<div class="col-12 col-sm-6">
434435
<Display Value="_selectedFoo.Address"></Display>

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,27 @@ private Task OnTimeZoneValueChanged(string timeZoneId)
251251

252252
private Foo _selectedFoo = new();
253253

254+
private async Task<Foo> TextConvertToValueCallback(string v)
255+
{
256+
// 模拟异步通讯切换线程
257+
await Task.Delay(10);
258+
259+
Foo? foo = null;
260+
var item = _genericItems.Find(i => i.Text == v);
261+
if (item == null)
262+
{
263+
var id = _genericItems.Count + 1;
264+
foo = new Foo() { Id = id, Address = $"New Address - {id}" };
265+
var fooItem = new SelectedItem<Foo> { Text = v, Value = foo };
266+
_genericItems.Add(fooItem);
267+
}
268+
else
269+
{
270+
foo = item.Value;
271+
}
272+
return foo!;
273+
}
274+
254275
/// <summary>
255276
/// 获得事件方法
256277
/// </summary>

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3266,7 +3266,7 @@
32663266
"SelectsVirtualizeDescription": "Component virtual scrolling supports two ways of providing data through <code>Items</code> or <code>OnQueryAsync</code> callback methods",
32673267
"SelectsGenericTitle": "Generic",
32683268
"SelectsGenericIntro": "Data source <code>Items</code> supports generics when using <code>SelectedItem&lt;TValue&gt;</code>",
3269-
"SelectsGenericDesc": "<p>Please refer to <a href=\"https://github.com/dotnetcore/BootstrapBlazor/issues/4497?wt.mc_id=DT-MVP-5004174\" target=\"_blank\">Design Ideas</a> to understand this feature. In this example, by selecting the drop-down box option, the value obtained is the <code>Foo</code> instance, and the value displayed in the text box on the right is the <code>Address</code> value of the <code>Foo</code> attribute</p><p>In this example, the <code>ValueEqualityComparer</code> and <code>CustomKeyAttribute</code> parameters are not set, and the <code>[Key]</code> tag of the <code>Id</code> attribute of <code>Foo</code> is used for equality judgment</p>",
3269+
"SelectsGenericDesc": "<p>Please refer to <a href=\"https://github.com/dotnetcore/BootstrapBlazor/issues/4497?wt.mc_id=DT-MVP-5004174\" target=\"_blank\">Design Ideas</a> to understand this feature. In this example, by selecting the drop-down box option, the value obtained is the <code>Foo</code> instance, and the value displayed in the text box on the right is the <code>Address</code> value of the <code>Foo</code> attribute</p><p>In this example, <code>IsEditable=\"true\"</code> and <code>TextConvertToValueCallback</code> parameters are set. When a <code>Foo</code> that does not exist in the original data source is entered, a new <code>Foo</code> instance is added to the data source in the <code></code> callback method</p>",
32703270
"SelectsOnInputChangedCallback": "Callback method for converting input text into corresponding Value in edit mode",
32713271
"TextConvertToValueCallback": "Callback method when input text changes in edit mode",
32723272
"SelectsIsEditable": "Whether editable",
@@ -5914,7 +5914,7 @@
59145914
"ImageViewerErrorTemplateTitle": "Load failed",
59155915
"ImageViewerErrorTemplateIntro": "Can be set up by the <code>Error Template</code> open Error Template function, Url parameter <code>Url</code> unable to load images displayed when the content of the Template",
59165916
"ImageViewerPreviewListTitle": "A larger preview",
5917-
"ImageViewerPreviewListIntro": "Can be set up by the <code>Preview List</code> opens a larger Preview of the function",
5917+
"ImageViewerPreviewListIntro": "Can be set up by the <code>Preview List</code> opens a larger Preview of the function, set <code>ZoomSpeed</code> to control the speed of scrolling and scaling",
59185918
"ImageViewersAttrUrl": "Picture Url",
59195919
"ImageViewersAttrAlt": "Native Alt attribute",
59205920
"ImageViewersAttrShowPlaceHolder": "Whether display placeholder for large images added",

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3266,7 +3266,7 @@
32663266
"SelectsVirtualizeDescription": "组件虚拟滚动支持两种形式通过 <code>Items</code> 或者 <code>OnQueryAsync</code> 回调方法提供数据",
32673267
"SelectsGenericTitle": "泛型支持",
32683268
"SelectsGenericIntro": "数据源 <code>Items</code> 使用 <code>SelectedItem&lt;TValue&gt;</code> 时即可支持泛型",
3269-
"SelectsGenericDesc": "<p>请参考 <a href=\"https://github.com/dotnetcore/BootstrapBlazor/issues/4497?wt.mc_id=DT-MVP-5004174\" target=\"_blank\">设计思路</a> 理解此功能。本例中通过选择下拉框选项,得到的值为 <code>Foo</code> 实例,右侧文本框内显示值为 <code>Foo</code> 属性 <code>Address</code> 值</p><p>本例中未设置 <code>ValueEqualityComparer</code> 以及 <code>CustomKeyAttribute</code> 参数,使用 <code>Foo</code> 属性 <code>Id</code> <code>[Key]</code> 标签进行相等判定</p>",
3269+
"SelectsGenericDesc": "<p>请参考 <a href=\"https://github.com/dotnetcore/BootstrapBlazor/issues/4497?wt.mc_id=DT-MVP-5004174\" target=\"_blank\">设计思路</a> 理解此功能。本例中通过选择下拉框选项,得到的值为 <code>Foo</code> 实例,右侧文本框内显示值为 <code>Foo</code> 属性 <code>Address</code> 值</p><p>本例中设置 <code>IsEditable=\"true\"</code> 以及 <code>TextConvertToValueCallback</code> 参数,录入原数据源中不存在的 <code>Foo</code> 时,在 <code></code> 回调方法中添加新 <code>Foo</code> 实例到数据源中</p>",
32703270
"SelectsOnInputChangedCallback": "编辑模式下输入文本转换为对应 Value 回调方法",
32713271
"TextConvertToValueCallback": "编辑模式下输入文本变化时回调方法",
32723272
"SelectsIsEditable": "是否可编辑",
@@ -5914,7 +5914,7 @@
59145914
"ImageViewerErrorTemplateTitle": "加载失败",
59155915
"ImageViewerErrorTemplateIntro": "可通过设置 <code>ErrorTemplate</code> 开启错误模板功能,参数 <code>Url</code> 无法加载图片时显示此模板内容",
59165916
"ImageViewerPreviewListTitle": "大图预览",
5917-
"ImageViewerPreviewListIntro": "可通过设置 <code>PreviewList</code> 开启预览大图的功能",
5917+
"ImageViewerPreviewListIntro": "可通过设置 <code>PreviewList</code> 开启预览大图的功能,设置 <code>ZoomSpeed</code> 控制滚动缩放时的速度",
59185918
"ImageViewersAttrUrl": "图片 Url",
59195919
"ImageViewersAttrAlt": "原生 alt 属性",
59205920
"ImageViewersAttrShowPlaceHolder": "是否显示占位符 适用于大图片加载",

src/BootstrapBlazor/BootstrapBlazor.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk.Razor">
22

33
<PropertyGroup>
4-
<Version>9.7.1-beta02</Version>
4+
<Version>9.7.1-beta03</Version>
55
</PropertyGroup>
66

77
<ItemGroup>

src/BootstrapBlazor/Components/ErrorLogger/BootstrapBlazorErrorBoundary.cs

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
using Microsoft.AspNetCore.Components.Rendering;
77
using Microsoft.Extensions.Configuration;
8+
using Microsoft.Extensions.Hosting;
89
using Microsoft.Extensions.Logging;
910
using System.Reflection;
1011

@@ -31,6 +32,10 @@ class BootstrapBlazorErrorBoundary : ErrorBoundaryBase
3132
[NotNull]
3233
private NavigationManager? NavigationManager { get; set; }
3334

35+
[Inject]
36+
[NotNull]
37+
private IHostEnvironment? HostEnvironment { get; set; }
38+
3439
/// <summary>
3540
/// 获得/设置 自定义错误处理回调方法
3641
/// </summary>
@@ -54,13 +59,10 @@ class BootstrapBlazorErrorBoundary : ErrorBoundaryBase
5459
/// <inheritdoc/>
5560
/// </summary>
5661
/// <param name="exception"></param>
57-
protected override async Task OnErrorAsync(Exception exception)
62+
protected override Task OnErrorAsync(Exception exception)
5863
{
59-
if (ShowToast)
60-
{
61-
await ToastService.Error(ToastTitle, exception.Message);
62-
}
6364
Logger.LogError(exception, "{BootstrapBlazorErrorBoundary} {OnErrorAsync} log this error occurred at {Page}", nameof(BootstrapBlazorErrorBoundary), nameof(OnErrorAsync), NavigationManager.Uri);
65+
return Task.CompletedTask;
6466
}
6567

6668
/// <summary>
@@ -69,13 +71,13 @@ protected override async Task OnErrorAsync(Exception exception)
6971
/// <param name="builder"></param>
7072
protected override void BuildRenderTree(RenderTreeBuilder builder)
7173
{
74+
// 页面生命周期内异常直接调用这里
7275
var ex = CurrentException ?? _exception;
7376
if (ex != null)
7477
{
7578
// 处理自定义异常逻辑
7679
if (OnErrorHandleAsync != null)
7780
{
78-
// 页面生命周期内异常直接调用这里
7981
_ = OnErrorHandleAsync(Logger, ex);
8082
return;
8183
}
@@ -132,7 +134,7 @@ private MarkupString GetErrorContentMarkupString(Exception ex)
132134
}
133135

134136
/// <summary>
135-
/// 渲染异常信息方法
137+
/// BootstrapBlazor 组件导致异常渲染方法
136138
/// </summary>
137139
/// <param name="exception"></param>
138140
/// <param name="handler"></param>
@@ -145,14 +147,35 @@ public async Task RenderException(Exception exception, IHandlerException? handle
145147
return;
146148
}
147149

150+
// 记录日志
151+
await OnErrorAsync(exception);
152+
148153
if (handler != null)
149154
{
150-
await handler.HandlerException(exception, ExceptionContent);
155+
if (HostEnvironment.IsDevelopment())
156+
{
157+
// IHandlerException 处理异常逻辑
158+
await handler.HandlerException(exception, ExceptionContent);
159+
}
160+
else
161+
{
162+
// 非开发模式下弹窗提示错误信息
163+
await ToastService.Error(ToastTitle, exception.Message);
164+
}
151165
return;
152166
}
153167

154-
await OnErrorAsync(exception);
168+
// 显示异常信息
169+
await ShowErrorToast(exception);
155170
_exception = exception;
156171
StateHasChanged();
157172
}
173+
174+
private async Task ShowErrorToast(Exception exception)
175+
{
176+
if (ShowToast)
177+
{
178+
await ToastService.Error(ToastTitle, exception.Message);
179+
}
180+
}
158181
}

src/BootstrapBlazor/Components/ErrorLogger/ErrorLogger.cs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ public class ErrorLogger : ComponentBase, IErrorLogger
2222
/// <inheritdoc/>
2323
/// </summary>
2424
[Parameter]
25-
public bool? EnableErrorLogger { get; set; }
25+
public bool EnableErrorLogger { get; set; } = true;
2626

2727
/// <summary>
2828
/// <inheritdoc/>
2929
/// </summary>
3030
[Parameter]
31-
public bool? ShowToast { get; set; }
31+
public bool ShowToast { get; set; } = true;
3232

3333
/// <summary>
3434
/// <inheritdoc/>
@@ -62,17 +62,9 @@ public class ErrorLogger : ComponentBase, IErrorLogger
6262
[Parameter]
6363
public Func<ErrorLogger, Task>? OnInitializedCallback { get; set; }
6464

65-
[Inject]
66-
[NotNull]
67-
private IOptionsMonitor<BootstrapBlazorOptions>? Options { get; set; }
68-
6965
[NotNull]
7066
private BootstrapBlazorErrorBoundary? _errorBoundary = default;
7167

72-
private bool _enableErrorLogger => EnableErrorLogger ?? Options.CurrentValue.EnableErrorLogger;
73-
74-
private bool _showToast => ShowToast ?? Options.CurrentValue.ShowErrorLoggerToast;
75-
7668
/// <summary>
7769
/// <inheritdoc/>
7870
/// </summary>
@@ -110,13 +102,13 @@ protected override void BuildRenderTree(RenderTreeBuilder builder)
110102
builder.CloseComponent();
111103
}
112104

113-
private RenderFragment? RenderContent => _enableErrorLogger ? RenderError : ChildContent;
105+
private RenderFragment? RenderContent => EnableErrorLogger ? RenderError : ChildContent;
114106

115107
private RenderFragment RenderError => builder =>
116108
{
117109
builder.OpenComponent<BootstrapBlazorErrorBoundary>(0);
118110
builder.AddAttribute(1, nameof(BootstrapBlazorErrorBoundary.OnErrorHandleAsync), OnErrorHandleAsync);
119-
builder.AddAttribute(2, nameof(BootstrapBlazorErrorBoundary.ShowToast), _showToast);
111+
builder.AddAttribute(2, nameof(BootstrapBlazorErrorBoundary.ShowToast), ShowToast);
120112
builder.AddAttribute(3, nameof(BootstrapBlazorErrorBoundary.ToastTitle), ToastTitle);
121113
builder.AddAttribute(4, nameof(BootstrapBlazorErrorBoundary.ErrorContent), ErrorContent);
122114
builder.AddAttribute(5, nameof(BootstrapBlazorErrorBoundary.ChildContent), ChildContent);

src/BootstrapBlazor/Components/ErrorLogger/IErrorLogger.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ namespace BootstrapBlazor.Components;
1111
public interface IErrorLogger
1212
{
1313
/// <summary>
14-
/// 获得/设置 是否开启全局异常捕获 默认 null 使用全局配置 <see cref="BootstrapBlazorOptions.EnableErrorLogger"/> 值
14+
/// 获得/设置 是否开启全局异常捕获 默认 true
1515
/// </summary>
16-
bool? EnableErrorLogger { get; set; }
16+
bool EnableErrorLogger { get; set; }
1717

1818
/// <summary>
1919
/// 获得/设置 自定义 Error 处理方法 默认 null
@@ -23,9 +23,9 @@ public interface IErrorLogger
2323
Task HandlerExceptionAsync(Exception ex);
2424

2525
/// <summary>
26-
/// 获得 是否显示 Error 提示弹窗 默认 null 使用全局配置 <see cref="BootstrapBlazorOptions.ShowErrorLoggerToast"/> 值
26+
/// 获得 是否显示 Error 提示弹窗 默认 true
2727
/// </summary>
28-
bool? ShowToast { get; }
28+
bool ShowToast { get; }
2929

3030
/// <summary>
3131
/// 获得 Error Toast 弹窗标题 默认读取资源文件内容

0 commit comments

Comments
 (0)