265 lines
10 KiB
Plaintext
265 lines
10 KiB
Plaintext
@page "/system/language/list"
|
|
@page "/{locale}/system/language/list"
|
|
@inject ILogger<LanguageList> Logger
|
|
@attribute [Authorize]
|
|
|
|
<PageContainer Title="语言管理">
|
|
<Breadcrumb>
|
|
<Breadcrumb>
|
|
<BreadcrumbItem Href="/">管理后台</BreadcrumbItem>
|
|
<BreadcrumbItem Href="/admin/list">系统功能</BreadcrumbItem>
|
|
<BreadcrumbItem>语言管理</BreadcrumbItem>
|
|
</Breadcrumb>
|
|
</Breadcrumb>
|
|
<ChildContent>
|
|
<Card Class="mt-3">
|
|
<Table DataSource="PagingList.Items" PageSize="100" HidePagination="true" Resizable>
|
|
<TitleTemplate>
|
|
<Flex Justify="FlexJustify.SpaceBetween">
|
|
多语言列表
|
|
<div>
|
|
<Button Class="me-3" OnClick="OnCreateClick" Type="ButtonType.Primary">新增</Button>
|
|
</div>
|
|
</Flex>
|
|
</TitleTemplate>
|
|
<ColumnDefinitions>
|
|
<PropertyColumn Property="c => c.Title" Title="语言名称">
|
|
|
|
</PropertyColumn>
|
|
<PropertyColumn Property="c => c.Name" Title="语言本地化">
|
|
</PropertyColumn>
|
|
|
|
<PropertyColumn Property="c => c.Culture" Title="语言文化" Width="100px" />
|
|
<PropertyColumn Property="c => c.Enabled" Title="状态" Width="80px" Align="ColumnAlign.Center">
|
|
@if (context.Enabled)
|
|
{
|
|
<AntDesign.Text Type="TextElementType.Success"><Icon Type="check" Theme=" IconThemeType.Outline" Width="1.3em" Height="1.3em" /></AntDesign.Text>
|
|
|
|
}
|
|
else
|
|
{
|
|
<Icon Type="close" Theme="IconThemeType.Outline" Width="1.3em" Height="1.3em" />
|
|
}
|
|
</PropertyColumn>
|
|
<PropertyColumn Property="c => c.ResourceVersion" Title="资源版本" />
|
|
<PropertyColumn Property="c => c.UpdateTime" Title="最后更新" />
|
|
<ActionColumn Title="操作" Align="ColumnAlign.Right">
|
|
<Space>
|
|
<SpaceItem>
|
|
<a href="@($"/system/locale/resource/list/{context.Id}")"> <Icon Type="@IconType.Outline.Edit" /> 语言资源</a>
|
|
</SpaceItem>
|
|
<SpaceItem>
|
|
<Dropdown Trigger="@(new Trigger[] { Trigger.Click })">
|
|
<Overlay>
|
|
<Menu>
|
|
|
|
<MenuItem>
|
|
<a @onclick="(e) => OnEditClick(context)"> <Icon Type="@IconType.Outline.Edit" /> 编辑</a>
|
|
</MenuItem>
|
|
<MenuDivider />
|
|
<MenuItem>
|
|
<Popconfirm Placement="@Placement.Left" Title="@("删除这条数据无法恢复,您确定要删除吗?")"
|
|
OnConfirm="@(e=>HandleDeleteConfirmAsync(e,context.Id))"
|
|
OkText="确定"
|
|
CancelText="取消">
|
|
<a> <Icon Type="@IconType.Outline.Delete" /> 删除</a>
|
|
</Popconfirm>
|
|
</MenuItem>
|
|
</Menu>
|
|
</Overlay>
|
|
<ChildContent>
|
|
<a class="ant-dropdown-link" @onclick:preventDefault>
|
|
<Icon Type="@IconType.Outline.Menu" />
|
|
</a>
|
|
</ChildContent>
|
|
</Dropdown>
|
|
</SpaceItem>
|
|
</Space>
|
|
</ActionColumn>
|
|
</ColumnDefinitions>
|
|
</Table>
|
|
</Card>
|
|
|
|
<Drawer Closable="true" Width="520" Visible="drawerVisible" Title='(model.Id == 0 ? "新增语言" : "编辑语言")' OnClose="_ => CloseDrawer()">
|
|
<Form LabelColSpan="5" @ref="@editform" Model="@model" OnFinish="OnFormFinish">
|
|
<FluentValidationValidator />
|
|
<FormItem Label="语言标题">
|
|
<Input @bind-Value="model.Title" For="(()=>model.Title)" Placeholder="语言名称" />
|
|
</FormItem>
|
|
<FormItem Label="语言名称">
|
|
<Input @bind-Value="model.Name" For="(()=>model.Name)" Placeholder="语言本地化" />
|
|
</FormItem>
|
|
<FormItem Label="语言文化">
|
|
<SimpleSelect @bind-Value="model.Culture" For="(()=>model.Culture)" Placeholder="语言文化">
|
|
<SelectOptions>
|
|
@foreach (var item in LanguageCultures)
|
|
{
|
|
<SimpleSelectOption Value="@item.Key" Label="@($"{item.Value} - {item.Key}")"></SimpleSelectOption>
|
|
}
|
|
</SelectOptions>
|
|
</SimpleSelect>
|
|
</FormItem>
|
|
<FormItem Label="显示排序">
|
|
<AntDesign.InputNumber @bind-Value="model.DisplayOrder" For="(()=>model.DisplayOrder)" Placeholder="显示排序" />
|
|
</FormItem>
|
|
<FormItem Label="可用状态">
|
|
<Checkbox T="bool" Label="启用" @bind-value="model.Enabled" Size="InputSize.Small" Class="ps-0" />
|
|
</FormItem>
|
|
<FormItem WrapperColOffset="4">
|
|
<Button Type="ButtonType.Primary" HtmlType="submit" Style="width: 100%;">保存</Button>
|
|
</FormItem>
|
|
</Form>
|
|
</Drawer>
|
|
</ChildContent>
|
|
</PageContainer>
|
|
|
|
@code {
|
|
[Parameter]
|
|
public string Locale { get; set; } = string.Empty;
|
|
|
|
[SupplyParameterFromQuery]
|
|
int? Page { get; set; }
|
|
|
|
[SupplyParameterFromQuery(Name = "size")]
|
|
int? PageSize { get; set; }
|
|
|
|
[SupplyParameterFromForm]
|
|
LanguageSearch search { get; set; } = default!;
|
|
|
|
[SupplyParameterFromForm]
|
|
LanguageModel model { get; set; } = default!;
|
|
Form<LanguageModel> editform = null!;
|
|
|
|
Dictionary<string, string> LanguageCultures = LanguageCulture.Descriptions.ToDictionary();
|
|
|
|
PagingList<Language> PagingList = new();
|
|
bool loading { get; set; } = true;
|
|
|
|
bool drawerVisible;
|
|
|
|
protected override void OnInitialized()
|
|
{
|
|
search ??= new LanguageSearch();
|
|
model ??= new LanguageModel();
|
|
base.OnInitialized();
|
|
}
|
|
|
|
protected override void OnParametersSet()
|
|
{
|
|
_ = LoadList();
|
|
|
|
base.OnParametersSet();
|
|
}
|
|
|
|
|
|
private async Task LoadList()
|
|
{
|
|
|
|
loading = true;
|
|
var url = "/api/language/search";
|
|
var apiResult = await HttpService.GetPagingList<Language>(url, search, Page.GetValueOrDefault(1), PageSize.GetValueOrDefault(20));
|
|
if (apiResult.Success)
|
|
{
|
|
if (apiResult.Data != null)
|
|
{
|
|
PagingList = apiResult.Data;
|
|
}
|
|
}
|
|
loading = false;
|
|
StateHasChanged();
|
|
}
|
|
|
|
private void OnSearch(int page)
|
|
{
|
|
var queryString = search.BuildQueryString();
|
|
if (string.IsNullOrEmpty(queryString))
|
|
{
|
|
if (page > 1)
|
|
{
|
|
Navigation.NavigateTo($"/system/language/list?page={page}");
|
|
}
|
|
else
|
|
{
|
|
Navigation.NavigateTo($"/system/language/list");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (page > 1)
|
|
{
|
|
Navigation.NavigateTo($"/system/language/list?page={page}&{queryString}");
|
|
}
|
|
else
|
|
{
|
|
Navigation.NavigateTo($"/system/language/list?{queryString}");
|
|
}
|
|
}
|
|
}
|
|
|
|
void OnCreateClick()
|
|
{
|
|
model = new() { Culture = LanguageCulture.zhHans };
|
|
drawerVisible = true;
|
|
}
|
|
|
|
void OnEditClick(Language admin)
|
|
{
|
|
this.model = admin.Adapt<LanguageModel>();
|
|
drawerVisible = true;
|
|
}
|
|
|
|
async Task HandleDeleteConfirmAsync(MouseEventArgs e, long id)
|
|
{
|
|
var url = $"/api/language/delete/{id}";
|
|
var apiResult = await HttpService.Post<ApiResult<string>>(url, new());
|
|
if (apiResult.Success)
|
|
{
|
|
_ = LoadList();
|
|
await ModalService.InfoAsync(new ConfirmOptions() { Title = "操作提示", Content = "删除数据成功" });
|
|
}
|
|
else
|
|
{
|
|
await ModalService.ErrorAsync(new ConfirmOptions() { Title = "操作提示", Content = $"数据删除失败.{apiResult.Message}" });
|
|
}
|
|
}
|
|
|
|
async Task OnFormFinish()
|
|
{
|
|
if (editform.Validate())
|
|
{
|
|
|
|
var url = $"api/language/save";
|
|
var result = await HttpService.Post<ApiResult<bool>>(url, model);
|
|
if (result.Success)
|
|
{
|
|
if (result.Data)
|
|
{
|
|
|
|
CloseDrawer();
|
|
_ = LoadList();
|
|
await ModalService.InfoAsync(new ConfirmOptions() { Title = "提示", Content = "数据提交成功!" });
|
|
}
|
|
else
|
|
{
|
|
await ModalService.ErrorAsync(new ConfirmOptions() { Title = "服务异常", Content = result.Message });
|
|
}
|
|
}
|
|
|
|
else
|
|
{
|
|
await ModalService.ErrorAsync(new ConfirmOptions() { Title = "服务异常", Content = result.Message });
|
|
}
|
|
}
|
|
}
|
|
|
|
private void OnPageChanged(int args)
|
|
{
|
|
OnSearch(args);
|
|
}
|
|
|
|
void CloseDrawer()
|
|
{
|
|
drawerVisible = false;
|
|
editform.Reset();
|
|
}
|
|
} |