From e198ab93ed4c1f7d907ace8c1d53e3a7ff5ab9af Mon Sep 17 00:00:00 2001 From: Seany <17074267@qq.com> Date: Fri, 26 Dec 2025 23:57:51 +0800 Subject: [PATCH] chore --- .../Atomx.Admin.Client/Models/AreaItem.cs | 11 + .../Atomx.Admin.Client/Models/AreaSearch.cs | 7 +- .../Pages/Settings/AreaEdit.razor | 196 +++++++++++++++++- .../Pages/Settings/AreaList.razor | 55 ++--- .../Pages/Settings/StateProvinceEdit.razor | 2 +- .../Pages/Settings/StateProvinceList.razor | 13 +- .../Atomx.Admin/Controllers/AreaController.cs | 53 ++++- .../Controllers/StateProvinceController.cs | 22 +- 8 files changed, 323 insertions(+), 36 deletions(-) create mode 100644 Atomx.Admin/Atomx.Admin.Client/Models/AreaItem.cs diff --git a/Atomx.Admin/Atomx.Admin.Client/Models/AreaItem.cs b/Atomx.Admin/Atomx.Admin.Client/Models/AreaItem.cs new file mode 100644 index 0000000..3b535dd --- /dev/null +++ b/Atomx.Admin/Atomx.Admin.Client/Models/AreaItem.cs @@ -0,0 +1,11 @@ +using Atomx.Common.Entities; + +namespace Atomx.Admin.Client.Models +{ + public class AreaItem : Area + { + public string CountryName { get; set; } = string.Empty; + public string StateProvinceName { get; set; } = string.Empty; + + } +} diff --git a/Atomx.Admin/Atomx.Admin.Client/Models/AreaSearch.cs b/Atomx.Admin/Atomx.Admin.Client/Models/AreaSearch.cs index dd5d875..0bde799 100644 --- a/Atomx.Admin/Atomx.Admin.Client/Models/AreaSearch.cs +++ b/Atomx.Admin/Atomx.Admin.Client/Models/AreaSearch.cs @@ -1,8 +1,11 @@ -namespace Atomx.Admin.Client.Models +using System.Runtime.Serialization; + +namespace Atomx.Admin.Client.Models { public class AreaSearch : BaseSearch { - public long CountryId { get; set; } + [IgnoreDataMember] + public long? CountryId { get; set; } public long StateProvinceId { get; set; } public string Name { get; set; } = string.Empty; } diff --git a/Atomx.Admin/Atomx.Admin.Client/Pages/Settings/AreaEdit.razor b/Atomx.Admin/Atomx.Admin.Client/Pages/Settings/AreaEdit.razor index 1182801..6bbd559 100644 --- a/Atomx.Admin/Atomx.Admin.Client/Pages/Settings/AreaEdit.razor +++ b/Atomx.Admin/Atomx.Admin.Client/Pages/Settings/AreaEdit.razor @@ -1,5 +1,199 @@ -

AreaEdit

+@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 Logger +@attribute [Authorize] + + + + + 管理后台 + 系统配置 + 国家管理 + 州/省管理 + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + +
+
+
+
+
@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 editform = null!; + List languageList = new(); + Country country = new(); + List 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>(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>>(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>>(url); + if (apiResult.Success) + { + if (apiResult.Data == null) + { + languageList = new List(); + } + 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>(url); + if (apiResult.Success) + { + if (apiResult.Data == null) + { + Navigation.NavigateTo($"/country/list"); + } + else + { + stateProvince = apiResult.Data; + model = apiResult.Data.Adapt(); + } + } + 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(); + result = await HttpService.Post>(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 }); + } + } + } } diff --git a/Atomx.Admin/Atomx.Admin.Client/Pages/Settings/AreaList.razor b/Atomx.Admin/Atomx.Admin.Client/Pages/Settings/AreaList.razor index 2a47eb9..9e886ca 100644 --- a/Atomx.Admin/Atomx.Admin.Client/Pages/Settings/AreaList.razor +++ b/Atomx.Admin/Atomx.Admin.Client/Pages/Settings/AreaList.razor @@ -5,23 +5,26 @@ - + - Home - 系统配置 - 国家管理 + 管理后台 + 系统配置 + 国家管理 + 州/省管理 - +
+ +
@@ -30,33 +33,35 @@ +
- +
+ - @if (context.Enabled) { - 已激活 + + } else { - 未激活 + } - 编辑 + 编辑 @* searchForm = new(); - CountrySearch search = new(); + Form searchForm = new(); + AreaSearch search = new(); - PagingList PagingList = new() { Size = 20 }; + PagingList 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(url, search, Page.GetValueOrDefault(1), PageSize.GetValueOrDefault(20)); + var url = "/api/area/search"; + var apiResult = await HttpService.GetPagingList(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}"); } } diff --git a/Atomx.Admin/Atomx.Admin.Client/Pages/Settings/StateProvinceEdit.razor b/Atomx.Admin/Atomx.Admin.Client/Pages/Settings/StateProvinceEdit.razor index 93165b3..abe9c0b 100644 --- a/Atomx.Admin/Atomx.Admin.Client/Pages/Settings/StateProvinceEdit.razor +++ b/Atomx.Admin/Atomx.Admin.Client/Pages/Settings/StateProvinceEdit.razor @@ -85,7 +85,7 @@ async Task LoadCountry() { - var url = $"/api/country?id={CountryId}"; + var url = $"/api/country/{CountryId}"; var apiResult = await HttpService.Get>(url); if (apiResult.Success) { diff --git a/Atomx.Admin/Atomx.Admin.Client/Pages/Settings/StateProvinceList.razor b/Atomx.Admin/Atomx.Admin.Client/Pages/Settings/StateProvinceList.razor index 28ecc07..62954f9 100644 --- a/Atomx.Admin/Atomx.Admin.Client/Pages/Settings/StateProvinceList.razor +++ b/Atomx.Admin/Atomx.Admin.Client/Pages/Settings/StateProvinceList.razor @@ -5,13 +5,13 @@ - + 管理后台 系统配置 国家管理 - 州省管理 + 州/省管理 @@ -60,6 +60,9 @@ + + 城市管理 + 编辑 @@ -132,7 +135,6 @@ { try { - Console.WriteLine(search.ToJson()); pageLoading = true; var url = "/api/stateprovince/search"; var apiResult = await HttpService.GetPagingList(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}"); + } + } \ No newline at end of file diff --git a/Atomx.Admin/Atomx.Admin/Controllers/AreaController.cs b/Atomx.Admin/Atomx.Admin/Controllers/AreaController.cs index 65fe811..7888a40 100644 --- a/Atomx.Admin/Atomx.Admin/Controllers/AreaController.cs +++ b/Atomx.Admin/Atomx.Admin/Controllers/AreaController.cs @@ -69,8 +69,11 @@ namespace Atomx.Admin.Controllers { page = 1; } - var result = new ApiResult>(); - var list = new PagingList() { Index = page, Size = size }; + var result = new ApiResult>(); + var list = new PagingList() { Index = page, Size = size }; + var countries = new List(); + var stateProvices = new List(); + var query = from p in _dbContext.Areas select p; @@ -94,7 +97,51 @@ namespace Atomx.Admin.Controllers select p; } list.Count = query.Count(); - list.Items = query.OrderByDescending(p => p.DisplayOrder).Skip((page - 1) * size).Take(size).ToList(); + var data = query.OrderByDescending(p => p.DisplayOrder).Skip((page - 1) * size).Take(size).ToList(); + + if (search.CountryId > 0) + { + var country = _dbContext.Countries.SingleOrDefault(p => p.Id == search.CountryId); + if (country != null) + { + countries.Add(country); + } + } + else + { + var countryIds = data.Select(p => p.CountryId).Distinct().ToList(); + countries = _dbContext.Countries.Where(p => countryIds.Contains(p.Id)).ToList(); + } + + if(search.StateProvinceId > 0) + { + var state = _dbContext.StateProvinces.SingleOrDefault(p => p.Id == search.StateProvinceId); + if (state != null) + { + stateProvices.Add(state); + } + } + else + { + var stateIds = data.Select(p => p.StateProvinceId).Distinct().ToList(); + stateProvices = _dbContext.StateProvinces.Where(p => stateIds.Contains(p.Id)).ToList(); + } + + foreach (var item in data) + { + var model = _mapper.Map(item); + var country = countries.SingleOrDefault(p => p.Id == item.CountryId); + if (country != null) + { + model.CountryName = country.Name; + } + var state = stateProvices.SingleOrDefault(p => p.Id == item.StateProvinceId); + if (state != null) + { + model.StateProvinceName = state.Name; + } + list.Items.Add(model); + } result = result.IsSuccess(list); diff --git a/Atomx.Admin/Atomx.Admin/Controllers/StateProvinceController.cs b/Atomx.Admin/Atomx.Admin/Controllers/StateProvinceController.cs index 72f9154..fc019bc 100644 --- a/Atomx.Admin/Atomx.Admin/Controllers/StateProvinceController.cs +++ b/Atomx.Admin/Atomx.Admin/Controllers/StateProvinceController.cs @@ -50,6 +50,25 @@ namespace Atomx.Admin.Controllers _localizer = localizer; } + /// + /// 数据查询 + /// + /// + /// + /// + /// + [HttpGet("select/{countryId:long}")] + public IActionResult AddressList(long countryId, int page, int size = 20) + { + var list = new List(); + var query = from p in _dbContext.StateProvinces + where p.CountryId == countryId && p.Enabled + select p; + list = query.OrderByDescending(p => p.DisplayOrder).Select(p => new KeyValue() { Key = p.Id.ToString(), Value = p.Name }).ToList(); + + return new JsonResult(new ApiResult>().IsSuccess(list)); + } + /// /// 数据查询 /// @@ -58,7 +77,6 @@ namespace Atomx.Admin.Controllers /// /// [HttpPost("search")] - [Authorize(Policy = Permissions.User.View)] public IActionResult AddressList(StateProvinceSearch search, int page, int size = 20) { if (page < 1) @@ -150,7 +168,7 @@ namespace Atomx.Admin.Controllers var message = validation.Errors.FirstOrDefault()?.ErrorMessage ?? string.Empty; return new JsonResult(new ApiResult().IsFail(message, null)); } - var data = _dbContext.StateProvinces.SingleOrDefault(p => p.CountryId == model.CountryId && p.Name == model.Name && p.Id != model.Id); + var data = _dbContext.StateProvinces.SingleOrDefault(p => p.CountryId == model.CountryId && p.Name == model.Name && p.Id != model.Id); if (data != null) { return new JsonResult(new ApiResult().IsFail("当前数据已经存在,请认真检查", null));