219 lines
8.0 KiB
Plaintext
219 lines
8.0 KiB
Plaintext
@page "/system/locale/resource/detail/{Name}"
|
|
@page "/{locale}/system/locale/resource/detail/{Name}"
|
|
@inject ILogger<LocaleResourceList> Logger
|
|
@attribute [Authorize]
|
|
|
|
<PageContainer Title="本地化语言资源">
|
|
<Breadcrumb>
|
|
<Breadcrumb>
|
|
<BreadcrumbItem Href="/">管理后台</BreadcrumbItem>
|
|
<BreadcrumbItem Href="/admin/list">系统功能</BreadcrumbItem>
|
|
<BreadcrumbItem>本地化语言资源</BreadcrumbItem>
|
|
</Breadcrumb>
|
|
</Breadcrumb>
|
|
<ChildContent>
|
|
<Spin Spinning="loading">
|
|
<Card Class="mt-3">
|
|
<Table DataSource="ResourceItems" PageSize="100" HidePagination="true" Resizable>
|
|
<TitleTemplate>
|
|
<Flex Justify="FlexJustify.SpaceBetween">
|
|
@(@Name)多语言资源列表,可用语言@(@languages.Count)种
|
|
<div>
|
|
<Button Class="me-3" OnClick="OnCreateClick" Type="ButtonType.Primary">新增</Button>
|
|
</div>
|
|
</Flex>
|
|
</TitleTemplate>
|
|
<ColumnDefinitions>
|
|
<PropertyColumn Property="c => c.Name" Title="资源Key">
|
|
</PropertyColumn>
|
|
<PropertyColumn Property="c => c.Title" Title="语言">
|
|
</PropertyColumn>
|
|
<PropertyColumn Property="c => c.Value" Title="内容">
|
|
|
|
</PropertyColumn>
|
|
<PropertyColumn Property="c => c.UpdateTime" Title="最后更新" Width="120px" />
|
|
<ActionColumn Title="操作" Align="ColumnAlign.Right" Width="100px">
|
|
<Space>
|
|
<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>
|
|
</Spin>
|
|
|
|
<Modal Title="@("语言资源设置")" Visible="@modalVisible" Width="700" MaskClosable="true" OkText="@("保存")" CancelText="@("取消")" OnOk="@HandleModalOk" OnCancel="@HandleCancel">
|
|
<Form Model="@model" @ref="@editform" LabelCol="new ColLayoutParam { Span = 5 }" WrapperCol="new ColLayoutParam { Span = 15 }" Name="modalForm" OnFinish="OnFormFinish">
|
|
<FluentValidationValidator />
|
|
<FormItem Label="语言文字">
|
|
@if (context.Id == 0)
|
|
{
|
|
<Select DataSource="@languages" @bind-Value="@context.LanguageId" ItemValue="p => p.Id" ItemLabel="p => p.Title">
|
|
</Select>
|
|
}
|
|
else
|
|
{
|
|
<Input Placeholder="资源名称" @bind-Value="@context.Title" Disabled />
|
|
}
|
|
|
|
</FormItem>
|
|
<FormItem Label="资源名称">
|
|
<Input Placeholder="资源名称" @bind-Value="@context.Name" Disabled />
|
|
</FormItem>
|
|
<FormItem Label="资源内容">
|
|
<TextArea Placeholder="资源内容" @bind-Value="@context.Value" />
|
|
</FormItem>
|
|
</Form>
|
|
</Modal>
|
|
</ChildContent>
|
|
</PageContainer>
|
|
|
|
@code {
|
|
|
|
bool loading = false;
|
|
[Parameter]
|
|
public string Locale { get; set; } = string.Empty;
|
|
|
|
[Parameter]
|
|
public string Name { get; set; }
|
|
|
|
[SupplyParameterFromForm]
|
|
LocaleResourceModel model { get; set; } = default!;
|
|
Form<LocaleResourceModel> editform = null!;
|
|
|
|
List<LocaleResourceItem> ResourceItems = new();
|
|
List<Language> languages = new();
|
|
|
|
bool modalVisible = false;
|
|
|
|
protected override void OnInitialized()
|
|
{
|
|
model ??= new LocaleResourceModel() { };
|
|
base.OnInitialized();
|
|
}
|
|
|
|
protected override async Task OnParametersSetAsync()
|
|
{
|
|
_ = LoadLanguages();
|
|
_ = LoadList();
|
|
}
|
|
|
|
private async Task LoadLanguages()
|
|
{
|
|
var url = $"/api/language/enabled";
|
|
var apiResult = await HttpService.Get<ApiResult<List<Language>>>(url);
|
|
if (apiResult.Success)
|
|
{
|
|
if (apiResult.Data != null)
|
|
{
|
|
languages = apiResult.Data;
|
|
StateHasChanged();
|
|
}
|
|
}
|
|
}
|
|
|
|
private async Task LoadList()
|
|
{
|
|
loading = true;
|
|
|
|
var url = $"/api/localeresource/{Name}";
|
|
|
|
var apiResult = await HttpService.Get<ApiResult<List<LocaleResourceItem>>>(url);
|
|
if (apiResult.Success)
|
|
{
|
|
if (apiResult.Data != null)
|
|
{
|
|
ResourceItems = apiResult.Data;
|
|
}
|
|
}
|
|
|
|
loading = false;
|
|
StateHasChanged();
|
|
}
|
|
|
|
void OnCreateClick()
|
|
{
|
|
Console.WriteLine("OnCreateClick");
|
|
model = new() { Name = Name };
|
|
modalVisible = true;
|
|
}
|
|
|
|
void OnEditClick(LocaleResourceItem data)
|
|
{
|
|
this.model = data.Adapt<LocaleResourceModel>();
|
|
modalVisible = true;
|
|
}
|
|
|
|
async Task HandleDeleteConfirmAsync(MouseEventArgs e, long id)
|
|
{
|
|
var url = $"/api/localeresource/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}" });
|
|
}
|
|
}
|
|
|
|
|
|
void HandleModalOk()
|
|
{
|
|
editform.Submit();
|
|
}
|
|
|
|
async Task OnFormFinish()
|
|
{
|
|
if (editform.Validate())
|
|
{
|
|
var result = new ApiResult<bool>();
|
|
|
|
var url = $"api/localeresource/save";
|
|
result = await HttpService.Post<ApiResult<bool>>(url, model);
|
|
|
|
if (result.Success)
|
|
{
|
|
modalVisible = false;
|
|
_ = LoadList();
|
|
}
|
|
else
|
|
{
|
|
await ModalService.ErrorAsync(new ConfirmOptions() { Title = "服务异常", Content = result.Message });
|
|
}
|
|
}
|
|
}
|
|
|
|
void HandleCancel()
|
|
{
|
|
modalVisible = false;
|
|
}
|
|
}
|