Skip to content

Commit 644fcb7

Browse files
committed
Merge remote-tracking branch 'origin/main'
2 parents 1d2a941 + e6c8012 commit 644fcb7

File tree

12 files changed

+82
-18
lines changed

12 files changed

+82
-18
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,9 +364,15 @@
364364
<DemoBlock Title="@Localizer["SelectsConfirmSelectTitle"]"
365365
Introduction="@Localizer["SelectsConfirmSelectIntro"]"
366366
Name="ConfirmSelect">
367+
<section ignore>
368+
<ul class="ul-demo">
369+
<li>@((MarkupString)Localizer["SelectConfifrmSelectDesc1"].Value)</li>
370+
<li>@((MarkupString)Localizer["SelectConfifrmSelectDesc2"].Value)</li>
371+
</ul>
372+
</section>
367373
<div class="row">
368374
<div class="col-12 col-sm-6">
369-
<Select TValue="string" Items="Items" OnBeforeSelectedItemChange="@OnBeforeSelectedItemChange"
375+
<Select TValue="string" Items="Items" ShowSwal="true"
370376
SwalTitle="@Localizer["SwalTitle"]" SwalContent="@Localizer["SwalContent"]" SwalFooter="@Localizer["SwalFooter"]" />
371377
</div>
372378
</div>

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3219,7 +3219,9 @@
32193219
"SelectsShowSearchTitle": "Drop-down box with search box",
32203220
"SelectsShowSearchIntro": "Controls whether the search box is displayed by setting the <code>ShowSearch</code> property, which is not displayed by default <b>false</b>. You can set the <code>IsAutoClearSearchTextWhenCollapsed</code> parameter to control whether the text in the search box is automatically cleared after the drop-down box is collapsed. The default value is <b>false</b>.",
32213221
"SelectsConfirmSelectTitle": "Drop-down box with confirmation",
3222-
"SelectsConfirmSelectIntro": "Block changes to the current value by setting the <code>OnBeforeSelectedItemChange</code> delegate.",
3222+
"SelectsConfirmSelectIntro": "Prevent the current value from changing by setting the <code>OnBeforeSelectedItemChange</code> delegate or setting the <code>ShowSwal</code> parameter to <code>true</code>.",
3223+
"SelectConfifrmSelectDesc1": "Set the <code>OnBeforeSelectedItemChange</code> callback method, and pop up a window in the callback method to confirm whether to change the value. If it returns <code>true</code>, the value will be changed, otherwise it will not be changed.",
3224+
"SelectConfifrmSelectDesc2": "Set <code>ShowSwal=\"true\"</code> and then confirm the value of the <code>SwalTitle</code> <code>SwalContent</code> parameter using the built-in popup window. In the callback method, you can confirm whether to change the value.",
32233225
"SelectsTimeZoneTitle": "Timezone",
32243226
"SelectsTimeZoneIntro": "Display data of Timezone",
32253227
"SwalTitle": "The drop-down box value changes",

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3219,7 +3219,9 @@
32193219
"SelectsShowSearchTitle": "带搜索框的下拉框",
32203220
"SelectsShowSearchIntro": "通过设置 <code>ShowSearch</code> 属性控制是否显示搜索框,默认为 <b>false</b> 不显示搜索框,可以通过设置 <code>IsAutoClearSearchTextWhenCollapsed</code> 参数控制下拉框收起后是否自动清空搜索框内文字,默认值为 <b>false</b> 不清空",
32213221
"SelectsConfirmSelectTitle": "带确认的下拉框",
3222-
"SelectsConfirmSelectIntro": "通过设置 <code>OnBeforeSelectedItemChange</code> 委托,阻止当前值的改变",
3222+
"SelectsConfirmSelectIntro": "通过设置 <code>OnBeforeSelectedItemChange</code> 委托或者设置 <code>ShowSwal</code> 参数值为 <code>true</code>,阻止当前值的改变。",
3223+
"SelectConfifrmSelectDesc1": "设置 <code>OnBeforeSelectedItemChange</code> 回调方法,在回调方法内自己弹窗确认是否更改值,返回 <code>true</code> 时更改,否则不更改",
3224+
"SelectConfifrmSelectDesc2": "设置 <code>ShowSwal=\"true\"</code> 然后通过设置 <code>SwalTitle</code> <code>SwalContent</code> 参数值使用内置弹窗进行确认即可,在回调方法内自己弹窗确认是否更改值",
32233225
"SelectsTimeZoneTitle": "时区下拉框",
32243226
"SelectsTimeZoneIntro": "下拉框展现时区数据",
32253227
"SwalTitle": "下拉框值变更",

src/BootstrapBlazor/Components/ErrorLogger/BootstrapBlazorErrorBoundary.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class BootstrapBlazorErrorBoundary : ErrorBoundaryBase
1818
{
1919
[Inject]
2020
[NotNull]
21-
private ILogger<ErrorLogger>? Logger { get; set; }
21+
private ILogger<BootstrapBlazorErrorBoundary>? Logger { get; set; }
2222

2323
[Inject]
2424
[NotNull]
@@ -48,6 +48,12 @@ class BootstrapBlazorErrorBoundary : ErrorBoundaryBase
4848
[Parameter]
4949
public bool ShowToast { get; set; } = true;
5050

51+
/// <summary>
52+
/// 获得/设置 是否启用日志记录功能 默认 true 启用
53+
/// </summary>
54+
[Parameter]
55+
public bool EnableILogger { get; set; } = true;
56+
5157
/// <summary>
5258
/// 获得/设置 Toast 弹窗标题
5359
/// </summary>
@@ -61,7 +67,10 @@ class BootstrapBlazorErrorBoundary : ErrorBoundaryBase
6167
/// <param name="exception"></param>
6268
protected override Task OnErrorAsync(Exception exception)
6369
{
64-
Logger.LogError(exception, "{BootstrapBlazorErrorBoundary} {OnErrorAsync} log this error occurred at {Page}", nameof(BootstrapBlazorErrorBoundary), nameof(OnErrorAsync), NavigationManager.Uri);
70+
if (EnableILogger)
71+
{
72+
Logger.LogError(exception, "BootstrapBlazorErrorBoundary OnErrorAsync log this error occurred at {Page}", NavigationManager.Uri);
73+
}
6574
return Task.CompletedTask;
6675
}
6776

src/BootstrapBlazor/Components/ErrorLogger/ErrorLogger.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ public class ErrorLogger : ComponentBase, IErrorLogger
3030
[Parameter]
3131
public bool ShowToast { get; set; } = true;
3232

33+
/// <summary>
34+
/// <inheritdoc/>
35+
/// </summary>
36+
[Parameter]
37+
public bool EnableILogger { get; set; } = true;
38+
3339
/// <summary>
3440
/// <inheritdoc/>
3541
/// </summary>
@@ -112,6 +118,7 @@ protected override void BuildRenderTree(RenderTreeBuilder builder)
112118
builder.AddAttribute(3, nameof(BootstrapBlazorErrorBoundary.ToastTitle), ToastTitle);
113119
builder.AddAttribute(4, nameof(BootstrapBlazorErrorBoundary.ErrorContent), ErrorContent);
114120
builder.AddAttribute(5, nameof(BootstrapBlazorErrorBoundary.ChildContent), ChildContent);
121+
builder.AddAttribute(6, nameof(BootstrapBlazorErrorBoundary.EnableILogger), EnableILogger);
115122
builder.AddComponentReferenceCapture(5, obj => _errorBoundary = (BootstrapBlazorErrorBoundary)obj);
116123
builder.CloseComponent();
117124
};

src/BootstrapBlazor/Components/ErrorLogger/IErrorLogger.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ public interface IErrorLogger
2727
/// </summary>
2828
bool ShowToast { get; }
2929

30+
/// <summary>
31+
/// 获得/设置 是否启用日志记录功能 默认 true 启用
32+
/// <para>设置 false 后关闭记录日志功能</para>
33+
/// </summary>
34+
bool EnableILogger { get; }
35+
3036
/// <summary>
3137
/// 获得 Error Toast 弹窗标题 默认读取资源文件内容
3238
/// </summary>

src/BootstrapBlazor/Components/IpAddress/IpAddress.razor.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ protected override void OnParametersSet()
3636
var ipSegments = CurrentValueAsString.Split(".", System.StringSplitOptions.RemoveEmptyEntries);
3737
if (ipSegments.Length == 4)
3838
{
39-
Value1 = ipSegments[0];
40-
Value2 = ipSegments[1];
41-
Value3 = ipSegments[2];
42-
Value4 = ipSegments[3];
39+
Value1 = ipSegments[0].Trim();
40+
Value2 = ipSegments[1].Trim();
41+
Value3 = ipSegments[2].Trim();
42+
Value4 = ipSegments[3].Trim();
4343
}
4444
else
4545
{

src/BootstrapBlazor/Components/IpAddress/IpAddress.razor.js

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ const selectCell = (el, index) => {
88
if (index > 3) {
99
index = 3
1010
}
11-
const c = el.querySelectorAll(".ipv4-cell")[index]
12-
c.focus()
13-
return c
11+
const cell = el.querySelectorAll(".ipv4-cell")[index];
12+
cell.focus();
1413
}
1514

1615
export function init(id) {
@@ -23,16 +22,26 @@ export function init(id) {
2322
Data.set(id, ip)
2423

2524
el.querySelectorAll(".ipv4-cell").forEach((c, index) => {
25+
EventHandler.on(c, 'compositionend', e => {
26+
e.preventDefault();
27+
c.value = ip.prevValues[index];
28+
});
29+
EventHandler.on(c, 'focus', e => {
30+
const input = e.target;
31+
input.select();
32+
});
2633
EventHandler.on(c, 'keydown', e => {
34+
const current = e.target;
2735
if ((e.keyCode >= 48 && e.keyCode <= 57) || (e.keyCode >= 96 && e.keyCode <= 105)) {
2836
// numbers, backup last status
2937
ip.prevValues[index] = c.value
3038
if (c.value === "0") {
3139
c.value = ""
3240
}
3341
else if (c.selectionStart !== c.selectionEnd) {
34-
const v = c.value.substring(c.selectionStart, c.selectionEnd)
35-
const newVal = c.value.replace(v, e.key)
42+
const v1 = c.value.substring(0, c.selectionStart);
43+
const v2 = c.value.substring(c.selectionEnd, c.value.length);
44+
const newVal = `${v1}${e.key}${v2}`;
3645
const num = Number(newVal)
3746
if (num > 255) {
3847
e.preventDefault()
@@ -47,15 +56,23 @@ export function init(id) {
4756
}
4857
else if (e.key === '.') {
4958
e.preventDefault()
50-
const c = selectCell(el, index + 1)
51-
c.select()
59+
selectCell(el, index + 1)
5260
}
5361
else if (e.key === 'Backspace') {
54-
if (c.value.length === 0) {
62+
if (c.value.length <= 1) {
5563
c.value = "0"
64+
e.preventDefault();
5665
selectCell(el, index - 1)
5766
}
5867
}
68+
else if (current.selectionStart === current.value.length && (e.code === 'Space' || e.code === 'ArrowRight')) {
69+
e.preventDefault()
70+
selectCell(el, index + 1)
71+
}
72+
else if (current.selectionStart === 0 && e.code === 'ArrowLeft') {
73+
e.preventDefault()
74+
selectCell(el, index - 1)
75+
}
5976
else if (e.key === 'Delete' || e.key === 'Tab' || e.key === 'ArrowLeft' || e.key === 'ArrowRight') {
6077

6178
}

src/BootstrapBlazor/Components/Layout/Layout.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@
127127
else
128128
{
129129
<ErrorLogger EnableErrorLogger="@_enableErrorLogger" ShowToast="@_showToast" ToastTitle="@ErrorLoggerToastTitle"
130-
OnErrorHandleAsync="OnErrorHandleAsync" OnInitializedCallback="OnErrorLoggerInitialized">
130+
EnableILogger="@_enableILogger" OnErrorHandleAsync="OnErrorHandleAsync" OnInitializedCallback="OnErrorLoggerInitialized">
131131
@HandlerMain()
132132
</ErrorLogger>
133133
}

src/BootstrapBlazor/Components/Layout/Layout.razor.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,12 @@ public partial class Layout : IHandlerException, ITabHeader
465465
[Parameter]
466466
public bool? ShowErrorLoggerToast { get; set; }
467467

468+
/// <summary>
469+
/// 获得/设置 是否启用日志记录功能 默认 null 启用 使用 <see cref="BootstrapBlazorOptions.EnableErrorLoggerILogger"/> 设置值
470+
/// </summary>
471+
[Parameter]
472+
public bool? EnableErrorLoggerILogger { get; set; }
473+
468474
/// <summary>
469475
/// 获得/设置 错误日志 <see cref="Toast"/> 弹窗标题 默认 null
470476
/// </summary>
@@ -503,6 +509,8 @@ public partial class Layout : IHandlerException, ITabHeader
503509

504510
private bool _showToast => ShowErrorLoggerToast ?? Options.CurrentValue.ShowErrorLoggerToast;
505511

512+
private bool _enableILogger => EnableErrorLoggerILogger ?? Options.CurrentValue.EnableErrorLoggerILogger;
513+
506514
/// <summary>
507515
/// <inheritdoc/>
508516
/// </summary>

0 commit comments

Comments
 (0)