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

View File

@ -6,21 +6,21 @@ using System.ComponentModel.DataAnnotations;
namespace Bootstrap.Admin.Components
{
/// <summary>
///
/// 验证组件基类
/// </summary>
public abstract class ValidatorComponentBase : ComponentBase
{
/// <summary>
///
/// 获得/设置 错误描述信息
/// </summary>
[Parameter]
public string ErrorMessage { get; set; } = "";
/// <summary>
///
/// 获得/设置 IRules 实例
/// </summary>
[CascadingParameter]
public LgbInputTextBase? Input { get; set; }
public IRules? Input { get; set; }
/// <summary>
/// 初始化方法
@ -30,7 +30,7 @@ namespace Bootstrap.Admin.Components
if (Input == null)
{
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.");
}
@ -38,7 +38,7 @@ namespace Bootstrap.Admin.Components
}
/// <summary>
///
/// 验证方法
/// </summary>
/// <param name="propertyValue"></param>
/// <param name="context"></param>

View File

@ -40,17 +40,17 @@
<RequiredValidator />
<StringLengthValidator Length="50" />
</LgbInputText>
<LgbInputText @bind-Value="@context.ParentName" placeholder="可为空50字以内" maxlength="50" />
<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.ParentName" 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.Url" placeholder="不可为空,2000字以内" maxlength="2000" ColumnClass="col-12" class="flex-sm-fill">
<RequiredValidator />
<StringLengthValidator Length="2000" />
</LgbInputText>
<Select Items="DefineResource" TItem="int" @bind-Value="@context.IsResource"></Select>
<Select Items="DefineTarget" TItem="string" @bind-Value="@context.Target"></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>
</EditTemplate>
</EditPage>

View File

@ -24,7 +24,7 @@ namespace Bootstrap.Pages.Admin.Components
/// 获得/设置 菜单类别
/// </summary>
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 = "1" }
});
@ -43,7 +43,7 @@ namespace Bootstrap.Pages.Admin.Components
/// 获得/设置 所属应用
/// </summary>
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>
protected override void OnParametersSet()
{
QueryModel.Category = "";
QueryModel.IsResource = -1;
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 }));
}
@ -125,6 +127,22 @@ namespace Bootstrap.Pages.Admin.Components
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>

View File

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