mirror of
https://gitee.com/LongbowEnterprise/BootstrapBlazor.git
synced 2024-12-02 03:59:14 +08:00
!1910 feat(#I4A2L8): add IsReadonlyWhenAdd/Edit parameter on IEditorItem interface
* chore: update bundle style * Merge remote-tracking branch 'origin/dev' into dev-table * chore: bump version to 5.12.7 * refactor: 完善继承 IEditorItem 实现类属性 * refactor: 移动只读属性到 IEditorItem 接口 * refactor: ITableColumn 增加新建只读与编辑只读属性 * style: 微调 Search 样式
This commit is contained in:
parent
31e9b2599c
commit
54dabc7eda
@ -42,6 +42,16 @@ namespace BootstrapBlazor.Components
|
||||
/// </summary>
|
||||
public bool SkipValidate { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获得/设置 新建时此列只读 默认为 false
|
||||
/// </summary>
|
||||
public bool IsReadonlyWhenAdd { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获得/设置 编辑时此列只读 默认为 false
|
||||
/// </summary>
|
||||
public bool IsReadonlyWhenEdit { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获得/设置 是否为默认排序规则 默认为 SortOrder.Unset
|
||||
/// </summary>
|
||||
|
@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Razor">
|
||||
|
||||
<PropertyGroup>
|
||||
<Version>5.12.6</Version>
|
||||
<Version>5.12.7</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup Condition="'$(TargetFramework)' == 'net5.0'">
|
||||
|
@ -145,7 +145,8 @@ namespace BootstrapBlazor.Components
|
||||
})),
|
||||
new(nameof(EditDialog<TModel>.RowType), option.RowType),
|
||||
new(nameof(EditDialog<TModel>.LabelAlign), option.LabelAlign),
|
||||
new(nameof(EditDialog<TModel>.IsTracking), option.IsTracking)
|
||||
new(nameof(EditDialog<TModel>.IsTracking), option.IsTracking),
|
||||
new(nameof(EditDialog<TModel>.ItemChangedType), option.ItemChangedType)
|
||||
};
|
||||
|
||||
if (option.ItemsPerRow.HasValue)
|
||||
|
@ -17,7 +17,7 @@
|
||||
}
|
||||
else
|
||||
{
|
||||
<EditorForm TModel="TModel" Items="Items" ItemsPerRow="ItemsPerRow" RowType="RowType" LabelAlign="LabelAlign">
|
||||
<EditorForm TModel="TModel" Items="Items" ItemChangedType="ItemChangedType" ItemsPerRow="ItemsPerRow" RowType="RowType" LabelAlign="LabelAlign">
|
||||
<Buttons>
|
||||
@if (!IsTracking)
|
||||
{
|
||||
|
@ -45,6 +45,12 @@ namespace BootstrapBlazor.Components
|
||||
[Parameter]
|
||||
public bool IsTracking { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获得/设置 实体类编辑模式 Add 还是 Update
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
public ItemChangedType ItemChangedType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获得/设置 查询按钮文本
|
||||
/// </summary>
|
||||
|
@ -37,6 +37,11 @@ namespace BootstrapBlazor.Components
|
||||
/// </summary>
|
||||
public bool ShowLabel { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获得/设置 实体类编辑模式 Add 还是 Update
|
||||
/// </summary>
|
||||
public ItemChangedType ItemChangedType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获得/设置 每行显示组件数量 默认为 null
|
||||
/// </summary>
|
||||
|
@ -38,6 +38,12 @@ namespace BootstrapBlazor.Components
|
||||
[Parameter]
|
||||
public int? ItemsPerRow { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获得/设置 实体类编辑模式 Add 还是 Update
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
public ItemChangedType ItemChangedType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获得/设置 设置行格式 默认 Row 布局
|
||||
/// </summary>
|
||||
@ -236,14 +242,14 @@ namespace BootstrapBlazor.Components
|
||||
|
||||
private RenderFragment AutoGenerateTemplate(IEditorItem item) => builder =>
|
||||
{
|
||||
if (IsDisplay || !item.IsEditable())
|
||||
if (IsDisplay || !item.IsEditable(ItemChangedType))
|
||||
{
|
||||
builder.CreateDisplayByFieldType(this, item, Model, ShowLabel);
|
||||
}
|
||||
else
|
||||
{
|
||||
item.PlaceHolder ??= PlaceHolderText;
|
||||
builder.CreateComponentByFieldType(this, item, Model, ShowLabel);
|
||||
builder.CreateComponentByFieldType(this, item, Model, ShowLabel, ItemChangedType);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -50,9 +50,20 @@ namespace BootstrapBlazor.Components
|
||||
/// <summary>
|
||||
/// 获得/设置 当前列编辑时是否为只读模式 默认为 false
|
||||
/// </summary>
|
||||
/// <remarks>此属性覆盖 <see cref="IsReadonlyWhenAdd"/> 与 <see cref="IsReadonlyWhenEdit"/> 即新建与编辑时均只读</remarks>
|
||||
[Parameter]
|
||||
public bool Readonly { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获得/设置 新建时此列只读 默认为 false
|
||||
/// </summary>
|
||||
public bool IsReadonlyWhenAdd { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获得/设置 编辑时此列只读 默认为 false
|
||||
/// </summary>
|
||||
public bool IsReadonlyWhenEdit { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获得/设置 是否不进行验证 默认为 false
|
||||
/// </summary>
|
||||
|
@ -26,8 +26,19 @@ namespace BootstrapBlazor.Components
|
||||
/// <summary>
|
||||
/// 获得/设置 当前列编辑时是否只读 默认为 false 自动生成 UI 为不可编辑 div
|
||||
/// </summary>
|
||||
/// <remarks>此属性覆盖 <see cref="IsReadonlyWhenAdd"/> 与 <see cref="IsReadonlyWhenEdit"/> 即新建与编辑时均只读</remarks>
|
||||
bool Readonly { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获得/设置 新建时此列只读 默认为 false
|
||||
/// </summary>
|
||||
bool IsReadonlyWhenAdd { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获得/设置 编辑时此列只读 默认为 false
|
||||
/// </summary>
|
||||
bool IsReadonlyWhenEdit { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获得/设置 是否不进行验证 默认为 false
|
||||
/// </summary>
|
||||
|
@ -41,6 +41,16 @@ namespace BootstrapBlazor.Components
|
||||
/// </summary>
|
||||
public bool SkipValidate { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获得/设置 新建时此列只读 默认为 false
|
||||
/// </summary>
|
||||
public bool IsReadonlyWhenAdd { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获得/设置 编辑时此列只读 默认为 false
|
||||
/// </summary>
|
||||
public bool IsReadonlyWhenEdit { get; set; }
|
||||
|
||||
public string? CssClass { get; set; }
|
||||
|
||||
public BreakPoint ShownWithBreakPoint { get; set; }
|
||||
@ -248,6 +258,8 @@ namespace BootstrapBlazor.Components
|
||||
if (source.ComponentType != null) dest.ComponentType = source.ComponentType;
|
||||
if (source.ComponentParameters != null) dest.ComponentParameters = source.ComponentParameters;
|
||||
if (source.OnCellRender != null) dest.OnCellRender = source.OnCellRender;
|
||||
if (!source.IsReadonlyWhenAdd) dest.IsReadonlyWhenAdd = source.IsReadonlyWhenAdd;
|
||||
if (!source.IsReadonlyWhenEdit) dest.IsReadonlyWhenEdit = source.IsReadonlyWhenEdit;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -576,6 +576,23 @@ form .table .table-cell > textarea {
|
||||
margin-bottom: .5rem;
|
||||
}
|
||||
|
||||
.table-search .card-header {
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.table-search .card-header .table-search-title {
|
||||
padding: .5rem 1rem;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.table-search .card-header .table-search-buttons {
|
||||
padding: .25rem 1rem;
|
||||
}
|
||||
|
||||
.table-search .card-header .table-search-buttons .btn {
|
||||
padding: .275rem .5rem;
|
||||
}
|
||||
|
||||
.table-excel .table-cell > input.form-control,
|
||||
.table-excel .table-cell .datetime-picker,
|
||||
.table-excel .table-cell .select {
|
||||
|
@ -30,29 +30,7 @@
|
||||
}
|
||||
else
|
||||
{
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<div class="d-flex">
|
||||
<div class="flex-fill">@SearchModalTitle</div>
|
||||
@if (ShowResetButton)
|
||||
{
|
||||
<Button Color="@Color.Secondary" Icon="fa fa-trash" class="btn-xs ms-2" OnClickWithoutRender="@ClearSearchClick">
|
||||
<span class="d-none d-sm-inline-block">@ResetSearchButtonText</span>
|
||||
</Button>
|
||||
}
|
||||
@if (ShowSearchButton)
|
||||
{
|
||||
<Button Color="@Color.Primary" Icon="fa fa-search" class="btn-xs ms-2" OnClickWithoutRender="@SearchClick">
|
||||
<span class="d-none d-sm-inline-block">@SearchButtonText</span>
|
||||
</Button>
|
||||
}
|
||||
</div>
|
||||
</CardHeader>
|
||||
<CardBody>
|
||||
<EditorForm Model="SearchModel" Items="GetSearchColumns()" IsSearch="true" ItemsPerRow="SearchDialogItemsPerRow" RowType="SearchDialogRowType" LabelAlign="SearchDialogLabelAlign">
|
||||
</EditorForm>
|
||||
</CardBody>
|
||||
</Card>
|
||||
@RenderSearch
|
||||
}
|
||||
</div>
|
||||
}
|
||||
@ -610,11 +588,11 @@ RenderFragment<TItem> RenderRow => item =>
|
||||
}
|
||||
@if (IsExcel)
|
||||
{
|
||||
@RenderExcelCell(col, item)
|
||||
@RenderExcelCell(col, item, ItemChangedType.Update)
|
||||
}
|
||||
else if(isInCell)
|
||||
{
|
||||
@RenderCell(col, EditModel)
|
||||
@RenderCell(col, EditModel, ItemChangedType.Update)
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -763,4 +741,31 @@ RenderFragment<TItem> RenderRowExtendButtons => item =>
|
||||
</div>
|
||||
</div>
|
||||
</td>;
|
||||
|
||||
RenderFragment RenderSearch =>
|
||||
@<Card>
|
||||
<CardHeader>
|
||||
<div class="d-flex">
|
||||
<div class="table-search-title">@SearchModalTitle</div>
|
||||
<div class="table-search-buttons">
|
||||
@if (ShowResetButton)
|
||||
{
|
||||
<Button Color="@Color.Secondary" Icon="fa fa-trash" class="btn-xs ms-2" OnClickWithoutRender="@ClearSearchClick">
|
||||
<span class="d-none d-sm-inline-block">@ResetSearchButtonText</span>
|
||||
</Button>
|
||||
}
|
||||
@if (ShowSearchButton)
|
||||
{
|
||||
<Button Color="@Color.Primary" Icon="fa fa-search" class="btn-xs ms-2" OnClickWithoutRender="@SearchClick">
|
||||
<span class="d-none d-sm-inline-block">@SearchButtonText</span>
|
||||
</Button>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</CardHeader>
|
||||
<CardBody>
|
||||
<EditorForm Model="SearchModel" Items="GetSearchColumns()" IsSearch="true" ItemsPerRow="SearchDialogItemsPerRow" RowType="SearchDialogRowType" LabelAlign="SearchDialogLabelAlign">
|
||||
</EditorForm>
|
||||
</CardBody>
|
||||
</Card>;
|
||||
}
|
||||
|
@ -506,6 +506,7 @@ namespace BootstrapBlazor.Components
|
||||
RowType = EditDialogRowType,
|
||||
ItemsPerRow = EditDialogItemsPerRow,
|
||||
LabelAlign = EditDialogLabelAlign,
|
||||
ItemChangedType = changedType,
|
||||
OnCloseAsync = async () =>
|
||||
{
|
||||
if (UseInjectDataService && GetDataService() is IEntityFrameworkCoreDataService ef)
|
||||
|
@ -852,20 +852,20 @@ 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.IsEditable()
|
||||
private RenderFragment RenderCell(ITableColumn col, TItem item, ItemChangedType changedType) => col.IsEditable(changedType)
|
||||
? (col.EditTemplate == null
|
||||
? builder => builder.CreateComponentByFieldType(this, col, item, false)
|
||||
? builder => builder.CreateComponentByFieldType(this, col, item, false, changedType)
|
||||
: col.EditTemplate(item))
|
||||
: (col.Template == null
|
||||
? builder => builder.CreateDisplayByFieldType(this, col, item, false)
|
||||
: col.Template(item));
|
||||
|
||||
private RenderFragment RenderExcelCell(ITableColumn col, TItem item)
|
||||
private RenderFragment RenderExcelCell(ITableColumn col, TItem item, ItemChangedType changedType)
|
||||
{
|
||||
col.PlaceHolder ??= "";
|
||||
|
||||
// 可编辑列未设置模板
|
||||
if (col.IsEditable() && col.EditTemplate == null)
|
||||
if (col.IsEditable(changedType) && col.EditTemplate == null)
|
||||
{
|
||||
if (DynamicContext != null)
|
||||
{
|
||||
@ -876,7 +876,7 @@ namespace BootstrapBlazor.Components
|
||||
SetEditTemplate();
|
||||
}
|
||||
}
|
||||
return RenderCell(col, item);
|
||||
return RenderCell(col, item, changedType);
|
||||
|
||||
void SetDynamicEditTemplate()
|
||||
{
|
||||
@ -890,7 +890,7 @@ namespace BootstrapBlazor.Components
|
||||
parameters.Add(new(nameof(ValidateBase<string>.OnValueChanged), onValueChanged.Invoke(d, col, (model, column, val) => DynamicContext.OnValueChanged(model, column, val))));
|
||||
col.ComponentParameters = parameters;
|
||||
}
|
||||
builder.CreateComponentByFieldType(this, col, row, false);
|
||||
builder.CreateComponentByFieldType(this, col, row, false, changedType);
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -119,9 +119,22 @@ namespace BootstrapBlazor.Components
|
||||
/// <summary>
|
||||
/// 获得/设置 当前列编辑时是否为只读模式 默认为 false
|
||||
/// </summary>
|
||||
/// <remarks>此属性覆盖 <see cref="IsReadonlyWhenAdd"/> 与 <see cref="IsReadonlyWhenEdit"/> 即新建与编辑时均只读</remarks>
|
||||
[Parameter]
|
||||
public bool Readonly { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获得/设置 新建时此列只读 默认为 false
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
public bool IsReadonlyWhenAdd { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获得/设置 编辑时此列只读 默认为 false
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
public bool IsReadonlyWhenEdit { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获得/设置 是否不进行验证 默认为 false
|
||||
/// </summary>
|
||||
|
@ -184,7 +184,13 @@ namespace BootstrapBlazor.Components
|
||||
/// 判断当前 IEditorItem 实例是否可以编辑
|
||||
/// </summary>
|
||||
/// <param name="item"></param>
|
||||
/// <param name="changedType"></param>
|
||||
/// <returns></returns>
|
||||
public static bool IsEditable(this IEditorItem item) => !item.Readonly && item.Editable;
|
||||
public static bool IsEditable(this IEditorItem item, ItemChangedType changedType) => item.Editable
|
||||
&& !item.Readonly && changedType switch
|
||||
{
|
||||
ItemChangedType.Add => !item.IsReadonlyWhenAdd,
|
||||
_ => !item.IsReadonlyWhenEdit
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -319,7 +319,8 @@ namespace BootstrapBlazor.Components
|
||||
/// <param name="component"></param>
|
||||
/// <param name="item"></param>
|
||||
/// <param name="showLabel"></param>
|
||||
public static void CreateComponentByFieldType(this RenderTreeBuilder builder, ComponentBase component, IEditorItem item, object model, bool? showLabel = null)
|
||||
/// <param name="changedType"></param>
|
||||
public static void CreateComponentByFieldType(this RenderTreeBuilder builder, ComponentBase component, IEditorItem item, object model, bool? showLabel = null, ItemChangedType changedType = ItemChangedType.Update)
|
||||
{
|
||||
var fieldType = item.PropertyType;
|
||||
var fieldName = item.GetFieldName();
|
||||
@ -337,7 +338,7 @@ namespace BootstrapBlazor.Components
|
||||
builder.AddAttribute(3, nameof(ValidateBase<string>.ValueChanged), fieldValueChanged);
|
||||
builder.AddAttribute(4, nameof(ValidateBase<string>.ValueExpression), valueExpression);
|
||||
|
||||
if (!item.IsEditable())
|
||||
if (!item.IsEditable(changedType))
|
||||
{
|
||||
builder.AddAttribute(5, nameof(ValidateBase<string>.IsDisabled), true);
|
||||
}
|
||||
|
File diff suppressed because one or more lines are too long
@ -47,6 +47,16 @@ namespace UnitTest.Emit
|
||||
|
||||
public bool Readonly { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获得/设置 新建时此列只读 默认为 false
|
||||
/// </summary>
|
||||
public bool IsReadonlyWhenAdd { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获得/设置 编辑时此列只读 默认为 false
|
||||
/// </summary>
|
||||
public bool IsReadonlyWhenEdit { get; set; }
|
||||
|
||||
public bool SkipValidate { get; set; }
|
||||
|
||||
public string Text { get; set; }
|
||||
|
Loading…
Reference in New Issue
Block a user