mirror of
https://gitee.com/LongbowEnterprise/BootstrapBlazor.git
synced 2024-12-02 03:59:14 +08:00
!1884 feat(#I4BB1T): add IsEditable extension method for IEditorItem
* feat: 增加扩展方法 IsEditable 统一组件渲染不可编辑逻辑
This commit is contained in:
parent
51889debbc
commit
b7c40407fc
@ -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);
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ namespace BootstrapBlazor.Components
|
||||
bool Editable { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获得/设置 当前列编辑时是否只读 默认为 false
|
||||
/// 获得/设置 当前列编辑时是否只读 默认为 false 自动生成 UI 为不可编辑 div
|
||||
/// </summary>
|
||||
bool Readonly { get; set; }
|
||||
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user