fix(#I18FGZ): Blazor 增加用户维护
#Comment comment #I18FGZ #Issue close https://gitee.com/LongbowEnterprise/dashboard/issues?id=I18FGZ
This commit is contained in:
parent
3562d92a9a
commit
94ddc1be82
|
@ -1,4 +1,5 @@
|
|||
using Bootstrap.Security;
|
||||
using Bootstrap.DataAccess;
|
||||
using Bootstrap.Security;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
|
@ -6,7 +7,7 @@ using System.Collections.Concurrent;
|
|||
namespace Microsoft.AspNetCore.Builder
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
///
|
||||
/// </summary>
|
||||
public static class DisplayNamesExtensions
|
||||
{
|
||||
|
@ -25,13 +26,13 @@ namespace Microsoft.AspNetCore.Builder
|
|||
_displayNameCache.TryAdd((typeof(BootstrapDict), nameof(BootstrapDict.Code)), "字典代码");
|
||||
_displayNameCache.TryAdd((typeof(BootstrapDict), nameof(BootstrapDict.Define)), "字典类型");
|
||||
|
||||
_displayNameCache.TryAdd((typeof(BootstrapUser), nameof(BootstrapUser.UserName)), "登录名称");
|
||||
_displayNameCache.TryAdd((typeof(BootstrapUser), nameof(BootstrapUser.DisplayName)), "显示名称");
|
||||
_displayNameCache.TryAdd((typeof(User), nameof(User.UserName)), "登录名称");
|
||||
_displayNameCache.TryAdd((typeof(User), nameof(User.DisplayName)), "显示名称");
|
||||
return services;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="cacheKey"></param>
|
||||
/// <param name="displayName"></param>
|
||||
|
@ -39,7 +40,7 @@ namespace Microsoft.AspNetCore.Builder
|
|||
public static bool TryGetValue((Type ModelType, string FieldName) cacheKey, out string? displayName) => _displayNameCache.TryGetValue(cacheKey, out displayName);
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="cacheKey"></param>
|
||||
/// <param name="valueFactory"></param>
|
||||
|
|
|
@ -1,41 +1,45 @@
|
|||
|
||||
@using System.Globalization
|
||||
@inherits UsersBase
|
||||
|
||||
<h1 style="font-style:@_headingFontStyle">@_headingText</h1>
|
||||
|
||||
<form>
|
||||
<div>
|
||||
@*
|
||||
A check box sets the font style and is bound to the
|
||||
_italicsCheck field.
|
||||
*@
|
||||
<input type="checkbox" id="italicsCheck"
|
||||
@bind="_italicsCheck" />
|
||||
<label class="form-check-label"
|
||||
for="italicsCheck">Use italics</label>
|
||||
</div>
|
||||
|
||||
@*
|
||||
When the form is submitted, the onclick event executes
|
||||
the UpdateHeading method.
|
||||
*@
|
||||
<button type="button" class="btn btn-primary" @onclick="UpdateHeading">
|
||||
Update heading
|
||||
</button>
|
||||
</form>
|
||||
|
||||
@code {
|
||||
private static TextInfo _tinfo = CultureInfo.CurrentCulture.TextInfo;
|
||||
private string _headingText =
|
||||
_tinfo.ToTitleCase("welcome to blazor!");
|
||||
private string _headingFontStyle = "normal";
|
||||
private bool _italicsCheck = false;
|
||||
|
||||
// When UpdateHeading is executed, _italicsCheck determines
|
||||
// the value of _headingFontStyle to set the font style of the
|
||||
// heading.
|
||||
public void UpdateHeading()
|
||||
{
|
||||
_headingFontStyle = _italicsCheck ? "italic" : "normal";
|
||||
}
|
||||
}
|
||||
<EditPage Id="dict" TItem="Bootstrap.DataAccess.User" QueryModel="QueryModel" OnQuery="Query" OnAdd="Add" OnDelete="Delete" OnSave="Save">
|
||||
<QueryBody>
|
||||
<LgbInputText @bind-Value="@context.UserName" maxlength="50" />
|
||||
<LgbInputText @bind-Value="@context.DisplayName" maxlength="50" />
|
||||
</QueryBody>
|
||||
<TableHeader>
|
||||
<LgbTableHeader TItem="string" @bind-Value="@context.UserName"></LgbTableHeader>
|
||||
<LgbTableHeader TItem="string" @bind-Value="@context.DisplayName"></LgbTableHeader>
|
||||
<LgbTableHeader TItem="DateTime" @bind-Value="@context.RegisterTime"></LgbTableHeader>
|
||||
<LgbTableHeader TItem="DateTime?" @bind-Value="@context.ApprovedTime"></LgbTableHeader>
|
||||
<LgbTableHeader TItem="string" @bind-Value="@context.ApprovedBy"></LgbTableHeader>
|
||||
<LgbTableHeader TItem="string" @bind-Value="@context.Description"></LgbTableHeader>
|
||||
</TableHeader>
|
||||
<RowTemplate>
|
||||
<td>@context.UserName</td>
|
||||
<td>@context.DisplayName</td>
|
||||
<td>@context.RegisterTime.ToString("yyyy-MM-dd HH:mm:ss")</td>
|
||||
<td>@(context.ApprovedTime?.ToString("yyyy-MM-dd HH:mm:ss") ?? "-")</td>
|
||||
<td>@context.ApprovedBy</td>
|
||||
<td>@context.Description</td>
|
||||
</RowTemplate>
|
||||
<EditTemplate>
|
||||
<div class="row">
|
||||
<LgbInputText @bind-Value="@context.UserName" placeholder="不可为空,16字以内" maxlength="16">
|
||||
<RequiredValidator />
|
||||
<StringLengthValidator Length="16" />
|
||||
</LgbInputText>
|
||||
<LgbInputText @bind-Value="@context.DisplayName" placeholder="不可为空,20字以内" maxlength="20">
|
||||
<RequiredValidator />
|
||||
<StringLengthValidator Length="20" />
|
||||
</LgbInputText>
|
||||
<LgbInputText InputType="password" @bind-Value="@context.Password" autocomplete="off" placeholder="不可为空,16字以内" maxlength="16">
|
||||
<RequiredValidator />
|
||||
<StringLengthValidator Length="16" />
|
||||
</LgbInputText>
|
||||
<LgbInputText InputType="password" @bind-Value="@context.NewPassword" autocomplete="off" placeholder="与登录密码一致" maxlength="16">
|
||||
<RequiredValidator />
|
||||
<StringLengthValidator Length="16" />
|
||||
<EqualToValidator @bind-Value="@context.Password" />
|
||||
</LgbInputText>
|
||||
</div>
|
||||
</EditTemplate>
|
||||
</EditPage>
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
using Bootstrap.Admin.Components;
|
||||
using Bootstrap.DataAccess;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Bootstrap.Pages.Admin.Components
|
||||
{
|
||||
/// <summary>
|
||||
/// 用户表维护组件
|
||||
/// </summary>
|
||||
public class UsersBase : QueryPageBase<User>
|
||||
{
|
||||
/// <summary>
|
||||
/// 查询方法
|
||||
/// </summary>
|
||||
/// <param name="pageIndex">页码</param>
|
||||
/// <param name="pageItems">每页显示数据条目数量</param>
|
||||
protected override QueryData<User> Query(int pageIndex, int pageItems)
|
||||
{
|
||||
var data = UserHelper.Retrieves();
|
||||
if (!string.IsNullOrEmpty(QueryModel.UserName)) data = data.Where(d => d.UserName.Contains(QueryModel.UserName, StringComparison.OrdinalIgnoreCase));
|
||||
if (!string.IsNullOrEmpty(QueryModel.DisplayName)) data = data.Where(d => d.DisplayName.Contains(QueryModel.DisplayName, StringComparison.OrdinalIgnoreCase));
|
||||
var totalCount = data.Count();
|
||||
var items = data.Skip((pageIndex - 1) * pageItems).Take(pageItems);
|
||||
return new QueryData<User>() { Items = items, TotalCount = totalCount, PageIndex = pageIndex, PageItems = pageItems };
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 保存方法
|
||||
/// </summary>
|
||||
protected override bool Save(User user) => UserHelper.Save(user);
|
||||
|
||||
/// <summary>
|
||||
/// 删除方法
|
||||
/// </summary>
|
||||
protected override bool Delete(IEnumerable<User> users) => UserHelper.Delete(users.Select(item => item.Id ?? ""));
|
||||
}
|
||||
}
|
|
@ -4,6 +4,7 @@ using Longbow.Security.Cryptography;
|
|||
using PetaPoco;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
|
||||
namespace Bootstrap.DataAccess
|
||||
|
@ -22,6 +23,7 @@ namespace Bootstrap.DataAccess
|
|||
/// <summary>
|
||||
/// 获取/设置 密码
|
||||
/// </summary>
|
||||
[DisplayName("登录密码")]
|
||||
public string Password { get; set; } = "";
|
||||
|
||||
/// <summary>
|
||||
|
@ -38,21 +40,25 @@ namespace Bootstrap.DataAccess
|
|||
/// <summary>
|
||||
/// 获得/设置 用户注册时间
|
||||
/// </summary>
|
||||
[DisplayName("注册时间")]
|
||||
public DateTime RegisterTime { get; set; } = DateTime.Now;
|
||||
|
||||
/// <summary>
|
||||
/// 获得/设置 用户被批复时间
|
||||
/// </summary>
|
||||
[DisplayName("授权时间")]
|
||||
public DateTime? ApprovedTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获得/设置 用户批复人
|
||||
/// </summary>
|
||||
[DisplayName("授权人")]
|
||||
public string? ApprovedBy { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获得/设置 用户的申请理由
|
||||
/// </summary>
|
||||
[DisplayName("说明")]
|
||||
public string Description { get; set; } = "";
|
||||
|
||||
/// <summary>
|
||||
|
@ -71,6 +77,7 @@ namespace Bootstrap.DataAccess
|
|||
/// 获得/设置 新密码
|
||||
/// </summary>
|
||||
[ResultColumn]
|
||||
[DisplayName("确认密码")]
|
||||
public string NewPassword { get; set; } = "";
|
||||
|
||||
/// <summary>
|
||||
|
|
Loading…
Reference in New Issue