Skip to content

Commit 205833a

Browse files
ArgoZhangeramosr16
andcommitted
refactor: 精简参数
Co-Authored-By: Ernesto Ramos Rio <[email protected]>
1 parent b46eb35 commit 205833a

File tree

2 files changed

+25
-29
lines changed

2 files changed

+25
-29
lines changed

src/BootstrapBlazor/Components/Table/Table.razor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1296,7 +1296,7 @@ protected RenderFragment GetValue(ITableColumn col, TItem item) => builder =>
12961296
}
12971297
else
12981298
{
1299-
builder.AddContent(20, col.RenderValue(item, LookupService));
1299+
builder.AddContent(20, col.RenderValue(item));
13001300
}
13011301
};
13021302
#endregion

src/BootstrapBlazor/Extensions/ITableColumnExtensions.cs

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -178,14 +178,13 @@ public static List<IFilterAction> ToSearches(this IEnumerable<ITableColumn> colu
178178
/// <typeparam name="TItem"></typeparam>
179179
/// <param name="col"></param>
180180
/// <param name="item"></param>
181-
/// <param name="lookupService"></param>
182181
/// <returns></returns>
183-
public static RenderFragment RenderValue<TItem>(this ITableColumn col, TItem item, ILookupService lookupService) => builder =>
182+
public static RenderFragment RenderValue<TItem>(this ITableColumn col, TItem item) => builder =>
184183
{
185184
var val = col.GetItemValue(item);
186185
if (col.IsLookup() && val != null)
187186
{
188-
builder.AddContent(10, col.RenderTooltip(val.ToString(), item, lookupService));
187+
builder.AddContent(10, col.RenderTooltip(val.ToString(), item));
189188
}
190189
else if (val is bool v1)
191190
{
@@ -221,7 +220,7 @@ public static RenderFragment RenderValue<TItem>(this ITableColumn col, TItem ite
221220
{
222221
content = val?.ToString();
223222
}
224-
builder.AddContent(30, col.RenderTooltip(content, item, lookupService));
223+
builder.AddContent(30, col.RenderTooltip(content, item));
225224
}
226225
}
227226
};
@@ -246,7 +245,7 @@ internal static RenderFragment RenderColor<TItem>(this ITableColumn col, TItem i
246245
builder.CloseElement();
247246
};
248247

249-
private static RenderFragment RenderTooltip<TItem>(this ITableColumn col, string? text, TItem item, ILookupService lookupService) => pb =>
248+
private static RenderFragment RenderTooltip<TItem>(this ITableColumn col, string? text, TItem item) => pb =>
250249
{
251250
if (col.GetShowTips())
252251
{
@@ -257,47 +256,44 @@ private static RenderFragment RenderTooltip<TItem>(this ITableColumn col, string
257256
{
258257
pb.AddAttribute(10, nameof(Tooltip.GetTitleCallback), new Func<Task<string?>>(() => col.GetTooltipTextCallback(item)));
259258
}
260-
else if (col.IsLookup())
261-
{
262-
pb.AddAttribute(10, nameof(Tooltip.GetTitleCallback), new Func<Task<string?>>(async () =>
263-
{
264-
var lookup = col.Lookup ?? await col.GetLookupService(lookupService).GetItemsAsync(col.LookupServiceKey, col.LookupServiceData);
265-
return lookup?.FirstOrDefault(l => string.Equals(l.Value, text, col.LookupStringComparison))?.Text ?? text;
266-
}));
267-
}
268259
else
269260
{
270261
pb.AddAttribute(11, nameof(Tooltip.Title), tooltipText);
271262
}
272263
pb.AddAttribute(12, "class", "text-truncate d-block");
273264
if (col.IsMarkupString)
274265
{
275-
pb.AddAttribute(13, nameof(Tooltip.ChildContent), new RenderFragment(builder => builder.AddMarkupContent(0, text)));
276-
pb.AddAttribute(14, nameof(Tooltip.IsHtml), true);
277-
}
278-
else
279-
{
280-
pb.AddAttribute(15, nameof(Tooltip.ChildContent), new RenderFragment(builder => builder.AddContent(0, text)));
266+
pb.AddAttribute(13, nameof(Tooltip.IsHtml), true);
281267
}
268+
pb.AddAttribute(14, nameof(Tooltip.ChildContent), col.RenderContent(text));
282269
pb.CloseComponent();
283270
}
284-
else if (col.IsLookup())
271+
else
272+
{
273+
pb.AddContent(20, col.RenderContent(text));
274+
}
275+
};
276+
277+
private static RenderFragment RenderContent(this ITableColumn col, string? text) => pb =>
278+
{
279+
if (col.IsLookup())
285280
{
286-
pb.OpenComponent<LookupContent>(20);
287-
pb.AddAttribute(21, nameof(LookupContent.LookupService), col.LookupService);
288-
pb.AddAttribute(22, nameof(LookupContent.LookupServiceKey), col.LookupServiceKey);
289-
pb.AddAttribute(23, nameof(LookupContent.LookupServiceData), col.LookupServiceData);
290-
pb.AddAttribute(24, nameof(LookupContent.LookupStringComparison), col.LookupStringComparison);
291-
pb.AddAttribute(25, nameof(LookupContent.Value), text);
281+
pb.OpenComponent<LookupContent>(100);
282+
pb.AddAttribute(101, nameof(LookupContent.LookupService), col.LookupService);
283+
pb.AddAttribute(102, nameof(LookupContent.LookupServiceKey), col.LookupServiceKey);
284+
pb.AddAttribute(103, nameof(LookupContent.LookupServiceData), col.LookupServiceData);
285+
pb.AddAttribute(104, nameof(LookupContent.LookupStringComparison), col.LookupStringComparison);
286+
pb.AddAttribute(105, nameof(LookupContent.Lookup), col.Lookup);
287+
pb.AddAttribute(106, nameof(LookupContent.Value), text);
292288
pb.CloseComponent();
293289
}
294290
else if (col.IsMarkupString)
295291
{
296-
pb.AddMarkupContent(30, text);
292+
pb.AddMarkupContent(110, text);
297293
}
298294
else
299295
{
300-
pb.AddContent(40, text);
296+
pb.AddContent(120, text);
301297
}
302298
};
303299

0 commit comments

Comments
 (0)