This commit is contained in:
2025-12-23 12:26:25 +08:00
parent 1f0c84f75e
commit 3c4144335f
14 changed files with 223 additions and 27 deletions

View File

@@ -5,7 +5,7 @@
/// <summary>
/// 数据ID
/// </summary>
public int Id { get; set; }
public int? Id { get; set; }
/// <summary>
/// 语言

View File

@@ -0,0 +1,137 @@
@page "/currency/create"
@page "/currency/edit/{id:long}"
@page "/{locale}/currency/create"
@page "/{locale}/currency/edit/{id:long}"
@inject ILogger<CurrencyEdit> Logger
@attribute [Authorize]
<PageContainer Title="@(Id > 0 ? "编辑货币信息" : "新增货币信息")">
<Breadcrumb>
<Breadcrumb>
<BreadcrumbItem Href="/">管理后台</BreadcrumbItem>
<BreadcrumbItem Href="/admin/list">系统功能</BreadcrumbItem>
<BreadcrumbItem>货币管理</BreadcrumbItem>
</Breadcrumb>
</Breadcrumb>
<ChildContent>
<Spin Spinning="pageLoading">
<Card Title="货币信息">
<Form @ref="editform" Model="@model" LabelColSpan="5" WrapperColSpan="14" OnFinish="OnFormFinishAsync">
<FormItem Label="名称" Required>
<Input @bind-Value="@context.Name" Placeholder="货币名称" />
</FormItem>
<FormItem Label="货币代码">
<Input @bind-Value="@context.CurrencyCode" Placeholder="货币代码" />
</FormItem>
<FormItem Label="汇率">
<Input @bind-Value="@context.Rate" Placeholder="汇率" />
</FormItem>
<FormItem Label="展示本地">
<SimpleSelect @bind-Value="@context.DisplayLocale" Placeholder="语言文化">
<SelectOptions>
@foreach (var item in LanguageCultures)
{
<SimpleSelectOption Value="@item.Key" Label="@($"{item.Value} - {item.Key}")"></SimpleSelectOption>
}
</SelectOptions>
</SimpleSelect>
</FormItem>
<FormItem Label="自定义格式">
<Input @bind-Value="@context.CustomFormatting" Placeholder="自定义格式" />
</FormItem>
<FormItem Label="显示排序">
<Input @bind-Value="@context.DisplayOrder" Placeholder="显示排序" />
</FormItem>
<FormItem Label="状态">
<Checkbox Checked="@context.Enabled">启用</Checkbox>
</FormItem>
<FormItem WrapperCol="new ColLayoutParam { Span = 24, Offset = 5 }">
<Button Type="@ButtonType.Primary" HtmlType="submit" Loading="saving">
提交保存
</Button>
</FormItem>
</Form>
</Card>
</Spin>
</ChildContent>
</PageContainer>
@code {
[Parameter]
public string Locale { get; set; } = string.Empty;
[Parameter]
public long Id { get; set; }
[SupplyParameterFromForm]
CurrencyModel model { get; set; } = new();
Form<CurrencyModel> editform = null!;
Dictionary<string, string> LanguageCultures = LanguageCulture.Descriptions.ToDictionary();
bool pageLoading = false;
bool saving = false;
protected override void OnInitialized()
{
base.OnInitialized();
}
protected override void OnParametersSet()
{
if (Id > 0)
{
LoadData();
}
base.OnParametersSet();
}
async void LoadData()
{
pageLoading = true;
var url = $"/api/currency/{Id}";
var apiResult = await HttpService.Get<ApiResult<Currency>>(url);
if (apiResult.Success)
{
if (apiResult.Data == null)
{
Navigation.NavigateTo($"/currency/create");
}
else
{
model = apiResult.Data.Adapt<CurrencyModel>();
}
}
else
{
Navigation.NavigateTo($"/currency/create");
}
pageLoading = false;
StateHasChanged();
}
async void OnFormFinishAsync()
{
if (editform.Validate())
{
saving = true;
var url = $"api/currency/save";
var result = new ApiResult<string>();
result = await HttpService.Post<ApiResult<string>>(url, model);
if (result.Code == (int)ResultCode.Success)
{
saving = false;
await ModalService.InfoAsync(new ConfirmOptions() { Title = "提示", Content = "数据提交成功!" });
Navigation.NavigateTo($"/currency/list");
}
else
{
saving = false;
await ModalService.ErrorAsync(new ConfirmOptions() { Title = "服务异常", Content = result.Message });
}
}
}
}

View File

@@ -3,8 +3,8 @@
@inject ILogger<CurrencyList> Logger
@attribute [Authorize]
<PageTitle>货币管理</PageTitle>
<PageContainer Title="语言管理">
<PageContainer Title="货币管理">
<Breadcrumb>
<Breadcrumb>
<BreadcrumbItem>Home</BreadcrumbItem>
@@ -112,7 +112,10 @@
</Table>
<br />
<Row Justify="RowJustify.End">
<Pagination PageIndex="pager.Index" Total="PagingList.Count" PageSize="PagingList.Size" ShowSizeChanger="false" OnChange="OnPageChanged"></Pagination>
@if (PagingList.Count > 0)
{
<Pagination Current="PagingList.Index" Total="PagingList.Count" PageSize="PagingList.Size" ShowSizeChanger="false" OnChange="OnPageChanged"></Pagination>
}
</Row>
</ChildContent>
</Card>
@@ -247,7 +250,7 @@
void HandleAddNew()
{
Navigation.NavigateTo($"/currency/edit");
Navigation.NavigateTo($"/currency/create");
}
@@ -256,4 +259,4 @@
Navigation.NavigateTo($"/currency/edit/{model.Id}");
}
}
}

View File

@@ -107,7 +107,10 @@
</Table>
<br />
<Row Justify="RowJustify.End">
<Pagination PageIndex="PagingList.Index" Total="PagingList.Count" PageSize="PagingList.Size" ShowSizeChanger="false" OnChange="OnPageChanged"></Pagination>
@if (PagingList.Count > 0)
{
<Pagination Current="PagingList.Index" Total="PagingList.Count" PageSize="PagingList.Size" ShowSizeChanger="false" OnChange="OnPageChanged"></Pagination>
}
</Row>
</Card>

View File

@@ -156,7 +156,10 @@
</Table>
<br />
<Row Justify="RowJustify.End">
<Pagination PageIndex="pager.Index" Total="PagingList.Count" PageSize="PagingList.Size" ShowSizeChanger="false" OnChange="OnPageChanged"></Pagination>
@if (PagingList.Count > 0)
{
<Pagination Current="PagingList.Index" Total="PagingList.Count" PageSize="PagingList.Size" ShowSizeChanger="false" OnChange="OnPageChanged"></Pagination>
}
</Row>
</Card>
</ChildContent>

View File

@@ -92,6 +92,13 @@
</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()">
@@ -290,9 +297,9 @@
}
}
private void OnPageChanged(int args)
private void OnPageChanged(PaginationEventArgs args)
{
OnSearch(args);
OnSearch(args.Page);
}
void CloseDrawer()

View File

@@ -98,7 +98,10 @@
</Table>
<br />
<Row Justify="RowJustify.End">
<Pagination PageIndex="pager.Index" Total="PagingList.Count" PageSize="PagingList.Size" ShowSizeChanger="false" OnChange="OnPageChanged"></Pagination>
@if (PagingList.Count > 0)
{
<Pagination Current="PagingList.Index" Total="PagingList.Count" PageSize="PagingList.Size" ShowSizeChanger="false" OnChange="OnPageChanged"></Pagination>
}
</Row>
</Card>

View File

@@ -78,6 +78,13 @@
</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()">
@@ -252,9 +259,9 @@
}
}
private void OnPageChanged(int args)
private void OnPageChanged(PaginationEventArgs args)
{
OnSearch(args);
OnSearch(args.Page);
}
void CloseDrawer()

View File

@@ -90,7 +90,10 @@
</Table>
<br />
<Row Justify="RowJustify.End">
<Pagination PageIndex="pager.Index" Total="PagingList.Count" PageSize="PagingList.Size" ShowSizeChanger="false" OnChange="OnPageChanged"></Pagination>
@if (PagingList.Count > 0)
{
<Pagination Current="PagingList.Index" Total="PagingList.Count" PageSize="PagingList.Size" ShowSizeChanger="false" OnChange="OnPageChanged"></Pagination>
}
</Row>
</Card>
</Spin>

View File

@@ -90,7 +90,10 @@
</Table>
<br />
<Row Justify="RowJustify.End">
<Pagination PageIndex="pager.Index" Total="PagingList.Count" PageSize="PagingList.Size" ShowSizeChanger="false" OnChange="OnPageChanged"></Pagination>
@if (PagingList.Count > 0)
{
<Pagination Current="PagingList.Index" Total="PagingList.Count" PageSize="PagingList.Size" ShowSizeChanger="false" OnChange="OnPageChanged"></Pagination>
}
</Row>
</Card>

View File

@@ -0,0 +1,11 @@
namespace Atomx.Admin.Client.Services
{
public interface INavigationService
{
}
public class NavigationService
{
}
}

View File

@@ -1,5 +1,4 @@
using AntDesign;
using Atomx.Admin.Client.Models;
using Atomx.Admin.Client.Models;
using Atomx.Admin.Services;
using Atomx.Common.Entities;
using Atomx.Common.Models;
@@ -8,8 +7,8 @@ using Atomx.Data.CacheServices;
using Atomx.Data.Services;
using Atomx.Utils.Extension;
using FluentValidation;
using Mapster;
using MapsterMapper;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Localization;
@@ -85,7 +84,7 @@ namespace Atomx.Admin.Controllers
/// <param name="size"></param>
/// <returns></returns>
[HttpPost("search")]
public async Task<IActionResult> GetList(CurrencySearchModel search, int page, int size = 20)
public async Task<IActionResult> GetList(CurrencySearchModel search, int page, int size = 20)
{
var startTime = search.RangeTime[0];
if (startTime != null)
@@ -197,7 +196,7 @@ namespace Atomx.Admin.Controllers
result.Success = false;
return new JsonResult(result);
}
if (model.IsEdit && model.Id > 0)
if (model.Id.HasValue && model.Id > 0)
{
var data = _dbContext.Currencies.SingleOrDefault(p => p.Id == model.Id);
if (data == null)
@@ -211,20 +210,33 @@ namespace Atomx.Admin.Controllers
data = _mapper.Map(model, data);
data.UpdateTime = DateTime.UtcNow;
_dbContext.SaveChanges();
await _cacheService.GetCurrenciesById(model.Id, data);
}
else
{
var data = _mapper.Map<Currency>(model);
data.CreateTime = DateTime.UtcNow;
var data = new Currency()
{
Name = model.Name,
CurrencyCode = model.CurrencyCode,
DisplayLocale = model.DisplayLocale,
CustomFormatting = model.CustomFormatting,
Rate = (decimal)model.Rate,
DisplayOrder = model.DisplayOrder,
EnableDisplay = model.Enabled,
Symbolic = "",
Enabled = model.Enabled,
Title = model.Name,
EnablePay = true,
CreateTime = DateTime.UtcNow
};
_dbContext.Currencies.Add(data);
_dbContext.SaveChanges();
await _cacheService.GetCurrenciesById(model.Id, data);
}
result.Data = true;
//todo 更新缓存
return new JsonResult(result);
}

View File

@@ -12,8 +12,8 @@ namespace Atomx.Common.Entities
/// <summary>
/// 数据ID
/// </summary>
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
/// <summary>

View File

@@ -23,7 +23,11 @@ namespace Atomx.Data
protected override void OnModelCreating(ModelBuilder builder)
{
base.OnModelCreating(builder);
builder.Entity<Currency>(entity =>
{
entity.Property(e => e.Id).ValueGeneratedOnAdd();
});
}
/// <summary>