feat: 菜单维护页面支持 int 属性类型的 Order

This commit is contained in:
Argo Zhang 2020-01-20 11:42:33 +08:00
parent aeee739b8f
commit 2da705ec22
No known key found for this signature in database
GPG Key ID: 152E398953DDF19F
9 changed files with 79 additions and 59 deletions

View File

@ -0,0 +1,15 @@
using System.Collections.Generic;
namespace Bootstrap.Admin.Components
{
/// <summary>
/// IRules 接口
/// </summary>
public interface IRules
{
/// <summary>
/// 获得 Rules 集合
/// </summary>
ICollection<ValidatorComponentBase> Rules { get; }
}
}

View File

@ -7,36 +7,22 @@ namespace Bootstrap.Admin.Components
/// <summary> /// <summary>
/// LgbInputText 组件 /// LgbInputText 组件
/// </summary> /// </summary>
public class LgbInputTextBase : ValidateInputBase<string> public class LgbInputBase<TItem> : ValidateInputBase<TItem>
{ {
/// <summary> /// <summary>
/// /// 获得/设置 控件样式 默认为 col-sm-6
/// </summary> /// </summary>
[Parameter] [Parameter]
public string ColumnClass { get; set; } = "col-sm-6"; public string ColumnClass { get; set; } = "col-sm-6";
/// <summary> /// <summary>
/// /// 获得/设置 控件 type 属性 默认为 text
/// </summary> /// </summary>
[Parameter] [Parameter]
public string InputType { get; set; } = "text"; public string InputType { get; set; } = "text";
/// <summary> /// <summary>
/// /// 获取 最大长度属性
/// </summary>
/// <param name="value"></param>
/// <param name="result"></param>
/// <param name="validationErrorMessage"></param>
/// <returns></returns>
protected override bool TryParseValueFromString(string value, out string result, out string validationErrorMessage)
{
result = value;
validationErrorMessage = "";
return true;
}
/// <summary>
///
/// </summary> /// </summary>
protected int? MaxLength protected int? MaxLength
{ {

View File

@ -0,0 +1,12 @@
using Bootstrap.Admin.Shared;
namespace Bootstrap.Admin.Components
{
/// <summary>
/// LgbInputText 组件
/// </summary>
public class LgbInputText : LgbInput<string>
{
}
}

View File

@ -1,12 +0,0 @@
using Microsoft.AspNetCore.Components;
namespace Bootstrap.Admin.Components
{
/// <summary>
///
/// </summary>
public class QueryInputTextBase<TItem> : LgbInputTextBase
{
}
}

View File

@ -11,24 +11,24 @@ using System.Linq;
namespace Bootstrap.Admin.Components namespace Bootstrap.Admin.Components
{ {
/// <summary> /// <summary>
/// /// 内置验证组件基类
/// </summary> /// </summary>
public abstract class ValidateInputBase<TItem> : InputBase<TItem>, IValidateComponent public abstract class ValidateInputBase<TItem> : InputBase<TItem>, IValidateComponent, IRules
{ {
/// <summary> /// <summary>
/// /// 获得 IJSRuntime 实例
/// </summary> /// </summary>
[Inject] [Inject]
protected IJSRuntime? JSRuntime { get; set; } protected IJSRuntime? JSRuntime { get; set; }
/// <summary> /// <summary>
/// /// 获得 LgbEditFormBase 实例
/// </summary> /// </summary>
[CascadingParameter] [CascadingParameter]
public LgbEditFormBase? EditForm { get; set; } public LgbEditFormBase? EditForm { get; set; }
/// <summary> /// <summary>
/// /// 获得 当前组件 Id
/// </summary> /// </summary>
public string Id public string Id
{ {
@ -36,13 +36,13 @@ namespace Bootstrap.Admin.Components
} }
/// <summary> /// <summary>
/// /// 获得 子组件 RenderFragment 实例
/// </summary> /// </summary>
[Parameter] [Parameter]
public RenderFragment? ChildContent { get; set; } public RenderFragment? ChildContent { get; set; }
/// <summary> /// <summary>
/// /// 获得 PlaceHolder 属性
/// </summary> /// </summary>
protected string? PlaceHolder protected string? PlaceHolder
{ {
@ -59,22 +59,22 @@ namespace Bootstrap.Admin.Components
} }
/// <summary> /// <summary>
/// /// 获得/设置 错误描述信息
/// </summary> /// </summary>
protected string ErrorMessage { get; set; } = ""; protected string ErrorMessage { get; set; } = "";
/// <summary> /// <summary>
/// /// 获得/设置 数据合规样式
/// </summary> /// </summary>
protected string ValidCss { get; set; } = ""; protected string ValidCss { get; set; } = "";
/// <summary> /// <summary>
/// /// 获得/设置 显示名称 默认为 -
/// </summary> /// </summary>
protected string DisplayName { get; set; } = "-"; protected string DisplayName { get; set; } = "-";
/// <summary> /// <summary>
/// /// OnInitialized 方法
/// </summary> /// </summary>
protected override void OnInitialized() protected override void OnInitialized()
{ {
@ -83,7 +83,7 @@ namespace Bootstrap.Admin.Components
} }
/// <summary> /// <summary>
/// /// OnAfterRender 方法
/// </summary> /// </summary>
/// <param name="firstRender"></param> /// <param name="firstRender"></param>
protected override void OnAfterRender(bool firstRender) protected override void OnAfterRender(bool firstRender)
@ -96,13 +96,13 @@ namespace Bootstrap.Admin.Components
} }
/// <summary> /// <summary>
/// /// 获得 数据验证方法集合
/// </summary> /// </summary>
public ICollection<ValidatorComponentBase> Rules { get; } = new HashSet<ValidatorComponentBase>(); public ICollection<ValidatorComponentBase> Rules { get; } = new HashSet<ValidatorComponentBase>();
private string _tooltipMethod = ""; private string _tooltipMethod = "";
/// <summary> /// <summary>
/// /// 属性验证方法
/// </summary> /// </summary>
/// <param name="propertyValue"></param> /// <param name="propertyValue"></param>
/// <param name="context"></param> /// <param name="context"></param>
@ -142,7 +142,7 @@ namespace Bootstrap.Admin.Components
} }
/// <summary> /// <summary>
/// /// 将 字符串 Value 属性转化为 泛型 Value 方法
/// </summary> /// </summary>
/// <param name="value"></param> /// <param name="value"></param>
/// <param name="result"></param> /// <param name="result"></param>

View File

@ -6,21 +6,21 @@ using System.ComponentModel.DataAnnotations;
namespace Bootstrap.Admin.Components namespace Bootstrap.Admin.Components
{ {
/// <summary> /// <summary>
/// /// 验证组件基类
/// </summary> /// </summary>
public abstract class ValidatorComponentBase : ComponentBase public abstract class ValidatorComponentBase : ComponentBase
{ {
/// <summary> /// <summary>
/// /// 获得/设置 错误描述信息
/// </summary> /// </summary>
[Parameter] [Parameter]
public string ErrorMessage { get; set; } = ""; public string ErrorMessage { get; set; } = "";
/// <summary> /// <summary>
/// /// 获得/设置 IRules 实例
/// </summary> /// </summary>
[CascadingParameter] [CascadingParameter]
public LgbInputTextBase? Input { get; set; } public IRules? Input { get; set; }
/// <summary> /// <summary>
/// 初始化方法 /// 初始化方法
@ -30,7 +30,7 @@ namespace Bootstrap.Admin.Components
if (Input == null) if (Input == null)
{ {
throw new InvalidOperationException($"{nameof(ValidatorComponentBase)} requires a cascading " + throw new InvalidOperationException($"{nameof(ValidatorComponentBase)} requires a cascading " +
$"parameter of type {nameof(LgbInputTextBase)}. For example, you can use {nameof(ValidatorComponentBase)} " + $"parameter of type {nameof(IRules)}. For example, you can use {nameof(ValidatorComponentBase)} " +
$"inside an LgbInputText."); $"inside an LgbInputText.");
} }
@ -38,7 +38,7 @@ namespace Bootstrap.Admin.Components
} }
/// <summary> /// <summary>
/// /// 验证方法
/// </summary> /// </summary>
/// <param name="propertyValue"></param> /// <param name="propertyValue"></param>
/// <param name="context"></param> /// <param name="context"></param>

View File

@ -40,17 +40,17 @@
<RequiredValidator /> <RequiredValidator />
<StringLengthValidator Length="50" /> <StringLengthValidator Length="50" />
</LgbInputText> </LgbInputText>
<LgbInputText @bind-Value="@context.ParentName" placeholder="可为空50字以内" maxlength="50" /> <LgbInputText @bind-Value="@context.ParentName" placeholder="请选择...(可为空)50字以内" maxlength="50" />
<LgbInputText @bind-Value="@context.Icon" placeholder="不可为空50字以内" maxlength="50" /> <LgbInput TItem="int" @bind-Value="@context.Order" placeholder="可为空默认为10" InputType="number" maxlength="6" />
<LgbInputText @bind-Value="@context.Icon" placeholder="不可为空50字以内" maxlength="50" /> <LgbInputText @bind-Value="@context.Icon" placeholder="请选择...(可为空)50字以内" maxlength="50" />
<LgbInputText @bind-Value="@context.Url" placeholder="不可为空,50字以内" maxlength="2000" ColumnClass="col-12" class="flex-sm-fill"> <LgbInputText @bind-Value="@context.Url" placeholder="不可为空,2000字以内" maxlength="2000" ColumnClass="col-12" class="flex-sm-fill">
<RequiredValidator /> <RequiredValidator />
<StringLengthValidator Length="2000" /> <StringLengthValidator Length="2000" />
</LgbInputText> </LgbInputText>
<Select Items="DefineResource" TItem="int" @bind-Value="@context.IsResource"></Select> <Select Items="DefineResource" TItem="int" @bind-Value="@context.IsResource"></Select>
<Select Items="DefineTarget" TItem="string" @bind-Value="@context.Target"></Select> <Select Items="DefineTarget" TItem="string" @bind-Value="@context.Target"></Select>
<Select Items="DefineApp" TItem="string" @bind-Value="@context.Application"></Select> <Select Items="DefineApp" TItem="string" @bind-Value="@context.Application"></Select>
<Select Items="DefineCategory" TItem="string" @bind-Value="@context.Category"></Select> <Select Items="DefineCategory" TItem="string" @bind-Value="@context.Category" Disabled="true"></Select>
</div> </div>
</EditTemplate> </EditTemplate>
</EditPage> </EditPage>

View File

@ -24,7 +24,7 @@ namespace Bootstrap.Pages.Admin.Components
/// 获得/设置 菜单类别 /// 获得/设置 菜单类别
/// </summary> /// </summary>
protected List<SelectedItem> QueryCategory { get; set; } = new List<SelectedItem>(new SelectedItem[] { protected List<SelectedItem> QueryCategory { get; set; } = new List<SelectedItem>(new SelectedItem[] {
new SelectedItem() { Text = "全部", Value = "-1", Active = true }, new SelectedItem() { Text = "全部", Value = "", Active = true },
new SelectedItem() { Text = "系统菜单", Value = "0" }, new SelectedItem() { Text = "系统菜单", Value = "0" },
new SelectedItem() { Text = "外部菜单", Value = "1" } new SelectedItem() { Text = "外部菜单", Value = "1" }
}); });
@ -43,7 +43,7 @@ namespace Bootstrap.Pages.Admin.Components
/// 获得/设置 所属应用 /// 获得/设置 所属应用
/// </summary> /// </summary>
protected List<SelectedItem> QueryApp { get; set; } = new List<SelectedItem>(new SelectedItem[] { protected List<SelectedItem> QueryApp { get; set; } = new List<SelectedItem>(new SelectedItem[] {
new SelectedItem() { Text = "全部", Value = "-1", Active = true } new SelectedItem() { Text = "全部", Value = "", Active = true }
}); });
@ -103,6 +103,8 @@ namespace Bootstrap.Pages.Admin.Components
/// <returns></returns> /// <returns></returns>
protected override void OnParametersSet() protected override void OnParametersSet()
{ {
QueryModel.Category = "";
QueryModel.IsResource = -1;
QueryApp.AddRange(DictHelper.RetrieveApps().Select(app => new SelectedItem() { Text = app.Value, Value = app.Key })); QueryApp.AddRange(DictHelper.RetrieveApps().Select(app => new SelectedItem() { Text = app.Value, Value = app.Key }));
DefineApp.AddRange(DictHelper.RetrieveApps().Select(app => new SelectedItem() { Text = app.Value, Value = app.Key })); DefineApp.AddRange(DictHelper.RetrieveApps().Select(app => new SelectedItem() { Text = app.Value, Value = app.Key }));
} }
@ -125,6 +127,22 @@ namespace Bootstrap.Pages.Admin.Components
return new QueryData<BootstrapMenu>() { Items = items, TotalCount = totalCount, PageIndex = pageIndex, PageItems = pageItems }; return new QueryData<BootstrapMenu>() { Items = items, TotalCount = totalCount, PageIndex = pageIndex, PageItems = pageItems };
} }
/// <summary>
/// 新建方法
/// </summary>
protected override BootstrapMenu Add()
{
return new BootstrapMenu()
{
Order = 10,
Icon = "fa fa-fa",
Target = "_self",
Category = "0",
IsResource = 0,
Application = DefineApp.First().Value
};
}
/// <summary> /// <summary>
/// 保存方法 /// 保存方法
/// </summary> /// </summary>

View File

@ -1,4 +1,5 @@
@inherits LgbInputTextBase @typeparam TItem
@inherits LgbInputBase<TItem>
<div class="@($"form-group {ColumnClass}")"> <div class="@($"form-group {ColumnClass}")">
<label class="control-label" for="@Id">@DisplayName</label> <label class="control-label" for="@Id">@DisplayName</label>