This commit is contained in:
2025-12-26 23:57:51 +08:00
parent 43820c6ec2
commit e198ab93ed
8 changed files with 323 additions and 36 deletions

View File

@@ -1,5 +1,199 @@
<h3>AreaEdit</h3>
@page "/area/create/{countryId:long}/{stateProvinceId:long}"
@page "/area/edit/{countryId:long}/{stateProvinceId:long}/{id:long}"
@page "/{locale}/area/create/{countryId:long}/{stateProvinceId:long}"
@page "/{locale}/area/create/{countryId:long}/{stateProvinceId:long}/{id:long}"
@inject ILogger<StateProvinceEdit> Logger
@attribute [Authorize]
<PageContainer Title="@(Id > 0 ? "编辑城市地区信息" : "新增城市地区信息")">
<Breadcrumb>
<Breadcrumb>
<BreadcrumbItem Href="/">管理后台</BreadcrumbItem>
<BreadcrumbItem Href="/settings">系统配置</BreadcrumbItem>
<BreadcrumbItem Href="/country/list">国家管理</BreadcrumbItem>
<BreadcrumbItem Href="@($"/stateprovince/list/{CountryId}")">州/省管理</BreadcrumbItem>
</Breadcrumb>
</Breadcrumb>
<ChildContent>
<Spin Spinning="pageLoading">
<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="名称" />
</FormItem>
<FormItem Label="首字母">
<Input @bind-Value="@context.Initial" Placeholder="首字母" />
</FormItem>
<FormItem Label="缩写">
<Input @bind-Value="@context.Abbreviation" Placeholder="缩写" />
</FormItem>
<FormItem Label="显示排序">
<Input @bind-Value="@context.DisplayOrder" Placeholder="显示排序" />
</FormItem>
<FormItem Label="状态">
<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">
提交保存
</Button>
</FormItem>
</Form>
</Card>
</Spin>
</ChildContent>
</PageContainer>
@code {
[Parameter]
public string Locale { get; set; } = string.Empty;
[Parameter]
public long CountryId { get; set; }
[Parameter]
public long StateProvinceId { get; set; }
[Parameter]
public long Id { get; set; }
[SupplyParameterFromForm]
StateProvinceModel model { get; set; } = new();
Form<StateProvinceModel> editform = null!;
List<KeyValue> languageList = new();
Country country = new();
List<KeyValue> stateProvinceList = new();
StateProvinceLocalizedModel stateProvince = new();
bool pageLoading = false;
bool saving = false;
protected override void OnInitialized()
{
base.OnInitialized();
}
protected override void OnParametersSet()
{
model.CountryId = CountryId;
_ = LoadLanguage();
_ = LoadCountry();
_ = LoadStateProvince();
if (Id > 0)
{
LoadData();
}
base.OnParametersSet();
}
async Task LoadCountry()
{
var url = $"/api/country/{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 LoadStateProvince()
{
var url = $"/api/stateprovince/select/{CountryId}";
var apiResult = await HttpService.Get<ApiResult<List<KeyValue>>>(url);
if (apiResult.Success)
{
if (apiResult.Data != null)
{
stateProvinceList = apiResult.Data;
StateHasChanged();
}
else
{
Navigation.NavigateTo($"/country/list");
}
stateProvinceList.Insert(0, new KeyValue() { Key = "0", Value = "请选择州/省" });
}
}
async Task LoadLanguage()
{
var url = $"/api/language/enabled";
var apiResult = await HttpService.Get<ApiResult<List<KeyValue>>>(url);
if (apiResult.Success)
{
if (apiResult.Data == null)
{
languageList = new List<KeyValue>();
}
else
{
languageList = apiResult.Data;
languageList.Insert(0, new KeyValue() { Key = "0", Value = "标准" });
}
StateHasChanged();
}
}
async void LoadData()
{
pageLoading = true;
var url = $"/api/stateprovince/detail?id={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($"/country/list");
}
pageLoading = false;
StateHasChanged();
}
async void OnFormFinishAsync()
{
if (editform.Validate())
{
saving = true;
var url = $"api/stateprovince/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($"/stateprovince/list/{CountryId}");
}
else
{
saving = false;
await ModalService.ErrorAsync(new ConfirmOptions() { Title = "服务异常", Content = result.Message });
}
}
}
}

View File

@@ -5,23 +5,26 @@
<PageContainer Title="国家管理">
<PageContainer Title="城市地区管理">
<Breadcrumb>
<Breadcrumb>
<BreadcrumbItem>Home</BreadcrumbItem>
<BreadcrumbItem>系统配置</BreadcrumbItem>
<BreadcrumbItem>国家管理</BreadcrumbItem>
<BreadcrumbItem Href="/">管理后台</BreadcrumbItem>
<BreadcrumbItem Href="/settings">系统配置</BreadcrumbItem>
<BreadcrumbItem Href="/country/list">国家管理</BreadcrumbItem>
<BreadcrumbItem Href="@($"/stateprovince/list/{CountryId}")">州/省管理</BreadcrumbItem>
</Breadcrumb>
</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">
<Col>
<FormItem Label="名称">
<Input @bind-Value="search.Name" Placeholder="名称" AllowClear />
</FormItem>
</Col>
<Col>
<div class="ant-form-item">
<Button Type="ButtonType.Primary" HtmlType="submit">查询</Button>
<Button Style="margin: 0 8px;" OnClick="OnSearchReset">重置</Button>
@@ -30,33 +33,35 @@
</Row>
</Form>
</Card>
<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.StateProvinceName" 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>
<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="@("删除这条数据无法恢复,您确定要删除吗?")"
@@ -86,7 +91,7 @@
[Parameter]
public string Locale { get; set; } = string.Empty;
[Parameter]
public long CountryId { get; set; }
public long CountryId { get; set; }
[SupplyParameterFromQuery]
int? Page { get; set; }
@@ -96,10 +101,10 @@
bool pageLoading = false;
Form<CountrySearch> searchForm = new();
CountrySearch search = new();
Form<AreaSearch> searchForm = new();
AreaSearch search = new();
PagingList<Country> PagingList = new() { Size = 20 };
PagingList<AreaItem> PagingList = new() { Size = 20 };
protected override async Task OnInitializedAsync()
@@ -119,6 +124,8 @@
var uri = new Uri(Navigation.Uri);
var query = uri.Query;
search.Name = query.GetQueryString("Name");
search.StateProvinceId = query.GetQueryString("StateProvinceId").ToLong();
search.CountryId = CountryId;
}
async Task LoadListAsync()
@@ -126,8 +133,8 @@
try
{
pageLoading = true;
var url = "/api/country/search";
var apiResult = await HttpService.GetPagingList<Country>(url, search, Page.GetValueOrDefault(1), PageSize.GetValueOrDefault(20));
var url = "/api/area/search";
var apiResult = await HttpService.GetPagingList<AreaItem>(url, search, Page.GetValueOrDefault(1), PageSize.GetValueOrDefault(20));
if (apiResult.Success)
{
if (apiResult.Data != null)
@@ -150,7 +157,7 @@
void OnSearchReset()
{
search = new CountrySearch();
search = new();
searchForm?.Reset();
}
@@ -161,22 +168,22 @@
{
if (page > 1)
{
Navigation.NavigateTo($"/country/list?page={page}");
Navigation.NavigateTo($"/area/list/{CountryId}?page={page}");
}
else
{
Navigation.NavigateTo($"/country/list");
Navigation.NavigateTo($"/area/list/{CountryId}");
}
}
else
{
if (page > 1)
{
Navigation.NavigateTo($"/country/list?page={page}&{queryString}");
Navigation.NavigateTo($"/area/list/{CountryId}?page={page}&{queryString}");
}
else
{
Navigation.NavigateTo($"/country/list?{queryString}");
Navigation.NavigateTo($"/area/list/{CountryId}?{queryString}");
}
}
}
@@ -195,13 +202,13 @@
void HandleAddNew()
{
Navigation.NavigateTo($"/country/create");
Navigation.NavigateTo($"/area/create/{CountryId}");
}
void HandleEdit(Country model)
void HandleEdit(Area model)
{
Navigation.NavigateTo($"/country/edit/{model.Id}");
Navigation.NavigateTo($"/area/edit/{model.Id}");
}
}

View File

@@ -85,7 +85,7 @@
async Task LoadCountry()
{
var url = $"/api/country?id={CountryId}";
var url = $"/api/country/{CountryId}";
var apiResult = await HttpService.Get<ApiResult<Country>>(url);
if (apiResult.Success)
{

View File

@@ -5,13 +5,13 @@
<PageContainer Title="州省管理">
<PageContainer Title="州/省管理">
<Breadcrumb>
<Breadcrumb>
<BreadcrumbItem Href="/">管理后台</BreadcrumbItem>
<BreadcrumbItem Href="/settings">系统配置</BreadcrumbItem>
<BreadcrumbItem Href="/country/list">国家管理</BreadcrumbItem>
<BreadcrumbItem>州省管理</BreadcrumbItem>
<BreadcrumbItem>州/省管理</BreadcrumbItem>
</Breadcrumb>
</Breadcrumb>
<ChildContent>
@@ -60,6 +60,9 @@
<PropertyColumn Property="c => c.DisplayOrder" Title="排序" />
<ActionColumn Title="操作" Align="ColumnAlign.Right">
<Space>
<SpaceItem>
<a @onclick="(e) => GotoArea(context)">城市管理</a>
</SpaceItem>
<SpaceItem>
<a @onclick="(e) => HandleEdit(context)">编辑</a>
</SpaceItem>
@@ -132,7 +135,6 @@
{
try
{
Console.WriteLine(search.ToJson());
pageLoading = true;
var url = "/api/stateprovince/search";
var apiResult = await HttpService.GetPagingList<StateProvince>(url, search, Page.GetValueOrDefault(1), PageSize.GetValueOrDefault(20));
@@ -212,4 +214,9 @@
Navigation.NavigateTo($"/stateprovince/{CountryId}/edit/{model.Id}");
}
void GotoArea(StateProvince model)
{
Navigation.NavigateTo($"/area/list/{CountryId}");
}
}