This commit is contained in:
2025-12-25 12:41:37 +08:00
parent 7b6ec9c1d8
commit f7bb6bb2dc
10 changed files with 363 additions and 109 deletions

View File

@@ -0,0 +1,5 @@
<h3>AreaEdit</h3>
@code {
}

View File

@@ -0,0 +1,207 @@
@page "/area/list/{countryId:long}"
@page "/{locale}/area/list/{countryId:long}"
@inject ILogger<CountryList> Logger
@attribute [Authorize]
<PageContainer Title="国家管理">
<Breadcrumb>
<Breadcrumb>
<BreadcrumbItem>Home</BreadcrumbItem>
<BreadcrumbItem>系统配置</BreadcrumbItem>
<BreadcrumbItem>国家管理</BreadcrumbItem>
</Breadcrumb>
</Breadcrumb>
<ChildContent>
<Spin Spinning="pageLoading">
<Card>
<Form @ref="searchForm" Model="search" Layout="FormLayout.Inline" Class="search-form" OnFinish="OnSearchFinish">
<Row Justify="RowJustify.Start" Gutter="16">
<Col>
<FormItem Label="名称">
<Input @bind-Value="search.Name" Placeholder="名称" AllowClear />
</FormItem>
<div class="ant-form-item">
<Button Type="ButtonType.Primary" HtmlType="submit">查询</Button>
<Button Style="margin: 0 8px;" OnClick="OnSearchReset">重置</Button>
</div>
</Col>
</Row>
</Form>
</Card>
<Card Title="" Class="hideborder">
<Extra>
<div class="extraContent">
<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.Initial" Title="首字母" />
<PropertyColumn Property="c => c.NumericISOCode" Title="ISO代码" />
<PropertyColumn Property="c => c.Enabled" Title="状态">
@if (context.Enabled)
{
<Text>已激活</text>
}
else
{
<Text>未激活</text>
}
</PropertyColumn>
<PropertyColumn Property="c => c.DisplayOrder" Title="排序" />
<ActionColumn Title="操作" Align="ColumnAlign.Right">
<Space>
<SpaceItem>
<a @onclick="(e)=>HandleEdit(context)">编辑</a>
</SpaceItem>
@*<SpaceItem>
<Popconfirm Placement="@Placement.Left" Title="@("删除这条数据无法恢复,您确定要删除吗?")"
OnConfirm="@(e=>HandleDeleteConfirmAsync(e,context.Id))"
OkText="确定"
CancelText="取消">
<a>删除</a>
</Popconfirm>
</SpaceItem>*@
</Space>
</ActionColumn>
</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>
</ChildContent>
</Card>
</Spin>
</ChildContent>
</PageContainer>
@code {
[Parameter]
public string Locale { get; set; } = string.Empty;
[Parameter]
public long CountryId { get; set; }
[SupplyParameterFromQuery]
int? Page { get; set; }
[SupplyParameterFromQuery(Name = "size")]
int? PageSize { get; set; }
bool pageLoading = false;
Form<CountrySearch> searchForm = new();
CountrySearch search = new();
PagingList<Country> PagingList = new() { Size = 20 };
protected override async Task OnInitializedAsync()
{
await base.OnInitializedAsync();
}
protected override async Task OnParametersSetAsync()
{
loadQueryString();
await LoadListAsync();
await base.OnParametersSetAsync();
}
void loadQueryString()
{
var uri = new Uri(Navigation.Uri);
var query = uri.Query;
search.Name = query.GetQueryString("Name");
}
async Task LoadListAsync()
{
try
{
pageLoading = true;
var url = "/api/country/search";
var apiResult = await HttpService.GetPagingList<Country>(url, search, Page.GetValueOrDefault(1), PageSize.GetValueOrDefault(20));
if (apiResult.Success)
{
if (apiResult.Data != null)
{
PagingList = apiResult.Data;
}
}
else if (apiResult.Code == 403)
{
ModalService.Error(new ConfirmOptions() { Title = "权限不足", Content = apiResult.Message });
}
StateHasChanged();
}
finally
{
pageLoading = false;
}
}
void OnSearchReset()
{
search = new CountrySearch();
searchForm?.Reset();
}
private void OnSearch(int page)
{
var queryString = search.BuildQueryString();
if (string.IsNullOrEmpty(queryString))
{
if (page > 1)
{
Navigation.NavigateTo($"/country/list?page={page}");
}
else
{
Navigation.NavigateTo($"/country/list");
}
}
else
{
if (page > 1)
{
Navigation.NavigateTo($"/country/list?page={page}&{queryString}");
}
else
{
Navigation.NavigateTo($"/country/list?{queryString}");
}
}
}
void OnSearchFinish()
{
Page = Page.GetValueOrDefault(1) - 1;
OnSearch(Page.Value);
}
private void OnPageChanged(PaginationEventArgs args)
{
OnSearch(args.Page);
}
void HandleAddNew()
{
Navigation.NavigateTo($"/country/create");
}
void HandleEdit(Country model)
{
Navigation.NavigateTo($"/country/edit/{model.Id}");
}
}

View File

@@ -17,29 +17,43 @@
<ChildContent>
<Spin Spinning="pageLoading">
<Card Title="货币信息">
<Card Title="国家信息">
<Form @ref="editform" Model="@model" LabelColSpan="5" WrapperColSpan="14" OnFinish="OnFormFinishAsync">
@if (Id > 0 && languageList.Any())
{
<Tabs ActiveKey="@context.LanguageId" OnTabClick="OnLanguageTabChange">
<TabPane Key="0">
<TabTemplate>
<span>标准</span>
</TabTemplate>
</TabPane>
@foreach (var item in languageList)
{
<TabPane Key="@item.Key.ToString()">
<TabTemplate>
<span>@item.Value</span>
</TabTemplate>
</TabPane>
}
</Tabs>
}
<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 Label="两个字母ISO代码">
<Input @bind-Value="@context.TwoLetterISOCode" Placeholder="两个字母ISO代码" />
</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 Label="三字母ISO代码">
<Input @bind-Value="@context.ThreeLetterISOCode" Placeholder="三字母ISO代码" />
</FormItem>
<FormItem Label="自定义格式">
<Input @bind-Value="@context.CustomFormatting" Placeholder="自定义格式" />
<FormItem Label="数字ISO代码">
<Input @bind-Value="@context.NumericISOCode" Placeholder="数字ISO代码" />
</FormItem>
<FormItem Label="允许发货">
<Checkbox Checked="@context.AllowShipping">允许发货</Checkbox>
</FormItem>
<FormItem Label="显示排序">
<Input @bind-Value="@context.DisplayOrder" Placeholder="显示排序" />
@@ -65,9 +79,13 @@
public long Id { get; set; }
[SupplyParameterFromForm]
CurrencyModel model { get; set; } = new();
Form<CurrencyModel> editform = null!;
Dictionary<string, string> LanguageCultures = LanguageCulture.Descriptions.ToDictionary();
CountryModel model { get; set; } = new();
Form<CountryModel> editform = null!;
Country Country = new();
List<KeyValue> languageList = new();
bool pageLoading = false;
bool saving = false;
@@ -85,6 +103,16 @@
base.OnParametersSet();
}
async Task LoadLanguage()
{
var url = $"/api/language/enabled";
var apiResult = await HttpService.Get<ApiResult<List<KeyValue>>>(url);
if (apiResult.Success)
{
languageList = apiResult.Data ?? new List<KeyValue>();
}
}
async void LoadData()
{
pageLoading = true;
@@ -98,7 +126,7 @@
}
else
{
model = apiResult.Data.Adapt<CurrencyModel>();
model = apiResult.Data.Adapt<CountryModel>();
}
}
else
@@ -134,4 +162,30 @@
}
}
void OnLanguageTabChange(string key)
{
if (key != "0")
{
model.LanguageId = key;
var data = model.Localized.Where(p => p.LanguageId == key.ToInt()).ToList();
if (data.Any())
{
var name = nameof(model.Name);
model.Name = data.SingleOrDefault(p => p.Key == name)?.Value ?? "";
}
else
{
model.Name = string.Empty;
}
}
else
{
// model = Mapper.Map<CountryModel>(model);
// model.LanguageId = key;
// model.IsEdit = true;
}
}
}

View File

@@ -5,12 +5,12 @@
<PageContainer Title="国家地区">
<PageContainer Title="国家管理">
<Breadcrumb>
<Breadcrumb>
<BreadcrumbItem>Home</BreadcrumbItem>
<BreadcrumbItem>系统配置</BreadcrumbItem>
<BreadcrumbItem>货币管理</BreadcrumbItem>
<BreadcrumbItem>国家管理</BreadcrumbItem>
</Breadcrumb>
</Breadcrumb>
<ChildContent>
@@ -22,41 +22,9 @@
<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">
<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>
@@ -65,25 +33,15 @@
<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.NumericISOCode" Title="ISO代码" />
<PropertyColumn Property="c => c.Enabled" Title="状态">
@if (context.Enabled)
{
@@ -135,12 +93,11 @@
int? PageSize { get; set; }
bool pageLoading = false;
bool searchExpand = false;
Form<CurrencySearchModel> searchForm = new();
CurrencySearchModel search = new();
Form<CountrySearch> searchForm = new();
CountrySearch search = new();
PagingList<CurrencyModel> PagingList = new() { Size = 20 };
PagingList<Country> PagingList = new() { Size = 20 };
protected override async Task OnInitializedAsync()
@@ -160,21 +117,6 @@
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();
}
}
}
async Task LoadListAsync()
@@ -182,8 +124,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/country/search";
var apiResult = await HttpService.GetPagingList<Country>(url, search, Page.GetValueOrDefault(1), PageSize.GetValueOrDefault(20));
if (apiResult.Success)
{
if (apiResult.Data != null)
@@ -206,7 +148,7 @@
void OnSearchReset()
{
search = new CurrencySearchModel();
search = new CountrySearch();
searchForm?.Reset();
}
@@ -217,22 +159,22 @@
{
if (page > 1)
{
Navigation.NavigateTo($"/currency/list?page={page}");
Navigation.NavigateTo($"/country/list?page={page}");
}
else
{
Navigation.NavigateTo($"/currency/list");
Navigation.NavigateTo($"/country/list");
}
}
else
{
if (page > 1)
{
Navigation.NavigateTo($"/currency/list?page={page}&{queryString}");
Navigation.NavigateTo($"/country/list?page={page}&{queryString}");
}
else
{
Navigation.NavigateTo($"/currency/list?{queryString}");
Navigation.NavigateTo($"/country/list?{queryString}");
}
}
}
@@ -251,17 +193,13 @@
void HandleAddNew()
{
Navigation.NavigateTo($"/currency/create");
Navigation.NavigateTo($"/country/create");
}
void HandleEdit(CurrencyModel model)
void HandleEdit(Country model)
{
Navigation.NavigateTo($"/currency/edit/{model.Id}");
Navigation.NavigateTo($"/country/edit/{model.Id}");
}
}
@code {
}