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

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,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
{