完善国家管理和数据多语言

This commit is contained in:
2025-12-26 00:21:11 +08:00
parent 46794708ff
commit 030299fa53
10 changed files with 182 additions and 150 deletions

View File

@@ -1,8 +1,11 @@
namespace Atomx.Admin.Client.Models
using System.Runtime.Serialization;
namespace Atomx.Admin.Client.Models
{
public class StateProvinceSearch
{
public long CountryId { get; set; }
[IgnoreDataMember]
public long? CountryId { get; set; }
public string Name { get; set; } = string.Empty;
}
}

View File

@@ -21,12 +21,12 @@
<Form @ref="editform" Model="@model" LabelColSpan="5" WrapperColSpan="14" OnFinish="OnFormFinishAsync">
@if (Id > 0 && languageList.Count() > 0)
{
<Tabs ActiveKey="@context.LanguageId" OnTabClick="OnLanguageTabChange">
<TabPane Key="0">
<Tabs ActiveKey="@model.LanguageId" OnTabClick="OnLanguageTabChange">
@* <TabPane Key="0">
<TabTemplate>
<span>标准</span>
</TabTemplate>
</TabPane>
</TabPane> *@
@foreach (var item in languageList)
{
<TabPane Key="@item.Key.ToString()">
@@ -38,28 +38,28 @@
</Tabs>
}
<FormItem Label="名称" Required>
<Input @bind-Value="@context.Name" Placeholder="国家" />
<Input @bind-Value="@model.Name" Placeholder="国家" />
</FormItem>
<FormItem Label="首字母">
<Input @bind-Value="@context.Initial" Placeholder="首字母" />
<Input @bind-Value="@model.Initial" Placeholder="首字母" />
</FormItem>
<FormItem Label="两个字母ISO代码">
<Input @bind-Value="@context.TwoLetterISOCode" Placeholder="两个字母ISO代码" />
<Input @bind-Value="@model.TwoLetterISOCode" Placeholder="两个字母ISO代码" />
</FormItem>
<FormItem Label="三字母ISO代码">
<Input @bind-Value="@context.ThreeLetterISOCode" Placeholder="三字母ISO代码" />
<Input @bind-Value="@model.ThreeLetterISOCode" Placeholder="三字母ISO代码" />
</FormItem>
<FormItem Label="数字ISO代码">
<Input @bind-Value="@context.NumericISOCode" Placeholder="数字ISO代码" />
<Input @bind-Value="@model.NumericISOCode" Placeholder="数字ISO代码" />
</FormItem>
<FormItem Label="允许发货">
<Checkbox Checked="@context.AllowShipping">允许发货</Checkbox>
<Checkbox Checked="@model.AllowShipping">允许发货</Checkbox>
</FormItem>
<FormItem Label="显示排序">
<Input @bind-Value="@context.DisplayOrder" Placeholder="显示排序" />
<Input @bind-Value="@model.DisplayOrder" Placeholder="显示排序" />
</FormItem>
<FormItem Label="状态">
<Checkbox Checked="@context.Enabled">启用</Checkbox>
<Checkbox T="bool" Label="启用" @bind-value="model.Enabled" Size="InputSize.Small" Class="ps-0" />
</FormItem>
<FormItem WrapperCol="new ColLayoutParam { Span = 24, Offset = 5 }">
<Button Type="@ButtonType.Primary" HtmlType="submit" Loading="saving">
@@ -71,6 +71,7 @@
</Spin>
</ChildContent>
</PageContainer>
@code {
[Parameter]
public string Locale { get; set; } = string.Empty;
@@ -110,7 +111,17 @@
var apiResult = await HttpService.Get<ApiResult<List<KeyValue>>>(url);
if (apiResult.Success)
{
languageList = apiResult.Data ?? new List<KeyValue>();
if(apiResult.Data == null)
{
languageList = new List<KeyValue>();
}
else
{
languageList = apiResult.Data;
languageList.Insert(0, new KeyValue() { Key = "0", Value = "标准" });
}
StateHasChanged();
}
}
@@ -145,6 +156,7 @@
{
if (editform.Validate())
{
Console.WriteLine(model.ToJson());
saving = true;
var url = $"api/country/save";
var result = new ApiResult<string>();

View File

@@ -48,16 +48,23 @@
<PropertyColumn Property="c => c.Enabled" Title="状态">
@if (context.Enabled)
{
<Text>已激活</text>
<AntDesign.Text Type="TextElementType.Success"><Icon Type="check" Theme=" IconThemeType.Outline" Width="1.3em" Height="1.3em" /></AntDesign.Text>
}
else
{
<Text>未激活</text>
<Icon Type="close" Theme="IconThemeType.Outline" Width="1.3em" Height="1.3em" />
}
</PropertyColumn>
<PropertyColumn Property="c => c.DisplayOrder" Title="排序" />
<ActionColumn Title="操作" Align="ColumnAlign.Right">
<Space>
<SpaceItem>
<a @onclick="(e) => GotoStateProvince(context)">州省管理</a>
</SpaceItem>
<SpaceItem>
<a @onclick="(e) => GotoArea(context)">城市管理</a>
</SpaceItem>
<SpaceItem>
<a @onclick="(e)=>HandleEdit(context)">编辑</a>
</SpaceItem>
@@ -127,7 +134,7 @@
pageLoading = true;
try
{
var url = "/api/country/searh";
var url = "/api/country/search";
var apiResult = await HttpService.GetPagingList<Country>(url, search, Page.GetValueOrDefault(1), PageSize.GetValueOrDefault(20));
if (apiResult.Success)
{
@@ -205,4 +212,13 @@
Navigation.NavigateTo($"/country/edit/{model.Id}");
}
void GotoStateProvince(Country model)
{
Navigation.NavigateTo($"/stateprovince/list/{model.Id}");
}
void GotoArea(Country model)
{
Navigation.NavigateTo($"/area/list/{model.Id}");
}
}

View File

@@ -16,7 +16,7 @@
<Spin Spinning="pageLoading">
<Card>
<Form @ref="searchForm" Model="search" Layout="FormLayout.Inline" Class="search-form" OnFinish="OnSearchFinish">
<Row Justify="RowJustify.Start" Gutter="16">
<Row Justify="RowJustify.Start" Gutter="(16, 16)">
<Col>
<FormItem Label="名称">
<Input @bind-Value="search.Name" Placeholder="名称" AllowClear />
@@ -43,7 +43,7 @@
</AntDesign.Col>
}
<Col>
<div class="ant-form-item">
<div class="ant-form-item" style="display:flex">
<Button Type="ButtonType.Primary" HtmlType="submit">查询</Button>
<Button Style="margin: 0 8px;" OnClick="OnSearchReset">重置</Button>
<a style="font-size:12px; display:flex; align-items:center;text-align:center;" @onclick="()=>{searchExpand=!searchExpand;}">
@@ -61,6 +61,7 @@
</Row>
</Form>
</Card>
<br />
<Card Title="" Class="hideborder">
<Extra>
<div class="extraContent">
@@ -86,11 +87,11 @@
<PropertyColumn Property="c => c.Enabled" Title="状态">
@if (context.Enabled)
{
<Text>已激活</text>
<AntDesign.Text Type="TextElementType.Success"><Icon Type="check" Theme=" IconThemeType.Outline" Width="1.3em" Height="1.3em" /></AntDesign.Text>
}
else
{
<Text>未激活</text>
<Icon Type="close" Theme="IconThemeType.Outline" Width="1.3em" Height="1.3em" />
}
</PropertyColumn>
<PropertyColumn Property="c => c.DisplayOrder" Title="排序" />

View File

@@ -1,51 +1,41 @@
@page "/stateprovince/create"
@page "/stateprovince/edit/{id:long}"
@page "/{locale}/stateprovince/create"
@page "/{locale}/stateprovince/edit/{id:long}"
@page "/stateprovince/{countryId:long}/create"
@page "/stateprovince/{countryId:long}/edit/{id:long}"
@page "/{locale}/stateprovince/{countryId:long}/create"
@page "/{locale}/stateprovince/{countryId:long}/edit/{id:long}"
@inject ILogger<StateProvinceEdit> Logger
@attribute [Authorize]
<PageContainer Title="@(Id > 0 ? "编辑国家信息" : "新增国家信息")">
<PageContainer Title="@(Id > 0 ? "编辑州省信息" : "新增州省信息")">
<Breadcrumb>
<Breadcrumb>
<BreadcrumbItem Href="/">管理后台</BreadcrumbItem>
<BreadcrumbItem Href="/admin/list">系统配置</BreadcrumbItem>
<BreadcrumbItem Href="/settings">系统配置</BreadcrumbItem>
<BreadcrumbItem Href="/country/list">国家管理</BreadcrumbItem>
</Breadcrumb>
</Breadcrumb>
<ChildContent>
<Spin Spinning="pageLoading">
<Card Title="货币信息">
<Card Title="州省信息">
<Form @ref="editform" Model="@model" LabelColSpan="5" WrapperColSpan="14" OnFinish="OnFormFinishAsync">
<FormItem Label="国家">
<Input @bind-Value="@country.Name" Placeholder="国家名称" Disabled />
</FormItem>
<FormItem Label="名称" Required>
<Input @bind-Value="@context.Name" Placeholder="货币名称" />
<Input @bind-Value="@context.Name" Placeholder="名称" />
</FormItem>
<FormItem Label="货币代码">
<Input @bind-Value="@context.CurrencyCode" Placeholder="货币代码" />
<FormItem Label="首字母">
<Input @bind-Value="@context.Initial" 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 Label="缩写">
<Input @bind-Value="@context.Abbreviation" Placeholder="缩写" />
</FormItem>
<FormItem Label="显示排序">
<Input @bind-Value="@context.DisplayOrder" Placeholder="显示排序" />
</FormItem>
<FormItem Label="状态">
<Checkbox Checked="@context.Enabled">启用</Checkbox>
<Checkbox T="bool" Label="启用" @bind-value="model.Enabled" Size="InputSize.Small" Class="ps-0" />
</FormItem>
<FormItem WrapperCol="new ColLayoutParam { Span = 24, Offset = 5 }">
<Button Type="@ButtonType.Primary" HtmlType="submit" Loading="saving">
@@ -60,14 +50,17 @@
@code {
[Parameter]
public string Locale { get; set; } = string.Empty;
[Parameter]
public long CountryId { get; set; }
[Parameter]
public long Id { get; set; }
[SupplyParameterFromForm]
CurrencyModel model { get; set; } = new();
Form<CurrencyModel> editform = null!;
Dictionary<string, string> LanguageCultures = LanguageCulture.Descriptions.ToDictionary();
StateProvinceModel model { get; set; } = new();
Form<StateProvinceModel> editform = null!;
List<KeyValue> languageList = new();
Country country = new();
StateProvinceLocalizedModel stateProvince = new();
bool pageLoading = false;
bool saving = false;
@@ -78,6 +71,8 @@
protected override void OnParametersSet()
{
_ = LoadLanguage();
_ = LoadCountry();
if (Id > 0)
{
LoadData();
@@ -85,25 +80,65 @@
base.OnParametersSet();
}
async void LoadData()
async Task LoadCountry()
{
pageLoading = true;
var url = $"/api/currency/{Id}";
var apiResult = await HttpService.Get<ApiResult<Currency>>(url);
var url = $"/api/country?id={CountryId}";
var apiResult = await HttpService.Get<ApiResult<Country>>(url);
if (apiResult.Success)
{
if (apiResult.Data != null)
{
country = apiResult.Data;
StateHasChanged();
}
else
{
Navigation.NavigateTo($"/country/list");
}
}
}
async Task LoadLanguage()
{
var url = $"/api/language/enabled";
var apiResult = await HttpService.Get<ApiResult<List<KeyValue>>>(url);
if (apiResult.Success)
{
if (apiResult.Data == null)
{
Navigation.NavigateTo($"/currency/create");
languageList = new List<KeyValue>();
}
else
{
model = apiResult.Data.Adapt<CurrencyModel>();
languageList = apiResult.Data;
languageList.Insert(0, new KeyValue() { Key = "0", Value = "标准" });
}
StateHasChanged();
}
}
async void LoadData()
{
pageLoading = true;
var url = $"/api/stateprovince/detail/{Id}";
var apiResult = await HttpService.Get<ApiResult<StateProvinceLocalizedModel>>(url);
if (apiResult.Success)
{
if (apiResult.Data == null)
{
Navigation.NavigateTo($"/country/list");
}
else
{
stateProvince = apiResult.Data;
model = apiResult.Data.Adapt<StateProvinceModel>();
}
}
else
{
Navigation.NavigateTo($"/currency/create");
Navigation.NavigateTo($"/country/list");
}
pageLoading = false;
@@ -115,7 +150,7 @@
if (editform.Validate())
{
saving = true;
var url = $"api/currency/save";
var url = $"api/stateprovince/save";
var result = new ApiResult<string>();
result = await HttpService.Post<ApiResult<string>>(url, model);
@@ -124,7 +159,7 @@
{
saving = false;
await ModalService.InfoAsync(new ConfirmOptions() { Title = "提示", Content = "数据提交成功!" });
Navigation.NavigateTo($"/currency/list");
Navigation.NavigateTo($"/stateprovince/list");
}
else
{

View File

@@ -1,5 +1,5 @@
@page "/stateprovince/list"
@page "/{locale}/stateprovince/list"
@page "/stateprovince/list/{countryId:long}"
@page "/{locale}/stateprovince/list/{countryId:long}"
@inject ILogger<StateProvinceList> Logger
@attribute [Authorize]
@@ -15,90 +15,52 @@
</Breadcrumb>
<ChildContent>
<Spin Spinning="pageLoading">
<Card>
<Card>
<Form @ref="searchForm" Model="search" Layout="FormLayout.Inline" Class="search-form" OnFinish="OnSearchFinish">
<Row Justify="RowJustify.Start" Gutter="16">
<Row Justify="RowJustify.Start" Gutter="(16, 16)">
<Col>
<FormItem Label="名称">
<Input @bind-Value="search.Name" Placeholder="名称" AllowClear />
</FormItem>
</Col>
@if (searchExpand)
{
<AntDesign.Col>
<FormItem Label="发布时间">
<RangePicker @bind-Value="search.RangeTime"></RangePicker>
</FormItem>
</AntDesign.Col>
<AntDesign.Col>
<FormItem Label="状态">
<SimpleSelect DefaultValue="" Style="width:120px;" @bind-Value="@search.Status">
<SelectOptions>
<SimpleSelectOption Value="" Label="全部"></SimpleSelectOption>
<SimpleSelectOption Value="1" Label="草稿"></SimpleSelectOption>
<SimpleSelectOption Value="2" Label="已发布"></SimpleSelectOption>
<SimpleSelectOption Value="3" Label="已删除"></SimpleSelectOption>
</SelectOptions>
</SimpleSelect>
</FormItem>
</AntDesign.Col>
}
<Col>
<div class="ant-form-item">
<div class="ant-form-item" style="display:flex">
<Button Type="ButtonType.Primary" HtmlType="submit">查询</Button>
<Button Style="margin: 0 8px;" OnClick="OnSearchReset">重置</Button>
<a style="font-size:12px; display:flex; align-items:center;text-align:center;" @onclick="()=>{searchExpand=!searchExpand;}">
<Icon Type="@(searchExpand?"up":"down")"></Icon> @if (searchExpand)
{
<span>收起</span>
}
else
{
<span>展开</span>
}
</a>
</div>
</Col>
</Row>
</Form>
</Card>
<Card Title="" Class="hideborder">
<br />
<Card Title="州、省列表" Class="hideborder">
<Extra>
<div class="extraContent">
<Button Type="ButtonType.Primary" HtmlType="submit" OnClick="HandleAddNew">新增货币</Button>
<Button Type="ButtonType.Primary" HtmlType="submit" OnClick="HandleAddNew">新增州省</Button>
</div>
</Extra>
<ChildContent>
<Table DataSource="PagingList.Items" PageSize="100" HidePagination="true">
<Selection CheckStrictly />
<PropertyColumn Property="c => c.Name" Title="名称" />
<PropertyColumn Property="c => c.CurrencyCode" Title="货币代码" />
<PropertyColumn Property="c => c.Rate" Title="汇率" />
<PropertyColumn Property="c => c.PrimaryCurrency" Title="默认货币">
@if (context.PrimaryCurrency)
{
<AntDesign.Text Type="TextElementType.Success"><Icon Type="check" Theme="IconThemeType.Outline" /></AntDesign.Text>
}
else
{
<Icon Type="minus" Theme="IconThemeType.Outline" />
}
</PropertyColumn>
<PropertyColumn Property="c => c.Initial" Title="首字母" />
<PropertyColumn Property="c => c.Abbreviation" Title="缩写" />
<PropertyColumn Property="c => c.Enabled" Title="状态">
@if (context.Enabled)
{
<Text>已激活</text>
<AntDesign.Text Type="TextElementType.Success"><Icon Type="check" Theme=" IconThemeType.Outline" Width="1.3em" Height="1.3em" /></AntDesign.Text>
}
else
{
<Text>未激活</text>
<Icon Type="close" Theme="IconThemeType.Outline" Width="1.3em" Height="1.3em" />
}
</PropertyColumn>
<PropertyColumn Property="c => c.DisplayOrder" Title="排序" />
<ActionColumn Title="操作" Align="ColumnAlign.Right">
<Space>
<SpaceItem>
<a @onclick="(e)=>HandleEdit(context)">编辑</a>
<a @onclick="(e) => HandleEdit(context)">编辑</a>
</SpaceItem>
@*<SpaceItem>
<Popconfirm Placement="@Placement.Left" Title="@("删除这条数据无法恢复,您确定要删除吗?")"
@@ -127,6 +89,8 @@
@code {
[Parameter]
public string Locale { get; set; } = string.Empty;
[Parameter]
public long CountryId { get; set; }
[SupplyParameterFromQuery]
int? Page { get; set; }
@@ -137,10 +101,10 @@
bool pageLoading = false;
bool searchExpand = false;
Form<CurrencySearchModel> searchForm = new();
CurrencySearchModel search = new();
Form<StateProvinceSearch> searchForm = new();
StateProvinceSearch search = new();
PagingList<CurrencyModel> PagingList = new() { Size = 20 };
PagingList<StateProvince> PagingList = new() { Size = 20 };
protected override async Task OnInitializedAsync()
@@ -160,21 +124,7 @@
var uri = new Uri(Navigation.Uri);
var query = uri.Query;
search.Name = query.GetQueryString("Name");
search.Status = query.GetQueryString("Status");
var data = query.GetQueryString("RangeTime");
if (!string.IsNullOrEmpty(data))
{
var rangetime = data.Split("-");
if (rangetime != null && rangetime.Length > 0)
{
searchExpand = true;
search.RangeTime[0] = rangetime[0].NumberToDateTime();
search.RangeTime[1] = rangetime[1].NumberToDateTime();
StateHasChanged();
}
}
search.CountryId = CountryId;
}
async Task LoadListAsync()
@@ -182,8 +132,8 @@
try
{
pageLoading = true;
var url = "/api/currency/search";
var apiResult = await HttpService.GetPagingList<CurrencyModel>(url, search, Page.GetValueOrDefault(1), PageSize.GetValueOrDefault(20));
var url = "/api/stateprovince/search";
var apiResult = await HttpService.GetPagingList<StateProvince>(url, search, Page.GetValueOrDefault(1), PageSize.GetValueOrDefault(20));
if (apiResult.Success)
{
if (apiResult.Data != null)
@@ -206,7 +156,7 @@
void OnSearchReset()
{
search = new CurrencySearchModel();
search = new();
searchForm?.Reset();
}
@@ -217,22 +167,22 @@
{
if (page > 1)
{
Navigation.NavigateTo($"/currency/list?page={page}");
Navigation.NavigateTo($"/stateprovince/list/{CountryId}?page={page}");
}
else
{
Navigation.NavigateTo($"/currency/list");
Navigation.NavigateTo($"/stateprovince/list/{CountryId}");
}
}
else
{
if (page > 1)
{
Navigation.NavigateTo($"/currency/list?page={page}&{queryString}");
Navigation.NavigateTo($"/stateprovince/list/{CountryId}?page={page}&{queryString}");
}
else
{
Navigation.NavigateTo($"/currency/list?{queryString}");
Navigation.NavigateTo($"/stateprovince/list/{CountryId}?{queryString}");
}
}
}
@@ -251,17 +201,13 @@
void HandleAddNew()
{
Navigation.NavigateTo($"/currency/create");
Navigation.NavigateTo($"/stateprovince/{CountryId}/create");
}
void HandleEdit(CurrencyModel model)
void HandleEdit(StateProvince model)
{
Navigation.NavigateTo($"/currency/edit/{model.Id}");
Navigation.NavigateTo($"/stateprovince/{CountryId}/edit/{model.Id}");
}
}
@code {
}
}

View File

@@ -61,7 +61,7 @@ namespace Atomx.Admin.Controllers
/// <param name="page"></param>
/// <param name="size"></param>
/// <returns></returns>
[HttpPost("searh")]
[HttpPost("search")]
[Authorize(Policy = Permissions.User.View)]
public IActionResult AddressList(AreaSearch search, int page, int size = 20)
{

View File

@@ -9,6 +9,7 @@ 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;
@@ -61,7 +62,7 @@ namespace Atomx.Admin.Controllers
/// <param name="page"></param>
/// <param name="size"></param>
/// <returns></returns>
[HttpPost("searh")]
[HttpPost("search")]
public IActionResult Search(CountrySearch search, int page, int size = 20)
{
if (page < 1)
@@ -214,8 +215,19 @@ namespace Atomx.Admin.Controllers
_dbContext.LocalizedProperties.AddRange(addLocalizedList);
}
data.Enabled = model.Enabled;
data.DisplayOrder = model.DisplayOrder;
var config = new TypeAdapterConfig();
config.NewConfig<CountryModel, Country>()
.Ignore(dest => dest.Name).Ignore(dest => dest.Id);
data = model.Adapt<CountryModel, Country>(data, config);
//data = _mapper.Map(model, data);
//data.TwoLetterISOCode = model.TwoLetterISOCode;
//data.Initial = model.Initial;
//data.AllowShipping = model.AllowShipping;
//data.NumericISOCode = model.NumericISOCode;
//data.ThreeLetterISOCode = model.ThreeLetterISOCode;
//data.Enabled = model.Enabled;
//data.DisplayOrder = model.DisplayOrder;
try

View File

@@ -57,7 +57,7 @@ namespace Atomx.Admin.Controllers
/// <param name="page"></param>
/// <param name="size"></param>
/// <returns></returns>
[HttpPost("searh")]
[HttpPost("search")]
[Authorize(Policy = Permissions.User.View)]
public IActionResult AddressList(StateProvinceSearch search, int page, int size = 20)
{