diff --git a/src/BootstrapBlazor.Server/Components/Samples/Table/Tables.razor.cs b/src/BootstrapBlazor.Server/Components/Samples/Table/Tables.razor.cs index c5ecf2d73a7..84af0b06ea6 100644 --- a/src/BootstrapBlazor.Server/Components/Samples/Table/Tables.razor.cs +++ b/src/BootstrapBlazor.Server/Components/Samples/Table/Tables.razor.cs @@ -38,8 +38,8 @@ private void OnClick() Items = Foo.GenerateFoo(FooLocalizer); } - private IEnumerable GetTableColumnAttributes() => new AttributeItem[] - { + private AttributeItem[] GetTableColumnAttributes() => + [ new() { Name = "TextWrap", @@ -113,22 +113,6 @@ private void OnClick() DefaultValue = " — " }, new() - { - Name = nameof(IEditorItem.IsReadonlyWhenAdd), - Description = Localizer["IsReadonlyWhenAddAttr"], - Type = "boolean", - ValueList = "true|false", - DefaultValue = "false" - }, - new() - { - Name = nameof(IEditorItem.IsReadonlyWhenEdit), - Description = Localizer["IsReadonlyWhenEditAttr"], - Type = "boolean", - ValueList = "true|false", - DefaultValue = "false" - }, - new() { Name = nameof(IEditorItem.Lookup), Description = Localizer["LookupAttr"], @@ -169,6 +153,22 @@ private void OnClick() DefaultValue = "false" }, new() + { + Name = nameof(IEditorItem.IsReadonlyWhenAdd), + Description = Localizer["IsReadonlyWhenAddAttr"], + Type = "boolean", + ValueList = "true|false", + DefaultValue = "false" + }, + new() + { + Name = nameof(IEditorItem.IsReadonlyWhenEdit), + Description = Localizer["IsReadonlyWhenEditAttr"], + Type = "boolean", + ValueList = "true|false", + DefaultValue = "false" + }, + new() { Name = "SearchTemplate", Description = Localizer["SearchTemplateColumnAttr"], @@ -257,6 +257,22 @@ private void OnClick() DefaultValue = "true" }, new() + { + Name = "IsVisibleWhenAdd", + Description = Localizer["IsVisibleWhenAddAttr"], + Type = "boolean", + ValueList = "true|false", + DefaultValue = "true" + }, + new() + { + Name = "IsVisibleWhenEdit", + Description = Localizer["IsVisibleWhenEditAttr"], + Type = "boolean", + ValueList = "true|false", + DefaultValue = "true" + }, + new() { Name = "Width", Description = Localizer["WidthAttr"], @@ -344,7 +360,7 @@ private void OnClick() ValueList = "true/false", DefaultValue = "false" } - }; + ]; private AttributeItem[] GetAttributes() => [ diff --git a/src/BootstrapBlazor.Server/Components/Samples/Table/TablesEdit.razor b/src/BootstrapBlazor.Server/Components/Samples/Table/TablesEdit.razor index 30cb354c525..256f15c57fe 100644 --- a/src/BootstrapBlazor.Server/Components/Samples/Table/TablesEdit.razor +++ b/src/BootstrapBlazor.Server/Components/Samples/Table/TablesEdit.razor @@ -7,9 +7,7 @@

@Localizer["TablesEditTitle"]

@((MarkupString)Localizer["TablesEditDescription"].Value)

- +
@((MarkupString)Localizer["TablesEditItemsDescription"].Value)
- + +
+ + + + + + + + +
+
+ +
@((MarkupString)Localizer["TablesEditTemplateDescription"].Value)
- +

@((MarkupString)Localizer["TablesEditOnAddAsyncDescription"].Value)

@((MarkupString)Localizer["TablesEditOnAddAsyncTips1"].Value)

@@ -80,9 +88,7 @@
- +
@((MarkupString)Localizer["TablesColumnEditTemplateDescription1"].Value)
@((MarkupString)Localizer["TablesColumnEditTemplateTips"].Value)
@@ -109,9 +115,7 @@ - +

@((MarkupString)Localizer["TablesEditModeDescription"].Value)

@((MarkupString)Localizer["TablesEditModeTips1"].Value)

@@ -127,10 +131,10 @@ - + - - + + @@ -138,7 +142,6 @@

@((MarkupString)Localizer["TablesEditModeInCell"].Value)

- - + - - + +
- +
@((MarkupString)Localizer["TablesEditInjectDataServiceDescription"].Value)
    @@ -182,9 +183,7 @@ - +
    @Localizer["TablesEditDataServiceDescription"]
    @((MarkupString)Localizer["TablesEditDataServiceTips1"].Value)
    @@ -201,9 +200,7 @@ - +

    @((MarkupString)Localizer["TablesEditFooterTemplateDescription"].Value)

    <EditFooterTemplate Context="model">
    diff --git a/src/BootstrapBlazor.Server/Locales/en-US.json b/src/BootstrapBlazor.Server/Locales/en-US.json
    index dc38908c3e2..793b90b8c86 100644
    --- a/src/BootstrapBlazor.Server/Locales/en-US.json
    +++ b/src/BootstrapBlazor.Server/Locales/en-US.json
    @@ -4823,6 +4823,8 @@
         "TextEllipsisAttr": "Whether to omit text when exceeded",
         "TemplateAttr": "Template",
         "VisibleAttr": "Whether to display this column",
    +    "IsVisibleWhenAddAttr": "Whether to display this column in new item dialog",
    +    "IsVisibleWhenEditAttr": "Whether to display this column in edit item dialog",
         "WidthAttr": "Column width (px)",
         "FixedAttr": "Whether to fix this column",
         "GroupNameAttr": "Current Property Grouping",
    @@ -4998,7 +5000,9 @@
         "TablesEditInjectDataServiceTips1": "Startup file injects data service",
         "TablesEditInjectDataServiceTips2": "Implementation principle and usage introduction",
         "TablesEditInjectDataServiceTips3": "custom data service",
    -    "TablesEditInjectDataServiceTips4": "After enabling the use of the injected data service, you can set the component individually by setting the DataServices parameter, if the instance provided by the internal use of the injected service is not set"
    +    "TablesEditInjectDataServiceTips4": "After enabling the use of the injected data service, you can set the component individually by setting the DataServices parameter, if the instance provided by the internal use of the injected service is not set",
    +    "TablesVisibleNormalTitle": "Editor Visible/Hidden",
    +    "TablesVisibleNormalIntro": "If the IsVisibleWhenAdd or IsVisibleWhenEdit property is set to false, hide this column when creating or updating. In this example, the New pop-up window does not display Count Edit Pop up window does not display Complete edit the item"
       },
       "BootstrapBlazor.Server.Components.Samples.Table.TablesVirtualization": {
         "TablesVirtualizationTitle": "Table virtual scroll row",
    diff --git a/src/BootstrapBlazor.Server/Locales/zh-CN.json b/src/BootstrapBlazor.Server/Locales/zh-CN.json
    index 2c45f86d579..1df6cae3c77 100644
    --- a/src/BootstrapBlazor.Server/Locales/zh-CN.json
    +++ b/src/BootstrapBlazor.Server/Locales/zh-CN.json
    @@ -4823,6 +4823,8 @@
         "TextEllipsisAttr": "是否文本超出时省略",
         "TemplateAttr": "模板",
         "VisibleAttr": "是否显示此列",
    +    "IsVisibleWhenAddAttr": "新建时此列是否显示",
    +    "IsVisibleWhenEditAttr": "编辑时此列是否显示",
         "WidthAttr": "列宽度(像素px)",
         "FixedAttr": "是否固定本列",
         "GroupNameAttr": "当前属性分组",
    @@ -4998,7 +5000,9 @@
         "TablesEditInjectDataServiceTips2": "实现原理与用法介绍",
         "TablesEditInjectDataServiceTips3": "自定义数据服务",
         "TablesEditInjectDataServiceTips4": "开启使用注入数据服务后,可通过设置 DataServices 参数对组件进行单独设置,如未设置内部使用注入服务提供的实例",
    -    "TablesEditShowSearchPlaceHolderString": "不可为空,50字以内"
    +    "TablesEditShowSearchPlaceHolderString": "不可为空,50字以内",
    +    "TablesVisibleTitle": "Table 编辑时显示/隐藏",
    +    "TablesVisibleIntro": "
    Visible 默认值为 true 如果有列设置了 IsVisibleWhenAdd 或者 IsVisibleWhenEdit 属性为 false 时, 新建或者更新时隐藏此列。本例中 新建 弹窗不显示 数量 编辑 弹窗不显示 是否 编辑项。
    可以通过在数据模型中使用 [AutoGenerateClass(Visible = false)] 全部禁止显示,再通过 IsVisibleWhenAdd 或者 IsVisibleWhenEdit 单独设置编辑状态下的可见性,本例中,地址 列默认不可见,新建、编辑 弹窗内均可以编辑
    " }, "BootstrapBlazor.Server.Components.Samples.Table.TablesVirtualization": { "TablesVirtualizationTitle": "Table 虚拟滚动行", diff --git a/src/BootstrapBlazor/Attributes/AutoGenerateBaseAttribute.cs b/src/BootstrapBlazor/Attributes/AutoGenerateBaseAttribute.cs index 7d50adb22d8..3ad36fd70fa 100644 --- a/src/BootstrapBlazor/Attributes/AutoGenerateBaseAttribute.cs +++ b/src/BootstrapBlazor/Attributes/AutoGenerateBaseAttribute.cs @@ -5,7 +5,7 @@ namespace BootstrapBlazor.Components; /// -/// +/// AutoGenerateColumn 标签基类,用于 标识自动生成列 /// public abstract class AutoGenerateBaseAttribute : Attribute { @@ -15,10 +15,15 @@ public abstract class AutoGenerateBaseAttribute : Attribute public bool Editable { get; set; } = true; /// - /// 获得/设置 当前列编辑时是否只读 默认为 false + /// 获得/设置 当前编辑项是否只读 默认为 false /// public bool Readonly { get; set; } + /// + /// 获得/设置 当前编辑项是否显示 默认为 true + /// + public bool Visible { get; set; } = true; + /// /// 获得/设置 是否允许排序 默认为 false /// diff --git a/src/BootstrapBlazor/Attributes/AutoGenerateClassAttribute.cs b/src/BootstrapBlazor/Attributes/AutoGenerateClassAttribute.cs index 1d506edfffd..9c5ae4a7d75 100644 --- a/src/BootstrapBlazor/Attributes/AutoGenerateClassAttribute.cs +++ b/src/BootstrapBlazor/Attributes/AutoGenerateClassAttribute.cs @@ -5,7 +5,7 @@ namespace BootstrapBlazor.Components; /// -/// +/// AutoGenerateColumn 标签类,用于 标识自动生成列 /// [AttributeUsage(AttributeTargets.Class)] public class AutoGenerateClassAttribute : AutoGenerateBaseAttribute diff --git a/src/BootstrapBlazor/Attributes/AutoGenerateColumnAttribute.cs b/src/BootstrapBlazor/Attributes/AutoGenerateColumnAttribute.cs index 68ed2be9717..9e53d49f9f8 100644 --- a/src/BootstrapBlazor/Attributes/AutoGenerateColumnAttribute.cs +++ b/src/BootstrapBlazor/Attributes/AutoGenerateColumnAttribute.cs @@ -37,15 +37,25 @@ public class AutoGenerateColumnAttribute : AutoGenerateBaseAttribute, ITableColu public bool SkipValidate { get; set; } /// - /// 获得/设置 新建时此列只读 默认为 false + /// /// public bool IsReadonlyWhenAdd { get; set; } /// - /// 获得/设置 编辑时此列只读 默认为 false + /// /// public bool IsReadonlyWhenEdit { get; set; } + /// + /// + /// + public bool IsVisibleWhenAdd { get; set; } = true; + + /// + /// + /// + public bool IsVisibleWhenEdit { get; set; } = true; + /// /// 获得/设置 是否显示标签 Tooltip 多用于标签文字过长导致裁减时使用 默认 false /// @@ -80,11 +90,6 @@ public class AutoGenerateColumnAttribute : AutoGenerateBaseAttribute, ITableColu /// public bool Fixed { get; set; } - /// - /// 获得/设置 列是否显示 默认为 true 可见的 - /// - public bool Visible { get; set; } = true; - /// /// 获得/设置 列 td 自定义样式 默认为 null 未设置 /// diff --git a/src/BootstrapBlazor/Components/EditorForm/EditorForm.razor b/src/BootstrapBlazor/Components/EditorForm/EditorForm.razor index c9ffb3da0e4..507bc849f96 100644 --- a/src/BootstrapBlazor/Components/EditorForm/EditorForm.razor +++ b/src/BootstrapBlazor/Components/EditorForm/EditorForm.razor @@ -5,7 +5,7 @@ @FieldItems?.Invoke(Model) -@if (FirstRender) +@if (_firstRender) {
    diff --git a/src/BootstrapBlazor/Components/EditorForm/EditorForm.razor.cs b/src/BootstrapBlazor/Components/EditorForm/EditorForm.razor.cs index 55cf838f807..6d9641877e3 100644 --- a/src/BootstrapBlazor/Components/EditorForm/EditorForm.razor.cs +++ b/src/BootstrapBlazor/Components/EditorForm/EditorForm.razor.cs @@ -188,10 +188,10 @@ public partial class EditorForm : IShowLabel /// private readonly List _formItems = []; - private IEnumerable UnsetGroupItems => _formItems.Where(i => string.IsNullOrEmpty(i.GroupName)); + private IEnumerable UnsetGroupItems => _formItems.Where(i => string.IsNullOrEmpty(i.GroupName) && i.IsVisible(ItemChangedType, IsSearch.Value)); private IEnumerable>> GroupItems => _formItems - .Where(i => !string.IsNullOrEmpty(i.GroupName)) + .Where(i => !string.IsNullOrEmpty(i.GroupName) && i.IsVisible(ItemChangedType, IsSearch.Value)) .GroupBy(i => i.GroupOrder).OrderBy(i => i.Key) .Select(i => new KeyValuePair>(i.First().GroupName!, i.OrderBy(x => x.Order))); @@ -230,10 +230,7 @@ protected override void OnParametersSet() ShowLabel ??= ValidateForm?.ShowLabel; } - /// - /// - /// - private bool FirstRender { get; set; } = true; + private bool _firstRender = true; /// /// OnAfterRenderAsync 方法 @@ -246,11 +243,10 @@ protected override async Task OnAfterRenderAsync(bool firstRender) if (firstRender) { - FirstRender = false; + _firstRender = false; if (Items != null) { - // 通过级联参数渲染组件 _formItems.AddRange(Items); } else @@ -267,8 +263,8 @@ protected override async Task OnAfterRenderAsync(bool firstRender) var item = items.FirstOrDefault(i => i.GetFieldName() == el.GetFieldName()); if (item != null) { - // 过滤掉不编辑的列 - if (!el.Editable) + // 过滤掉不编辑与不可见的列 + if (!el.Editable || !el.IsVisible(ItemChangedType, IsSearch.Value)) { items.Remove(item); } @@ -280,11 +276,11 @@ protected override async Task OnAfterRenderAsync(bool firstRender) } } } - _formItems.AddRange(items.Where(i => i.Editable)); + _formItems.AddRange(items); } else { - _formItems.AddRange(_editorItems.Where(i => i.Editable)); + _formItems.AddRange(_editorItems.Where(i => i.Editable && i.IsVisible(ItemChangedType, IsSearch.Value))); } } StateHasChanged(); diff --git a/src/BootstrapBlazor/Components/EditorForm/EditorItem.cs b/src/BootstrapBlazor/Components/EditorForm/EditorItem.cs index dc0d7c4878d..3ced0d3ee34 100644 --- a/src/BootstrapBlazor/Components/EditorForm/EditorItem.cs +++ b/src/BootstrapBlazor/Components/EditorForm/EditorItem.cs @@ -48,22 +48,41 @@ public class EditorItem : ComponentBase, IEditorItem public bool Editable { get; set; } = true; /// - /// 获得/设置 当前列编辑时是否为只读模式 默认为 false + /// > /// - /// 此属性覆盖 即新建与编辑时均只读 [Parameter] public bool Readonly { get; set; } /// - /// 获得/设置 新建时此列只读 默认为 false + /// > /// + [Parameter] public bool IsReadonlyWhenAdd { get; set; } /// - /// 获得/设置 编辑时此列只读 默认为 false + /// > /// + [Parameter] public bool IsReadonlyWhenEdit { get; set; } + /// + /// > + /// + [Parameter] + public bool Visible { get; set; } = true; + + /// + /// > + /// + [Parameter] + public bool IsVisibleWhenAdd { get; set; } = true; + + /// + /// > + /// + [Parameter] + public bool IsVisibleWhenEdit { get; set; } = true; + /// /// 获得/设置 是否不进行验证 默认为 false /// diff --git a/src/BootstrapBlazor/Components/EditorForm/IEditorItem.cs b/src/BootstrapBlazor/Components/EditorForm/IEditorItem.cs index 6b252b5cf71..cdff849ba6d 100644 --- a/src/BootstrapBlazor/Components/EditorForm/IEditorItem.cs +++ b/src/BootstrapBlazor/Components/EditorForm/IEditorItem.cs @@ -20,21 +20,43 @@ public interface IEditorItem bool Editable { get; set; } /// - /// 获得/设置 当前列编辑时是否只读 默认为 false 自动生成 UI 为不可编辑 div + /// 获得/设置 当前编辑项是否只读 默认为 false + /// 新建与编辑时可单独设置 /// - /// 此属性覆盖 即新建与编辑时均只读 + /// 设置 值为 true 时, 值被覆盖 bool Readonly { get; set; } /// /// 获得/设置 新建时此列只读 默认为 false /// + /// 设置 值为 true 时, 值被覆盖 bool IsReadonlyWhenAdd { get; set; } /// /// 获得/设置 编辑时此列只读 默认为 false /// + /// 设置 值为 true 时, 值被覆盖 bool IsReadonlyWhenEdit { get; set; } + /// + /// 获得/设置 当前编辑项是否显示 默认为 true + /// 新建与编辑时可单独设置 + /// 设置 值为 false 时, 值被覆盖 + /// + bool Visible { get; set; } + + /// + /// 获得/设置 新建时是否此列显示 默认为 true + /// + /// 设置 值为 false 时, 值被覆盖 + bool IsVisibleWhenAdd { get; set; } + + /// + /// 获得/设置 编辑时是否此列显示 默认为 true + /// + /// 设置 值为 false 时, 值被覆盖 + bool IsVisibleWhenEdit { get; set; } + /// /// 获得/设置 是否不进行验证 默认为 false /// diff --git a/src/BootstrapBlazor/Components/Table/ITableColumn.cs b/src/BootstrapBlazor/Components/Table/ITableColumn.cs index 44b0fee6495..a14aca0c6ba 100644 --- a/src/BootstrapBlazor/Components/Table/ITableColumn.cs +++ b/src/BootstrapBlazor/Components/Table/ITableColumn.cs @@ -44,11 +44,6 @@ public interface ITableColumn : IEditorItem /// bool Fixed { get; set; } - /// - /// 获得/设置 列是否显示 默认为 true 可见的 - /// - bool Visible { get; set; } - /// /// 获得/设置 本列是否允许换行 默认为 false /// diff --git a/src/BootstrapBlazor/Components/Table/InternalTableColumn.cs b/src/BootstrapBlazor/Components/Table/InternalTableColumn.cs index 0e3909f4638..e8f0d56ae19 100644 --- a/src/BootstrapBlazor/Components/Table/InternalTableColumn.cs +++ b/src/BootstrapBlazor/Components/Table/InternalTableColumn.cs @@ -28,8 +28,6 @@ class InternalTableColumn(string fieldName, Type fieldType, string? fieldText = public bool Fixed { get; set; } - public bool Visible { get; set; } = true; - public bool TextWrap { get; set; } public bool TextEllipsis { get; set; } @@ -40,15 +38,35 @@ class InternalTableColumn(string fieldName, Type fieldType, string? fieldText = public bool SkipValidate { get; set; } /// - /// 获得/设置 新建时此列只读 默认为 false + /// + /// + public bool Readonly { get; set; } + + /// + /// /// public bool IsReadonlyWhenAdd { get; set; } /// - /// 获得/设置 编辑时此列只读 默认为 false + /// /// public bool IsReadonlyWhenEdit { get; set; } + /// + /// + /// + public bool Visible { get; set; } = true; + + /// + /// + /// + public bool IsVisibleWhenAdd { get; set; } = true; + + /// + /// + /// + public bool IsVisibleWhenEdit { get; set; } = true; + /// /// 获得/设置 是否显示标签 Tooltip 多用于标签文字过长导致裁减时使用 默认 null /// @@ -88,8 +106,6 @@ class InternalTableColumn(string fieldName, Type fieldType, string? fieldText = public bool Editable { get; set; } = true; - public bool Readonly { get; set; } - public string? Step { get; set; } public int Rows { get; set; } diff --git a/src/BootstrapBlazor/Components/Table/Table.razor b/src/BootstrapBlazor/Components/Table/Table.razor index 4f803c922e3..41c7af1e638 100644 --- a/src/BootstrapBlazor/Components/Table/Table.razor +++ b/src/BootstrapBlazor/Components/Table/Table.razor @@ -645,7 +645,7 @@ @{ var index = 0; var colIndex = 0; - var isInCell = EditInCell && SelectedRows.FirstOrDefault() == item; + var isInCell = InCellMode && SelectedRows.FirstOrDefault() == item; } @if (ShowExtendButtons && IsExtendButtonsInRowHeader) { @@ -707,7 +707,7 @@ } else if(isInCell) { - @RenderCell(col, EditModel, ItemChangedType.Update) + @RenderCell(col, EditModel, AddInCell ? ItemChangedType.Add : ItemChangedType.Update) } else { @@ -781,7 +781,7 @@ else { - +
    @if(!IsTracking) @@ -849,7 +849,7 @@
    @{ - var isInCell = EditInCell && SelectedRows.FirstOrDefault() == item; + var isInCell = InCellMode && SelectedRows.FirstOrDefault() == item; } @if (!isInCell) { diff --git a/src/BootstrapBlazor/Components/Table/Table.razor.Toolbar.cs b/src/BootstrapBlazor/Components/Table/Table.razor.Toolbar.cs index b7a3dfa2c73..769032f3c79 100644 --- a/src/BootstrapBlazor/Components/Table/Table.razor.Toolbar.cs +++ b/src/BootstrapBlazor/Components/Table/Table.razor.Toolbar.cs @@ -442,6 +442,8 @@ public IEnumerable GetVisibleColumns() private bool AddInCell { get; set; } + private bool InCellMode => AddInCell || EditInCell; + /// /// 新建按钮方法 /// @@ -473,7 +475,7 @@ async Task AddItemAsync() else if (EditMode == EditMode.InCell) { AddInCell = true; - EditInCell = true; + EditInCell = false; SelectedRows.Add(EditModel); } await OnSelectedRowsChanged(); diff --git a/src/BootstrapBlazor/Components/Table/Table.razor.scss b/src/BootstrapBlazor/Components/Table/Table.razor.scss index ab5e14630e4..134b06b1089 100644 --- a/src/BootstrapBlazor/Components/Table/Table.razor.scss +++ b/src/BootstrapBlazor/Components/Table/Table.razor.scss @@ -431,12 +431,13 @@ tr.active:not(.is-edit):hover { .table-row .table-cell label:not(.form-check) { font-weight: bold; - width: var(--bb-table-cardview-label-width); margin-bottom: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-right: 6px; + flex-basis: var(--bb-table-cardview-label-width); + flex-shrink: 0; } .table-row .table-cell > span { diff --git a/src/BootstrapBlazor/Components/Table/TableColumn.cs b/src/BootstrapBlazor/Components/Table/TableColumn.cs index faa0389f3d9..ed83b6312da 100644 --- a/src/BootstrapBlazor/Components/Table/TableColumn.cs +++ b/src/BootstrapBlazor/Components/Table/TableColumn.cs @@ -148,24 +148,41 @@ public class TableColumn : BootstrapComponentBase, ITableColumn public bool Editable { get; set; } = true; /// - /// 获得/设置 当前列编辑时是否为只读模式 默认为 false + /// /// - /// 此属性覆盖 即新建与编辑时均只读 [Parameter] public bool Readonly { get; set; } /// - /// 获得/设置 新建时此列只读 默认为 false + /// /// [Parameter] public bool IsReadonlyWhenAdd { get; set; } /// - /// 获得/设置 编辑时此列只读 默认为 false + /// /// [Parameter] public bool IsReadonlyWhenEdit { get; set; } + /// + /// + /// + [Parameter] + public bool Visible { get; set; } = true; + + /// + /// + /// + [Parameter] + public bool IsVisibleWhenAdd { get; set; } = true; + + /// + /// + /// + [Parameter] + public bool IsVisibleWhenEdit { get; set; } = true; + /// /// 获得/设置 是否不进行验证 默认为 false /// @@ -202,12 +219,6 @@ public class TableColumn : BootstrapComponentBase, ITableColumn [Parameter] public bool ShowCopyColumn { get; set; } - /// - /// 获得/设置 是否显示本列 默认 true 显示 - /// - [Parameter] - public bool Visible { get; set; } = true; - /// /// 获得/设置 字段鼠标悬停提示 /// diff --git a/src/BootstrapBlazor/Extensions/ITableColumnExtensions.cs b/src/BootstrapBlazor/Extensions/ITableColumnExtensions.cs index ea369d7b900..b132aea2b6d 100644 --- a/src/BootstrapBlazor/Extensions/ITableColumnExtensions.cs +++ b/src/BootstrapBlazor/Extensions/ITableColumnExtensions.cs @@ -51,6 +51,9 @@ public static void CopyValue(this ITableColumn dest, IEditorItem source) if (source.IsReadonlyWhenAdd) dest.IsReadonlyWhenAdd = source.IsReadonlyWhenAdd; if (source.IsReadonlyWhenEdit) dest.IsReadonlyWhenEdit = source.IsReadonlyWhenEdit; if (source.Readonly) dest.Readonly = source.Readonly; + if (!source.IsVisibleWhenAdd) dest.IsVisibleWhenAdd = source.IsVisibleWhenAdd; + if (!source.IsVisibleWhenEdit) dest.IsVisibleWhenEdit = source.IsVisibleWhenEdit; + if (source.Visible) dest.Visible = source.Visible; if (source.Rows > 0) dest.Rows = source.Rows; if (source.SkipValidate) dest.SkipValidate = source.SkipValidate; if (!string.IsNullOrEmpty(source.Text)) dest.Text = source.Text; diff --git a/src/BootstrapBlazor/Extensions/ObjectExtensions.cs b/src/BootstrapBlazor/Extensions/ObjectExtensions.cs index f67ae793280..46ecb5a86c7 100644 --- a/src/BootstrapBlazor/Extensions/ObjectExtensions.cs +++ b/src/BootstrapBlazor/Extensions/ObjectExtensions.cs @@ -206,12 +206,34 @@ public static bool TryConvertTo(this string? source, [MaybeNullWhen(fals /// /// /// - public static bool IsEditable(this IEditorItem item, ItemChangedType changedType, bool search = false) => item.Editable + public static bool IsEditable(this IEditorItem item, ItemChangedType changedType, bool search = false) => search || item.Editable && !item.Readonly && changedType switch { ItemChangedType.Add => !item.IsReadonlyWhenAdd, _ => !item.IsReadonlyWhenEdit - } || search; + }; + + /// + /// 判断当前 IEditorItem 实例是否显示 + /// + /// + /// + /// + /// + public static bool IsVisible(this IEditorItem item, ItemChangedType changedType, bool search = false) => search || item.Editable + && (IsVisible(item, changedType) || IsRevertVisible(item, changedType)); + + private static bool IsVisible(IEditorItem item, ItemChangedType changedType) => item.Visible && changedType switch + { + ItemChangedType.Add => item.IsVisibleWhenAdd, + _ => item.IsVisibleWhenEdit + }; + + private static bool IsRevertVisible(IEditorItem item, ItemChangedType changedType) => !item.Visible || changedType switch + { + ItemChangedType.Add => item.IsVisibleWhenAdd, + _ => item.IsVisibleWhenEdit + }; /// /// 判断当前 IEditorItem 示例是否可以编辑 @@ -221,7 +243,7 @@ public static bool IsEditable(this IEditorItem item, ItemChangedType changedType /// /// /// - public static bool CanWrite(this IEditorItem item, Type modelType, ItemChangedType changedType, bool search = false) => item.CanWrite(modelType) && item.IsEditable(changedType, search); + public static bool CanWrite(this IEditorItem item, Type modelType, ItemChangedType changedType, bool search = false) => item.CanWrite(modelType) && item.IsEditable(changedType, search) && item.IsVisible(changedType, search); /// /// 判断模型是否可写 diff --git a/test/UnitTest/Attributes/AutoGenerateClassTest.cs b/test/UnitTest/Attributes/AutoGenerateClassTest.cs index c6b65fe0edf..4eb5d806494 100644 --- a/test/UnitTest/Attributes/AutoGenerateClassTest.cs +++ b/test/UnitTest/Attributes/AutoGenerateClassTest.cs @@ -43,6 +43,8 @@ public void AutoGenerateColumn_Ok() SkipValidate = true, IsReadonlyWhenAdd = true, IsReadonlyWhenEdit = true, + IsVisibleWhenAdd = false, + IsVisibleWhenEdit = false, ShowLabelTooltip = true, DefaultSortOrder = SortOrder.Asc, Width = 10, @@ -73,6 +75,8 @@ public void AutoGenerateColumn_Ok() Assert.True(attr.SkipValidate); Assert.True(attr.IsReadonlyWhenAdd); Assert.True(attr.IsReadonlyWhenEdit); + Assert.False(attr.IsVisibleWhenAdd); + Assert.False(attr.IsVisibleWhenEdit); Assert.True(attr.ShowLabelTooltip); Assert.Equal(SortOrder.Asc, attr.DefaultSortOrder); Assert.Equal(10, attr.Width); @@ -158,5 +162,11 @@ public void AutoGenerateColumn_Ok() // 增加 GetDisplay 单元覆盖率 attr.Text = null; Assert.Equal(string.Empty, attr.GetDisplayName()); + + attrEditor.IsVisibleWhenAdd = false; + Assert.False(attrEditor.IsVisibleWhenAdd); + + attrEditor.IsVisibleWhenEdit = false; + Assert.False(attrEditor.IsVisibleWhenEdit); } } diff --git a/test/UnitTest/Components/EditorFormTest.cs b/test/UnitTest/Components/EditorFormTest.cs index 77a2b0c0123..bc8d1d38317 100644 --- a/test/UnitTest/Components/EditorFormTest.cs +++ b/test/UnitTest/Components/EditorFormTest.cs @@ -213,20 +213,35 @@ public void EditTemplate_Coverage() [Fact] public void IsEditable_Ok() { - var editorItem = new EditorItem() - { - IsReadonlyWhenAdd = true, - IsReadonlyWhenEdit = false - }; + var editorItem = new EditorItem(); editorItem.SetParametersAsync(ParameterView.FromDictionary(new Dictionary { ["Editable"] = true, ["Readonly"] = false, + ["Visible"] = true, + ["IsReadonlyWhenAdd"] = true, + ["IsReadonlyWhenEdit"] = false })); Assert.False(editorItem.IsEditable(ItemChangedType.Add)); Assert.True(editorItem.IsEditable(ItemChangedType.Update)); } + + [Fact] + public void IsVisible_Ok() + { + var editorItem = new EditorItem(); + editorItem.SetParametersAsync(ParameterView.FromDictionary(new Dictionary + { + ["Editable"] = true, + ["Readonly"] = false, + ["IsVisibleWhenAdd"] = true, + ["IsVisibleWhenEdit"] = false + })); + Assert.True(editorItem.IsVisible(ItemChangedType.Add)); + Assert.False(editorItem.IsVisible(ItemChangedType.Update)); + } + [Fact] public void EditorItem_Ok() { @@ -384,7 +399,7 @@ public void ColumnOrderCallback_Ok() var v = itemsField.GetValue(editor) as List; Assert.NotNull(v); - Assert.Equal(new List() { 60, 50, 40, 20, 10, 1 }, v.Select(i => i.Order)); + Assert.Equal(new List() { 70, 60, 50, 40, 20, 10, 1 }, v.Select(i => i.Order)); } [Fact] diff --git a/test/UnitTest/Components/TableTest.cs b/test/UnitTest/Components/TableTest.cs index afe785e5080..eb52277a68e 100644 --- a/test/UnitTest/Components/TableTest.cs +++ b/test/UnitTest/Components/TableTest.cs @@ -2,7 +2,6 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Website: https://www.blazor.zone or https://argozhang.github.io/ -using AngleSharp.Dom; using Microsoft.AspNetCore.Components.Forms; using Microsoft.AspNetCore.Components.Web; using Microsoft.Extensions.DependencyInjection; @@ -114,11 +113,11 @@ public void SelectedRowsChanged_Bind() } [Theory] + [InlineData(InsertRowMode.First, false)] [InlineData(InsertRowMode.First, true)] [InlineData(InsertRowMode.Last, true)] - [InlineData(InsertRowMode.First, false)] [InlineData(InsertRowMode.Last, false)] - public void Items_Add(InsertRowMode insertMode, bool bind) + public async Task Items_Add(InsertRowMode insertMode, bool bind) { var localizer = Context.Services.GetRequiredService>(); var items = Foo.GenerateFoo(localizer, 2); @@ -141,13 +140,14 @@ public void Items_Add(InsertRowMode insertMode, bool bind) }); }); var table = cut.FindComponent>(); - cut.InvokeAsync(() => table.Instance.AddAsync()); + await cut.InvokeAsync(() => table.Instance.AddAsync()); if (insertMode == InsertRowMode.First) { - cut.InvokeAsync(() => + // 保存按钮 + var button = cut.Find("tbody tr button"); + await cut.InvokeAsync(() => { - var button = cut.Find("tbody tr button"); button.Click(); }); if (bind) @@ -163,9 +163,9 @@ public void Items_Add(InsertRowMode insertMode, bool bind) } else if (insertMode == InsertRowMode.Last) { - cut.InvokeAsync(() => + var button = cut.FindAll("tbody tr button").Last(i => i.ClassList.Contains("btn-success")); + await cut.InvokeAsync(() => { - var button = cut.FindAll("tbody tr button").Last(i => i.ClassList.Contains("btn-success")); button.Click(); }); if (bind) @@ -4611,6 +4611,8 @@ public void TableColumn_Property() builder.AddAttribute(28, "GroupOrder", 1); builder.AddAttribute(29, "ShowSearchWhenSelect", true); builder.AddAttribute(30, "IsPopover", false); + builder.AddAttribute(31, "IsVisibleWhenAdd", false); + builder.AddAttribute(32, "IsVisibleWhenEdit", false); builder.CloseComponent(); }); }); @@ -4619,6 +4621,8 @@ public void TableColumn_Property() Assert.True(column.Instance.Readonly); Assert.True(column.Instance.IsReadonlyWhenAdd); Assert.True(column.Instance.IsReadonlyWhenEdit); + Assert.False(column.Instance.IsVisibleWhenAdd); + Assert.False(column.Instance.IsVisibleWhenEdit); Assert.True(column.Instance.SkipValidate); Assert.Equal("test", column.Instance.Text); Assert.True(column.Instance.Visible); @@ -5135,8 +5139,8 @@ public async Task OnAddAsync_Ok(EditMode mode) var form = cut.Find("tbody form"); await cut.InvokeAsync(() => form.Submit()); Assert.Equal(ItemChangedType.Add, itemChanged); + Assert.True(afterModify); } - Assert.True(afterModify); } [Theory] diff --git a/test/UnitTest/Extensions/ITableColumnExtensionsTest.cs b/test/UnitTest/Extensions/ITableColumnExtensionsTest.cs index ca4bfa6eb24..a8f01f79563 100644 --- a/test/UnitTest/Extensions/ITableColumnExtensionsTest.cs +++ b/test/UnitTest/Extensions/ITableColumnExtensionsTest.cs @@ -88,6 +88,8 @@ public void CopyValue_Ok() Template = new RenderFragment(obj => builder => builder.AddContent(0, "test-template")), TextEllipsis = true, Visible = false, + IsVisibleWhenAdd = false, + IsVisibleWhenEdit = false, Width = 100, ShowHeaderTooltip = true, HeaderTextEllipsis = true, @@ -112,6 +114,8 @@ public void CopyValue_Ok() Assert.Equal(true, col.LookupServiceData); Assert.True(col.IsReadonlyWhenAdd); Assert.True(col.IsReadonlyWhenEdit); + Assert.False(col.IsVisibleWhenAdd); + Assert.False(col.IsVisibleWhenEdit); Assert.True(col.Readonly); Assert.Equal(3, col.Rows); Assert.True(col.SkipValidate); diff --git a/test/UnitTest/Extensions/ObjectExtensionsTest.cs b/test/UnitTest/Extensions/ObjectExtensionsTest.cs index 4f34214e92b..eee23ebaddc 100644 --- a/test/UnitTest/Extensions/ObjectExtensionsTest.cs +++ b/test/UnitTest/Extensions/ObjectExtensionsTest.cs @@ -177,10 +177,11 @@ public void IsEditable_Readonly(ItemChangedType itemChangedType) [InlineData(ItemChangedType.Add, false)] public void IsEditable_IsReadonlyWhenAdd(ItemChangedType itemChangedType, bool val) { - var editorItem = new EditorItem() + var editorItem = new EditorItem(); + editorItem.SetParametersAsync(ParameterView.FromDictionary(new Dictionary { - IsReadonlyWhenAdd = val - }; + ["IsReadonlyWhenAdd"] = val + })); Assert.Equal(val, !editorItem.IsEditable(itemChangedType)); } @@ -189,13 +190,41 @@ public void IsEditable_IsReadonlyWhenAdd(ItemChangedType itemChangedType, bool v [InlineData(ItemChangedType.Update, false)] public void IsEditable_IsReadonlyWhenEdit(ItemChangedType itemChangedType, bool val) { - var editorItem = new EditorItem() + var editorItem = new EditorItem(); + editorItem.SetParametersAsync(ParameterView.FromDictionary(new Dictionary { - IsReadonlyWhenEdit = val - }; + ["IsReadonlyWhenEdit"] = val + })); Assert.Equal(val, !editorItem.IsEditable(itemChangedType)); } + + [Theory] + [InlineData(ItemChangedType.Add, true)] + [InlineData(ItemChangedType.Add, false)] + public void IsVisible_IsVisibleWhenAdd(ItemChangedType itemChangedType, bool val) + { + var editorItem = new EditorItem(); + editorItem.SetParametersAsync(ParameterView.FromDictionary(new Dictionary + { + ["IsVisibleWhenAdd"] = val + })); + Assert.Equal(val, editorItem.IsVisible(itemChangedType)); + } + + [Theory] + [InlineData(ItemChangedType.Update, true)] + [InlineData(ItemChangedType.Update, false)] + public void IsVisible_IsVisibleWhenEdit(ItemChangedType itemChangedType, bool val) + { + var editorItem = new EditorItem(); + editorItem.SetParametersAsync(ParameterView.FromDictionary(new Dictionary + { + ["IsVisibleWhenEdit"] = val + })); + Assert.Equal(val, editorItem.IsVisible(itemChangedType)); + } + [Theory] [InlineData(ItemChangedType.Add)] [InlineData(ItemChangedType.Update)] diff --git a/test/UnitTest/Utils/UtilityTest.cs b/test/UnitTest/Utils/UtilityTest.cs index 1e4ff04b9f7..fffaca5805c 100644 --- a/test/UnitTest/Utils/UtilityTest.cs +++ b/test/UnitTest/Utils/UtilityTest.cs @@ -550,10 +550,12 @@ public void GenerateTableColumns_Ok() { var cols = Utility.GetTableColumns(new InternalTableColumn[] { - new(nameof(Cat.Name), typeof(string)) { Text = "test-Name", LookupServiceData = true } + new(nameof(Cat.Name), typeof(string)) { Text = "test-Name", LookupServiceData = true, IsVisibleWhenAdd = false, IsVisibleWhenEdit = false } }); Assert.Equal(2, cols.Count()); Assert.Equal(true, cols.First().LookupServiceData); + Assert.False(cols.First().IsVisibleWhenAdd); + Assert.False(cols.First().IsVisibleWhenEdit); } [Fact]