Skip to content

Commit 7bc48d2

Browse files
committed
refactor: 重构自动判定列宽逻辑
1 parent 9d2f789 commit 7bc48d2

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

src/BootstrapBlazor/Components/EditorForm/EditorForm.razor.cs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,15 @@ public partial class EditorForm<TModel> : IShowLabel
2727
/// <returns></returns>
2828
private string? GetCssString(IEditorItem item)
2929
{
30-
int cols = 0;
30+
int cols = Math.Max(0, Math.Min(12, item.Cols));
3131
double mdCols = 6;
32-
if (item is AutoGenerateColumnAttribute a && a.Cols > 0 && a.Cols < 13)
33-
{
34-
cols = a.Cols;
35-
}
3632
if (ItemsPerRow.HasValue)
3733
{
38-
mdCols = Math.Min(12, Math.Ceiling(12d / ItemsPerRow.Value));
34+
mdCols = Math.Max(0, Math.Min(12, Math.Ceiling(12d / ItemsPerRow.Value)));
3935
}
4036
return CssBuilder.Default("col-12")
4137
.AddClass($"col-sm-{cols}", cols > 0) // 指定 Cols
42-
.AddClass($"col-sm-6 col-md-{mdCols}", mdCols < 12 && cols == 0 && item.Items == null && item.Rows == 0) // 指定 ItemsPerRow
38+
.AddClass($"col-sm-6 col-md-{mdCols}", mdCols > 0 && cols == 0 && item.Rows == 0 && !Utility.IsCheckboxList(item.PropertyType, item.ComponentType)) // 指定 ItemsPerRow
4339
.Build();
4440
}
4541

0 commit comments

Comments
 (0)