实现网站应用管理
This commit is contained in:
@@ -18,6 +18,11 @@
|
||||
/// </summary>
|
||||
public string Name { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 介绍
|
||||
/// </summary>
|
||||
public string Description { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 是否可用
|
||||
/// </summary>
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
<a href="/system/language/list">多语言设置</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="/system/locale/resource/list">多语言资源设置</a>
|
||||
<a href="/system/app/list">网站应用</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="/system/role/list">角色管理</a>
|
||||
|
||||
@@ -3,20 +3,243 @@
|
||||
@inject ILogger<SiteAppList> Logger
|
||||
@attribute [Authorize]
|
||||
|
||||
<PageContainer Title="系统工具">
|
||||
<PageContainer Title="网站应用">
|
||||
<Breadcrumb>
|
||||
<Breadcrumb>
|
||||
<BreadcrumbItem Href="/">管理后台</BreadcrumbItem>
|
||||
<BreadcrumbItem Href="/admin/list">系统功能</BreadcrumbItem>
|
||||
<BreadcrumbItem>系统工具</BreadcrumbItem>
|
||||
<BreadcrumbItem>网站应用</BreadcrumbItem>
|
||||
</Breadcrumb>
|
||||
</Breadcrumb>
|
||||
<ChildContent>
|
||||
<h3>Tools</h3>
|
||||
<Card Class="mt-3">
|
||||
<Table DataSource="PagingList.Items" PageSize="100" HidePagination="true" Resizable>
|
||||
<TitleTemplate>
|
||||
<Flex Justify="FlexJustify.SpaceBetween">
|
||||
网站应用
|
||||
<div>
|
||||
<Button Class="me-3" OnClick="OnCreateClick" Type="ButtonType.Primary">新增</Button>
|
||||
</div>
|
||||
</Flex>
|
||||
</TitleTemplate>
|
||||
<ColumnDefinitions>
|
||||
<PropertyColumn Property="c => c.Name" Title="名称">
|
||||
</PropertyColumn>
|
||||
<PropertyColumn Property="c => c.Description" Title="说明" />
|
||||
<PropertyColumn Property="c => c.Enabled" Title="状态" Width="80px" Align="ColumnAlign.Center">
|
||||
@if (context.Enabled)
|
||||
{
|
||||
<AntDesign.Text Type="TextElementType.Success"><Icon Type="check" Theme=" IconThemeType.Outline" Width="1.3em" Height="1.3em" /></AntDesign.Text>
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
<Icon Type="close" Theme="IconThemeType.Outline" Width="1.3em" Height="1.3em" />
|
||||
}
|
||||
</PropertyColumn>
|
||||
|
||||
<PropertyColumn Property="c => c.UpdateTime" Title="最后更新" Width="190px" />
|
||||
<ActionColumn Title="操作" Align="ColumnAlign.Right" Width="160px">
|
||||
<Space>
|
||||
<SpaceItem>
|
||||
<Dropdown Trigger="@(new Trigger[] { Trigger.Click })">
|
||||
<Overlay>
|
||||
<Menu>
|
||||
|
||||
<MenuItem>
|
||||
<a @onclick="(e) => OnEditClick(context)"> <Icon Type="@IconType.Outline.Edit" /> 编辑</a>
|
||||
</MenuItem>
|
||||
<MenuDivider />
|
||||
<MenuItem>
|
||||
<Popconfirm Placement="@Placement.Left" Title="@("删除这条数据无法恢复,您确定要删除吗?")"
|
||||
OnConfirm="@(e=>HandleDeleteConfirmAsync(e,context.Id))"
|
||||
OkText="确定"
|
||||
CancelText="取消">
|
||||
<a> <Icon Type="@IconType.Outline.Delete" /> 删除</a>
|
||||
</Popconfirm>
|
||||
</MenuItem>
|
||||
</Menu>
|
||||
</Overlay>
|
||||
<ChildContent>
|
||||
<a class="ant-dropdown-link" @onclick:preventDefault>
|
||||
<Icon Type="@IconType.Outline.Menu" />
|
||||
</a>
|
||||
</ChildContent>
|
||||
</Dropdown>
|
||||
</SpaceItem>
|
||||
</Space>
|
||||
</ActionColumn>
|
||||
</ColumnDefinitions>
|
||||
</Table>
|
||||
<br />
|
||||
<Row Justify="RowJustify.End">
|
||||
@if (PagingList.Count > 0)
|
||||
{
|
||||
<Pagination Current="PagingList.Index" Total="PagingList.Count" PageSize="PagingList.Size" ShowSizeChanger="false" OnChange="OnPageChanged"></Pagination>
|
||||
}
|
||||
</Row>
|
||||
</Card>
|
||||
|
||||
<Drawer Closable="true" Width="520" Visible="drawerVisible" Title='(model.Id == 0 ? "新增应用" : "编辑应用")' OnClose="_ => CloseDrawer()">
|
||||
<Form LabelColSpan="5" @ref="@editform" Model="@model" OnFinish="OnFormFinish">
|
||||
<FluentValidationValidator />
|
||||
<FormItem Label="名称">
|
||||
<Input @bind-Value="model.Name" For="(()=>model.Name)" Placeholder="名称" />
|
||||
</FormItem>
|
||||
<FormItem Label="说明">
|
||||
<Input @bind-Value="model.Description" For="(()=>model.Culture)" Placeholder="说明" />
|
||||
</FormItem>
|
||||
<FormItem Label="状态">
|
||||
<Checkbox T="bool" Label="启用" @bind-value="model.Enabled" Size="InputSize.Small" Class="ps-0" />
|
||||
</FormItem>
|
||||
<FormItem WrapperColOffset="4">
|
||||
<Button Type="ButtonType.Primary" HtmlType="submit" Style="width: 100%;">保存</Button>
|
||||
</FormItem>
|
||||
</Form>
|
||||
</Drawer>
|
||||
</ChildContent>
|
||||
</PageContainer>
|
||||
|
||||
@code {
|
||||
[Parameter]
|
||||
public string Locale { get; set; } = string.Empty;
|
||||
|
||||
[SupplyParameterFromQuery]
|
||||
int? Page { get; set; }
|
||||
|
||||
[SupplyParameterFromQuery(Name = "size")]
|
||||
int? PageSize { get; set; }
|
||||
|
||||
[SupplyParameterFromForm]
|
||||
SiteAppSearch search { get; set; } = default!;
|
||||
|
||||
[SupplyParameterFromForm]
|
||||
SiteAppModel model { get; set; } = default!;
|
||||
Form<SiteAppModel> editform = null!;
|
||||
|
||||
PagingList<SiteApp> PagingList = new();
|
||||
bool loading { get; set; } = true;
|
||||
|
||||
bool drawerVisible;
|
||||
bool isSave = false;
|
||||
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
search ??= new SiteAppSearch();
|
||||
model ??= new SiteAppModel();
|
||||
base.OnInitialized();
|
||||
}
|
||||
|
||||
protected override async Task OnParametersSetAsync()
|
||||
{
|
||||
await LoadList();
|
||||
}
|
||||
|
||||
|
||||
private async Task LoadList()
|
||||
{
|
||||
|
||||
loading = true;
|
||||
var url = "/api/siteapp/search";
|
||||
var apiResult = await HttpService.GetPagingList<SiteApp>(url, search ?? new SiteAppSearch(), Page.GetValueOrDefault(1), PageSize.GetValueOrDefault(20));
|
||||
if (apiResult.Success)
|
||||
{
|
||||
if (apiResult.Data != null)
|
||||
{
|
||||
PagingList = apiResult.Data;
|
||||
}
|
||||
}
|
||||
loading = false;
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private void OnSearch(int page)
|
||||
{
|
||||
var queryString = search.BuildQueryString();
|
||||
if (string.IsNullOrEmpty(queryString))
|
||||
{
|
||||
if (page > 1)
|
||||
{
|
||||
Navigation.NavigateTo($"/system/app/list?page={page}");
|
||||
}
|
||||
else
|
||||
{
|
||||
Navigation.NavigateTo($"/system/app/list");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (page > 1)
|
||||
{
|
||||
Navigation.NavigateTo($"/system/app/list?page={page}&{queryString}");
|
||||
}
|
||||
else
|
||||
{
|
||||
Navigation.NavigateTo($"/system/app/list?{queryString}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OnCreateClick()
|
||||
{
|
||||
model = new();
|
||||
drawerVisible = true;
|
||||
}
|
||||
|
||||
void OnEditClick(SiteApp role)
|
||||
{
|
||||
model = role.Adapt<SiteAppModel>();
|
||||
drawerVisible = true;
|
||||
}
|
||||
|
||||
async Task HandleDeleteConfirmAsync(MouseEventArgs e, long id)
|
||||
{
|
||||
var url = $"/api/siteapp/delete/{id}";
|
||||
var apiResult = await HttpService.Post<ApiResult<string>>(url, new());
|
||||
if (apiResult.Success)
|
||||
{
|
||||
await LoadList();
|
||||
await ModalService.InfoAsync(new ConfirmOptions() { Title = "操作提示", Content = "删除数据成功" });
|
||||
}
|
||||
else
|
||||
{
|
||||
await ModalService.ErrorAsync(new ConfirmOptions() { Title = "操作提示", Content = $"数据删除失败.{apiResult.Message}" });
|
||||
}
|
||||
}
|
||||
|
||||
async Task OnFormFinish()
|
||||
{
|
||||
if (editform.Validate())
|
||||
{
|
||||
var apiResult = new ApiResult<string>();
|
||||
if (model != null)
|
||||
{
|
||||
var url = $"api/siteapp/save";
|
||||
apiResult = await HttpService.Post<ApiResult<string>>(url, model);
|
||||
|
||||
if (apiResult.Success)
|
||||
{
|
||||
ModalService.Success(new ConfirmOptions() { Title = "提示", Content = "数据提交成功!" });
|
||||
CloseDrawer();
|
||||
await LoadList();
|
||||
}
|
||||
else
|
||||
{
|
||||
await ModalService.ErrorAsync(new ConfirmOptions() { Title = "服务异常", Content = apiResult.Message });
|
||||
}
|
||||
}
|
||||
}
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private void OnPageChanged(PaginationEventArgs args)
|
||||
{
|
||||
OnSearch(args.Page);
|
||||
}
|
||||
|
||||
void CloseDrawer()
|
||||
{
|
||||
drawerVisible = false;
|
||||
editform.Reset();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ using Atomx.Admin.Client.Validators;
|
||||
using Atomx.Admin.Services;
|
||||
using Atomx.Common.Entities;
|
||||
using Atomx.Common.Models;
|
||||
using Atomx.Core.Jos;
|
||||
using Atomx.Data;
|
||||
using Atomx.Data.CacheServices;
|
||||
using Atomx.Data.Services;
|
||||
@@ -24,8 +25,9 @@ namespace Atomx.Admin.Controllers
|
||||
readonly IMapper _mapper;
|
||||
readonly DataContext _dbContext;
|
||||
readonly ICacheService _cacheService;
|
||||
private readonly IValidator<SiteAppModel> _validator;
|
||||
private readonly IStringLocalizer<SiteAppController> _localizer;
|
||||
readonly IBackgroundJobService _backgroundService;
|
||||
readonly IValidator<SiteAppModel> _validator;
|
||||
readonly IStringLocalizer<SiteAppController> _localizer;
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
@@ -35,7 +37,7 @@ namespace Atomx.Admin.Controllers
|
||||
/// <param name="messageTemplateService"></param>
|
||||
/// <param name="mapper"></param>
|
||||
public SiteAppController(ILogger<SiteAppController> logger, IIdentityService identityService, IIdCreatorService idCreator, IMapper mapper, DataContext dataContext, ICacheService cacheService,
|
||||
IValidator<SiteAppModel> validator, IStringLocalizer<SiteAppController> localizer)
|
||||
IBackgroundJobService backgroundJobService, IValidator<SiteAppModel> validator, IStringLocalizer<SiteAppController> localizer)
|
||||
{
|
||||
_logger = logger;
|
||||
_identityService = identityService;
|
||||
@@ -43,6 +45,7 @@ namespace Atomx.Admin.Controllers
|
||||
_mapper = mapper;
|
||||
_dbContext = dataContext;
|
||||
_cacheService = cacheService;
|
||||
_backgroundService = backgroundJobService;
|
||||
_validator = validator;
|
||||
_localizer = localizer;
|
||||
|
||||
@@ -117,7 +120,7 @@ namespace Atomx.Admin.Controllers
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("add")]
|
||||
[HttpPost("save")]
|
||||
public IActionResult Add(SiteAppModel model)
|
||||
{
|
||||
var result = new ApiResult<string>();
|
||||
@@ -130,40 +133,8 @@ namespace Atomx.Admin.Controllers
|
||||
}
|
||||
try
|
||||
{
|
||||
model.Id = _idCreator.CreateId();
|
||||
var message = _mapper.Map<SiteApp>(model);
|
||||
message.CreateTime = DateTime.UtcNow;
|
||||
|
||||
_dbContext.SiteApps.Add(message);
|
||||
var count = _dbContext.SaveChanges();
|
||||
|
||||
result = result.IsSuccess(count.ToString());
|
||||
}
|
||||
catch (Exception ex)
|
||||
if (model.Id > 0)
|
||||
{
|
||||
result = result.IsFail(ex.Message);
|
||||
_logger.LogError(ex.Message);
|
||||
}
|
||||
return new JsonResult(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 编辑
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("edit")]
|
||||
public IActionResult Edit(SiteAppModel model)
|
||||
{
|
||||
var result = new ApiResult<string>();
|
||||
var validation = _validator.Validate(model);
|
||||
if (!validation.IsValid)
|
||||
{
|
||||
var message = validation.Errors.FirstOrDefault()?.ErrorMessage;
|
||||
result = result.IsFail(message ?? string.Empty, null);
|
||||
return new JsonResult(result);
|
||||
}
|
||||
|
||||
var data = _dbContext.SiteApps.SingleOrDefault(p => p.Id == model.Id);
|
||||
if (data == null)
|
||||
{
|
||||
@@ -173,20 +144,30 @@ namespace Atomx.Admin.Controllers
|
||||
|
||||
data.UpdateTime = DateTime.UtcNow;
|
||||
|
||||
try
|
||||
{
|
||||
int count = _dbContext.SaveChanges();
|
||||
result = result.IsSuccess(count.ToString());
|
||||
}
|
||||
else
|
||||
{
|
||||
model.Id = _idCreator.CreateId();
|
||||
var message = _mapper.Map<SiteApp>(model);
|
||||
message.CreateTime = DateTime.UtcNow;
|
||||
|
||||
_dbContext.SiteApps.Add(message);
|
||||
|
||||
var count = _dbContext.SaveChanges();
|
||||
result = result.IsSuccess(count.ToString());
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
result = result.IsFail(ex.Message);
|
||||
_logger.LogError(ex.Message);
|
||||
Console.WriteLine(ex.Message);
|
||||
}
|
||||
return new JsonResult(result);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 根据ID删除
|
||||
/// </summary>
|
||||
|
||||
@@ -17,17 +17,22 @@ namespace Atomx.Common.Entities
|
||||
public int Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 网站应用类型
|
||||
/// 网站应用类型,
|
||||
/// </summary>
|
||||
public int Type { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 网站应用名称
|
||||
/// </summary>
|
||||
[Column(TypeName = "varchar(64)")]
|
||||
public string Name { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 介绍
|
||||
/// </summary>
|
||||
[Column(TypeName = "varchar(512)")]
|
||||
public string Description { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 是否可用
|
||||
/// </summary>
|
||||
|
||||
1532
Atomx.Data/Migrations/20260106161128_0.3.Designer.cs
generated
Normal file
1532
Atomx.Data/Migrations/20260106161128_0.3.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
29
Atomx.Data/Migrations/20260106161128_0.3.cs
Normal file
29
Atomx.Data/Migrations/20260106161128_0.3.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Atomx.Data.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class _03 : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AddColumn<string>(
|
||||
name: "Description",
|
||||
table: "SiteApps",
|
||||
type: "varchar(512)",
|
||||
nullable: false,
|
||||
defaultValue: "");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropColumn(
|
||||
name: "Description",
|
||||
table: "SiteApps");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1298,6 +1298,10 @@ namespace Atomx.Data.Migrations
|
||||
b.Property<DateTime>("CreateTime")
|
||||
.HasColumnType("timestamptz");
|
||||
|
||||
b.Property<string>("Description")
|
||||
.IsRequired()
|
||||
.HasColumnType("varchar(512)");
|
||||
|
||||
b.Property<bool>("Enabled")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user