Skip to content

Commit 0c441f0

Browse files
committed
feat: 增加 GetTitleCallback 参数
1 parent 00d6f83 commit 0c441f0

File tree

3 files changed

+37
-13
lines changed

3 files changed

+37
-13
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@ private Task<QueryData<Foo>> OnQueryAsync(QueryPageOptions options)
3838
return Task.FromResult(new QueryData<Foo>() { Items = items, TotalCount = total, IsSorted = true, IsFiltered = true, IsSearch = true });
3939
}
4040

41-
private async Task<string?> GetTooltipTextCallback(object? v)
41+
private static async Task<string?> GetTooltipTextCallback(object? v)
4242
{
43-
await Task.Delay(0);
43+
await Task.Delay(5);
4444

4545
var ret = string.Empty;
4646
if (v is Foo foo)
4747
{
48-
ret = $"{foo.Name}-{DateTime.Now}";
48+
ret = $"{foo.Name}-{foo.Address}";
4949
}
5050
return ret;
5151
}

src/BootstrapBlazor/Components/Tooltip/Tooltip.razor.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ public partial class Tooltip : ITooltip
5555
[Parameter]
5656
public string? Title { get; set; }
5757

58+
/// <summary>
59+
/// 获得/设置 获得显示内容异步回调方法 默认 null
60+
/// </summary>
61+
[Parameter]
62+
public Func<Task<string>>? GetTitleCallback { get; set; }
63+
5864
/// <summary>
5965
/// 获得/设置 显示文字是否为 Html 默认为 false
6066
/// </summary>
@@ -119,6 +125,20 @@ protected override void OnParametersSet()
119125
Trigger ??= "focus hover";
120126
}
121127

128+
/// <summary>
129+
/// <inheritdoc/>
130+
/// </summary>
131+
/// <returns></returns>
132+
protected override async Task OnParametersSetAsync()
133+
{
134+
await base.OnParametersSetAsync();
135+
136+
if (string.IsNullOrEmpty(Title) && GetTitleCallback != null)
137+
{
138+
Title ??= await GetTitleCallback();
139+
}
140+
}
141+
122142
/// <summary>
123143
/// 设置参数方法
124144
/// </summary>

src/BootstrapBlazor/Extensions/ITableColumnExtensions.cs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -238,36 +238,40 @@ internal static RenderFragment RenderColor<TItem>(this ITableColumn col, TItem i
238238
builder.CloseElement();
239239
};
240240

241-
private static RenderFragment RenderTooltip<TItem>(this ITableColumn col, string? text, TItem item) => async pb =>
241+
private static RenderFragment RenderTooltip<TItem>(this ITableColumn col, string? text, TItem item) => pb =>
242242
{
243243
if (col.GetShowTips())
244244
{
245+
pb.OpenComponent<Tooltip>(0);
246+
pb.SetKey(item);
245247
var tooltipText = text;
246248
if (col.GetTooltipTextCallback != null)
247249
{
248-
tooltipText = await col.GetTooltipTextCallback(item);
250+
pb.AddAttribute(10, nameof(Tooltip.GetTitleCallback), new Func<Task<string?>>(() => col.GetTooltipTextCallback(item)));
249251
}
250-
pb.OpenComponent<Tooltip>(0);
251-
pb.AddAttribute(1, nameof(Tooltip.Title), tooltipText);
252-
pb.AddAttribute(2, "class", "text-truncate d-block");
252+
else
253+
{
254+
pb.AddAttribute(11, nameof(Tooltip.Title), tooltipText);
255+
}
256+
pb.AddAttribute(12, "class", "text-truncate d-block");
253257
if (col.IsMarkupString)
254258
{
255-
pb.AddAttribute(3, nameof(Tooltip.ChildContent), new RenderFragment(builder => builder.AddMarkupContent(0, text)));
256-
pb.AddAttribute(4, nameof(Tooltip.IsHtml), true);
259+
pb.AddAttribute(13, nameof(Tooltip.ChildContent), new RenderFragment(builder => builder.AddMarkupContent(0, text)));
260+
pb.AddAttribute(14, nameof(Tooltip.IsHtml), true);
257261
}
258262
else
259263
{
260-
pb.AddAttribute(3, nameof(Tooltip.ChildContent), new RenderFragment(builder => builder.AddContent(0, text)));
264+
pb.AddAttribute(15, nameof(Tooltip.ChildContent), new RenderFragment(builder => builder.AddContent(0, text)));
261265
}
262266
pb.CloseComponent();
263267
}
264268
else if (col.IsMarkupString)
265269
{
266-
pb.AddMarkupContent(3, text);
270+
pb.AddMarkupContent(20, text);
267271
}
268272
else
269273
{
270-
pb.AddContent(4, text);
274+
pb.AddContent(30, text);
271275
}
272276
};
273277

0 commit comments

Comments
 (0)