chore fix

This commit is contained in:
2025-12-06 13:30:17 +08:00
parent 2972886576
commit 8aca372fc1
43 changed files with 984 additions and 595 deletions

View File

@@ -3,6 +3,7 @@
@layout EmptyLayout
@inject ILogger<Login> Logger
@inject IJSRuntime JS
@inject IStringLocalizer<Login> Localizer
<PageTitle>登录</PageTitle>
@@ -12,6 +13,10 @@
}
else
{
<LanguageSelector></LanguageSelector>
<p>
@LanguageProvider.CurrentLanguage 网站名称 @Localizer["site.name"]
</p>
<Flex Style="height:100vh" Justify="FlexJustify.Center" Align="FlexAlign.Center" Direction="FlexDirection.Vertical">
<GridRow Justify="RowJustify.Center" Class="">
<GridCol>

View File

@@ -0,0 +1,207 @@
@page "/system/locale/resource/detail/{Name}"
@inject ILogger<LocaleResourceList> Logger
@attribute [Authorize]
<PageTitle>本地化语言资源</PageTitle>
<Title Level="4">多语言本地资源管理</Title>
<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>
@code {
bool loading = false;
[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;
}
}

View File

@@ -33,7 +33,7 @@
<Table DataSource="PagingList.Items" PageSize="100" HidePagination="true" Resizable>
<TitleTemplate>
<Flex Justify="FlexJustify.SpaceBetween">
多语言列表
@(@language.Name)语言资源列表
<div>
<Button Class="me-3" OnClick="OnCreateClick" Type="ButtonType.Primary">新增</Button>
</div>
@@ -45,11 +45,11 @@
<PropertyColumn Property="c => c.Value" Title="内容">
</PropertyColumn>
<PropertyColumn Property="c => c.UpdateTime" Title="最后更新" />
<ActionColumn Title="操作" Align="ColumnAlign.Right">
<PropertyColumn Property="c => c.UpdateTime" Title="最后更新" Width="120px" />
<ActionColumn Title="操作" Align="ColumnAlign.Right" Width="120px">
<Space>
<SpaceItem>
<a href="@($"/system/locale/resource/list/{context.Id}")"> <Icon Type="@IconType.Outline.Edit" /> 语言资源</a>
<a @onclick="(e) => OnEditClick(context)"> <Icon Type="@IconType.Outline.Edit" /> 编辑</a>
</SpaceItem>
<SpaceItem>
<Dropdown Trigger="@(new Trigger[] { Trigger.Click })">
@@ -57,7 +57,7 @@
<Menu>
<MenuItem>
<a @onclick="(e) => OnEditClick(context)"> <Icon Type="@IconType.Outline.Edit" /> 编辑</a>
<a href="@($"/system/locale/resource/detail/{context.Name}")"> <Icon Type="@IconType.Outline.Edit" /> 其他语言比对</a>
</MenuItem>
<MenuDivider />
<MenuItem>
@@ -88,14 +88,17 @@
</Card>
</Spin>
<Modal Title="@("消息模版设置")" Visible="@modalVisible" Width="700" MaskClosable="true" OkText="@("保存")" CancelText="@("取消")" OnOk="@HandleModalOk" OnCancel="@HandleCancel">
<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="消息模版名称">
<Input Placeholder="消息模版名称" @bind-Value="@context.Name" />
<FormItem Label="语言文字">
@language.Name
</FormItem>
<FormItem Label="消息内容">
<TextArea Placeholder="消息内容" @bind-Value="@context.Value" />
<FormItem Label="资源名称">
<Input Placeholder="资源名称" @bind-Value="@context.Name" />
</FormItem>
<FormItem Label="资源内容">
<TextArea Placeholder="资源内容" @bind-Value="@context.Value" />
</FormItem>
</Form>
</Modal>
@@ -121,6 +124,7 @@
LocaleResourceModel model { get; set; } = default!;
Form<LocaleResourceModel> editform = null!;
Language language = new();
PagingList<LocaleResource> PagingList = new();
bool modalVisible = false;
@@ -134,9 +138,23 @@
protected override async Task OnParametersSetAsync()
{
await LoadLanguage();
await LoadList();
}
private async Task LoadLanguage()
{
var url = $"/api/language/{Id}";
var apiResult = await HttpService.Get<ApiResult<Language>>(url);
if (apiResult.Success)
{
if (apiResult.Data != null)
{
language = apiResult.Data;
}
}
}
private async Task LoadList()
{
loading = true;
@@ -172,18 +190,20 @@
void OnCreateClick()
{
model = new() { Culture = LanguageCulture.zhHans };
Console.WriteLine("OnCreateClick");
model = new() { Culture = LanguageCulture.zhHans, LanguageId = Id };
modalVisible = true;
}
void OnEditClick(LocaleResource data)
{
this.model = data.Adapt<LocaleResourceModel>();
// drawerVisible = true;
modalVisible = true;
}
async Task HandleDeleteConfirmAsync(MouseEventArgs e, long id)
{
var url = $"/api/language/delete/{id}";
var url = $"/api/localeresource/delete/{id}";
var apiResult = await HttpService.Post<ApiResult<string>>(url, new());
if (apiResult.Success)
{
@@ -196,35 +216,6 @@
}
}
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 OnSearch(int page)
{
var queryString = search.BuildQueryString();
@@ -257,9 +248,34 @@
OnSearch(args.Page);
}
void CloseDrawer()
void HandleModalOk()
{
// drawerVisible = false;
editform.Reset();
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;
}
}