!1884 feat(#I4BB1T): add IsEditable extension method for IEditorItem

* feat: 增加扩展方法 IsEditable 统一组件渲染不可编辑逻辑
This commit is contained in:
Argo 2021-09-22 06:06:25 +00:00
parent 51889debbc
commit b7c40407fc
5 changed files with 22 additions and 9 deletions

View File

@ -229,7 +229,7 @@ namespace BootstrapBlazor.Components
private RenderFragment AutoGenerateTemplate(IEditorItem item) => builder =>
{
if (IsDisplay || item.Readonly || !item.Editable)
if (IsDisplay || !item.IsEditable())
{
builder.CreateDisplayByFieldType(this, item, Model, ShowLabel);
}

View File

@ -24,7 +24,7 @@ namespace BootstrapBlazor.Components
bool Editable { get; set; }
/// <summary>
/// 获得/设置 当前列编辑时是否只读 默认为 false
/// 获得/设置 当前列编辑时是否只读 默认为 false 自动生成 UI 为不可编辑 div
/// </summary>
bool Readonly { get; set; }

View File

@ -846,16 +846,18 @@ namespace BootstrapBlazor.Components
private static ConcurrentDictionary<(Type Type, string PropertyName), Func<TItem, object?>> GetPropertyCache { get; } = new();
#endregion
private RenderFragment RenderCell(ITableColumn col, TItem item) => col.EditTemplate == null
? (col.Readonly || !col.Editable
? builder => builder.CreateDisplayByFieldType(this, col, item, false)
: builder => builder.CreateComponentByFieldType(this, col, item, false))
: col.EditTemplate.Invoke(item);
private RenderFragment RenderCell(ITableColumn col, TItem item) => col.IsEditable()
? (col.EditTemplate == null
? builder => builder.CreateComponentByFieldType(this, col, item, false)
: col.EditTemplate(item))
: builder => builder.CreateDisplayByFieldType(this, col, item, false);
private RenderFragment RenderExcelCell(ITableColumn col, TItem item)
{
col.PlaceHolder ??= "";
if (col.EditTemplate == null)
// 可编辑列未设置模板
if (col.IsEditable() && col.EditTemplate == null)
{
if (DynamicContext != null)
{

View File

@ -179,5 +179,12 @@ namespace BootstrapBlazor.Components
>= 1024 * 1024 * 1024 => $"{Math.Round(fileSize / 1024 / 1024 / 1024D, 0, MidpointRounding.AwayFromZero)} GB",
_ => $"{fileSize} B"
};
/// <summary>
/// 判断当前 IEditorItem 实例是否可以编辑
/// </summary>
/// <param name="item"></param>
/// <returns></returns>
public static bool IsEditable(this IEditorItem item) => !item.Readonly && item.Editable;
}
}

View File

@ -325,7 +325,11 @@ namespace BootstrapBlazor.Components
builder.AddAttribute(2, nameof(ValidateBase<string>.Value), fieldValue);
builder.AddAttribute(3, nameof(ValidateBase<string>.ValueChanged), fieldValueChanged);
builder.AddAttribute(4, nameof(ValidateBase<string>.ValueExpression), valueExpression);
builder.AddAttribute(5, nameof(ValidateBase<string>.IsDisabled), item.Readonly);
if (!item.IsEditable())
{
builder.AddAttribute(5, nameof(ValidateBase<string>.IsDisabled), true);
}
}
if (IsCheckboxList(fieldType) && item.Items != null)