Skip to content

Commit 66521bd

Browse files
ArgoZhangeramosr16
andcommitted
refactor: 重构代码
Co-Authored-By: Ernesto Ramos Rio <[email protected]>
1 parent 205833a commit 66521bd

File tree

1 file changed

+25
-21
lines changed

1 file changed

+25
-21
lines changed

src/BootstrapBlazor/Extensions/ITableColumnExtensions.cs

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ public static RenderFragment RenderValue<TItem>(this ITableColumn col, TItem ite
184184
var val = col.GetItemValue(item);
185185
if (col.IsLookup() && val != null)
186186
{
187-
builder.AddContent(10, col.RenderTooltip(val.ToString(), item));
187+
builder.AddContent(10, col.RenderLookupContent(val.ToString(), item));
188188
}
189189
else if (val is bool v1)
190190
{
@@ -220,7 +220,7 @@ public static RenderFragment RenderValue<TItem>(this ITableColumn col, TItem ite
220220
{
221221
content = val?.ToString();
222222
}
223-
builder.AddContent(30, col.RenderTooltip(content, item));
223+
builder.AddContent(30, col.RenderLookupContent(content, item));
224224
}
225225
}
226226
};
@@ -245,35 +245,39 @@ internal static RenderFragment RenderColor<TItem>(this ITableColumn col, TItem i
245245
builder.CloseElement();
246246
};
247247

248-
private static RenderFragment RenderTooltip<TItem>(this ITableColumn col, string? text, TItem item) => pb =>
248+
private static RenderFragment RenderLookupContent<TItem>(this ITableColumn col, string? text, TItem item) => pb =>
249249
{
250250
if (col.GetShowTips())
251251
{
252-
pb.OpenComponent<Tooltip>(0);
253-
pb.SetKey(item);
254-
var tooltipText = text;
255-
if (col.GetTooltipTextCallback != null)
256-
{
257-
pb.AddAttribute(10, nameof(Tooltip.GetTitleCallback), new Func<Task<string?>>(() => col.GetTooltipTextCallback(item)));
258-
}
259-
else
260-
{
261-
pb.AddAttribute(11, nameof(Tooltip.Title), tooltipText);
262-
}
263-
pb.AddAttribute(12, "class", "text-truncate d-block");
264-
if (col.IsMarkupString)
265-
{
266-
pb.AddAttribute(13, nameof(Tooltip.IsHtml), true);
267-
}
268-
pb.AddAttribute(14, nameof(Tooltip.ChildContent), col.RenderContent(text));
269-
pb.CloseComponent();
252+
pb.AddContent(10, col.RenderTooltip(text, item));
270253
}
271254
else
272255
{
273256
pb.AddContent(20, col.RenderContent(text));
274257
}
275258
};
276259

260+
private static RenderFragment RenderTooltip<TItem>(this ITableColumn col, string? text, TItem item) => pb =>
261+
{
262+
pb.OpenComponent<Tooltip>(0);
263+
pb.SetKey(item);
264+
if (col.GetTooltipTextCallback != null)
265+
{
266+
pb.AddAttribute(10, nameof(Tooltip.GetTitleCallback), new Func<Task<string?>>(() => col.GetTooltipTextCallback(item)));
267+
}
268+
else
269+
{
270+
pb.AddAttribute(11, nameof(Tooltip.Title), text);
271+
}
272+
if (col.IsMarkupString)
273+
{
274+
pb.AddAttribute(12, nameof(Tooltip.IsHtml), true);
275+
}
276+
pb.AddAttribute(13, "class", "text-truncate d-block");
277+
pb.AddAttribute(14, nameof(Tooltip.ChildContent), col.RenderContent(text));
278+
pb.CloseComponent();
279+
};
280+
277281
private static RenderFragment RenderContent(this ITableColumn col, string? text) => pb =>
278282
{
279283
if (col.IsLookup())

0 commit comments

Comments
 (0)