chore
This commit is contained in:
@@ -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 });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user