Skip to content

Commit 586170d

Browse files
committed
2 parents 2bded4a + ddc61cd commit 586170d

File tree

11 files changed

+60
-30
lines changed

11 files changed

+60
-30
lines changed

src/BootstrapBlazor.Server/BootstrapBlazor.Server.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
<PackageReference Include="BootstrapBlazor.SvgEditor" Version="9.0.3" />
7070
<PackageReference Include="BootstrapBlazor.SummerNote" Version="9.0.4" />
7171
<PackageReference Include="BootstrapBlazor.TableExport" Version="9.2.6" />
72-
<PackageReference Include="BootstrapBlazor.Topology" Version="9.0.0" />
72+
<PackageReference Include="BootstrapBlazor.Topology" Version="9.0.1" />
7373
<PackageReference Include="BootstrapBlazor.UniverIcon" Version="9.0.1" />
7474
<PackageReference Include="BootstrapBlazor.UniverSheet" Version="9.0.5" />
7575
<PackageReference Include="BootstrapBlazor.Vditor" Version="9.0.0" />

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,7 @@
145145
<CollapseItems>
146146
<CollapseItem Text="@Localizer["Consistency"]">
147147
<HeaderTemplate>
148-
<div class="p-2">
149-
<Select Items="Items" @bind-Value="Value" IsPopover="true"></Select>
150-
</div>
148+
<Select Items="Items" @bind-Value="Value" IsPopover="true"></Select>
151149
</HeaderTemplate>
152150
<ChildContent>
153151
<div>@Localizer["ConsistencyItem1"]</div>
@@ -157,7 +155,7 @@
157155
</CollapseItem>
158156
<CollapseItem Text="@Localizer["Feedback"]">
159157
<HeaderTemplate>
160-
<div class="p-2">Header-Test</div>
158+
Header-Test
161159
</HeaderTemplate>
162160
<ChildContent>
163161
<div>@Localizer["FeedbackItem1"]</div>
@@ -166,7 +164,7 @@
166164
</CollapseItem>
167165
<CollapseItem Text="@Localizer["Controllability"]">
168166
<HeaderTemplate>
169-
<div class="p-2">Header-Test</div>
167+
Header-Test
170168
</HeaderTemplate>
171169
<ChildContent>
172170
<div>@Localizer["ControllabilityItem1"]</div>

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,22 @@ class MockEntity
110110
return new Foo() { Id = data.Span[0], Name = name };
111111
}
112112
}</Pre>
113+
114+
<p class="code-label">针对第三方程序集的数据类型解决方案如下:</p>
115+
<p>使用 <code></code></p>
116+
117+
<Pre>builder.Services.ConfigureSocketDataConverters(options =>
118+
{
119+
options.AddTypeConverter&lt;MockEntity&gt;();
120+
options.AddPropertyConverter&lt;MockEntity&gt;(entity =&gt; entity.Header, new SocketDataPropertyConverterAttribute()
121+
{
122+
Offset = 0,
123+
Length = 5
124+
});
125+
options.AddPropertyConverter&lt;MockEntity&gt;(entity =&gt; entity.Body, new SocketDataPropertyConverterAttribute()
126+
{
127+
Offset = 5,
128+
Length = 2
129+
});
130+
});
131+
</Pre>

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.8.2-beta02</Version>
4+
<Version>9.8.2-beta04</Version>
55
</PropertyGroup>
66

77
<ItemGroup>

src/BootstrapBlazor/Components/Collapse/Collapse.razor

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,23 @@
1010
{
1111
<div @key="item" class="@GetItemClassString(item)">
1212
<div class="@GetHeaderClassString(item)">
13-
@if (item.HeaderTemplate != null)
14-
{
15-
<div class="accordion-header-body">
16-
@item.HeaderTemplate
17-
</div>
18-
}
1913
<div class="@GetHeaderButtonClassString(item)"
2014
data-bs-toggle="collapse" data-bs-target="@GetTargetIdString(item)"
2115
aria-expanded="@(item.IsCollapsed ? "false" : "true")" @onclick="() => OnClickItem(item)">
22-
@if(!string.IsNullOrEmpty(item.Icon))
16+
@if (item.HeaderTemplate != null)
17+
{
18+
<div class="accordion-header-body">
19+
@item.HeaderTemplate
20+
</div>
21+
}
22+
else if(!string.IsNullOrEmpty(item.Icon))
2323
{
2424
<i class="@GetItemIconString(item)"></i>
2525
}
26-
<span>@item.Text</span>
26+
else
27+
{
28+
<span>@item.Text</span>
29+
}
2730
</div>
2831
</div>
2932
<div class="@GetClassString(item.IsCollapsed)" id="@GetTargetId(item)" data-bs-parent="@ParentIdString">

src/BootstrapBlazor/Components/Tab/Tab.razor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ public partial class Tab
432432
public ITabHeader? TabHeader { get; set; }
433433

434434
/// <summary>
435-
/// 获得/设置 是否开启全局异常捕获 默认 null 读取配置文件 EnableErrorLogger 值
435+
/// 获得/设置 是否开启全局异常捕获 默认 null 读取配置文件 <see cref="BootstrapBlazorOptions.EnableErrorLogger"/>
436436
/// </summary>
437437
[Parameter]
438438
public bool? EnableErrorLogger { get; set; }

src/BootstrapBlazor/Components/Tab/TabItemContent.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ class TabItemContent : IComponent, IHandlerException, IDisposable
1515
[Parameter, NotNull]
1616
public TabItem? Item { get; set; }
1717

18+
[CascadingParameter]
19+
private Layout? Layout { get; set; }
20+
1821
[CascadingParameter, NotNull]
1922
private Tab? TabSet { get; set; }
2023

@@ -67,6 +70,7 @@ private void BuildRenderTree(RenderTreeBuilder builder)
6770
_logger.Register(this);
6871
return Task.CompletedTask;
6972
}));
73+
builder.AddAttribute(6, nameof(ErrorLogger.OnErrorHandleAsync), Layout?.OnErrorHandleAsync);
7074
builder.CloseComponent();
7175
}
7276

src/BootstrapBlazor/Services/TcpSocket/DataConverter/SocketDataConverterCollections.cs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,35 +10,41 @@
1010
namespace BootstrapBlazor.Components;
1111

1212
/// <summary>
13-
///
13+
/// 数据转换器集合类
1414
/// </summary>
15-
public class SocketDataConverterCollections
15+
public sealed class SocketDataConverterCollections
1616
{
1717
readonly ConcurrentDictionary<Type, ISocketDataConverter> _converters = new();
1818
readonly ConcurrentDictionary<MemberInfo, SocketDataPropertyConverterAttribute> _propertyConverters = new();
1919

2020
/// <summary>
21-
/// 增加数据类型转换器方法
21+
/// 增加指定 <see cref="ISocketDataConverter{TEntity}"/> 数据类型转换器方法
2222
/// </summary>
2323
/// <typeparam name="TEntity"></typeparam>
2424
/// <param name="converter"></param>
25-
public void AddOrUpdateTypeConverter<TEntity>(ISocketDataConverter<TEntity> converter)
25+
public void AddTypeConverter<TEntity>(ISocketDataConverter<TEntity> converter)
2626
{
2727
var type = typeof(TEntity);
2828
_converters.AddOrUpdate(type, t => converter, (t, v) => converter);
2929
}
3030

31+
/// <summary>
32+
/// 增加默认数据类型转换器方法 转换器使用 <see cref="SocketDataConverter{TEntity}"/>
33+
/// </summary>
34+
/// <typeparam name="TEntity"></typeparam>
35+
public void AddTypeConverter<TEntity>() => AddTypeConverter(new SocketDataConverter<TEntity>(this));
36+
3137
/// <summary>
3238
/// 添加属性类型转化器方法
3339
/// </summary>
3440
/// <typeparam name="TEntity"></typeparam>
3541
/// <param name="propertyExpression"></param>
3642
/// <param name="attribute"></param>
37-
public void AddOrUpdatePropertyConverter<TEntity>(Expression<Func<TEntity, object?>> propertyExpression, SocketDataPropertyConverterAttribute attribute)
43+
public void AddPropertyConverter<TEntity>(Expression<Func<TEntity, object?>> propertyExpression, SocketDataPropertyConverterAttribute attribute)
3844
{
3945
if (propertyExpression.Body is MemberExpression memberExpression)
4046
{
41-
if(attribute.Type == null)
47+
if (attribute.Type == null)
4248
{
4349
attribute.Type = memberExpression.Type;
4450
}

test/UnitTest/Services/SocketDataConverterCollectionsTest.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,21 @@ protected override void ConfigureConfiguration(IServiceCollection services)
1616

1717
services.ConfigureSocketDataConverters(options =>
1818
{
19-
options.AddOrUpdateTypeConverter(new SocketDataConverter<MockEntity>());
20-
options.AddOrUpdatePropertyConverter<MockEntity>(entity => entity.Header, new SocketDataPropertyConverterAttribute()
19+
options.AddTypeConverter<MockEntity>();
20+
options.AddPropertyConverter<MockEntity>(entity => entity.Header, new SocketDataPropertyConverterAttribute()
2121
{
2222
Offset = 0,
2323
Length = 5
2424
});
25-
options.AddOrUpdatePropertyConverter<MockEntity>(entity => entity.Body, new SocketDataPropertyConverterAttribute()
25+
options.AddPropertyConverter<MockEntity>(entity => entity.Body, new SocketDataPropertyConverterAttribute()
2626
{
2727
Offset = 5,
2828
Length = 2
2929
});
3030

3131
// 为提高代码覆盖率 重复添加转换器以后面的为准
32-
options.AddOrUpdateTypeConverter(new SocketDataConverter<MockEntity>());
33-
options.AddOrUpdatePropertyConverter<MockEntity>(entity => entity.Header, new SocketDataPropertyConverterAttribute()
32+
options.AddTypeConverter<MockEntity>();
33+
options.AddPropertyConverter<MockEntity>(entity => entity.Header, new SocketDataPropertyConverterAttribute()
3434
{
3535
Offset = 0,
3636
Length = 5

0 commit comments

Comments
 (0)