diff --git a/Atomx.Admin/Atomx.Admin.Client/Pages/Settings/AreaEdit.razor b/Atomx.Admin/Atomx.Admin.Client/Pages/Settings/AreaEdit.razor index 6bbd559..02b826d 100644 --- a/Atomx.Admin/Atomx.Admin.Client/Pages/Settings/AreaEdit.razor +++ b/Atomx.Admin/Atomx.Admin.Client/Pages/Settings/AreaEdit.razor @@ -1,5 +1,7 @@ -@page "/area/create/{countryId:long}/{stateProvinceId:long}" +@page "/area/create/{countryId:long}" +@page "/area/create/{countryId:long}/{stateProvinceId:long}" @page "/area/edit/{countryId:long}/{stateProvinceId:long}/{id:long}" +@page "/{locale}/area/create/{countryId:long}" @page "/{locale}/area/create/{countryId:long}/{stateProvinceId:long}" @page "/{locale}/area/create/{countryId:long}/{stateProvinceId:long}/{id:long}" @@ -24,15 +26,28 @@ + + + + + + - - - @@ -60,8 +75,8 @@ public long Id { get; set; } [SupplyParameterFromForm] - StateProvinceModel model { get; set; } = new(); - Form editform = null!; + AreaModel model { get; set; } = new(); + Form editform = null!; List languageList = new(); Country country = new(); List stateProvinceList = new(); @@ -125,6 +140,25 @@ } } + async Task LoadStateProvince(long id) + { + 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"; diff --git a/Atomx.Admin/Atomx.Admin.Client/Pages/Settings/AreaList.razor b/Atomx.Admin/Atomx.Admin.Client/Pages/Settings/AreaList.razor index 9e886ca..c86f74c 100644 --- a/Atomx.Admin/Atomx.Admin.Client/Pages/Settings/AreaList.razor +++ b/Atomx.Admin/Atomx.Admin.Client/Pages/Settings/AreaList.razor @@ -1,5 +1,7 @@ @page "/area/list/{countryId:long}" +@page "/area/list/{countryId:long}/{stateProvinceId:long}" @page "/{locale}/area/list/{countryId:long}" +@page "/{locale}/area/list/{countryId:long}/{stateProvinceId:long}" @inject ILogger Logger @attribute [Authorize] @@ -92,6 +94,8 @@ public string Locale { get; set; } = string.Empty; [Parameter] public long CountryId { get; set; } + [Parameter] + public long StateProvinceId { get; set; } [SupplyParameterFromQuery] int? Page { get; set; } @@ -202,7 +206,15 @@ void HandleAddNew() { - Navigation.NavigateTo($"/area/create/{CountryId}"); + if (StateProvinceId > 0) + { + Navigation.NavigateTo($"/area/create/{CountryId}/{StateProvinceId}"); + } + else + { + Navigation.NavigateTo($"/area/create/{CountryId}"); + } + } diff --git a/Atomx.Admin/Atomx.Admin.Client/Pages/Settings/StateProvinceList.razor b/Atomx.Admin/Atomx.Admin.Client/Pages/Settings/StateProvinceList.razor index 62954f9..e9cd4bc 100644 --- a/Atomx.Admin/Atomx.Admin.Client/Pages/Settings/StateProvinceList.razor +++ b/Atomx.Admin/Atomx.Admin.Client/Pages/Settings/StateProvinceList.razor @@ -216,7 +216,7 @@ void GotoArea(StateProvince model) { - Navigation.NavigateTo($"/area/list/{CountryId}"); + Navigation.NavigateTo($"/area/list/{CountryId}/{model.Id}"); } } \ 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 7888a40..2123fe9 100644 --- a/Atomx.Admin/Atomx.Admin/Controllers/AreaController.cs +++ b/Atomx.Admin/Atomx.Admin/Controllers/AreaController.cs @@ -54,6 +54,22 @@ namespace Atomx.Admin.Controllers _localizer = localizer; } + /// + /// + /// + /// + [HttpGet("select/{id}")] + public IActionResult Select(long id) + { + var list = new List(); + var query = from p in _dbContext.Areas + where p.ParentId == id && 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)); + } + /// /// 数据查询 /// @@ -62,7 +78,6 @@ namespace Atomx.Admin.Controllers /// /// [HttpPost("search")] - [Authorize(Policy = Permissions.User.View)] public IActionResult AddressList(AreaSearch search, int page, int size = 20) { if (page < 1)