Compare commits

..

27 Commits

Author SHA1 Message Date
yxw
43820c6ec2 chore 2025-12-26 16:43:55 +08:00
13cc258cad 修复httpservice获取分页long丢失精度问题 2025-12-26 12:33:13 +08:00
030299fa53 完善国家管理和数据多语言 2025-12-26 00:21:11 +08:00
yxw
46794708ff 处理国家多语言数据 2025-12-25 18:43:30 +08:00
f7bb6bb2dc chore 2025-12-25 12:41:37 +08:00
7b6ec9c1d8 chore 2025-12-25 01:08:36 +08:00
53b6ceaa69 新增国家、州省地区的API 2025-12-25 00:59:03 +08:00
e396e66959 调整地区实体 2025-12-24 12:15:53 +08:00
yxw
a1516490d2 更新数据库 2025-12-23 18:39:39 +08:00
3c4144335f chore 2025-12-23 12:26:25 +08:00
yxw
1f0c84f75e chore 2025-12-22 17:54:57 +08:00
yxw
903d6d9304 添加页面 2025-12-17 17:16:11 +08:00
da8ac8a22b 增加app 版本管理 2025-12-17 00:37:57 +08:00
yxw
9d396fa96e chore 2025-12-16 19:23:39 +08:00
ed32b98867 调整数据库结构,实现消息模板管理 2025-12-16 11:26:55 +08:00
yxw
98e3f7ab73 调整UI布局,消息模版新增语言字段 2025-12-15 18:28:17 +08:00
9b8bf43eb6 chore 2025-12-15 13:04:44 +08:00
yxw
9edff983d8 完善语言文件的生成 2025-12-14 18:27:21 +08:00
54e9c7962d add jobs 2025-12-14 02:43:40 +08:00
0741368b44 chore 2025-12-13 13:11:03 +08:00
yxw
8a1ff0edf9 chore 2025-12-12 16:18:27 +08:00
cd43abc7eb chore 2025-12-12 12:56:22 +08:00
yxw
46e209081d update references 2025-12-11 19:15:02 +08:00
yxw
ed2e3ecd24 fix localization 2025-12-09 19:10:10 +08:00
yxw
2318dff192 fix localization 2025-12-09 17:39:21 +08:00
yxw
7334a9576f merge 2025-12-09 14:19:18 +08:00
yxw
e4550a9533 ? 2025-12-09 14:18:45 +08:00
190 changed files with 6933 additions and 3108 deletions

View File

@@ -7,4 +7,16 @@
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<PackageReference Update="Microsoft.Testing.Extensions.TrxReport" Version="2.0.2" />
</ItemGroup>
<ItemGroup>
<PackageReference Update="MSTest.TestAdapter" Version="4.0.2" />
</ItemGroup>
<ItemGroup>
<PackageReference Update="MSTest.TestFramework" Version="4.0.2" />
</ItemGroup>
</Project> </Project>

View File

@@ -9,24 +9,28 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="AntDesign" Version="1.5.0" /> <Compile Remove="wwwroot\localization\**" />
<Content Remove="wwwroot\localization\**" />
<EmbeddedResource Remove="wwwroot\localization\**" />
<None Remove="wwwroot\localization\**" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="AntDesign" Version="1.5.1" />
<PackageReference Include="AntDesign.ProLayout" Version="1.4.0" /> <PackageReference Include="AntDesign.ProLayout" Version="1.4.0" />
<PackageReference Include="Blazilla" Version="2.0.1" />
<PackageReference Include="Blazored.LocalStorage" Version="4.5.0" /> <PackageReference Include="Blazored.LocalStorage" Version="4.5.0" />
<PackageReference Include="Blazored.FluentValidation" Version="2.2.0" /> <PackageReference Include="Blazored.FluentValidation" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Components.Authorization" Version="10.0.0" /> <PackageReference Include="FluentValidation.DependencyInjectionExtensions" Version="12.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="10.0.0" /> <PackageReference Include="Microsoft.AspNetCore.Components.Authorization" Version="10.0.1" />
<PackageReference Include="Microsoft.Extensions.Http" Version="10.0.0" /> <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="10.0.1" />
<PackageReference Include="Microsoft.Extensions.Localization" Version="10.0.0" /> <PackageReference Include="Microsoft.Extensions.Http" Version="10.0.1" />
<PackageReference Include="Microsoft.Extensions.Localization" Version="10.0.1" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.15.0" /> <PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.15.0" />
<PackageReference Include="TinyMCE.Blazor" Version="2.2.1" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\..\Atomx.Common\Atomx.Common.csproj" /> <ProjectReference Include="..\..\Atomx.Common\Atomx.Common.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Folder Include="wwwroot\localization\" />
</ItemGroup>
</Project> </Project>

View File

@@ -47,6 +47,9 @@
<ChildContent> <ChildContent>
@Body @Body
</ChildContent> </ChildContent>
<FooterRender>
<FooterView Copyright="2025 Atomlust.com"></FooterView>
</FooterRender>
</AntDesign.ProLayout.BasicLayout> </AntDesign.ProLayout.BasicLayout>
</ChildContent> </ChildContent>
<ErrorContent Context="ex"> <ErrorContent Context="ex">

View File

@@ -1,15 +1,10 @@
using System.ComponentModel.DataAnnotations.Schema; namespace Atomx.Admin.Client.Models
using System.ComponentModel.DataAnnotations;
namespace Atomx.Admin.Client.Models
{ {
public class AppVersionModel public class AppVersionModel
{ {
/// <summary> /// <summary>
/// 数据ID /// 数据ID
/// </summary> /// </summary>
[DatabaseGenerated(DatabaseGeneratedOption.None)]
[Key]
public long Id { get; set; } public long Id { get; set; }
/// <summary> /// <summary>
@@ -20,43 +15,36 @@ namespace Atomx.Admin.Client.Models
/// <summary> /// <summary>
/// 应用名称KEY /// 应用名称KEY
/// </summary> /// </summary>
[Column(TypeName = "varchar(64)")]
public string AppName { get; set; } = string.Empty; public string AppName { get; set; } = string.Empty;
/// <summary> /// <summary>
/// 版本标题 /// 版本标题
/// </summary> /// </summary>
[Column(TypeName = "varchar(64)")]
public string Title { get; set; } = string.Empty; public string Title { get; set; } = string.Empty;
/// <summary> /// <summary>
/// 版本 /// 版本
/// </summary> /// </summary>
[Column(TypeName = "varchar(64)")]
public string Version { get; set; } = string.Empty; public string Version { get; set; } = string.Empty;
/// <summary> /// <summary>
/// 主版本号(major)无法向下兼容时,需要递增 /// 主版本号(major)无法向下兼容时,需要递增
/// </summary> /// </summary>
[Column(TypeName = "varchar(64)")]
public int VersionX { get; set; } public int VersionX { get; set; }
/// <summary> /// <summary>
/// 次版本号(minor)新增新的特性时,需要递增 /// 次版本号(minor)新增新的特性时,需要递增
/// </summary> /// </summary>
[Column(TypeName = "varchar(64)")]
public int VersionY { get; set; } public int VersionY { get; set; }
/// <summary> /// <summary>
/// 修订版本号(patch)修复问题时,需要递增 /// 修订版本号(patch)修复问题时,需要递增
/// </summary> /// </summary>
[Column(TypeName = "varchar(64)")]
public int VersionZ { get; set; } public int VersionZ { get; set; }
/// <summary> /// <summary>
/// 版本日期 /// 版本日期
/// </summary> /// </summary>
[Column(TypeName = "varchar(64)")]
public int VersionDate { get; set; } public int VersionDate { get; set; }
/// <summary> /// <summary>
@@ -67,7 +55,6 @@ namespace Atomx.Admin.Client.Models
/// <summary> /// <summary>
/// 更新内容说明 /// 更新内容说明
/// </summary> /// </summary>
[Column(TypeName = "text")]
public string Content { get; set; } = string.Empty; public string Content { get; set; } = string.Empty;
/// <summary> /// <summary>

View File

@@ -10,7 +10,7 @@
/// <summary> /// <summary>
/// 状态 /// 状态
/// </summary> /// </summary>
public string Status { get; set; } = string.Empty; public string? Status { get; set; } = string.Empty;
/// <summary> /// <summary>
/// 开始时间 /// 开始时间

View File

@@ -0,0 +1,8 @@
using Atomx.Common.Entities;
namespace Atomx.Admin.Client.Models
{
public class AreaModel:Area
{
}
}

View File

@@ -0,0 +1,9 @@
namespace Atomx.Admin.Client.Models
{
public class AreaSearch : BaseSearch
{
public long CountryId { get; set; }
public long StateProvinceId { get; set; }
public string Name { get; set; } = string.Empty;
}
}

View File

@@ -0,0 +1,13 @@
using Atomx.Common.Entities;
namespace Atomx.Admin.Client.Models
{
public class CountryModel:Country
{
/// <summary>
/// 语言
/// </summary>
public string LanguageId { get; set; } = string.Empty;
public List<LocalizedProperty> Localized { get; set; } = new List<LocalizedProperty>();
}
}

View File

@@ -0,0 +1,7 @@
namespace Atomx.Admin.Client.Models
{
public class CountrySearch
{
public string Name { get; set; } = string.Empty;
}
}

View File

@@ -5,7 +5,7 @@
/// <summary> /// <summary>
/// 数据ID /// 数据ID
/// </summary> /// </summary>
public int Id { get; set; } public int? Id { get; set; }
/// <summary> /// <summary>
/// 语言 /// 语言
@@ -52,5 +52,10 @@
/// 是否编辑 /// 是否编辑
/// </summary> /// </summary>
public bool IsEdit { get; set; } public bool IsEdit { get; set; }
/// <summary>
/// 是否主货币
/// </summary>
public bool PrimaryCurrency { get; set; }
} }
} }

View File

@@ -0,0 +1,20 @@
namespace Atomx.Admin.Client.Models
{
public class CurrencySearchModel:BaseSearch
{
/// <summary>
/// 用户名
/// </summary>
public string Name { get; set; } = string.Empty;
/// <summary>
/// 状态
/// </summary>
public string Status { get; set; } = string.Empty;
/// <summary>
/// 开始时间
/// </summary>
public DateTime?[] RangeTime { get; set; } = new DateTime?[] { null, null };
}
}

View File

@@ -1,20 +0,0 @@
namespace Atomx.Admin.Client.Models
{
public class MaterialSearch : BaseSearch
{
/// <summary>
/// 类型
/// </summary>
public int? Type { get; set; }
/// <summary>
/// 原料归属公司ID
/// </summary>
public long CorporationId { get; set; }
/// <summary>
/// 原料归属店铺网点ID
/// </summary>
public long StoreId { get; set; }
}
}

View File

@@ -7,6 +7,16 @@
/// </summary> /// </summary>
public long Id { get; set; } public long Id { get; set; }
/// <summary>
/// 站点ID
/// </summary>
public long SiteId { get; set; }
/// <summary>
/// 语言编码
/// </summary>
public int LanguageId { get; set; }
/// <summary> /// <summary>
/// 消息模板类型 /// 消息模板类型
/// </summary> /// </summary>
@@ -32,6 +42,11 @@
/// </summary> /// </summary>
public string Body { get; set; } = string.Empty; public string Body { get; set; } = string.Empty;
/// <summary>
/// 附件文件地址列表,多个附件以逗号分隔
/// </summary>
public string Attachments { get; set; } = string.Empty;
/// <summary> /// <summary>
/// 是否可用 /// 是否可用
/// </summary> /// </summary>

View File

@@ -4,6 +4,8 @@
{ {
public int? Type { get; set; } public int? Type { get; set; }
public int? Language { get; set; }
public string Key { get; set; } = string.Empty; public string Key { get; set; } = string.Empty;
} }
} }

View File

@@ -0,0 +1,8 @@
using Atomx.Common.Entities;
namespace Atomx.Admin.Client.Models
{
public class StateProvinceModel: StateProvince
{
}
}

View File

@@ -0,0 +1,11 @@
using System.Runtime.Serialization;
namespace Atomx.Admin.Client.Models
{
public class StateProvinceSearch
{
[IgnoreDataMember]
public long? CountryId { get; set; }
public string Name { get; set; } = string.Empty;
}
}

View File

@@ -0,0 +1,24 @@
@page "/content/blog/create"
@page "/content/blog/edit/{id:long}"
@page "/{locale}/content/blog/create"
@page "/{locale}/content/blog/edit/{id:long}"
<PageContainer Title="@(Id > 0 ? "编辑博客文章" : "新增博客文章")">
<Breadcrumb>
<Breadcrumb>
<BreadcrumbItem Href="/">管理后台</BreadcrumbItem>
<BreadcrumbItem Href="/content/page/list">内容管理</BreadcrumbItem>
<BreadcrumbItem>博客文章</BreadcrumbItem>
</Breadcrumb>
</Breadcrumb>
<ChildContent>
<h3>Tools</h3>
</ChildContent>
</PageContainer>
@code {
[Parameter]
public string Locale { get; set; } = string.Empty;
[Parameter]
public long? Id { get; set; }
}

View File

@@ -0,0 +1,20 @@
@page "/content/blog/list"
@page "/{locale}/content/blog/list"
<PageContainer Title="博客文章">
<Breadcrumb>
<Breadcrumb>
<BreadcrumbItem Href="/">管理后台</BreadcrumbItem>
<BreadcrumbItem Href="/content/page/list">内容管理</BreadcrumbItem>
<BreadcrumbItem>博客文章</BreadcrumbItem>
</Breadcrumb>
</Breadcrumb>
<ChildContent>
<h3>Tools</h3>
</ChildContent>
</PageContainer>
@code {
[Parameter]
public string Locale { get; set; } = string.Empty;
}

View File

@@ -1,5 +1,24 @@
<h3>PageEdit</h3> @page "/content/page/create"
@page "/content/page/edit/{id:long}"
@page "/{locale}/content/page/create"
@page "/{locale}/content/page/edit/{id:long}"
<PageContainer Title="@(Id > 0 ? "编辑主题页面" : "新增主题页面")">
<Breadcrumb>
<Breadcrumb>
<BreadcrumbItem Href="/">管理后台</BreadcrumbItem>
<BreadcrumbItem Href="/content/page/list">内容管理</BreadcrumbItem>
<BreadcrumbItem>主题页面</BreadcrumbItem>
</Breadcrumb>
</Breadcrumb>
<ChildContent>
<h3>Tools</h3>
</ChildContent>
</PageContainer>
@code { @code {
[Parameter]
public string Locale { get; set; } = string.Empty;
[Parameter]
public long? Id { get; set; }
} }

View File

@@ -1,8 +1,20 @@
@page "/content/page/list" @page "/content/page/list"
@page "/{locale}/content/page/list"
<PageContainer Title="主题页面">
<h3>PageList</h3> <Breadcrumb>
<Breadcrumb>
<BreadcrumbItem Href="/">管理后台</BreadcrumbItem>
<BreadcrumbItem Href="/content/page/list">内容管理</BreadcrumbItem>
<BreadcrumbItem>主题页面</BreadcrumbItem>
</Breadcrumb>
</Breadcrumb>
<ChildContent>
<h3>Tools</h3>
</ChildContent>
</PageContainer>
@code { @code {
[Parameter]
public string Locale { get; set; } = string.Empty;
} }

View File

@@ -113,7 +113,7 @@
{ {
try try
{ {
jsResult = await JS.InvokeAsync<string>("CookieReader.Read", "atomx.culture"); jsResult = await JS.InvokeAsync<string>("cookies.Read", "atomx.culture");
} }
catch (Exception ex) catch (Exception ex)
{ {

View File

@@ -1,7 +1,9 @@
@page "/" @page "/"
@page "/{locale}/"
@attribute [Authorize] @attribute [Authorize]
<PageContainer Title="控制台首页">
<PageTitle>Home</PageTitle>
<h1>Hello, world!</h1> <h1>Hello, world!</h1>
@@ -22,3 +24,15 @@ Welcome to your new app.
<li> <li>
<a href="/system/role/list">角色管理</a> <a href="/system/role/list">角色管理</a>
</li> </li>
<li>
<a href="/currency/list">货币设置</a>
</li>
<li>
<a href="/country/list">国家管理</a>
</li>
</PageContainer>
@code {
[Parameter]
public string Locale { get; set; } = string.Empty;
}

View File

@@ -1,12 +1,9 @@
@page "/account/login" @page "/account/login"
@page "/{locale}/account/login" @page "/{locale}/account/login"
@using System.Text.Json
@layout EmptyLayout @layout EmptyLayout
@inject ILogger<Login> Logger @inject ILogger<Login> Logger
@inject IJSRuntime JS
@using Microsoft.Extensions.Localization
@inject IStringLocalizer<Login> L @inject IStringLocalizer<Login> L
@inject Atomx.Admin.Client.Services.ILocalizationProvider LocalizationProvider
<PageTitle>@L["login.title"]</PageTitle> <PageTitle>@L["login.title"]</PageTitle>
@@ -144,41 +141,30 @@ else
if (!OperatingSystem.IsBrowser()) if (!OperatingSystem.IsBrowser())
{ {
// Server 模式:使用浏览器发起的 fetch通过 JS并携带 credentials: 'include' // Server 模式:使用浏览器发起的 fetch通过 JS并携带 credentials: 'include'
Logger.LogInformation("Server 模式,使用浏览器 fetch 登录"); var jsResult = await JS.InvokeAsync<JsonElement>("ajax.Post", api, login);
var jsResult = await JS.InvokeAsync<JsonElement>("__atomx_post_json", api, login); var result = jsResult.ToJson().FromJson<ApiResult<AuthResponse>>();
if (result != null && result.Success)
var success = jsResult.TryGetProperty("success", out var sprop) && sprop.GetBoolean();
if (success && jsResult.TryGetProperty("data", out var dprop) && dprop.ValueKind == JsonValueKind.Object)
{ {
var token = dprop.TryGetProperty("token", out var t) ? t.GetString() ?? string.Empty : string.Empty; var auth = result.Data;
var refresh = dprop.TryGetProperty("refreshToken", out var r) ? r.GetString() ?? string.Empty : string.Empty; await localStorage.SetItemAsync(StorageKeys.AccessToken, auth.Token);
await localStorage.SetItemAsync(StorageKeys.RefreshToken, auth.RefreshToken);
// WASM 的 localStorage 在 Server Circuit 中无意义兼容auto模式写入 localStorage。
try
{
await localStorage.SetItemAsync(StorageKeys.AccessToken, token);
await localStorage.SetItemAsync(StorageKeys.RefreshToken, refresh);
if (AuthStateProvider is PersistentAuthenticationStateProvider provider) if (AuthStateProvider is PersistentAuthenticationStateProvider provider)
{ {
provider.UpdateAuthenticationState(token); provider.UpdateAuthenticationState(auth.Token);
} }
}
catch { }
// 浏览器已通过 fetch 收到 Set-Cookie强制重载使 Circuit 使用新 Cookie。
Logger.LogInformation($"登录成功server 跳转: {ReturnUrl}"); Logger.LogInformation($"登录成功server 跳转: {ReturnUrl}");
Navigation.NavigateTo(ReturnUrl ?? "/", forceLoad: true); Navigation.NavigateTo(ReturnUrl ?? "/", forceLoad: true);
} }
else else
{ {
var msg = jsResult.TryGetProperty("message", out var m) ? m.GetString() ?? "登录失败" : "登录失败"; ModalService.Error(new ConfirmOptions() { Title = "提示", Content = result.Message });
ModalService.Error(new ConfirmOptions() { Title = "提示", Content = msg });
} }
} }
else else
{ {
// Wasm 模式:继续使用 HttpService之前逻辑保存 localStorage 并更新 AuthStateProvider // Wasm 模式:保存 localStorage 并更新 AuthStateProvider
var result = await HttpService.Post<ApiResult<AuthResponse>>(api, login); var result = await HttpService.Post<ApiResult<AuthResponse>>(api, login);
if (result.Success && result.Data != null) if (result.Success && result.Data != null)
{ {
@@ -225,35 +211,4 @@ else
login.Account = "admin"; login.Account = "admin";
login.Password = "admin888"; login.Password = "admin888";
} }
private string GetShortCulture(string current)
{
if (string.IsNullOrEmpty(current)) return current;
if (current.StartsWith("zh", StringComparison.OrdinalIgnoreCase)) return "zh";
if (current.StartsWith("en", StringComparison.OrdinalIgnoreCase)) return "en";
var prefix = current.Split('-', StringSplitOptions.RemoveEmptyEntries).FirstOrDefault();
return prefix ?? current;
} }
}
@* 页面内 JS 辅助:用于在 Server 模式下从浏览器发起 POST 并携带凭证,使浏览器接收 Set-Cookie *@
<script>
window.__atomx_post_json = async function (url, data) {
try {
const res = await fetch(url, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
credentials: 'include',
body: JSON.stringify(data)
});
const text = await res.text();
try {
return JSON.parse(text);
} catch {
return { success: res.ok, message: text };
}
} catch (err) {
return { success: false, message: err?.toString() ?? 'network error' };
}
};
</script>

View File

@@ -0,0 +1,20 @@
@page "/deposit/list"
@page "/{locale}/deposit/list"
<PageContainer Title="储值订单">
<Breadcrumb>
<Breadcrumb>
<BreadcrumbItem Href="/">管理后台</BreadcrumbItem>
<BreadcrumbItem Href="/content/page/list">内容管理</BreadcrumbItem>
<BreadcrumbItem>储值订单</BreadcrumbItem>
</Breadcrumb>
</Breadcrumb>
<ChildContent>
<h3>Tools</h3>
</ChildContent>
</PageContainer>
@code {
[Parameter]
public string Locale { get; set; } = string.Empty;
}

View File

@@ -0,0 +1,22 @@
@page "/deposit/detail/{id:long}"
@page "/{locale}/deposit/detail/{id:long}"
<PageContainer Title="@($"订单{Id}详情")">
<Breadcrumb>
<Breadcrumb>
<BreadcrumbItem Href="/">管理后台</BreadcrumbItem>
<BreadcrumbItem Href="/content/page/list">内容管理</BreadcrumbItem>
<BreadcrumbItem>主题页面</BreadcrumbItem>
</Breadcrumb>
</Breadcrumb>
<ChildContent>
<h3>Tools</h3>
</ChildContent>
</PageContainer>
@code {
[Parameter]
public string Locale { get; set; } = string.Empty;
[Parameter]
public long? Id { get; set; }
}

View File

@@ -1,5 +1,20 @@
<h3>OrderList</h3> @page "/order/list"
@page "/{locale}/order/list"
<PageContainer Title="购物订单">
<Breadcrumb>
<Breadcrumb>
<BreadcrumbItem Href="/">管理后台</BreadcrumbItem>
<BreadcrumbItem Href="/content/page/list">内容管理</BreadcrumbItem>
<BreadcrumbItem>购物订单</BreadcrumbItem>
</Breadcrumb>
</Breadcrumb>
<ChildContent>
<h3>Tools</h3>
</ChildContent>
</PageContainer>
@code { @code {
[Parameter]
public string Locale { get; set; } = string.Empty;
} }

View File

@@ -1,16 +1,23 @@
@page "/product/category/edit" @page "/product/category/edit"
@page "/product/category/edit/{Id:long?}" @page "/product/category/edit/{Id:long?}"
@page "/{locale}/product/category/edit"
@page "/{locale}/product/category/edit/{Id:long?}"
@inject ILogger<CategoryEdit> Logger @inject ILogger<CategoryEdit> Logger
@attribute [Authorize] @attribute [Authorize]
<PageTitle>分类编辑</PageTitle> <PageContainer Title="编辑产品分类">
<Title Level="4">分类信息</Title> <Breadcrumb>
<Breadcrumb>
<BreadcrumbItem Href="/">管理后台</BreadcrumbItem>
<BreadcrumbItem Href="/product/list">系统功能</BreadcrumbItem>
<BreadcrumbItem>分类管理</BreadcrumbItem>
</Breadcrumb>
</Breadcrumb>
<ChildContent>
<Spin Spinning="pageLoading"> <Spin Spinning="pageLoading">
<Card Title="" Class="hideborder" <Card Title="分类信息">
Style="margin-top: 24px;"
BodyStyle="padding: 0 32px 40px 32px">
<Form @ref="editform" Model="@model" LabelColSpan="5" WrapperColSpan="19" OnFinish="OnFormFinishAsync"> <Form @ref="editform" Model="@model" LabelColSpan="5" WrapperColSpan="19" OnFinish="OnFormFinishAsync">
@* @if (languages.Count > 1 && Id > 0) @* @if (languages.Count > 1 && Id > 0)
{ {
@@ -79,8 +86,13 @@
</Form> </Form>
</Card> </Card>
</Spin> </Spin>
</ChildContent>
</PageContainer>
@code { @code {
[Parameter]
public string Locale { get; set; } = string.Empty;
[SupplyParameterFromQuery] [SupplyParameterFromQuery]
int? Lang { get; set; } int? Lang { get; set; }

View File

@@ -1,10 +1,18 @@
@page "/category/list" @page "/category/list"
@page "/{locale}/category/list"
@inject ILogger<CategoryList> Logger @inject ILogger<CategoryList> Logger
@attribute [Authorize] @attribute [Authorize]
<PageTitle>分类管理</PageTitle> <PageContainer Title="产品分类管理">
<Title Level="4">菜单管理</Title> <Breadcrumb>
<Breadcrumb>
<BreadcrumbItem Href="/">管理后台</BreadcrumbItem>
<BreadcrumbItem Href="/product/list">系统功能</BreadcrumbItem>
<BreadcrumbItem>分类管理</BreadcrumbItem>
</Breadcrumb>
</Breadcrumb>
<ChildContent>
<Card> <Card>
<Form @ref="searchForm" Model="search" Layout="FormLayout.Inline" Class="search-form" OnFinish="OnSearchFinish"> <Form @ref="searchForm" Model="search" Layout="FormLayout.Inline" Class="search-form" OnFinish="OnSearchFinish">
<Row Justify="RowJustify.Start" Gutter="16"> <Row Justify="RowJustify.Start" Gutter="16">
@@ -23,6 +31,7 @@
</Row> </Row>
</Form> </Form>
</Card> </Card>
<br/>
<Card Class="mt-3"> <Card Class="mt-3">
<Table DataSource="categories" PageSize="100" HidePagination="true" Resizable> <Table DataSource="categories" PageSize="100" HidePagination="true" Resizable>
<TitleTemplate> <TitleTemplate>
@@ -132,10 +141,13 @@
</FormItem> </FormItem>
</Form> </Form>
</Drawer> </Drawer>
</ChildContent>
</PageContainer>
@code { @code {
[Parameter]
public string Locale { get; set; } = string.Empty;
[SupplyParameterFromQuery] [SupplyParameterFromQuery]
int? Page { get; set; } int? Page { get; set; }

View File

@@ -120,8 +120,6 @@
bool searchExpand { get; set; } = false; bool searchExpand { get; set; } = false;
private bool drawerVisible; private bool drawerVisible;
SpecificationAttributeOptionModelValidator validator = new();
protected override void OnInitialized() protected override void OnInitialized()
{ {
base.OnInitialized(); base.OnInitialized();

View File

@@ -0,0 +1,5 @@
<h3>AreaEdit</h3>
@code {
}

View File

@@ -0,0 +1,207 @@
@page "/area/list/{countryId:long}"
@page "/{locale}/area/list/{countryId:long}"
@inject ILogger<CountryList> Logger
@attribute [Authorize]
<PageContainer Title="国家管理">
<Breadcrumb>
<Breadcrumb>
<BreadcrumbItem>Home</BreadcrumbItem>
<BreadcrumbItem>系统配置</BreadcrumbItem>
<BreadcrumbItem>国家管理</BreadcrumbItem>
</Breadcrumb>
</Breadcrumb>
<ChildContent>
<Spin Spinning="pageLoading">
<Card>
<Form @ref="searchForm" Model="search" Layout="FormLayout.Inline" Class="search-form" OnFinish="OnSearchFinish">
<Row Justify="RowJustify.Start" Gutter="16">
<Col>
<FormItem Label="名称">
<Input @bind-Value="search.Name" Placeholder="名称" AllowClear />
</FormItem>
<div class="ant-form-item">
<Button Type="ButtonType.Primary" HtmlType="submit">查询</Button>
<Button Style="margin: 0 8px;" OnClick="OnSearchReset">重置</Button>
</div>
</Col>
</Row>
</Form>
</Card>
<Card Title="" Class="hideborder">
<Extra>
<div class="extraContent">
<Button Type="ButtonType.Primary" HtmlType="submit" OnClick="HandleAddNew">新增国家</Button>
</div>
</Extra>
<ChildContent>
<Table DataSource="PagingList.Items" PageSize="100" HidePagination="true">
<Selection CheckStrictly />
<PropertyColumn Property="c => c.Name" Title="名称" />
<PropertyColumn Property="c => c.Initial" Title="首字母" />
<PropertyColumn Property="c => c.NumericISOCode" Title="ISO代码" />
<PropertyColumn Property="c => c.Enabled" Title="状态">
@if (context.Enabled)
{
<Text>已激活</text>
}
else
{
<Text>未激活</text>
}
</PropertyColumn>
<PropertyColumn Property="c => c.DisplayOrder" Title="排序" />
<ActionColumn Title="操作" Align="ColumnAlign.Right">
<Space>
<SpaceItem>
<a @onclick="(e)=>HandleEdit(context)">编辑</a>
</SpaceItem>
@*<SpaceItem>
<Popconfirm Placement="@Placement.Left" Title="@("删除这条数据无法恢复,您确定要删除吗?")"
OnConfirm="@(e=>HandleDeleteConfirmAsync(e,context.Id))"
OkText="确定"
CancelText="取消">
<a>删除</a>
</Popconfirm>
</SpaceItem>*@
</Space>
</ActionColumn>
</Table>
<br />
<Row Justify="RowJustify.End">
@if (PagingList.Count > 0)
{
<Pagination Current="PagingList.Index" Total="PagingList.Count" PageSize="PagingList.Size" ShowSizeChanger="false" OnChange="OnPageChanged"></Pagination>
}
</Row>
</ChildContent>
</Card>
</Spin>
</ChildContent>
</PageContainer>
@code {
[Parameter]
public string Locale { get; set; } = string.Empty;
[Parameter]
public long CountryId { get; set; }
[SupplyParameterFromQuery]
int? Page { get; set; }
[SupplyParameterFromQuery(Name = "size")]
int? PageSize { get; set; }
bool pageLoading = false;
Form<CountrySearch> searchForm = new();
CountrySearch search = new();
PagingList<Country> PagingList = new() { Size = 20 };
protected override async Task OnInitializedAsync()
{
await base.OnInitializedAsync();
}
protected override async Task OnParametersSetAsync()
{
loadQueryString();
await LoadListAsync();
await base.OnParametersSetAsync();
}
void loadQueryString()
{
var uri = new Uri(Navigation.Uri);
var query = uri.Query;
search.Name = query.GetQueryString("Name");
}
async Task LoadListAsync()
{
try
{
pageLoading = true;
var url = "/api/country/search";
var apiResult = await HttpService.GetPagingList<Country>(url, search, Page.GetValueOrDefault(1), PageSize.GetValueOrDefault(20));
if (apiResult.Success)
{
if (apiResult.Data != null)
{
PagingList = apiResult.Data;
}
}
else if (apiResult.Code == 403)
{
ModalService.Error(new ConfirmOptions() { Title = "权限不足", Content = apiResult.Message });
}
StateHasChanged();
}
finally
{
pageLoading = false;
}
}
void OnSearchReset()
{
search = new CountrySearch();
searchForm?.Reset();
}
private void OnSearch(int page)
{
var queryString = search.BuildQueryString();
if (string.IsNullOrEmpty(queryString))
{
if (page > 1)
{
Navigation.NavigateTo($"/country/list?page={page}");
}
else
{
Navigation.NavigateTo($"/country/list");
}
}
else
{
if (page > 1)
{
Navigation.NavigateTo($"/country/list?page={page}&{queryString}");
}
else
{
Navigation.NavigateTo($"/country/list?{queryString}");
}
}
}
void OnSearchFinish()
{
Page = Page.GetValueOrDefault(1) - 1;
OnSearch(Page.Value);
}
private void OnPageChanged(PaginationEventArgs args)
{
OnSearch(args.Page);
}
void HandleAddNew()
{
Navigation.NavigateTo($"/country/create");
}
void HandleEdit(Country model)
{
Navigation.NavigateTo($"/country/edit/{model.Id}");
}
}

View File

@@ -0,0 +1,202 @@
@page "/country/create"
@page "/country/edit/{id:long}"
@page "/{locale}/country/create"
@page "/{locale}/country/edit/{id:long}"
@inject ILogger<CountryEdit> Logger
@attribute [Authorize]
<PageContainer Title="@(Id > 0 ? "编辑国家信息" : "新增国家信息")">
<Breadcrumb>
<Breadcrumb>
<BreadcrumbItem Href="/">管理后台</BreadcrumbItem>
<BreadcrumbItem Href="/settings">系统配置</BreadcrumbItem>
<BreadcrumbItem Href="/country/list">国家管理</BreadcrumbItem>
</Breadcrumb>
</Breadcrumb>
<ChildContent>
<Spin Spinning="pageLoading">
<Card Title="国家信息">
<Form @ref="editform" Model="@model" LabelColSpan="5" WrapperColSpan="14" OnFinish="OnFormFinishAsync">
@if (Id > 0 && languageList.Count() > 0)
{
<Tabs ActiveKey="@model.LanguageId" OnTabClick="OnLanguageTabChange">
@* <TabPane Key="0">
<TabTemplate>
<span>标准</span>
</TabTemplate>
</TabPane> *@
@foreach (var item in languageList)
{
<TabPane Key="@item.Key.ToString()">
<TabTemplate>
<span>@item.Value</span>
</TabTemplate>
</TabPane>
}
</Tabs>
}
<FormItem Label="名称" Required>
<Input @bind-Value="@model.Name" Placeholder="国家" />
</FormItem>
<FormItem Label="首字母">
<Input @bind-Value="@model.Initial" Placeholder="首字母" />
</FormItem>
<FormItem Label="两个字母ISO代码">
<Input @bind-Value="@model.TwoLetterISOCode" Placeholder="两个字母ISO代码" />
</FormItem>
<FormItem Label="三字母ISO代码">
<Input @bind-Value="@model.ThreeLetterISOCode" Placeholder="三字母ISO代码" />
</FormItem>
<FormItem Label="数字ISO代码">
<Input @bind-Value="@model.NumericISOCode" Placeholder="数字ISO代码" />
</FormItem>
<FormItem Label="允许发货">
<Checkbox Checked="@model.AllowShipping">允许发货</Checkbox>
</FormItem>
<FormItem Label="显示排序">
<Input @bind-Value="@model.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 Id { get; set; }
[SupplyParameterFromForm]
CountryModel model { get; set; } = new();
Form<CountryModel> editform = null!;
CountryLocalizedModel country = new();
List<KeyValue> languageList = new();
bool pageLoading = false;
bool saving = false;
protected override void OnInitialized()
{
base.OnInitialized();
}
protected override void OnParametersSet()
{
_ = LoadLanguage();
if (Id > 0)
{
LoadData();
}
base.OnParametersSet();
}
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/country/detail?id={Id}";
var apiResult = await HttpService.Get<ApiResult<CountryLocalizedModel>>(url);
if (apiResult.Success)
{
if (apiResult.Data == null)
{
Navigation.NavigateTo($"/country/create");
}
else
{
country = apiResult.Data;
model = apiResult.Data.Adapt<CountryModel>();
}
}
else
{
Navigation.NavigateTo($"/country/create");
}
pageLoading = false;
StateHasChanged();
}
async void OnFormFinishAsync()
{
if (editform.Validate())
{
Console.WriteLine(model.ToJson());
saving = true;
var url = $"api/country/save";
var result = new ApiResult<string>();
result = await HttpService.Post<ApiResult<string>>(url, model);
if (result.Success)
{
saving = false;
await ModalService.InfoAsync(new ConfirmOptions() { Title = "提示", Content = "数据提交成功!" });
Navigation.NavigateTo($"/country/list");
}
else
{
saving = false;
await ModalService.ErrorAsync(new ConfirmOptions() { Title = "服务异常", Content = result.Message });
}
}
}
void OnLanguageTabChange(string key)
{
if (key != "0")
{
model.LanguageId = key;
var data = country.Locales.Where(p => p.LanguageId == key.ToInt()).ToList();
if (data.Any())
{
var name = nameof(model.Name);
model.Name = data.SingleOrDefault(p => p.Key == name)?.Value ?? "";
}
else
{
model.Name = string.Empty;
}
}
else
{
model = country.Adapt<CountryModel>();
model.LanguageId = key;
}
}
}

View File

@@ -0,0 +1,224 @@
@page "/country/list"
@page "/{locale}/country/list"
@inject ILogger<CountryList> Logger
@attribute [Authorize]
<PageContainer Title="国家管理">
<Breadcrumb>
<Breadcrumb>
<BreadcrumbItem Href="/">管理后台</BreadcrumbItem>
<BreadcrumbItem Href="/settings">系统配置</BreadcrumbItem>
<BreadcrumbItem>国家管理</BreadcrumbItem>
</Breadcrumb>
</Breadcrumb>
<ChildContent>
<Spin Spinning="pageLoading">
<Card>
<Form @ref="searchForm" Model="search" Layout="FormLayout.Inline" Class="search-form" OnFinish="OnSearchFinish">
<Row Justify="RowJustify.Start" Gutter="16">
<Col>
<FormItem Label="名称">
<Input @bind-Value="search.Name" Placeholder="名称" AllowClear />
</FormItem>
</Col>
<Col>
<div class="ant-form-item">
<Button Type="ButtonType.Primary" HtmlType="submit">查询</Button>
<Button Style="margin: 0 8px;" OnClick="OnSearchReset">重置</Button>
</div>
</Col>
</Row>
</Form>
</Card>
<br />
<Card Title="国家列表" Class="hideborder">
<Extra>
<div class="extraContent">
<Button Type="ButtonType.Primary" HtmlType="submit" OnClick="HandleAddNew">新增国家</Button>
</div>
</Extra>
<ChildContent>
<Table DataSource="PagingList.Items" PageSize="100" HidePagination="true">
<Selection CheckStrictly />
<PropertyColumn Property="c => c.Name" Title="名称" />
<PropertyColumn Property="c => c.Initial" Title="首字母" />
<PropertyColumn Property="c => c.NumericISOCode" Title="ISO代码" />
<PropertyColumn Property="c => c.Enabled" Title="状态">
@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.DisplayOrder" Title="排序" />
<ActionColumn Title="操作" Align="ColumnAlign.Right">
<Space>
<SpaceItem>
<a @onclick="(e) => GotoStateProvince(context)">州省管理</a>
</SpaceItem>
<SpaceItem>
<a @onclick="(e) => GotoArea(context)">城市管理</a>
</SpaceItem>
<SpaceItem>
<a @onclick="(e)=>HandleEdit(context)">编辑</a>
</SpaceItem>
@*<SpaceItem>
<Popconfirm Placement="@Placement.Left" Title="@("删除这条数据无法恢复,您确定要删除吗?")"
OnConfirm="@(e=>HandleDeleteConfirmAsync(e,context.Id))"
OkText="确定"
CancelText="取消">
<a>删除</a>
</Popconfirm>
</SpaceItem>*@
</Space>
</ActionColumn>
</Table>
<br />
<Row Justify="RowJustify.End">
@if (PagingList.Count > 0)
{
<Pagination Current="PagingList.Index" Total="PagingList.Count" PageSize="PagingList.Size" ShowSizeChanger="false" OnChange="OnPageChanged"></Pagination>
}
</Row>
</ChildContent>
</Card>
</Spin>
</ChildContent>
</PageContainer>
@code {
[Parameter]
public string Locale { get; set; } = string.Empty;
[SupplyParameterFromQuery]
int? Page { get; set; }
[SupplyParameterFromQuery(Name = "size")]
int? PageSize { get; set; }
bool pageLoading = false;
Form<CountrySearch> searchForm = new();
CountrySearch search = new();
PagingList<Country> PagingList = new() { Size = 20 };
protected override async Task OnInitializedAsync()
{
await base.OnInitializedAsync();
}
protected override async Task OnParametersSetAsync()
{
loadQueryString();
await LoadListAsync();
await base.OnParametersSetAsync();
}
void loadQueryString()
{
var uri = new Uri(Navigation.Uri);
var query = uri.Query;
search.Name = query.GetQueryString("Name");
}
async Task LoadListAsync()
{
pageLoading = true;
try
{
var url = "/api/country/search";
var apiResult = await HttpService.GetPagingList<Country>(url, search, Page.GetValueOrDefault(1), PageSize.GetValueOrDefault(20));
if (apiResult.Success)
{
if (apiResult.Data != null)
{
PagingList = apiResult.Data;
}
}
else if (apiResult.Code == 403)
{
ModalService.Error(new ConfirmOptions() { Title = "权限不足", Content = apiResult.Message });
}
StateHasChanged();
}
finally
{
pageLoading = false;
}
}
void OnSearchReset()
{
search = new CountrySearch();
searchForm?.Reset();
}
private void OnSearch(int page)
{
var queryString = search.BuildQueryString();
if (string.IsNullOrEmpty(queryString))
{
if (page > 1)
{
Navigation.NavigateTo($"/country/list?page={page}");
}
else
{
Navigation.NavigateTo($"/country/list");
}
}
else
{
if (page > 1)
{
Navigation.NavigateTo($"/country/list?page={page}&{queryString}");
}
else
{
Navigation.NavigateTo($"/country/list?{queryString}");
}
}
}
void OnSearchFinish()
{
Page = Page.GetValueOrDefault(1) - 1;
OnSearch(Page.Value);
}
private void OnPageChanged(PaginationEventArgs args)
{
OnSearch(args.Page);
}
void HandleAddNew()
{
Navigation.NavigateTo($"/country/create");
}
void HandleEdit(Country model)
{
Navigation.NavigateTo($"/country/edit/{model.Id}");
}
void GotoStateProvince(Country model)
{
Navigation.NavigateTo($"/stateprovince/list/{model.Id}");
}
void GotoArea(Country model)
{
Navigation.NavigateTo($"/area/list/{model.Id}");
}
}

View File

@@ -0,0 +1,137 @@
@page "/currency/create"
@page "/currency/edit/{id:long}"
@page "/{locale}/currency/create"
@page "/{locale}/currency/edit/{id:long}"
@inject ILogger<CurrencyEdit> Logger
@attribute [Authorize]
<PageContainer Title="@(Id > 0 ? "编辑货币信息" : "新增货币信息")">
<Breadcrumb>
<Breadcrumb>
<BreadcrumbItem Href="/">管理后台</BreadcrumbItem>
<BreadcrumbItem Href="/admin/list">系统配置</BreadcrumbItem>
<BreadcrumbItem Href="/currency/list">货币管理</BreadcrumbItem>
</Breadcrumb>
</Breadcrumb>
<ChildContent>
<Spin Spinning="pageLoading">
<Card Title="货币信息">
<Form @ref="editform" Model="@model" LabelColSpan="5" WrapperColSpan="14" OnFinish="OnFormFinishAsync">
<FormItem Label="名称" Required>
<Input @bind-Value="@context.Name" Placeholder="货币名称" />
</FormItem>
<FormItem Label="货币代码">
<Input @bind-Value="@context.CurrencyCode" Placeholder="货币代码" />
</FormItem>
<FormItem Label="汇率">
<Input @bind-Value="@context.Rate" Placeholder="汇率" />
</FormItem>
<FormItem Label="展示本地">
<SimpleSelect @bind-Value="@context.DisplayLocale" Placeholder="语言文化">
<SelectOptions>
@foreach (var item in LanguageCultures)
{
<SimpleSelectOption Value="@item.Key" Label="@($"{item.Value} - {item.Key}")"></SimpleSelectOption>
}
</SelectOptions>
</SimpleSelect>
</FormItem>
<FormItem Label="自定义格式">
<Input @bind-Value="@context.CustomFormatting" Placeholder="自定义格式" />
</FormItem>
<FormItem Label="显示排序">
<Input @bind-Value="@context.DisplayOrder" Placeholder="显示排序" />
</FormItem>
<FormItem Label="状态">
<Checkbox Checked="@context.Enabled">启用</Checkbox>
</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 Id { get; set; }
[SupplyParameterFromForm]
CurrencyModel model { get; set; } = new();
Form<CurrencyModel> editform = null!;
Dictionary<string, string> LanguageCultures = LanguageCulture.Descriptions.ToDictionary();
bool pageLoading = false;
bool saving = false;
protected override void OnInitialized()
{
base.OnInitialized();
}
protected override void OnParametersSet()
{
if (Id > 0)
{
LoadData();
}
base.OnParametersSet();
}
async void LoadData()
{
pageLoading = true;
var url = $"/api/currency/{Id}";
var apiResult = await HttpService.Get<ApiResult<Currency>>(url);
if (apiResult.Success)
{
if (apiResult.Data == null)
{
Navigation.NavigateTo($"/currency/create");
}
else
{
model = apiResult.Data.Adapt<CurrencyModel>();
}
}
else
{
Navigation.NavigateTo($"/currency/create");
}
pageLoading = false;
StateHasChanged();
}
async void OnFormFinishAsync()
{
if (editform.Validate())
{
saving = true;
var url = $"api/currency/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($"/currency/list");
}
else
{
saving = false;
await ModalService.ErrorAsync(new ConfirmOptions() { Title = "服务异常", Content = result.Message });
}
}
}
}

View File

@@ -0,0 +1,263 @@
@page "/currency/list"
@page "/{locale}/currency/list"
@inject ILogger<CurrencyList> Logger
@attribute [Authorize]
<PageContainer Title="货币管理">
<Breadcrumb>
<Breadcrumb>
<BreadcrumbItem Href="/">管理后台</BreadcrumbItem>
<BreadcrumbItem Href="/settings">系统配置</BreadcrumbItem>
<BreadcrumbItem>货币管理</BreadcrumbItem>
</Breadcrumb>
</Breadcrumb>
<ChildContent>
<Spin Spinning="pageLoading">
<Card>
<Form @ref="searchForm" Model="search" Layout="FormLayout.Inline" Class="search-form" OnFinish="OnSearchFinish">
<Row Justify="RowJustify.Start" Gutter="(16, 16)">
<Col>
<FormItem Label="名称">
<Input @bind-Value="search.Name" Placeholder="名称" AllowClear />
</FormItem>
</Col>
@if (searchExpand)
{
<AntDesign.Col>
<FormItem Label="发布时间">
<RangePicker @bind-Value="search.RangeTime"></RangePicker>
</FormItem>
</AntDesign.Col>
<AntDesign.Col>
<FormItem Label="状态">
<SimpleSelect DefaultValue="" Style="width:120px;" @bind-Value="@search.Status">
<SelectOptions>
<SimpleSelectOption Value="" Label="全部"></SimpleSelectOption>
<SimpleSelectOption Value="1" Label="草稿"></SimpleSelectOption>
<SimpleSelectOption Value="2" Label="已发布"></SimpleSelectOption>
<SimpleSelectOption Value="3" Label="已删除"></SimpleSelectOption>
</SelectOptions>
</SimpleSelect>
</FormItem>
</AntDesign.Col>
}
<Col>
<div class="ant-form-item" style="display:flex">
<Button Type="ButtonType.Primary" HtmlType="submit">查询</Button>
<Button Style="margin: 0 8px;" OnClick="OnSearchReset">重置</Button>
<a style="font-size:12px; display:flex; align-items:center;text-align:center;" @onclick="()=>{searchExpand=!searchExpand;}">
<Icon Type="@(searchExpand?"up":"down")"></Icon> @if (searchExpand)
{
<span>收起</span>
}
else
{
<span>展开</span>
}
</a>
</div>
</Col>
</Row>
</Form>
</Card>
<br />
<Card Title="" Class="hideborder">
<Extra>
<div class="extraContent">
<Button Type="ButtonType.Primary" HtmlType="submit" OnClick="HandleAddNew">新增货币</Button>
</div>
</Extra>
<ChildContent>
<Table DataSource="PagingList.Items" PageSize="100" HidePagination="true">
<Selection CheckStrictly />
<PropertyColumn Property="c => c.Name" Title="名称" />
<PropertyColumn Property="c => c.CurrencyCode" Title="货币代码" />
<PropertyColumn Property="c => c.Rate" Title="汇率" />
<PropertyColumn Property="c => c.PrimaryCurrency" Title="默认货币">
@if (context.PrimaryCurrency)
{
<AntDesign.Text Type="TextElementType.Success"><Icon Type="check" Theme="IconThemeType.Outline" /></AntDesign.Text>
}
else
{
<Icon Type="minus" Theme="IconThemeType.Outline" />
}
</PropertyColumn>
<PropertyColumn Property="c => c.Enabled" Title="状态">
@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.DisplayOrder" Title="排序" />
<ActionColumn Title="操作" Align="ColumnAlign.Right">
<Space>
<SpaceItem>
<a @onclick="(e)=>HandleEdit(context)">编辑</a>
</SpaceItem>
@*<SpaceItem>
<Popconfirm Placement="@Placement.Left" Title="@("删除这条数据无法恢复,您确定要删除吗?")"
OnConfirm="@(e=>HandleDeleteConfirmAsync(e,context.Id))"
OkText="确定"
CancelText="取消">
<a>删除</a>
</Popconfirm>
</SpaceItem>*@
</Space>
</ActionColumn>
</Table>
<br />
<Row Justify="RowJustify.End">
@if (PagingList.Count > 0)
{
<Pagination Current="PagingList.Index" Total="PagingList.Count" PageSize="PagingList.Size" ShowSizeChanger="false" OnChange="OnPageChanged"></Pagination>
}
</Row>
</ChildContent>
</Card>
</Spin>
</ChildContent>
</PageContainer>
@code {
[Parameter]
public string Locale { get; set; } = string.Empty;
[SupplyParameterFromQuery]
int? Page { get; set; }
[SupplyParameterFromQuery(Name = "size")]
int? PageSize { get; set; }
bool pageLoading = false;
bool searchExpand = false;
Form<CurrencySearchModel> searchForm = new();
CurrencySearchModel search = new();
PagingList<CurrencyModel> PagingList = new() { Size = 20 };
protected override async Task OnInitializedAsync()
{
await base.OnInitializedAsync();
}
protected override async Task OnParametersSetAsync()
{
loadQueryString();
await LoadListAsync();
await base.OnParametersSetAsync();
}
void loadQueryString()
{
var uri = new Uri(Navigation.Uri);
var query = uri.Query;
search.Name = query.GetQueryString("Name");
search.Status = query.GetQueryString("Status");
var data = query.GetQueryString("RangeTime");
if (!string.IsNullOrEmpty(data))
{
var rangetime = data.Split("-");
if (rangetime != null && rangetime.Length > 0)
{
searchExpand = true;
search.RangeTime[0] = rangetime[0].NumberToDateTime();
search.RangeTime[1] = rangetime[1].NumberToDateTime();
StateHasChanged();
}
}
}
async Task LoadListAsync()
{
try
{
pageLoading = true;
var url = "/api/currency/search";
var apiResult = await HttpService.GetPagingList<CurrencyModel>(url, search, Page.GetValueOrDefault(1), PageSize.GetValueOrDefault(20));
if (apiResult.Success)
{
if (apiResult.Data != null)
{
PagingList = apiResult.Data;
}
}
else if (apiResult.Code == 403)
{
ModalService.Error(new ConfirmOptions() { Title = "权限不足", Content = apiResult.Message });
}
StateHasChanged();
}
finally
{
pageLoading = false;
}
}
void OnSearchReset()
{
search = new CurrencySearchModel();
searchForm?.Reset();
}
private void OnSearch(int page)
{
var queryString = search.BuildQueryString();
if (string.IsNullOrEmpty(queryString))
{
if (page > 1)
{
Navigation.NavigateTo($"/currency/list?page={page}");
}
else
{
Navigation.NavigateTo($"/currency/list");
}
}
else
{
if (page > 1)
{
Navigation.NavigateTo($"/currency/list?page={page}&{queryString}");
}
else
{
Navigation.NavigateTo($"/currency/list?{queryString}");
}
}
}
void OnSearchFinish()
{
Page = Page.GetValueOrDefault(1) - 1;
OnSearch(Page.Value);
}
private void OnPageChanged(PaginationEventArgs args)
{
OnSearch(args.Page);
}
void HandleAddNew()
{
Navigation.NavigateTo($"/currency/create");
}
void HandleEdit(CurrencyModel model)
{
Navigation.NavigateTo($"/currency/edit/{model.Id}");
}
}

View File

@@ -1,10 +1,17 @@
@page "/setting/messagetemplate/list" @page "/setting/messagetemplate/list"
@page "/{locale}/setting/messagetemplate/list"
@inject ILogger<MessageTemplateList> Logger @inject ILogger<MessageTemplateList> Logger
@attribute [Authorize] @attribute [Authorize]
<PageTitle>消息模板</PageTitle> <PageContainer Title="消息模板">
<Title Level="4">消息模版管理</Title> <Breadcrumb>
<Breadcrumb>
<BreadcrumbItem Href="/">管理后台</BreadcrumbItem>
<BreadcrumbItem Href="/admin/list">系统功能</BreadcrumbItem>
<BreadcrumbItem>系统设置</BreadcrumbItem>
</Breadcrumb>
</Breadcrumb>
<ChildContent>
<Card> <Card>
<Form @ref="searchForm" Model="search" Layout="FormLayout.Inline" Class="search-form" OnFinish="OnSearchFinish"> <Form @ref="searchForm" Model="search" Layout="FormLayout.Inline" Class="search-form" OnFinish="OnSearchFinish">
<Row Justify="RowJustify.Start" Gutter="16"> <Row Justify="RowJustify.Start" Gutter="16">
@@ -22,7 +29,7 @@
</Row> </Row>
</Form> </Form>
</Card> </Card>
<br />
<Card Class="mt-3"> <Card Class="mt-3">
<Table DataSource="PagingList.Items" PageSize="100" HidePagination="true" Resizable> <Table DataSource="PagingList.Items" PageSize="100" HidePagination="true" Resizable>
<TitleTemplate> <TitleTemplate>
@@ -49,6 +56,9 @@
} }
</PropertyColumn> </PropertyColumn>
<PropertyColumn Property="c => c.Name" Title="模版名称" /> <PropertyColumn Property="c => c.Name" Title="模版名称" />
<PropertyColumn Property="c => c.LanguageId" Title="语言">
@GetLanuageName(context.LanguageId)
</PropertyColumn>
<PropertyColumn Property="c => c.Key" Title="模版Code" Width="100px" /> <PropertyColumn Property="c => c.Key" Title="模版Code" Width="100px" />
<PropertyColumn Property="c => c.Title" Title="模版标题" /> <PropertyColumn Property="c => c.Title" Title="模版标题" />
<PropertyColumn Property="c => c.Enabled" Title="状态" Width="80px" Align="ColumnAlign.Center"> <PropertyColumn Property="c => c.Enabled" Title="状态" Width="80px" Align="ColumnAlign.Center">
@@ -95,15 +105,19 @@
</ActionColumn> </ActionColumn>
</ColumnDefinitions> </ColumnDefinitions>
</Table> </Table>
<br />
<Row Justify="RowJustify.End"> <Row Justify="RowJustify.End">
<Pagination PageIndex="PagingList.Index" Total="PagingList.Count" PageSize="PagingList.Size" ShowSizeChanger="false" OnChange="OnPageChanged"></Pagination> @if (PagingList.Count > 0)
{
<Pagination Current="PagingList.Index" Total="PagingList.Count" PageSize="PagingList.Size" ShowSizeChanger="false" OnChange="OnPageChanged"></Pagination>
}
</Row> </Row>
</Card> </Card>
<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="@template" @ref="@editForm" LabelCol="new ColLayoutParam { Span = 5 }" WrapperCol="new ColLayoutParam { Span = 15 }" Name="modalForm" OnFinish="OnFormFinish"> <Form Model="@model" @ref="@editForm" LabelCol="new ColLayoutParam { Span = 5 }" WrapperCol="new ColLayoutParam { Span = 15 }" Name="modalForm" OnFinish="OnFormFinish">
<FluentValidationValidator /> <FluentValidationValidator />
<FormItem Label="消息模版类型"> <FormItem Label="消息模版类型">
<SimpleSelect DefaultValue="" Style="width:120px;" @bind-Value="@context.Type"> <SimpleSelect DefaultValue="" Style="width:120px;" @bind-Value="@context.Type">
@@ -118,7 +132,10 @@
<FormItem Label="消息模版名称"> <FormItem Label="消息模版名称">
<Input Placeholder="消息模版名称" @bind-Value="@context.Name" /> <Input Placeholder="消息模版名称" @bind-Value="@context.Name" />
</FormItem> </FormItem>
<FormItem Label="语言">
<Select DataSource="@languages" @bind-Value="@context.LanguageId" ItemValue="p => p.Id" ItemLabel="p => p.Title" Disabled="@(context.Id > 0)">
</Select>
</FormItem>
<FormItem Label="模版Code"> <FormItem Label="模版Code">
<Input Placeholder="模版Code" @bind-Value="@context.Key" Disabled="@(context.Id > 0)" /> <Input Placeholder="模版Code" @bind-Value="@context.Key" Disabled="@(context.Id > 0)" />
</FormItem> </FormItem>
@@ -135,10 +152,14 @@
</FormItem> </FormItem>
</Form> </Form>
</Modal> </Modal>
</ChildContent>
</PageContainer>
@code { @code {
[Parameter]
public string Locale { get; set; } = string.Empty;
[SupplyParameterFromQuery] [SupplyParameterFromQuery]
int? Page { get; set; } int? Page { get; set; }
@@ -147,10 +168,10 @@
Form<MessageTemplateSearch> searchForm = null!; Form<MessageTemplateSearch> searchForm = null!;
[SupplyParameterFromForm] [SupplyParameterFromForm]
MessageTemplateModel template { get; set; } = new(); MessageTemplateModel model { get; set; } = new();
Form<MessageTemplateModel> editForm = null!; Form<MessageTemplateModel> editForm = null!;
List<Language> languages = new();
PagingList<MessageTemplate> PagingList = new(); PagingList<MessageTemplate> PagingList = new();
bool loading { get; set; } = true; bool loading { get; set; } = true;
bool searchExpand { get; set; } = false; bool searchExpand { get; set; } = false;
@@ -166,7 +187,7 @@
{ {
loadQueryString(); loadQueryString();
LoadList(); LoadList();
_ = LoadLanguages();
base.OnParametersSet(); base.OnParametersSet();
} }
@@ -177,6 +198,20 @@
search.Key = query.GetQueryString("Key"); search.Key = query.GetQueryString("Key");
} }
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 void LoadList() private async void LoadList()
{ {
@@ -265,13 +300,13 @@
void OnCreateClick() void OnCreateClick()
{ {
template = new(); model = new();
modalVisible = true; modalVisible = true;
} }
void HandleEdit(MessageTemplate model) void HandleEdit(MessageTemplate data)
{ {
template = model.Adapt<MessageTemplateModel>(); model = data.Adapt<MessageTemplateModel>();
modalVisible = true; modalVisible = true;
} }
@@ -285,18 +320,8 @@
if (editForm.Validate()) if (editForm.Validate())
{ {
var result = new ApiResult<string>(); var result = new ApiResult<string>();
var data = template.Adapt<MessageTemplate>(); var url = $"api/messagetemplate/save";
result = await HttpService.Post<ApiResult<string>>(url, model);
if (template.Id > 0)
{
var url = $"api/messagetemplate/edit";
result = await HttpService.Post<ApiResult<string>>(url, data);
}
else
{
var url = $"api/messagetemplate/add";
result = await HttpService.Post<ApiResult<string>>(url, data);
}
if (result.Code == (int)ResultCode.Success) if (result.Code == (int)ResultCode.Success)
{ {
@@ -314,4 +339,14 @@
{ {
modalVisible = false; modalVisible = false;
} }
string GetLanuageName(int languageId)
{
var language = languages.FirstOrDefault(l => l.Id == languageId);
if (language != null)
{
return language.Title;
}
return "-";
}
} }

View File

@@ -1,7 +1,22 @@
@page "/settings" @page "/settings"
@page "/{locale}/settings"
@attribute [Authorize] @attribute [Authorize]
@inject ILogger<Settings> Logger @inject ILogger<Settings> Logger
@code { <PageContainer Title="系统设置">
<Breadcrumb>
<Breadcrumb>
<BreadcrumbItem Href="/">管理后台</BreadcrumbItem>
<BreadcrumbItem Href="/admin/list">系统功能</BreadcrumbItem>
<BreadcrumbItem>系统设置</BreadcrumbItem>
</Breadcrumb>
</Breadcrumb>
<ChildContent>
<h3>Tools</h3>
</ChildContent>
</PageContainer>
@code {
[Parameter]
public string Locale { get; set; } = string.Empty;
} }

View File

@@ -0,0 +1,175 @@
@page "/stateprovince/{countryId:long}/create"
@page "/stateprovince/{countryId:long}/edit/{id:long}"
@page "/{locale}/stateprovince/{countryId:long}/create"
@page "/{locale}/stateprovince/{countryId:long}/edit/{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 Id { get; set; }
[SupplyParameterFromForm]
StateProvinceModel model { get; set; } = new();
Form<StateProvinceModel> editform = null!;
List<KeyValue> languageList = new();
Country country = 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();
if (Id > 0)
{
LoadData();
}
base.OnParametersSet();
}
async Task LoadCountry()
{
var url = $"/api/country?id={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 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 });
}
}
}
}

View File

@@ -0,0 +1,215 @@
@page "/stateprovince/list/{countryId:long}"
@page "/{locale}/stateprovince/list/{countryId:long}"
@inject ILogger<StateProvinceList> Logger
@attribute [Authorize]
<PageContainer Title="州省管理">
<Breadcrumb>
<Breadcrumb>
<BreadcrumbItem Href="/">管理后台</BreadcrumbItem>
<BreadcrumbItem Href="/settings">系统配置</BreadcrumbItem>
<BreadcrumbItem Href="/country/list">国家管理</BreadcrumbItem>
<BreadcrumbItem>州省管理</BreadcrumbItem>
</Breadcrumb>
</Breadcrumb>
<ChildContent>
<Spin Spinning="pageLoading">
<Card>
<Form @ref="searchForm" Model="search" Layout="FormLayout.Inline" Class="search-form" OnFinish="OnSearchFinish">
<Row Justify="RowJustify.Start" Gutter="(16, 16)">
<Col>
<FormItem Label="名称">
<Input @bind-Value="search.Name" Placeholder="名称" AllowClear />
</FormItem>
</Col>
<Col>
<div class="ant-form-item" style="display:flex">
<Button Type="ButtonType.Primary" HtmlType="submit">查询</Button>
<Button Style="margin: 0 8px;" OnClick="OnSearchReset">重置</Button>
</div>
</Col>
</Row>
</Form>
</Card>
<br />
<Card Title="州、省列表" Class="hideborder">
<Extra>
<div class="extraContent">
<Button Type="ButtonType.Primary" HtmlType="submit" OnClick="HandleAddNew">新增州省</Button>
</div>
</Extra>
<ChildContent>
<Table DataSource="PagingList.Items" PageSize="100" HidePagination="true">
<Selection CheckStrictly />
<PropertyColumn Property="c => c.Name" Title="名称" />
<PropertyColumn Property="c => c.Initial" Title="首字母" />
<PropertyColumn Property="c => c.Abbreviation" Title="缩写" />
<PropertyColumn Property="c => c.Enabled" Title="状态">
@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.DisplayOrder" Title="排序" />
<ActionColumn Title="操作" Align="ColumnAlign.Right">
<Space>
<SpaceItem>
<a @onclick="(e) => HandleEdit(context)">编辑</a>
</SpaceItem>
@*<SpaceItem>
<Popconfirm Placement="@Placement.Left" Title="@("删除这条数据无法恢复,您确定要删除吗?")"
OnConfirm="@(e=>HandleDeleteConfirmAsync(e,context.Id))"
OkText="确定"
CancelText="取消">
<a>删除</a>
</Popconfirm>
</SpaceItem>*@
</Space>
</ActionColumn>
</Table>
<br />
<Row Justify="RowJustify.End">
@if (PagingList.Count > 0)
{
<Pagination Current="PagingList.Index" Total="PagingList.Count" PageSize="PagingList.Size" ShowSizeChanger="false" OnChange="OnPageChanged"></Pagination>
}
</Row>
</ChildContent>
</Card>
</Spin>
</ChildContent>
</PageContainer>
@code {
[Parameter]
public string Locale { get; set; } = string.Empty;
[Parameter]
public long CountryId { get; set; }
[SupplyParameterFromQuery]
int? Page { get; set; }
[SupplyParameterFromQuery(Name = "size")]
int? PageSize { get; set; }
bool pageLoading = false;
bool searchExpand = false;
Form<StateProvinceSearch> searchForm = new();
StateProvinceSearch search = new();
PagingList<StateProvince> PagingList = new() { Size = 20 };
protected override async Task OnInitializedAsync()
{
await base.OnInitializedAsync();
}
protected override async Task OnParametersSetAsync()
{
loadQueryString();
await LoadListAsync();
await base.OnParametersSetAsync();
}
void loadQueryString()
{
var uri = new Uri(Navigation.Uri);
var query = uri.Query;
search.Name = query.GetQueryString("Name");
search.CountryId = CountryId;
}
async Task LoadListAsync()
{
try
{
Console.WriteLine(search.ToJson());
pageLoading = true;
var url = "/api/stateprovince/search";
var apiResult = await HttpService.GetPagingList<StateProvince>(url, search, Page.GetValueOrDefault(1), PageSize.GetValueOrDefault(20));
if (apiResult.Success)
{
if (apiResult.Data != null)
{
PagingList = apiResult.Data;
}
}
else if (apiResult.Code == 403)
{
ModalService.Error(new ConfirmOptions() { Title = "权限不足", Content = apiResult.Message });
}
StateHasChanged();
}
finally
{
pageLoading = false;
}
}
void OnSearchReset()
{
search = new();
searchForm?.Reset();
}
private void OnSearch(int page)
{
var queryString = search.BuildQueryString();
if (string.IsNullOrEmpty(queryString))
{
if (page > 1)
{
Navigation.NavigateTo($"/stateprovince/list/{CountryId}?page={page}");
}
else
{
Navigation.NavigateTo($"/stateprovince/list/{CountryId}");
}
}
else
{
if (page > 1)
{
Navigation.NavigateTo($"/stateprovince/list/{CountryId}?page={page}&{queryString}");
}
else
{
Navigation.NavigateTo($"/stateprovince/list/{CountryId}?{queryString}");
}
}
}
void OnSearchFinish()
{
Page = Page.GetValueOrDefault(1) - 1;
OnSearch(Page.Value);
}
private void OnPageChanged(PaginationEventArgs args)
{
OnSearch(args.Page);
}
void HandleAddNew()
{
Navigation.NavigateTo($"/stateprovince/{CountryId}/create");
}
void HandleEdit(StateProvince model)
{
Navigation.NavigateTo($"/stateprovince/{CountryId}/edit/{model.Id}");
}
}

View File

@@ -0,0 +1,152 @@
@page "/system/app/version/create"
@page "/system/app/version/edit/{id:long}"
@page "/{locale}/system/app/version/create"
@page "/{locale}/system/app/version/edit/{id:long}"
@inject ILogger<AppVersionEdit> Logger
@attribute [Authorize]
<PageContainer Title="@(Id > 0 ? "编辑版本信息" : "新增版本信息")">
<Breadcrumb>
<Breadcrumb>
<BreadcrumbItem Href="/">管理后台</BreadcrumbItem>
<BreadcrumbItem Href="/admin/list">系统功能</BreadcrumbItem>
<BreadcrumbItem>版本管理</BreadcrumbItem>
</Breadcrumb>
</Breadcrumb>
<ChildContent>
<Spin Spinning="pageLoading">
<Card Title="版本信息">
<Form @ref="editform" Model="@model" LabelColSpan="5" WrapperColSpan="14" OnFinish="OnFormFinishAsync">
<FormItem Label="应用名称" Required>
<Input @bind-Value="@context.AppName" Placeholder="应用名称" />
</FormItem>
<FormItem Label="版本标题" Required>
<Input @bind-Value="@context.Title" Placeholder="版本标题" />
</FormItem>
<FormItem Label="运行平台">
<Select TItemValue="int" TItem="int" Style="width:250px;" @bind-Value="@context.Platform">
<SelectOption Value="0" Label="请选择运行平台"></SelectOption>
<SelectOption Value="1" Label="Windows桌面"></SelectOption>
<SelectOption Value="2" Label="安卓系统"></SelectOption>
<SelectOption Value="3" Label="iOS系统"></SelectOption>
</Select>
</FormItem>
<FormItem Label="版本状态">
<Select TItemValue="int" TItem="int" Style="width:250px;" @bind-Value="@context.VersionState">
<SelectOption Value="0" Label="请选版本状态"></SelectOption>
<SelectOption Value="1" Label="开发版"></SelectOption>
<SelectOption Value="2" Label="Alphal内测版"></SelectOption>
<SelectOption Value="3" Label="Beta公测版"></SelectOption>
<SelectOption Value="4" Label="Rc版"></SelectOption>
<SelectOption Value="5" Label="正式版"></SelectOption>
</Select>
</FormItem>
<FormItem Label="版本信息" Required>
<InputGroup Compact>
<Input @bind-Value="@context.VersionX" Placeholder="主版本号" Style="width: 20%;" />
<Input @bind-Value="@context.VersionY" Placeholder="次版本号" Style="width: 20%;" />
<Input @bind-Value="@context.VersionZ" Placeholder="修订版本" Style="width: 20%;" />
</InputGroup>
</FormItem>
<FormItem Label="更新内容" Required>
<TextArea Rows="10" @bind-Value="@context.Content" Placeholder="更新内容" />
</FormItem>
<FormItem Label="状态">
<RadioGroup @bind-Value="@context.Status">
<Radio RadioButton Value=1>草稿</Radio>
<Radio RadioButton Value=2>发布</Radio>
</RadioGroup>
</FormItem>
<FormItem WrapperCol="new ColLayoutParam { Span = 24, Offset = 5 }">
<Button Type="@ButtonType.Primary" HtmlType="submit">
提交保存
</Button>
</FormItem>
</Form>
</Card>
</Spin>
</ChildContent>
</PageContainer>
@code {
[Parameter]
public string Locale { get; set; } = string.Empty;
[Parameter]
public long Id { get; set; }
[SupplyParameterFromForm]
AppVersionModel model { get; set; } = new();
Form<AppVersionModel> editform = null!;
bool pageLoading = false;
protected override void OnInitialized()
{
base.OnInitialized();
}
protected override void OnParametersSet()
{
if (Id > 0)
{
LoadData();
}
base.OnParametersSet();
}
async void LoadData()
{
pageLoading = true;
var url = $"/api/appversion/{Id}";
var apiResult = await HttpService.Get<ApiResult<AppVersion>>(url);
if (apiResult.Success)
{
if (apiResult.Data == null)
{
Navigation.NavigateTo($"/system/app/version/create");
}
else
{
model = apiResult.Data.Adapt<AppVersionModel>();
}
}
else
{
Navigation.NavigateTo($"/system/app/version/create");
}
pageLoading = false;
StateHasChanged();
}
async void OnFormFinishAsync()
{
if (editform.Validate())
{
var result = new ApiResult<string>();
if (model.Id > 0)
{
var url = $"api/appversion/edit";
result = await HttpService.Post<ApiResult<string>>(url, model);
}
else
{
var url = $"api/appversion/add";
result = await HttpService.Post<ApiResult<string>>(url, model);
}
if (result.Code == (int)ResultCode.Success)
{
await ModalService.InfoAsync(new ConfirmOptions() { Title = "提示", Content = "数据提交成功!" });
Navigation.NavigateTo($"/system/app/version/list");
}
else
{
await ModalService.ErrorAsync(new ConfirmOptions() { Title = "服务异常", Content = result.Message });
}
}
}
}

View File

@@ -1,9 +1,318 @@
@page "/system/app/version/list" @page "/system/app/version/list"
@page "/{locale}/system/app/version/list"
@inject ILogger<AppVersionList> Logger @inject ILogger<AppVersionList> Logger
@attribute [Authorize] @attribute [Authorize]
<PageContainer Title="App版本管理">
<Breadcrumb>
<Breadcrumb>
<BreadcrumbItem Href="/">管理后台</BreadcrumbItem>
<BreadcrumbItem Href="/settings">系统配置</BreadcrumbItem>
<BreadcrumbItem>版本管理</BreadcrumbItem>
</Breadcrumb>
</Breadcrumb>
<ChildContent>
<Card Class="">
<Form @ref="searchForm" Model="search" Layout="FormLayout.Inline" Class="search-form" OnFinish="OnSearchFinish">
<Row Justify="RowJustify.Start" Gutter="16">
<Col>
<FormItem Label="名称">
<Input @bind-Value="search.Name" Placeholder="名称" AllowClear />
</FormItem>
</Col>
<Col>
<FormItem Label="状态">
<SimpleSelect DefaultValue="" Style="width:120px;" @bind-Value="@context.Status">
<SelectOptions>
<SimpleSelectOption Value="" Label="全部"></SimpleSelectOption>
<SimpleSelectOption Value="1" Label="草稿"></SimpleSelectOption>
<SimpleSelectOption Value="2" Label="已发布"></SimpleSelectOption>
</SelectOptions>
</SimpleSelect>
</FormItem>
</Col>
<Col>
<div class="ant-form-item" style="width:200px;display:flex;">
<Button Type="ButtonType.Primary" HtmlType="submit">查询</Button>
<Button Style="margin: 0 8px;" OnClick="OnReset">重置</Button>
</div>
</Col>
</Row>
</Form>
</Card>
<br />
<Card Class="mt-3">
<Table DataSource="PagingList.Items" PageSize="100" HidePagination="true" Resizable>
<TitleTemplate>
<Flex Justify="FlexJustify.SpaceBetween">
版本记录
<div>
<AuthorizeCheck Permission="@Permissions.Admin.Create">
<Button Class="me-3" OnClick="OnCreateClick" Type="ButtonType.Primary">新增</Button>
</AuthorizeCheck>
</div>
</Flex>
</TitleTemplate>
<ColumnDefinitions>
<PropertyColumn Property="c => c.Title" Title="标题">
</PropertyColumn>
<PropertyColumn Property="c => c.AppName" Title="应用">
</PropertyColumn>
<PropertyColumn Property="c => c.Platform" Title="平台">
@if (context.Platform == 1)
{
<Tag>windows</Tag>
}
else if (context.Platform == 2)
{
<Tag>安卓</Tag>
}
else if (context.Platform == 3)
{
<Tag>iOS</Tag>
}
else
{
<Tag>未设置</Tag>
}
</PropertyColumn>
<PropertyColumn Property="c => c.VersionX" Title="版本号">
@context.VersionX.@context.VersionY.@context.VersionZ
</PropertyColumn>
<PropertyColumn Property="c => c.VersionState" Title="版本状态">
@if (context.VersionState == 1)
{
<Tag>开发版</Tag>
}
else if (context.VersionState == 2)
{
<Tag>Alphal内测版</Tag>
}
else if (context.VersionState == 3)
{
<Tag>Beta公测版</Tag>
}
else if (context.VersionState == 4)
{
<Tag>Rc版</Tag>
}
else if (context.VersionState == 5)
{
<Tag>正式版</Tag>
}
else
{
<Tag>未设置</Tag>
}
</PropertyColumn>
<PropertyColumn Property="c => c.Status" Title="状态" Width="80px" Align="ColumnAlign.Center">
@if (context.Status == 1)
{
<Tag>草稿</Tag>
}
else if (context.Status == 2)
{
<Tag>发布</Tag>
}
else
{
<Tag>未设置</Tag>
}
</PropertyColumn>
<PropertyColumn Property="c => c.UpdateTime" Title="最后更新" />
<ActionColumn Title="操作" Align="ColumnAlign.Right" Width="160px">
<Space>
<SpaceItem>
<Dropdown Trigger="@(new Trigger[] { Trigger.Click })">
<Overlay>
<Menu>
<MenuItem>
<a @onclick="(e) => OnEditClick(context.Id)"> <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>
<br />
<Row Justify="RowJustify.End">
@if (PagingList.Count > 0)
{
<Pagination Current="PagingList.Index" Total="PagingList.Count" PageSize="PagingList.Size" ShowSizeChanger="false" OnChange="OnPageChanged"></Pagination>
}
</Row>
</Card>
</ChildContent>
</PageContainer>
@code { @code {
[Parameter]
public string Locale { get; set; } = string.Empty;
[SupplyParameterFromQuery]
int? Page { get; set; }
[SupplyParameterFromQuery(Name = "size")]
int? PageSize { get; set; }
[SupplyParameterFromForm]
AppVersionSearch search { get; set; } = new();
Form<AppVersionSearch> searchForm = null!;
PagingList<AppVersion> PagingList = new();
bool loading { get; set; } = true;
bool searchExpand { get; set; } = false;
bool drawerVisible;
protected override void OnInitialized()
{
base.OnInitialized();
}
protected override void OnParametersSet()
{
loadQueryString();
_ = LoadList();
base.OnParametersSet();
}
void loadQueryString()
{
var uri = new Uri(Navigation.Uri);
var query = uri.Query;
search.Name = query.GetQueryString("Name");
search.Status = query.GetQueryString("Status");
var data = query.GetQueryString("RangeTime");
if (!string.IsNullOrEmpty(data))
{
var rangetime = data.Split("-");
if (rangetime != null && rangetime.Length > 0)
{
searchExpand = true;
search.RangeTime[0] = rangetime[0].NumberToDateTime();
search.RangeTime[1] = rangetime[1].NumberToDateTime();
StateHasChanged();
}
}
} }
private async Task LoadList()
{
loading = true;
var url = "/api/appversion/search";
var apiResult = await HttpService.GetPagingList<AppVersion>(url, search, Page.GetValueOrDefault(1), PageSize.GetValueOrDefault(20));
if (apiResult.Success)
{
if (apiResult.Data != null)
{
PagingList = apiResult.Data;
}
}
loading = false;
StateHasChanged();
}
void OnSearchFinish()
{
Page = Page.GetValueOrDefault(1) - 1;
OnSearch(Page.Value);
}
private void OnReset()
{
search = new();
}
private void OnSearch(int page)
{
var queryString = search.BuildQueryString();
if (string.IsNullOrEmpty(queryString))
{
if (page > 1)
{
Navigation.NavigateTo($"/system/app/version/list?page={page}");
}
else
{
Navigation.NavigateTo($"/system/app/version/list");
}
}
else
{
if (page > 1)
{
Navigation.NavigateTo($"/system/app/version/list?page={page}&{queryString}");
}
else
{
Navigation.NavigateTo($"/system/app/version/list?{queryString}");
}
}
}
async Task HandleDeleteConfirmAsync(MouseEventArgs e, long id)
{
var url = $"/api/appversion/delete/{id}";
var apiResult = await HttpService.Post<ApiResult<string>>(url, new());
if (apiResult.Success)
{
await LoadList();
await ModalService.InfoAsync(new ConfirmOptions() { Title = "操作提示", Content = "删除数据成功" });
}
else
{
await ModalService.ErrorAsync(new ConfirmOptions() { Title = "操作提示", Content = $"数据删除失败.{apiResult.Message}" });
}
}
private void OnPageChanged(PaginationEventArgs args)
{
OnSearch(args.Page);
}
void OnCreateClick()
{
Navigation.NavigateTo($"/system/app/version/create");
}
void OnEditClick(long id)
{
Navigation.NavigateTo($"/system/app/version/edit/{id}");
}
}

View File

@@ -1,7 +1,22 @@
@page "/system/app/list" @page "/system/app/list"
@page "/{locale}/system/app/list"
@inject ILogger<SiteAppList> Logger @inject ILogger<SiteAppList> Logger
@attribute [Authorize] @attribute [Authorize]
@code { <PageContainer Title="系统工具">
<Breadcrumb>
<Breadcrumb>
<BreadcrumbItem Href="/">管理后台</BreadcrumbItem>
<BreadcrumbItem Href="/admin/list">系统功能</BreadcrumbItem>
<BreadcrumbItem>系统工具</BreadcrumbItem>
</Breadcrumb>
</Breadcrumb>
<ChildContent>
<h3>Tools</h3>
</ChildContent>
</PageContainer>
@code {
[Parameter]
public string Locale { get; set; } = string.Empty;
} }

View File

@@ -1,9 +1,17 @@
@page "/system/file/list" @page "/system/file/list"
@page "/{locale}/system/file/list"
@inject ILogger<UploadList> Logger @inject ILogger<UploadList> Logger
@attribute [Authorize] @attribute [Authorize]
<PageTitle>上传文件</PageTitle> <PageContainer Title="上传文件">
<Title Level="4">上传文件</Title> <Breadcrumb>
<Breadcrumb>
<BreadcrumbItem Href="/">管理后台</BreadcrumbItem>
<BreadcrumbItem Href="/admin/list">系统功能</BreadcrumbItem>
<BreadcrumbItem>上传文件</BreadcrumbItem>
</Breadcrumb>
</Breadcrumb>
<ChildContent>
<Card> <Card>
<Form @ref="searchForm" Model="search" Layout="FormLayout.Inline" Class="search-form" OnFinish="OnSearchFinish"> <Form @ref="searchForm" Model="search" Layout="FormLayout.Inline" Class="search-form" OnFinish="OnSearchFinish">
<Row Justify="RowJustify.Start" Gutter="16"> <Row Justify="RowJustify.Start" Gutter="16">
@@ -84,6 +92,13 @@
</ActionColumn> </ActionColumn>
</ColumnDefinitions> </ColumnDefinitions>
</Table> </Table>
<br />
<Row Justify="RowJustify.End">
@if (PagingList.Count > 0)
{
<Pagination Current="PagingList.Index" Total="PagingList.Count" PageSize="PagingList.Size" ShowSizeChanger="false" OnChange="OnPageChanged"></Pagination>
}
</Row>
</Card> </Card>
<Drawer Closable="true" Width="520" Visible="drawerVisible" Title='(model.Id == 0 ? "新增帐号" : "编辑帐号")' OnClose="_ => CloseDrawer()"> <Drawer Closable="true" Width="520" Visible="drawerVisible" Title='(model.Id == 0 ? "新增帐号" : "编辑帐号")' OnClose="_ => CloseDrawer()">
@@ -98,6 +113,8 @@
</FormItem> </FormItem>
</Form> </Form>
</Drawer> </Drawer>
</ChildContent>
</PageContainer>
@code { @code {
[SupplyParameterFromQuery] [SupplyParameterFromQuery]
@@ -280,9 +297,9 @@
} }
} }
private void OnPageChanged(int args) private void OnPageChanged(PaginationEventArgs args)
{ {
OnSearch(args); OnSearch(args.Page);
} }
void CloseDrawer() void CloseDrawer()

View File

@@ -1,11 +1,18 @@
@page "/admin/list" @page "/admin/list"
@page "/{locale}/admin/list"
@inject ILogger<AdminList> Logger @inject ILogger<AdminList> Logger
@attribute [Authorize] @attribute [Authorize]
<PageTitle>管理员账号管理</PageTitle> <PageContainer Title="管理员管理">
<Breadcrumb>
<Title Level="4">管理员帐号</Title> <Breadcrumb>
<BreadcrumbItem Href="/">管理后台</BreadcrumbItem>
<BreadcrumbItem Href="/admin/list">系统功能</BreadcrumbItem>
<BreadcrumbItem>管理员管理</BreadcrumbItem>
</Breadcrumb>
</Breadcrumb>
<ChildContent>
<Card Class=""> <Card Class="">
<Form @ref="searchForm" Model="search" Layout="FormLayout.Inline" Class="search-form" OnFinish="OnSearchFinish"> <Form @ref="searchForm" Model="search" Layout="FormLayout.Inline" Class="search-form" OnFinish="OnSearchFinish">
<Row Justify="RowJustify.Start" Gutter="16"> <Row Justify="RowJustify.Start" Gutter="16">
@@ -31,7 +38,7 @@
<Flex Justify="FlexJustify.SpaceBetween"> <Flex Justify="FlexJustify.SpaceBetween">
帐号列表 帐号列表
<div> <div>
<AuthorizeCheck Permission="@Permissions.Admin.Create">\ <AuthorizeCheck Permission="@Permissions.Admin.Create">
<Button Class="me-3" OnClick="OnCreateClick" Type="ButtonType.Primary">新增</Button> <Button Class="me-3" OnClick="OnCreateClick" Type="ButtonType.Primary">新增</Button>
</AuthorizeCheck> </AuthorizeCheck>
</div> </div>
@@ -55,7 +62,7 @@
<Icon Type="close" Theme="IconThemeType.Outline" Width="1.3em" Height="1.3em" /> <Icon Type="close" Theme="IconThemeType.Outline" Width="1.3em" Height="1.3em" />
} }
</PropertyColumn> </PropertyColumn>
<PropertyColumn Property="c => c.LastLogin" Title="最后登录" Width="120px" /> <PropertyColumn Property="c => c.LastLogin" Title="最后登录" />
<PropertyColumn Property="c => c.UpdateTime" Title="最后更新" /> <PropertyColumn Property="c => c.UpdateTime" Title="最后更新" />
<ActionColumn Title="操作" Align="ColumnAlign.Right" Width="160px"> <ActionColumn Title="操作" Align="ColumnAlign.Right" Width="160px">
<Space> <Space>
@@ -89,6 +96,13 @@
</ActionColumn> </ActionColumn>
</ColumnDefinitions> </ColumnDefinitions>
</Table> </Table>
<br />
<Row Justify="RowJustify.End">
@if (PagingList.Count > 0)
{
<Pagination Current="PagingList.Index" Total="PagingList.Count" PageSize="PagingList.Size" ShowSizeChanger="false" OnChange="OnPageChanged"></Pagination>
}
</Row>
</Card> </Card>
<Drawer Closable="true" Width="520" Visible="drawerVisible" Title='(model.Id == 0 ? "新增帐号" : "编辑帐号")' OnClose="_ => CloseDrawer()"> <Drawer Closable="true" Width="520" Visible="drawerVisible" Title='(model.Id == 0 ? "新增帐号" : "编辑帐号")' OnClose="_ => CloseDrawer()">
@@ -142,8 +156,13 @@
</FormItem> </FormItem>
</Form> </Form>
</Drawer> </Drawer>
</ChildContent>
</PageContainer>
@code { @code {
[Parameter]
public string Locale { get; set; } = string.Empty;
[SupplyParameterFromQuery] [SupplyParameterFromQuery]
int? Page { get; set; } int? Page { get; set; }
@@ -276,6 +295,11 @@
} }
} }
private void OnPageChanged(PaginationEventArgs args)
{
OnSearch(args.Page);
}
void OnCreateClick() void OnCreateClick()
{ {
model = new(); model = new();

View File

@@ -1,9 +0,0 @@
@page "/system/currency/list"
@inject ILogger<CurrencyList> Logger
@attribute [Authorize]
<h3>CurrencyList</h3>
@code {
}

View File

@@ -0,0 +1,19 @@
@page "/system/info"
@page "/{locale}/system/info"
<PageContainer Title="系统信息">
<Breadcrumb>
<Breadcrumb>
<BreadcrumbItem Href="/">管理后台</BreadcrumbItem>
<BreadcrumbItem Href="/admin/list">系统功能</BreadcrumbItem>
<BreadcrumbItem>系统信息</BreadcrumbItem>
</Breadcrumb>
</Breadcrumb>
<ChildContent>
<h3>Tools</h3>
</ChildContent>
</PageContainer>
@code {
[Parameter]
public string Locale { get; set; } = string.Empty;
}

View File

@@ -1,11 +1,17 @@
@page "/system/language/list" @page "/system/language/list"
@page "/{locale}/system/language/list"
@inject ILogger<LanguageList> Logger @inject ILogger<LanguageList> Logger
@attribute [Authorize] @attribute [Authorize]
<PageTitle>语言管理</PageTitle> <PageContainer Title="语言管理">
<Breadcrumb>
<Title Level="4">多语言</Title> <Breadcrumb>
<BreadcrumbItem Href="/">管理后台</BreadcrumbItem>
<BreadcrumbItem Href="/admin/list">系统功能</BreadcrumbItem>
<BreadcrumbItem>语言管理</BreadcrumbItem>
</Breadcrumb>
</Breadcrumb>
<ChildContent>
<Card Class="mt-3"> <Card Class="mt-3">
<Table DataSource="PagingList.Items" PageSize="100" HidePagination="true" Resizable> <Table DataSource="PagingList.Items" PageSize="100" HidePagination="true" Resizable>
<TitleTemplate> <TitleTemplate>
@@ -17,11 +23,12 @@
</Flex> </Flex>
</TitleTemplate> </TitleTemplate>
<ColumnDefinitions> <ColumnDefinitions>
<PropertyColumn Property="c => c.Name" Title="语言名称"> <PropertyColumn Property="c => c.Title" Title="语言名称">
</PropertyColumn>
<PropertyColumn Property="c => c.Title" Title="语言标题">
</PropertyColumn> </PropertyColumn>
<PropertyColumn Property="c => c.Name" Title="语言本地化">
</PropertyColumn>
<PropertyColumn Property="c => c.Culture" Title="语言文化" Width="100px" /> <PropertyColumn Property="c => c.Culture" Title="语言文化" Width="100px" />
<PropertyColumn Property="c => c.Enabled" Title="状态" Width="80px" Align="ColumnAlign.Center"> <PropertyColumn Property="c => c.Enabled" Title="状态" Width="80px" Align="ColumnAlign.Center">
@if (context.Enabled) @if (context.Enabled)
@@ -71,16 +78,23 @@
</ActionColumn> </ActionColumn>
</ColumnDefinitions> </ColumnDefinitions>
</Table> </Table>
<br />
<Row Justify="RowJustify.End">
@if (PagingList.Count > 0)
{
<Pagination Current="PagingList.Index" Total="PagingList.Count" PageSize="PagingList.Size" ShowSizeChanger="false" OnChange="OnPageChanged"></Pagination>
}
</Row>
</Card> </Card>
<Drawer Closable="true" Width="520" Visible="drawerVisible" Title='(model.Id == 0 ? "新增语言" : "编辑语言")' OnClose="_ => CloseDrawer()"> <Drawer Closable="true" Width="520" Visible="drawerVisible" Title='(model.Id == 0 ? "新增语言" : "编辑语言")' OnClose="_ => CloseDrawer()">
<Form LabelColSpan="5" @ref="@editform" Model="@model" OnFinish="OnFormFinish"> <Form LabelColSpan="5" @ref="@editform" Model="@model" OnFinish="OnFormFinish">
<FluentValidationValidator /> <FluentValidationValidator />
<FormItem Label="语言标题"> <FormItem Label="语言标题">
<Input @bind-Value="model.Title" For="(()=>model.Title)" Placeholder="语言标题" /> <Input @bind-Value="model.Title" For="(()=>model.Title)" Placeholder="语言名称" />
</FormItem> </FormItem>
<FormItem Label="语言名称"> <FormItem Label="语言名称">
<Input @bind-Value="model.Name" For="(()=>model.Name)" Placeholder="语言名称" /> <Input @bind-Value="model.Name" For="(()=>model.Name)" Placeholder="语言本地化" />
</FormItem> </FormItem>
<FormItem Label="语言文化"> <FormItem Label="语言文化">
<SimpleSelect @bind-Value="model.Culture" For="(()=>model.Culture)" Placeholder="语言文化"> <SimpleSelect @bind-Value="model.Culture" For="(()=>model.Culture)" Placeholder="语言文化">
@@ -103,8 +117,13 @@
</FormItem> </FormItem>
</Form> </Form>
</Drawer> </Drawer>
</ChildContent>
</PageContainer>
@code { @code {
[Parameter]
public string Locale { get; set; } = string.Empty;
[SupplyParameterFromQuery] [SupplyParameterFromQuery]
int? Page { get; set; } int? Page { get; set; }
@@ -240,9 +259,9 @@
} }
} }
private void OnPageChanged(int args) private void OnPageChanged(PaginationEventArgs args)
{ {
OnSearch(args); OnSearch(args.Page);
} }
void CloseDrawer() void CloseDrawer()

View File

@@ -1,10 +1,17 @@
@page "/system/locale/resource/detail/{Name}" @page "/system/locale/resource/detail/{Name}"
@page "/{locale}/system/locale/resource/detail/{Name}"
@inject ILogger<LocaleResourceList> Logger @inject ILogger<LocaleResourceList> Logger
@attribute [Authorize] @attribute [Authorize]
<PageContainer Title="本地化语言资源">
<PageTitle>本地化语言资源</PageTitle> <Breadcrumb>
<Title Level="4">多语言本地资源管理</Title> <Breadcrumb>
<BreadcrumbItem Href="/">管理后台</BreadcrumbItem>
<BreadcrumbItem Href="/admin/list">系统功能</BreadcrumbItem>
<BreadcrumbItem>本地化语言资源</BreadcrumbItem>
</Breadcrumb>
</Breadcrumb>
<ChildContent>
<Spin Spinning="loading"> <Spin Spinning="loading">
<Card Class="mt-3"> <Card Class="mt-3">
<Table DataSource="ResourceItems" PageSize="100" HidePagination="true" Resizable> <Table DataSource="ResourceItems" PageSize="100" HidePagination="true" Resizable>
@@ -83,10 +90,14 @@
</FormItem> </FormItem>
</Form> </Form>
</Modal> </Modal>
</ChildContent>
</PageContainer>
@code { @code {
bool loading = false; bool loading = false;
[Parameter]
public string Locale { get; set; } = string.Empty;
[Parameter] [Parameter]
public string Name { get; set; } public string Name { get; set; }

View File

@@ -1,10 +1,17 @@
@page "/system/locale/resource/list/{Id:int}" @page "/system/locale/resource/list/{Id:int}"
@page "/{locale}/system/locale/resource/list/{Id:int}"
@inject ILogger<LocaleResourceList> Logger @inject ILogger<LocaleResourceList> Logger
@attribute [Authorize] @attribute [Authorize]
<PageContainer Title="多语言本地资源管理">
<PageTitle>本地化语言资源</PageTitle> <Breadcrumb>
<Title Level="4">多语言本地资源管理</Title> <Breadcrumb>
<BreadcrumbItem Href="/">管理后台</BreadcrumbItem>
<BreadcrumbItem Href="/admin/list">系统功能</BreadcrumbItem>
<BreadcrumbItem>多语言本地资源管理</BreadcrumbItem>
</Breadcrumb>
</Breadcrumb>
<ChildContent>
<Spin Spinning="loading"> <Spin Spinning="loading">
<Card> <Card>
<Form @ref="searchForm" Model="search" Layout="FormLayout.Inline" Class="search-form" OnFinish="OnSearchFinish"> <Form @ref="searchForm" Model="search" Layout="FormLayout.Inline" Class="search-form" OnFinish="OnSearchFinish">
@@ -83,7 +90,10 @@
</Table> </Table>
<br /> <br />
<Row Justify="RowJustify.End"> <Row Justify="RowJustify.End">
<Pagination PageIndex="pager.Index" Total="PagingList.Count" PageSize="PagingList.Size" ShowSizeChanger="false" OnChange="OnPageChanged"></Pagination> @if (PagingList.Count > 0)
{
<Pagination Current="PagingList.Index" Total="PagingList.Count" PageSize="PagingList.Size" ShowSizeChanger="false" OnChange="OnPageChanged"></Pagination>
}
</Row> </Row>
</Card> </Card>
</Spin> </Spin>
@@ -102,10 +112,13 @@
</FormItem> </FormItem>
</Form> </Form>
</Modal> </Modal>
</ChildContent>
</PageContainer>
@code { @code {
bool loading = false; bool loading = false;
[Parameter]
public string Locale { get; set; } = string.Empty;
[Parameter] [Parameter]
public int Id { get; set; } public int Id { get; set; }

View File

@@ -1,13 +1,19 @@
@page "/system/menu/list" @page "/system/menu/list"
@page "/{locale}/system/menu/list"
@inject ILogger<MenuList> Logger @inject ILogger<MenuList> Logger
@using MenuItem = Atomx.Admin.Client.Models.MenuItem @using MenuItem = Atomx.Admin.Client.Models.MenuItem
@using Menu = Atomx.Common.Entities.Menu @using Menu = Atomx.Common.Entities.Menu
@attribute [Authorize] @attribute [Authorize]
<PageTitle>菜单管理</PageTitle> <PageContainer Title="菜单管理">
<Breadcrumb>
<Title Level="4">菜单管理</Title> <Breadcrumb>
<BreadcrumbItem Href="/">管理后台</BreadcrumbItem>
<BreadcrumbItem Href="/admin/list">系统功能</BreadcrumbItem>
<BreadcrumbItem>菜单管理</BreadcrumbItem>
</Breadcrumb>
</Breadcrumb>
<ChildContent>
<Card> <Card>
<Form @ref="searchForm" Model="search" Layout="FormLayout.Inline" Class="search-form" OnFinish="OnSearchFinish"> <Form @ref="searchForm" Model="search" Layout="FormLayout.Inline" Class="search-form" OnFinish="OnSearchFinish">
<Row Justify="RowJustify.Start" Gutter="16"> <Row Justify="RowJustify.Start" Gutter="16">
@@ -42,7 +48,8 @@
<AntDesign.Text>@GetName(context)</AntDesign.Text> <AntDesign.Text>@GetName(context)</AntDesign.Text>
</PropertyColumn> </PropertyColumn>
<PropertyColumn Property="c => c.Icon" Title="图标" Width="60px" Align="ColumnAlign.Center"> <PropertyColumn Property="c => c.Icon" Title="图标" Width="60px" Align="ColumnAlign.Center">
@if (!string.IsNullOrEmpty(context.Icon)) { @if (!string.IsNullOrEmpty(context.Icon))
{
<Icon Type="@context.Icon" Theme="IconThemeType.Outline" Width="1.3em" Height="1.3em" /> <Icon Type="@context.Icon" Theme="IconThemeType.Outline" Width="1.3em" Height="1.3em" />
} }
</PropertyColumn> </PropertyColumn>
@@ -132,11 +139,14 @@
</FormItem> </FormItem>
</Form> </Form>
</Drawer> </Drawer>
</ChildContent>
</PageContainer>
@code { @code {
[Parameter]
public string Locale { get; set; } = string.Empty;
[SupplyParameterFromQuery] [SupplyParameterFromQuery]
int? Page { get; set; } int? Page { get; set; }

View File

@@ -1,10 +1,18 @@
@page "/system/role/permission/{RoleId:long}" @page "/system/role/permission/{RoleId:long}"
@page "/{locale}/system/role/permission/{RoleId:long}"
@attribute [Authorize] @attribute [Authorize]
@inject ILogger<RoleList> Logger @inject ILogger<RoleList> Logger
<PageTitle>权限设置</PageTitle> <PageContainer Title="权限角色设置">
<Breadcrumb>
<Breadcrumb>
<BreadcrumbItem Href="/">管理后台</BreadcrumbItem>
<BreadcrumbItem Href="/admin/list">系统功能</BreadcrumbItem>
<BreadcrumbItem>权限编辑</BreadcrumbItem>
</Breadcrumb>
</Breadcrumb>
<ChildContent>
<Spin Spinning="loading"> <Spin Spinning="loading">
<Title Level="4">编辑角色权限</Title>
<Card> <Card>
<Form @ref="editForm" Model="model" LabelColSpan="2" WrapperColSpan="22" Class="search-form" OnFinish="OnFormFinishAsync"> <Form @ref="editForm" Model="model" LabelColSpan="2" WrapperColSpan="22" Class="search-form" OnFinish="OnFormFinishAsync">
<FormItem Label="角色"> <FormItem Label="角色">
@@ -84,7 +92,12 @@
</Card> </Card>
</Spin> </Spin>
</ChildContent>
</PageContainer>
@code { @code {
[Parameter]
public string Locale { get; set; } = string.Empty;
[Parameter] [Parameter]
public long RoleId { get; set; } public long RoleId { get; set; }

View File

@@ -1,11 +1,17 @@
@page "/system/role/list" @page "/system/role/list"
@page "/{locale}/system/role/list"
@attribute [Authorize] @attribute [Authorize]
@inject ILogger<RoleList> Logger @inject ILogger<RoleList> Logger
<PageTitle>角色管理</PageTitle> <PageContainer Title="角色管理">
<Breadcrumb>
<Title Level="4">角色管理</Title> <Breadcrumb>
<BreadcrumbItem Href="/">管理后台</BreadcrumbItem>
<BreadcrumbItem Href="/admin/list">系统功能</BreadcrumbItem>
<BreadcrumbItem>角色管理</BreadcrumbItem>
</Breadcrumb>
</Breadcrumb>
<ChildContent>
<Card Class="mt-3"> <Card Class="mt-3">
<Table DataSource="PagingList.Items" PageSize="100" HidePagination="true" Resizable> <Table DataSource="PagingList.Items" PageSize="100" HidePagination="true" Resizable>
<TitleTemplate> <TitleTemplate>
@@ -84,7 +90,10 @@
</Table> </Table>
<br /> <br />
<Row Justify="RowJustify.End"> <Row Justify="RowJustify.End">
<Pagination PageIndex="pager.Index" Total="PagingList.Count" PageSize="PagingList.Size" ShowSizeChanger="false" OnChange="OnPageChanged"></Pagination> @if (PagingList.Count > 0)
{
<Pagination Current="PagingList.Index" Total="PagingList.Count" PageSize="PagingList.Size" ShowSizeChanger="false" OnChange="OnPageChanged"></Pagination>
}
</Row> </Row>
</Card> </Card>
@@ -105,8 +114,13 @@
</FormItem> </FormItem>
</Form> </Form>
</Drawer> </Drawer>
</ChildContent>
</PageContainer>
@code { @code {
[Parameter]
public string Locale { get; set; } = string.Empty;
[SupplyParameterFromQuery] [SupplyParameterFromQuery]
int? Page { get; set; } int? Page { get; set; }

View File

@@ -0,0 +1,20 @@
@page "/system/tools"
@page "/{locale}/system/tools"
<PageContainer Title="系统工具">
<Breadcrumb>
<Breadcrumb>
<BreadcrumbItem Href="/">管理后台</BreadcrumbItem>
<BreadcrumbItem Href="/admin/list">系统功能</BreadcrumbItem>
<BreadcrumbItem>系统工具</BreadcrumbItem>
</Breadcrumb>
</Breadcrumb>
<ChildContent>
<h3>Tools</h3>
</ChildContent>
</PageContainer>
@code {
[Parameter]
public string Locale { get; set; } = string.Empty;
}

View File

@@ -1,5 +1,20 @@
<h3>UserList</h3> @page "/user/list"
@page "/{locale}/user/list"
<PageContainer Title="用户列表">
<Breadcrumb>
<Breadcrumb>
<BreadcrumbItem Href="/">管理后台</BreadcrumbItem>
<BreadcrumbItem Href="/content/page/list">内容管理</BreadcrumbItem>
<BreadcrumbItem>用户列表</BreadcrumbItem>
</Breadcrumb>
</Breadcrumb>
<ChildContent>
<h3>Tools</h3>
</ChildContent>
</PageContainer>
@code { @code {
[Parameter]
public string Locale { get; set; } = string.Empty;
} }

View File

@@ -1,11 +1,12 @@
using Atomx.Admin.Client.Services; using Atomx.Admin.Client.Services;
using Atomx.Admin.Client.Utils; using Atomx.Admin.Client.Utils;
using Atomx.Admin.Client.Validators;
using Blazored.LocalStorage; using Blazored.LocalStorage;
using FluentValidation;
using Microsoft.AspNetCore.Components.Authorization; using Microsoft.AspNetCore.Components.Authorization;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting; using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Localization; using Microsoft.Extensions.Localization;
using System.Net.Http;
var builder = WebAssemblyHostBuilder.CreateDefault(args); var builder = WebAssemblyHostBuilder.CreateDefault(args);
@@ -67,6 +68,8 @@ builder.Services.AddScoped<HttpService>(sp =>
return new HttpService(httpClient, httpContextAccessor); return new HttpService(httpClient, httpContextAccessor);
}); });
builder.Services.AddValidatorsFromAssembly(typeof(LoginModelValidator).Assembly);
builder.Services.AddAntDesign(); builder.Services.AddAntDesign();

View File

@@ -72,10 +72,11 @@ namespace Atomx.Admin.Client.Services
page = 1; page = 1;
} }
url = $"{url}?page={page}&size={size}"; url = $"{url}?page={page}&size={size}";
var json = data.ToJson();
using var request = new HttpRequestMessage(HttpMethod.Post, url) using var request = new HttpRequestMessage(HttpMethod.Post, url)
{ {
Content = JsonContent.Create(data) Content = new StringContent(json, Encoding.UTF8, "application/json")
//Content = JsonContent.Create(data)
}; };
AttachCookieIfServer(request); AttachCookieIfServer(request);

View File

@@ -0,0 +1,82 @@
using Microsoft.Extensions.Localization;
using System.Globalization;
namespace Atomx.Admin.Client.Services
{
/// <summary>
/// 基于 ILocalizationProvider 的 IStringLocalizer 实现:
/// 使用 JSON 文件中的键值,未找到返回 key 本身。
/// 名称改为 JsonStringLocalizer 避免与框架的 StringLocalizer 冲突。
/// </summary>
public class JsonStringLocalizer<T> : IStringLocalizer<T>
{
private readonly ILocalizationProvider _provider;
public JsonStringLocalizer(ILocalizationProvider provider)
{
_provider = provider;
}
public LocalizedString this[string name]
{
get
{
var value = _provider.GetString(name);
if (value == null)
{
// 避免在服务端 prerender 阶段进行同步阻塞。以后台方式启动加载并返回 key。
try
{
_ = _provider.LoadCultureAsync(_provider.CurrentCulture);
}
catch { }
}
var result = value ?? name;
return new LocalizedString(name, result, resourceNotFound: result == name);
}
}
public LocalizedString this[string name, params object[] arguments]
{
get
{
var fmt = _provider.GetString(name);
if (fmt == null)
{
try
{
_ = _provider.LoadCultureAsync(_provider.CurrentCulture);
}
catch { }
}
var format = fmt ?? name;
var value = string.Format(format, arguments);
return new LocalizedString(name, value, resourceNotFound: format == name);
}
}
public IEnumerable<LocalizedString> GetAllStrings(bool includeParentCultures)
{
var list = new List<LocalizedString>();
var providerType = _provider.GetType();
var currentProp = providerType.GetProperty("CurrentCulture");
var culture = currentProp?.GetValue(_provider) as string ?? string.Empty;
var cacheField = providerType.GetField("_cache", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
if (!string.IsNullOrEmpty(culture) && cacheField?.GetValue(_provider) is Dictionary<string, Dictionary<string, string>> cache && cache.TryGetValue(culture, out var dict))
{
foreach (var kv in dict)
{
list.Add(new LocalizedString(kv.Key, kv.Value, resourceNotFound: false));
}
}
return list;
}
public IStringLocalizer WithCulture(CultureInfo culture)
{
return this;
}
}
}

View File

@@ -1,16 +1,20 @@
using Microsoft.JSInterop;
using System.Collections.Concurrent; using System.Collections.Concurrent;
using System.Globalization; using System.Globalization;
using System.Text.Json; using System.Text.Json;
using Microsoft.JSInterop;
using Microsoft.Extensions.Localization;
namespace Atomx.Admin.Client.Services namespace Atomx.Admin.Client.Services
{ {
/// <summary> /// <summary>
/// <20><EFBFBD><E1B9A9><EFBFBD><EFBFBD><EFBFBD><EFBFBD> JSON <20>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD>ء<EFBFBD><D8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD>л<EFBFBD><D0BB><EFBFBD>ʵ<EFBFBD>֡<EFBFBD> /// <20><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> JSON <20>ļ<EFBFBD><C4BC>ļ<EFBFBD><EFBFBD>ء<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD>л<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܡ<EFBFBD>
/// - <20><> Server <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͨ<EFBFBD><CDA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> IWebHostEnvironment <20><> webroot<6F><74><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>ϵͳ<CFB5><CDB3>ȡ {culture}.json <20>ļ<EFBFBD><EFBFBD><EFBFBD> /// <EFBFBD><EFBFBD>Ҫְ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
/// - <20><> WASM <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD><EFBFBD>ע<EFBFBD><EFBFBD><EFBFBD><EFBFBD> HttpClient <20><> /localization/{culture}.json <20><><EFBFBD>ز<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> /// - <20><> Server <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> prerender <20><> Blazor Server<65><72>ʱ<EFBFBD><CAB1><EFBFBD>Դ<EFBFBD> webroot ͬ<><CDAC><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD>ػ<EFBFBD> JSON <20>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
/// ͬʱ<EFBFBD><EFBFBD><EFBFBD>л<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱд<EFBFBD><EFBFBD> Cookie <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҳ<EFBFBD><EFBFBD> HTML lang <20><><EFBFBD>ԡ<EFBFBD> /// <20>Ա<EFBFBD><EFBFBD>ڷ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ⱦ<EFBFBD>׶<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>á<EFBFBD>
/// - <20><> WASM <20><><EFBFBD><EFBFBD>ʱʹ<CAB1><CAB9>ע<EFBFBD><D7A2><EFBFBD><EFBFBD> HttpClient <20><> /localization/{culture}.json <20><><EFBFBD>ز<EFBFBD><D8B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
/// - <20><><EFBFBD>л<EFBFBD><D0BB><EFBFBD><EFBFBD><EFBFBD>ʱд<CAB1><D0B4><EFBFBD><EFBFBD>Ϊ `atomx.culture` <20><> cookie<69><65><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˶<EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҳ<EFBFBD><D2B3><EFBFBD><EFBFBD> HTML lang <20><><EFBFBD>ԡ<EFBFBD>
/// - <20><EFBFBD>¼<EFBFBD>֪ͨ LanguageChanged<65><64><EFBFBD><EFBFBD> UI <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><D3A6><EFBFBD>Ա<EFBFBD><D4B1><EFBFBD><EFBFBD><EFBFBD>
///
/// ˵<><CBB5><EFBFBD><EFBFBD>Ϊ<EFBFBD>˼<EFBFBD><CBBC><EFBFBD> Server <20><> WASM<53><4D><EFBFBD><EFBFBD> Provider <20><EFBFBD><E1BEA1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD><CAB5><EFBFBD>Դ<EFBFBD><D4B4><EFBFBD>ط<EFBFBD>ʽ<EFBFBD><CABD>
/// </summary> /// </summary>
public interface ILocalizationProvider public interface ILocalizationProvider
{ {
@@ -25,6 +29,12 @@ namespace Atomx.Admin.Client.Services
event EventHandler<string>? LanguageChanged; event EventHandler<string>? LanguageChanged;
} }
/// <summary>
/// LocalizationProvider <20><>ʵ<EFBFBD>֣<EFBFBD>
/// - ά<><CEAC>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>̬<EFBFBD><CCAC><EFBFBD><EFBFBD><E6A3AC><EFBFBD><EFBFBD><EFBFBD>ظ<EFBFBD><D8B8><EFBFBD><EFBFBD><EFBFBD>/<2F><>ȡ<EFBFBD><C8A1>Դ<EFBFBD><D4B4>
/// - ֧<>ֶ<EFBFBD><D6B6><EFBFBD><EBA3A8> zh / en<65><6E><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> culture<72><65><EFBFBD><EFBFBD> zh-Hans / en-US<55><53>֮<EFBFBD><D6AE><EFBFBD><EFBFBD>ӳ<EFBFBD>
/// - <20><> Server <20><>֧<EFBFBD><D6A7>ͬ<EFBFBD><CDAC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> prerender <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
/// </summary>
public class LocalizationProvider : ILocalizationProvider public class LocalizationProvider : ILocalizationProvider
{ {
private readonly IServiceProvider _sp; private readonly IServiceProvider _sp;
@@ -33,23 +43,27 @@ namespace Atomx.Admin.Client.Services
private readonly ILogger<LocalizationProvider> _logger; private readonly ILogger<LocalizationProvider> _logger;
private readonly ILocalizationService _localizationService; private readonly ILocalizationService _localizationService;
// <20><><EFBFBD>棺culture -> translations // <20><><EFBFBD>棺culture -> translations<EFBFBD><EFBFBD>ʹ<EFBFBD><EFBFBD> ConcurrentDictionary <20><><EFBFBD>̰߳<DFB3>ȫ<EFBFBD>ع<EFBFBD><D8B9><EFBFBD><EFBFBD><EFBFBD>
// Use a static concurrent dictionary so files loaded during middleware/server prerender // ʹ<EFBFBD>þ<EFBFBD>̬<EFBFBD>ֶ<EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD>ʹ<EFBFBD>м<EFBFBD><EFBFBD><EFBFBD>/<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬһ<CDAC><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܹ<EFBFBD><DCB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ѽ<EFBFBD><D1BC>صķ<D8B5><C4B7><EFBFBD><EBA3AC><EFBFBD><EFBFBD><EFBFBD>ظ<EFBFBD> I/O<><4F>
// are visible to provider instances created later in the same request pipeline.
private static readonly ConcurrentDictionary<string, Dictionary<string, string>> _cache = new(); private static readonly ConcurrentDictionary<string, Dictionary<string, string>> _cache = new();
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> culture <20><>ӳ<EFBFBD><EFBFBD> // ֧<EFBFBD>ֵĶ<EFBFBD><EFBFBD><EFBFBD>ӳ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>չ<EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӡ<EFBFBD>
private static readonly Dictionary<string, string> ShortToCulture = new(StringComparer.OrdinalIgnoreCase) private static readonly Dictionary<string, string> ShortToCulture = new(StringComparer.OrdinalIgnoreCase)
{ {
{ "zh", "zh-Hans" }, { "zh", "zh-Hans" },
{ "en", "en-US" } { "en", "en-US" }
}; };
// Ĭ<><C4AC><EFBFBD>Ļ<EFBFBD><C4BB><EFBFBD><EFBFBD><EFBFBD>δ<EFBFBD>ܴ<EFBFBD><DCB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>/URL/Cookie <20>н<EFBFBD><D0BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ļ<EFBFBD>ʱʹ<CAB1>ã<EFBFBD>
private string _currentCulture = "zh-Hans"; private string _currentCulture = "zh-Hans";
private const string CookieName = "atomx.culture"; private const string CookieName = "atomx.culture";
public LocalizationProvider(IServiceProvider sp, IHttpClientFactory? httpClientFactory, IJSRuntime? jsRuntime, ILogger<LocalizationProvider> logger, ILocalizationService localizationService) /// <summary>
/// <20><><EFBFBD><EFBFBD><ECBAAF><EFBFBD><EFBFBD>ͨ<EFBFBD><CDA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ע<EFBFBD><D7A2><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
/// ע<><EFBFBD><EFBFBD><ECBAAF><EFBFBD>в<EFBFBD>Ӧִ<D3A6>к<EFBFBD>ʱ<EFBFBD><CAB1> JS <20><><EFBFBD>ص<EFBFBD>ͬ<EFBFBD><CDAC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
/// </summary>
public LocalizationProvider(IServiceProvider sp, ILogger<LocalizationProvider> logger, IHttpClientFactory? httpClientFactory, IJSRuntime? jsRuntime, ILocalizationService localizationService)
{ {
_sp = sp; _sp = sp;
_httpClientFactory = httpClientFactory; _httpClientFactory = httpClientFactory;
@@ -57,22 +71,22 @@ namespace Atomx.Admin.Client.Services
_logger = logger; _logger = logger;
_localizationService = localizationService; _localizationService = localizationService;
// <20><><EFBFBD>ڹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>н<EFBFBD><EFBFBD><EFBFBD> JS <20><><EFBFBD><EFBFBD>ͬ<EFBFBD><CDAC> IO<49><4F><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ը<EFBFBD><D4B8><EFBFBD><EFBFBD>߳<EFBFBD> culture <20><><EFBFBD>ó<EFBFBD>ʼֵ<CABC><D6B5><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>Ϊ<EFBFBD><EFBFBD><EFBFBD><EFBFBD> culture // <20><><EFBFBD>Ը<EFBFBD><EFBFBD>ݵ<EFBFBD>ǰ<EFBFBD>߳<EFBFBD> culture <20><>ʼ<EFBFBD><CABC> _currentCulture<72><65><EFBFBD><EFBFBD><EFBFBD>׳<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
try try
{ {
var threadUi = CultureInfo.DefaultThreadCurrentUICulture ?? CultureInfo.CurrentUICulture; var threadUi = CultureInfo.DefaultThreadCurrentUICulture ?? CultureInfo.CurrentUICulture;
if (!string.IsNullOrEmpty(threadUi?.Name)) if (!string.IsNullOrEmpty(threadUi?.Name))
{ {
_currentCulture = MapToFullCulture(threadUi!.Name); _currentCulture = MapToFullCulture(threadUi!.Name);
_logger?.LogDebug("LocalizationProvider ctor detected thread UI culture: {Culture}", _currentCulture); _logger.LogDebug("LocalizationProvider <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߳<EFBFBD> UI <20>Ļ<EFBFBD>: {Culture}", _currentCulture);
} }
} }
catch (Exception ex) catch (Exception ex)
{ {
_logger?.LogDebug(ex, "LocalizationProvider ctor failed to read thread culture"); _logger.LogDebug(ex, "LocalizationProvider <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD>߳<EFBFBD><EFBFBD>Ļ<EFBFBD>ʧ<EFBFBD><EFBFBD>");
} }
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> Server<65><72>IWebHostEnvironment <EFBFBD><EFBFBD><EFBFBD>ã<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> JSRuntime <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ã<EFBFBD>˵<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ر<EFBFBD><EFBFBD>ػ<EFBFBD><EFBFBD>ļ<EFBFBD> // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> Server <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>δ<EFBFBD><EFBFBD>ʹ<EFBFBD><EFBFBD> JSRuntime<6D><65><EFBFBD><EFBFBD>ζ<EFBFBD>ŷ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>ϵͳ<EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD><EFBFBD>ػ<EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD>֧<EFBFBD><EFBFBD> prerender
try try
{ {
var envType = Type.GetType("Microsoft.AspNetCore.Hosting.IWebHostEnvironment, Microsoft.AspNetCore.Hosting.Abstractions") var envType = Type.GetType("Microsoft.AspNetCore.Hosting.IWebHostEnvironment, Microsoft.AspNetCore.Hosting.Abstractions")
@@ -93,23 +107,23 @@ namespace Atomx.Admin.Client.Services
var json = File.ReadAllText(path); var json = File.ReadAllText(path);
var dict = JsonSerializer.Deserialize<Dictionary<string, string>>(json) ?? new Dictionary<string, string>(); var dict = JsonSerializer.Deserialize<Dictionary<string, string>>(json) ?? new Dictionary<string, string>();
_cache[_currentCulture] = dict; _cache[_currentCulture] = dict;
_logger?.LogInformation("Loaded localization file for {Culture} from path {Path}, entries: {Count}", _currentCulture, path, dict.Count); _logger.LogInformation("(Server ͬ<><CDAC>) <20><>·<EFBFBD><C2B7><EFBFBD><EFBFBD><EFBFBD>ر<EFBFBD><D8B1>ػ<EFBFBD><D8BB>ļ<EFBFBD> {Path}<7D><>Culture:{Culture}<7D><><EFBFBD><EFBFBD>Ŀ<EFBFBD><C4BF>:{Count}", path, _currentCulture, dict.Count);
} }
catch (Exception ex) catch (Exception ex)
{ {
_logger?.LogWarning(ex, "Failed to read localization file synchronously: {Path}", path); _logger.LogWarning(ex, "(Server ͬ<><CDAC>) <20><>ȡ<EFBFBD><C8A1><EFBFBD>ػ<EFBFBD><D8BB>ļ<EFBFBD>ʧ<EFBFBD><CAA7>: {Path}", path);
} }
} }
else else
{ {
_logger?.LogDebug("Localization file not found at {Path}", path); _logger.LogDebug("<EFBFBD><EFBFBD><EFBFBD>ػ<EFBFBD><EFBFBD>ļ<EFBFBD>δ<EFBFBD><EFBFBD>·<EFBFBD><EFBFBD><EFBFBD>ҵ<EFBFBD>: {Path}", path);
} }
} }
} }
} }
catch (Exception ex) catch (Exception ex)
{ {
_logger?.LogDebug(ex, "Synchronous file load attempt failed in ctor"); _logger.LogDebug(ex, "LocalizationProvider <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬ<EFBFBD><CDAC><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD>س<EFBFBD><D8B3><EFBFBD>ʧ<EFBFBD><CAA7>");
} }
} }
@@ -117,6 +131,9 @@ namespace Atomx.Admin.Client.Services
public event EventHandler<string>? LanguageChanged; public event EventHandler<string>? LanguageChanged;
/// <summary>
/// <20>ӻ<EFBFBD><D3BB><EFBFBD><EFBFBD>ж<EFBFBD>ȡָ<C8A1><D6B8><EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD><C4B1>ػ<EFBFBD><D8BB>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD>δ<EFBFBD>ҵ<EFBFBD><D2B5><EFBFBD><EFBFBD><EFBFBD> null<6C><6C>
/// </summary>
public string? GetString(string key) public string? GetString(string key)
{ {
if (string.IsNullOrEmpty(key)) return null; if (string.IsNullOrEmpty(key)) return null;
@@ -129,9 +146,14 @@ namespace Atomx.Admin.Client.Services
return null; return null;
} }
/// <summary>
/// <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD>̣<EFBFBD><CCA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ˣ<EFBFBD>
/// <20><><EFBFBD>ȼ<EFBFBD><C8BC><EFBFBD>URL <20><><EFBFBD><EFBFBD>ǰ׺ -> Cookie(atomx.culture) -> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> -> Ĭ<><C4AC>
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EBA3A8> zh/en<65><6E><EFBFBD><EFBFBD>ӳ<EFBFBD><D3B3>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD>Ļ<EFBFBD><C4BB><EFBFBD><EFBFBD><EFBFBD> zh-Hans/en-US<55><53><EFBFBD><EFBFBD>
/// </summary>
public async Task InitializeAsync() public async Task InitializeAsync()
{ {
_logger?.LogDebug("LocalizationProvider.InitializeAsync start. CurrentCulture={Culture}", _currentCulture); _logger.LogDebug("LocalizationProvider.InitializeAsync <EFBFBD><EFBFBD>ʼ. CurrentCulture={Culture}", _currentCulture);
string? urlFirstSegment = null; string? urlFirstSegment = null;
@@ -140,7 +162,7 @@ namespace Atomx.Admin.Client.Services
if (_jsRuntime != null && OperatingSystem.IsBrowser()) if (_jsRuntime != null && OperatingSystem.IsBrowser())
{ {
var path = await _jsRuntime.InvokeAsync<string>("eval", "location.pathname"); var path = await _jsRuntime.InvokeAsync<string>("eval", "location.pathname");
_logger?.LogDebug("JS location.pathname='{Path}'", path); _logger.LogDebug("JS location.pathname='{Path}'", path);
if (!string.IsNullOrEmpty(path)) if (!string.IsNullOrEmpty(path))
{ {
var trimmed = path.Trim('/'); var trimmed = path.Trim('/');
@@ -148,19 +170,19 @@ namespace Atomx.Admin.Client.Services
{ {
var seg = trimmed.Split('/', StringSplitOptions.RemoveEmptyEntries).FirstOrDefault(); var seg = trimmed.Split('/', StringSplitOptions.RemoveEmptyEntries).FirstOrDefault();
urlFirstSegment = seg; urlFirstSegment = seg;
_logger?.LogDebug("Detected url first segment: {Segment}", urlFirstSegment); _logger.LogDebug("<EFBFBD><EFBFBD><EFBFBD>⵽ URL <20>׶<EFBFBD>: {Segment}", urlFirstSegment);
} }
} }
} }
} }
catch (Exception ex) catch (Exception ex)
{ {
_logger?.LogDebug(ex, "<22><>ȡ location.pathname ʧ<><CAA7>"); _logger.LogDebug(ex, "<22><>ȡ location.pathname ʧ<><CAA7>");
} }
if (!string.IsNullOrEmpty(urlFirstSegment) && ShortToCulture.TryGetValue(urlFirstSegment, out var mapped)) if (!string.IsNullOrEmpty(urlFirstSegment) && ShortToCulture.TryGetValue(urlFirstSegment, out var mapped))
{ {
_logger?.LogDebug("URL short segment '{Seg}' mapped to culture '{Culture}'", urlFirstSegment, mapped); _logger.LogDebug("URL <EFBFBD><EFBFBD><EFBFBD><EFBFBD> '{Seg}' ӳ<><D3B3>Ϊ<EFBFBD>Ļ<EFBFBD> '{Culture}'", urlFirstSegment, mapped);
await SetCultureInternalAsync(mapped, persistCookie: false); await SetCultureInternalAsync(mapped, persistCookie: false);
return; return;
} }
@@ -169,19 +191,19 @@ namespace Atomx.Admin.Client.Services
{ {
if (_jsRuntime != null && OperatingSystem.IsBrowser()) if (_jsRuntime != null && OperatingSystem.IsBrowser())
{ {
var cookieVal = await _jsRuntime.InvokeAsync<string>("CookieReader.Read", CookieName); var cookieVal = await _jsRuntime.InvokeAsync<string>("cookies.Read", CookieName);
_logger?.LogDebug("Cookie '{CookieName}'='{CookieVal}'", CookieName, cookieVal); _logger.LogDebug("<EFBFBD><EFBFBD>ȡ Cookie '{CookieName}'='{CookieVal}'", CookieName, cookieVal);
if (!string.IsNullOrEmpty(cookieVal)) if (!string.IsNullOrEmpty(cookieVal))
{ {
if (ShortToCulture.TryGetValue(cookieVal, out var mappedFromCookie)) if (ShortToCulture.TryGetValue(cookieVal, out var mappedFromCookie))
{ {
_logger?.LogDebug("Cookie short '{Cookie}' mapped to {Culture}", cookieVal, mappedFromCookie); _logger.LogDebug("Cookie <EFBFBD><EFBFBD><EFBFBD><EFBFBD> '{Cookie}' ӳ<EFBFBD><EFBFBD>Ϊ<EFBFBD>Ļ<EFBFBD> {Culture}", cookieVal, mappedFromCookie);
await SetCultureInternalAsync(mappedFromCookie, persistCookie: false); await SetCultureInternalAsync(mappedFromCookie, persistCookie: false);
return; return;
} }
else else
{ {
// <20><><EFBFBD><EFBFBD> cookie <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> culture<72><65><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD><EFBFBD> // cookie <20>п<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> culture<72><65><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD>
await SetCultureInternalAsync(MapToFullCulture(cookieVal), persistCookie: false); await SetCultureInternalAsync(MapToFullCulture(cookieVal), persistCookie: false);
return; return;
} }
@@ -190,7 +212,7 @@ namespace Atomx.Admin.Client.Services
} }
catch (Exception ex) catch (Exception ex)
{ {
_logger?.LogDebug(ex, "<22><>ȡ Cookie ʧ<><CAA7>"); _logger.LogDebug(ex, "<22><>ȡ Cookie ʧ<><CAA7>");
} }
try try
@@ -198,11 +220,11 @@ namespace Atomx.Admin.Client.Services
if (_jsRuntime != null && OperatingSystem.IsBrowser()) if (_jsRuntime != null && OperatingSystem.IsBrowser())
{ {
var browserLang = await _jsRuntime.InvokeAsync<string>("getBrowserLanguage"); var browserLang = await _jsRuntime.InvokeAsync<string>("getBrowserLanguage");
_logger?.LogDebug("Browser language: {BrowserLang}", browserLang); _logger.LogDebug("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: {BrowserLang}", browserLang);
if (!string.IsNullOrEmpty(browserLang)) if (!string.IsNullOrEmpty(browserLang))
{ {
var mappedFromBrowser = MapToFullCulture(browserLang); var mappedFromBrowser = MapToFullCulture(browserLang);
_logger?.LogDebug("Browser mapped to {Culture}", mappedFromBrowser); _logger.LogDebug("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӳ<EFBFBD><EFBFBD>Ϊ {Culture}", mappedFromBrowser);
await SetCultureInternalAsync(mappedFromBrowser, persistCookie: false); await SetCultureInternalAsync(mappedFromBrowser, persistCookie: false);
return; return;
} }
@@ -210,15 +232,18 @@ namespace Atomx.Admin.Client.Services
} }
catch (Exception ex) catch (Exception ex)
{ {
_logger?.LogDebug(ex, "<22><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><CAA7>"); _logger.LogDebug(ex, "<22><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><CAA7>");
} }
// <20><><EFBFBD><EFBFBD>ȷ<EFBFBD><C8B7><EFBFBD><EFBFBD><EFBFBD>ص<EFBFBD>ǰ culture // <20><><EFBFBD>˵<EFBFBD><EFBFBD><EFBFBD>ǰĬ<EFBFBD><EFBFBD><EFBFBD>Ļ<EFBFBD><EFBFBD><EFBFBD>ȷ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Դ
_logger?.LogDebug("InitializeAsync falling back to current culture {Culture}", _currentCulture); _logger.LogDebug("InitializeAsync <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD>õ<EFBFBD>ǰ<EFBFBD>Ļ<EFBFBD> {Culture}", _currentCulture);
await EnsureCultureLoadedAsync(_currentCulture); await EnsureCultureLoadedAsync(_currentCulture);
await SetCultureInternalAsync(_currentCulture, persistCookie: false); await SetCultureInternalAsync(_currentCulture, persistCookie: false);
} }
/// <summary>
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><ECB2BD><EFBFBD><EFBFBD><EFBFBD>Ļ<EFBFBD><C4BB><EFBFBD><EFBFBD>ɴ<EFBFBD><C9B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> culture<72><65><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1><EFBFBD>Ƿ<EFBFBD><C7B7>־û<D6BE><C3BB><EFBFBD> Cookie
/// </summary>
public async Task SetCultureAsync(string cultureShortOrFull) public async Task SetCultureAsync(string cultureShortOrFull)
{ {
if (string.IsNullOrEmpty(cultureShortOrFull)) return; if (string.IsNullOrEmpty(cultureShortOrFull)) return;
@@ -235,9 +260,8 @@ namespace Atomx.Admin.Client.Services
public Task LoadCultureAsync(string culture) => EnsureCultureLoadedAsync(MapToFullCulture(culture)); public Task LoadCultureAsync(string culture) => EnsureCultureLoadedAsync(MapToFullCulture(culture));
/// <summary> /// <summary>
/// Server-side synchronous culture set used during prerender to ensure translations /// Server <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> prerender ʱ<><CAB1>ͬ<EFBFBD><CDAC><EFBFBD><EFBFBD><EFBFBD>ã<EFBFBD><C3A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߳<EFBFBD> Culture <20><><EFBFBD><EFBFBD><EFBFBD>Դ<EFBFBD> webroot ͬ<><CDAC><EFBFBD><EFBFBD><EFBFBD>ر<EFBFBD><D8B1>ػ<EFBFBD><D8BB>ļ<EFBFBD><C4BC><EFBFBD>
/// are available immediately. This method will attempt to load localization /// <EFBFBD>÷<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> JS <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʺ<EFBFBD><CABA><EFBFBD><EFBFBD>м<EFBFBD><D0BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD>á<EFBFBD>
/// JSON from the server's webroot synchronously and set thread cultures.
/// </summary> /// </summary>
public void SetCultureForServer(string cultureShortOrFull) public void SetCultureForServer(string cultureShortOrFull)
{ {
@@ -246,7 +270,7 @@ namespace Atomx.Admin.Client.Services
var cultureFull = MapToFullCulture(cultureShortOrFull); var cultureFull = MapToFullCulture(cultureShortOrFull);
if (string.IsNullOrEmpty(cultureFull)) return; if (string.IsNullOrEmpty(cultureFull)) return;
// set thread culture // <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߳<EFBFBD> culture<72><65>Ӱ<EFBFBD><D3B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˴<EFBFBD><CBB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> IStringLocalizer<65><72>
try try
{ {
var ci = new CultureInfo(cultureFull); var ci = new CultureInfo(cultureFull);
@@ -256,7 +280,7 @@ namespace Atomx.Admin.Client.Services
} }
catch { } catch { }
// try load from webroot synchronously via IWebHostEnvironment if available // ͬ<EFBFBD><EFBFBD><EFBFBD><EFBFBD> webroot <20><><EFBFBD><EFBFBD> JSON <20><><EFBFBD>ػ<EFBFBD><D8BB>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڣ<EFBFBD>
try try
{ {
var envType = Type.GetType("Microsoft.AspNetCore.Hosting.IWebHostEnvironment, Microsoft.AspNetCore.Hosting.Abstractions") var envType = Type.GetType("Microsoft.AspNetCore.Hosting.IWebHostEnvironment, Microsoft.AspNetCore.Hosting.Abstractions")
@@ -277,11 +301,11 @@ namespace Atomx.Admin.Client.Services
var json = File.ReadAllText(path); var json = File.ReadAllText(path);
var dict = JsonSerializer.Deserialize<Dictionary<string, string>>(json) ?? new Dictionary<string, string>(); var dict = JsonSerializer.Deserialize<Dictionary<string, string>>(json) ?? new Dictionary<string, string>();
_cache[cultureFull] = dict; _cache[cultureFull] = dict;
_logger?.LogInformation("(Server sync) Loaded localization file for {Culture} from path {Path}, entries: {Count}", cultureFull, path, dict.Count); _logger.LogInformation("(Server ͬ<EFBFBD><EFBFBD>) <20><>Ϊ {Culture} <20><>·<EFBFBD><C2B7><EFBFBD><EFBFBD><EFBFBD>ر<EFBFBD><D8B1>ػ<EFBFBD><D8BB>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>Ŀ<EFBFBD><C4BF>: {Count}", cultureFull, dict.Count);
} }
catch (Exception ex) catch (Exception ex)
{ {
_logger?.LogWarning(ex, "(Server sync) Failed to read localization file synchronously: {Path}", path); _logger.LogWarning(ex, "(Server ͬ<EFBFBD><EFBFBD>) <20><>ȡ<EFBFBD><C8A1><EFBFBD>ػ<EFBFBD><D8BB>ļ<EFBFBD>ʧ<EFBFBD><CAA7>: {Path}", path);
} }
} }
} }
@@ -289,18 +313,21 @@ namespace Atomx.Admin.Client.Services
} }
catch (Exception ex) catch (Exception ex)
{ {
_logger?.LogDebug(ex, "SetCultureForServer failed to load file for {Culture}", cultureFull); _logger.LogDebug(ex, "SetCultureForServer <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: {Culture}", cultureFull);
} }
} }
catch (Exception ex) catch (Exception ex)
{ {
_logger?.LogDebug(ex, "SetCultureForServer encountered error"); _logger.LogDebug(ex, "SetCultureForServer ִ<EFBFBD>й<EFBFBD><EFBFBD><EFBFBD><EFBFBD>з<EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
} }
} }
/// <summary>
/// <20>ڲ<EFBFBD><DAB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ļ<EFBFBD><C4BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫʱ<D2AA>־û<D6BE> Cookie<69><65><EFBFBD><EFBFBD><EFBFBD><EFBFBD> localization service <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><C2BC><EFBFBD>
/// </summary>
private async Task SetCultureInternalAsync(string cultureFull, bool persistCookie) private async Task SetCultureInternalAsync(string cultureFull, bool persistCookie)
{ {
_logger?.LogDebug("SetCultureInternalAsync start: {Culture}, persist={Persist}", cultureFull, persistCookie); //_logger.LogDebug("<22><><EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><DAB2>Ļ<EFBFBD><C4BB><EFBFBD><ECB2BD>ʼ: {Culture}, <EFBFBD>־û<EFBFBD>={Persist}", cultureFull, persistCookie);
await EnsureCultureLoadedAsync(cultureFull); await EnsureCultureLoadedAsync(cultureFull);
try try
@@ -310,11 +337,11 @@ namespace Atomx.Admin.Client.Services
CultureInfo.DefaultThreadCurrentUICulture = ci; CultureInfo.DefaultThreadCurrentUICulture = ci;
_currentCulture = cultureFull; _currentCulture = cultureFull;
_localizationService.SetLanguage(ci); _localizationService.SetLanguage(ci);
_logger?.LogDebug("Culture set to {Culture}", cultureFull); _logger.LogDebug("<EFBFBD>Ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ {Culture}", cultureFull);
} }
catch (Exception ex) catch (Exception ex)
{ {
_logger?.LogWarning(ex, "<22><><EFBFBD><EFBFBD> Culture ʧ<><CAA7>: {Culture}", cultureFull); _logger.LogWarning(ex, "<22><><EFBFBD><EFBFBD> Culture ʧ<><CAA7>: {Culture}", cultureFull);
} }
if (persistCookie && _jsRuntime != null) if (persistCookie && _jsRuntime != null)
@@ -322,11 +349,12 @@ namespace Atomx.Admin.Client.Services
try try
{ {
var shortKey = ShortToCulture.FirstOrDefault(kv => string.Equals(kv.Value, cultureFull, StringComparison.OrdinalIgnoreCase)).Key ?? cultureFull; var shortKey = ShortToCulture.FirstOrDefault(kv => string.Equals(kv.Value, cultureFull, StringComparison.OrdinalIgnoreCase)).Key ?? cultureFull;
// <20><> shortKey д<><D0B4> cookie<69><65><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD> Server ģʽ<C4A3>µ<EFBFBD><C2B5>м<EFBFBD><D0BC><EFBFBD><EFBFBD><EFBFBD>
await _jsRuntime.InvokeVoidAsync("cookies.Write", CookieName, shortKey, DateTime.UtcNow.AddYears(1).ToString("o")); await _jsRuntime.InvokeVoidAsync("cookies.Write", CookieName, shortKey, DateTime.UtcNow.AddYears(1).ToString("o"));
} }
catch (Exception ex) catch (Exception ex)
{ {
_logger?.LogDebug(ex, "д Cookie ʧ<><CAA7>"); _logger.LogDebug(ex, <EFBFBD><EFBFBD> Cookie ʧ<><CAA7>");
} }
} }
@@ -334,41 +362,46 @@ namespace Atomx.Admin.Client.Services
{ {
if (_jsRuntime != null) if (_jsRuntime != null)
{ {
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> HTML <20><> lang <20><><EFBFBD>ԣ<EFBFBD><D4A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϰ<EFBFBD>/SEO
await _jsRuntime.InvokeVoidAsync("setHtmlLang", cultureFull); await _jsRuntime.InvokeVoidAsync("setHtmlLang", cultureFull);
} }
} }
catch { } catch { }
// ֪ͨ<CDA8><D6AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
LanguageChanged?.Invoke(this, cultureFull); LanguageChanged?.Invoke(this, cultureFull);
} }
/// <summary>
/// ȷ<><C8B7>ָ<EFBFBD><D6B8><EFBFBD>Ļ<EFBFBD><C4BB><EFBFBD> JSON <20>ļ<EFBFBD><C4BC>ѱ<EFBFBD><D1B1><EFBFBD><EFBFBD>ص<EFBFBD><D8B5><EFBFBD><EFBFBD><EFBFBD><E6A1A3><EFBFBD><EFBFBD>˳<EFBFBD><CBB3><EFBFBD><EFBFBD>WASM HttpClient -> <20>ļ<EFBFBD>ϵͳ -> <20><><EFBFBD>ֵ<EFBFBD>ռλ<D5BC><CEBB>
/// </summary>
private async Task EnsureCultureLoadedAsync(string cultureFull) private async Task EnsureCultureLoadedAsync(string cultureFull)
{ {
// Normalize possible short codes (e.g. zh -> zh-Hans, en -> en-US) and variants (zh-CN -> zh-Hans) // <EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> zh -> zh-Hans<6E><73>
cultureFull = MapToFullCulture(cultureFull); cultureFull = MapToFullCulture(cultureFull);
if (string.IsNullOrEmpty(cultureFull)) return; if (string.IsNullOrEmpty(cultureFull)) return;
if (_cache.ContainsKey(cultureFull)) if (_cache.ContainsKey(cultureFull))
{ {
_logger?.LogDebug("EnsureCultureLoadedAsync: culture {Culture} already cached", cultureFull); _logger.LogDebug("EnsureCultureLoadedAsync: <EFBFBD>Ļ<EFBFBD> {Culture} <EFBFBD>ѻ<EFBFBD><EFBFBD><EFBFBD>", cultureFull);
return; return;
} }
// Prefer HttpClient when running in browser (WASM) // <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>WASM<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD><EFBFBD> HttpClient <20><><EFBFBD>ر<EFBFBD><D8B1>ػ<EFBFBD> JSON
if (_jsRuntime != null && OperatingSystem.IsBrowser()) if (_jsRuntime != null && OperatingSystem.IsBrowser())
{ {
_logger?.LogInformation("EnsureCultureLoadedAsync: running in browser, will attempt HttpClient for {Culture}", cultureFull); _logger.LogInformation("EnsureCultureLoadedAsync: <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͨ<EFBFBD><EFBFBD> HttpClient <EFBFBD><EFBFBD><EFBFBD><EFBFBD> {Culture}", cultureFull);
try try
{ {
var http = _sp.GetService(typeof(HttpClient)) as HttpClient; var http = _sp.GetService(typeof(HttpClient)) as HttpClient;
if (http == null && _httpClientFactory != null) if (http == null && _httpClientFactory != null)
{ {
_logger?.LogDebug("HttpClient not found from service provider, using factory"); _logger.LogDebug("δ<EFBFBD><EFBFBD> ServiceProvider <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> HttpClient<6E><74>ʹ<EFBFBD><CAB9> IHttpClientFactory <20><><EFBFBD><EFBFBD>");
http = _httpClientFactory.CreateClient(); http = _httpClientFactory.CreateClient();
} }
else else
{ {
_logger?.LogDebug("HttpClient resolved from service provider: {HasClient}", http != null); _logger.LogDebug("<EFBFBD><EFBFBD> ServiceProvider <20><><EFBFBD><EFBFBD> HttpClient: {HasClient}", http != null);
} }
if (http != null) if (http != null)
@@ -376,7 +409,7 @@ namespace Atomx.Admin.Client.Services
var url = $"/localization/{cultureFull}.json"; var url = $"/localization/{cultureFull}.json";
Uri? requestUri = null; Uri? requestUri = null;
// If HttpClient has a BaseAddress, use it. Otherwise, if running in browser, build absolute URI from location.origin // <EFBFBD><EFBFBD> HttpClient <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> BaseAddress ʱʹ<CAB1>ã<EFBFBD><C3A3><EFBFBD><EFBFBD><EFBFBD>ͨ<EFBFBD><CDA8> JS <20><>ȡ location.origin <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> URI
if (http.BaseAddress != null) if (http.BaseAddress != null)
{ {
requestUri = new Uri(http.BaseAddress, url); requestUri = new Uri(http.BaseAddress, url);
@@ -388,43 +421,42 @@ namespace Atomx.Admin.Client.Services
var origin = await _jsRuntime.InvokeAsync<string>("eval", "location.origin"); var origin = await _jsRuntime.InvokeAsync<string>("eval", "location.origin");
if (!string.IsNullOrEmpty(origin)) if (!string.IsNullOrEmpty(origin))
{ {
// ensure no double slashes
requestUri = new Uri(new Uri(origin), url); requestUri = new Uri(new Uri(origin), url);
} }
} }
catch (Exception jsEx) catch (Exception jsEx)
{ {
_logger?.LogDebug(jsEx, "Failed to get location.origin from JS"); _logger.LogDebug(jsEx, "<EFBFBD><EFBFBD> JS <20><>ȡ location.origin ʧ<EFBFBD><EFBFBD>");
} }
} }
if (requestUri != null) if (requestUri != null)
{ {
_logger?.LogInformation("Downloading localization from {Url}", requestUri); _logger.LogInformation("<EFBFBD><EFBFBD> {Url} <20><><EFBFBD>ر<EFBFBD><D8B1>ػ<EFBFBD><D8BB><EFBFBD>Դ", requestUri);
var txt = await http.GetStringAsync(requestUri); var txt = await http.GetStringAsync(requestUri);
var dict = JsonSerializer.Deserialize<Dictionary<string, string>>(txt) ?? new Dictionary<string, string>(); var dict = JsonSerializer.Deserialize<Dictionary<string, string>>(txt) ?? new Dictionary<string, string>();
_cache[cultureFull] = dict; _cache[cultureFull] = dict;
_logger?.LogInformation("Loaded localization via HttpClient for {Culture}, entries: {Count}", cultureFull, dict.Count); _logger.LogInformation("ͨ<EFBFBD><EFBFBD> HttpClient Ϊ {Culture} <20><><EFBFBD>ص<EFBFBD><D8B5><EFBFBD><EFBFBD>ػ<EFBFBD><D8BB><EFBFBD><EFBFBD>ݣ<EFBFBD><DDA3><EFBFBD>Ŀ<EFBFBD><C4BF>: {Count}", cultureFull, dict.Count);
return; return;
} }
else else
{ {
_logger?.LogWarning("HttpClient has no BaseAddress and JSRuntime unavailable to construct absolute URL; skipping HttpClient load for {Culture}", cultureFull); _logger.LogWarning("HttpClient <EFBFBD>޷<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> URL<52><4C><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͨ<EFBFBD><CDA8> HttpClient <EFBFBD><EFBFBD><EFBFBD><EFBFBD> {Culture}", cultureFull);
} }
} }
else else
{ {
_logger?.LogWarning("No HttpClient available to load localization for {Culture}", cultureFull); _logger.LogWarning("δ<EFBFBD>ҵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD> HttpClient <EFBFBD>Լ<EFBFBD><EFBFBD><EFBFBD> {Culture}", cultureFull);
} }
} }
catch (Exception ex) catch (Exception ex)
{ {
_logger?.LogDebug(ex, <><CDA8> HttpClient <20><><EFBFBD>ر<EFBFBD><D8B1>ػ<EFBFBD><D8BB>ļ<EFBFBD>ʧ<EFBFBD><CAA7>: {Culture}", cultureFull); _logger.LogDebug(ex, <><CDA8> HttpClient <20><><EFBFBD>ر<EFBFBD><D8B1>ػ<EFBFBD><D8BB>ļ<EFBFBD>ʧ<EFBFBD><CAA7>: {Culture}", cultureFull);
} }
} }
_logger?.LogDebug("EnsureCultureLoadedAsync trying filesystem for {Culture}", cultureFull); _logger.LogDebug("EnsureCultureLoadedAsync: <20><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>ϵͳ<CFB5><CDB3><EFBFBD><EFBFBD> {Culture}", cultureFull);
// <20><><EFBFBD><EFBFBD>ͨ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ IWebHostEnvironment<6E><74>Server ʱ<><CAB1><EFBFBD>ã<EFBFBD> // <20><><EFBFBD>ˣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͨ<EFBFBD><EFBFBD> IWebHostEnvironment <20><><EFBFBD>ļ<EFBFBD>ϵͳ<CFB5><CDB3>ȡ<EFBFBD><EFBFBD>Server ʱ<><CAB1><EFBFBD>ã<EFBFBD>
try try
{ {
var envType = Type.GetType("Microsoft.AspNetCore.Hosting.IWebHostEnvironment, Microsoft.AspNetCore.Hosting.Abstractions") var envType = Type.GetType("Microsoft.AspNetCore.Hosting.IWebHostEnvironment, Microsoft.AspNetCore.Hosting.Abstractions")
@@ -438,147 +470,75 @@ namespace Atomx.Admin.Client.Services
var contentRootProp = envType.GetProperty("ContentRootPath"); var contentRootProp = envType.GetProperty("ContentRootPath");
var webRoot = webRootProp?.GetValue(env) as string ?? Path.Combine(contentRootProp?.GetValue(env) as string ?? ".", "wwwroot"); var webRoot = webRootProp?.GetValue(env) as string ?? Path.Combine(contentRootProp?.GetValue(env) as string ?? ".", "wwwroot");
var path = Path.Combine(webRoot ?? ".", "localization", cultureFull + ".json"); var path = Path.Combine(webRoot ?? ".", "localization", cultureFull + ".json");
_logger?.LogDebug("Looking for localization file at {Path}", path); _logger.LogDebug("<EFBFBD><EFBFBD><EFBFBD>ұ<EFBFBD><EFBFBD>ػ<EFBFBD><EFBFBD>ļ<EFBFBD>·<EFBFBD><EFBFBD>: {Path}", path);
if (File.Exists(path)) if (File.Exists(path))
{ {
var json = await File.ReadAllTextAsync(path); var json = await File.ReadAllTextAsync(path);
var dict = JsonSerializer.Deserialize<Dictionary<string, string>>(json) ?? new Dictionary<string, string>(); var dict = JsonSerializer.Deserialize<Dictionary<string, string>>(json) ?? new Dictionary<string, string>();
_cache[cultureFull] = dict; _cache[cultureFull] = dict;
_logger?.LogInformation("Loaded localization from file for {Culture}, entries: {Count}", cultureFull, dict.Count); _logger.LogInformation("<EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>Ϊ {Culture} <20><><EFBFBD>ر<EFBFBD><D8B1>ػ<EFBFBD><D8BB><EFBFBD><EFBFBD><EFBFBD>Ŀ<EFBFBD><C4BF>: {Count}", cultureFull, dict.Count);
return; return;
} }
else else
{ {
_logger?.LogDebug("Localization file not found at {Path}", path); _logger.LogDebug("δ<EFBFBD><EFBFBD>·<EFBFBD><EFBFBD><EFBFBD>ҵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ػ<EFBFBD><EFBFBD>ļ<EFBFBD>: {Path}", path);
// Fallback: check build output wwwroot under AppContext.BaseDirectory // <EFBFBD><EFBFBD><EFBFBD><EFBFBD>·<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ¼<EFBFBD><EFBFBD> wwwroot
try try
{ {
var alt = Path.Combine(AppContext.BaseDirectory ?? ".", "wwwroot", "localization", cultureFull + ".json"); var alt = Path.Combine(AppContext.BaseDirectory ?? ".", "wwwroot", "localization", cultureFull + ".json");
_logger?.LogDebug("Looking for localization file at alternative path {AltPath}", alt); _logger.LogDebug("<EFBFBD><EFBFBD><EFBFBD>ұ<EFBFBD><EFBFBD><EFBFBD>·<EFBFBD><EFBFBD>: {AltPath}", alt);
if (File.Exists(alt)) if (File.Exists(alt))
{ {
var json2 = await File.ReadAllTextAsync(alt); var json2 = await File.ReadAllTextAsync(alt);
var dict2 = JsonSerializer.Deserialize<Dictionary<string, string>>(json2) ?? new Dictionary<string, string>(); var dict2 = JsonSerializer.Deserialize<Dictionary<string, string>>(json2) ?? new Dictionary<string, string>();
_cache[cultureFull] = dict2; _cache[cultureFull] = dict2;
_logger?.LogInformation("Loaded localization from alternative file path for {Culture}, entries: {Count}", cultureFull, dict2.Count); _logger.LogInformation("<EFBFBD>ӱ<EFBFBD><EFBFBD><EFBFBD>·<EFBFBD><EFBFBD>Ϊ {Culture} <20><><EFBFBD>ص<EFBFBD><D8B5><EFBFBD><EFBFBD>ػ<EFBFBD><D8BB>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>Ŀ<EFBFBD><C4BF>: {Count}", cultureFull, dict2.Count);
return; return;
} }
else else
{ {
_logger?.LogDebug("Localization file not found at alternative path {AltPath}", alt); _logger.LogDebug("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>·<EFBFBD><EFBFBD>δ<EFBFBD>ҵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ػ<EFBFBD><EFBFBD>ļ<EFBFBD>: {AltPath}", alt);
} }
} }
catch (Exception exAlt) catch (Exception exAlt)
{ {
_logger?.LogDebug(exAlt, "Error while checking alternative localization path"); _logger.LogDebug(exAlt, "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ñ<EFBFBD><EFBFBD>ػ<EFBFBD>·<EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
} }
} }
} }
else else
{ {
_logger?.LogDebug("IWebHostEnvironment not resolved from service provider"); _logger.LogDebug("<EFBFBD>޷<EFBFBD><EFBFBD><EFBFBD> ServiceProvider <20><>ȡ IWebHostEnvironment ʵ<><CAB5>");
} }
} }
else else
{ {
_logger?.LogDebug("IWebHostEnvironment type not found via reflection"); _logger.LogDebug("ͨ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>δ<EFBFBD><EFBFBD><EFBFBD>ҵ<EFBFBD> IWebHostEnvironment <EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
} }
} }
catch (Exception ex) catch (Exception ex)
{ {
_logger?.LogDebug(ex, "<22><><EFBFBD>ļ<EFBFBD>ϵͳ<CFB5><CDB3><EFBFBD>ر<EFBFBD><D8B1>ػ<EFBFBD><D8BB>ļ<EFBFBD>ʧ<EFBFBD><CAA7>: {Culture}", cultureFull); _logger.LogDebug(ex, "ͨ<EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>ϵͳ<EFBFBD><EFBFBD><EFBFBD>ر<EFBFBD><EFBFBD>ػ<EFBFBD><EFBFBD>ļ<EFBFBD>ʧ<EFBFBD><EFBFBD>: {Culture}", cultureFull);
} }
_logger?.LogDebug("EnsureCultureLoadedAsync fallback to empty dict for {Culture}", cultureFull); _logger.LogDebug("EnsureCultureLoadedAsync: <20><><EFBFBD><EFBFBD>Ϊ {Culture} <20>Ŀ<EFBFBD><C4BF>ֵ<EFBFBD>ռλ", cultureFull);
_cache[cultureFull] = new Dictionary<string, string>(); _cache[cultureFull] = new Dictionary<string, string>();
} }
/// <summary>
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>ӳ<EFBFBD><D3B3>Ϊ<EFBFBD>ڲ<EFBFBD>ʹ<EFBFBD>õ<EFBFBD><C3B5><EFBFBD><EFBFBD><EFBFBD> culture<72><65><EFBFBD><EFBFBD><EFBFBD><EFBFBD> zh -> zh-Hans<6E><73>
/// </summary>
private string MapToFullCulture(string culture) private string MapToFullCulture(string culture)
{ {
if (string.IsNullOrEmpty(culture)) return culture; if (string.IsNullOrEmpty(culture)) return culture;
// direct mapping // ֱ<EFBFBD><EFBFBD>ӳ<EFBFBD><EFBFBD>
if (ShortToCulture.TryGetValue(culture, out var mapped)) return mapped; if (ShortToCulture.TryGetValue(culture, out var mapped)) return mapped;
// consider prefix, e.g. zh-CN -> zh // <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ׺<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> zh-CN -> zh
var prefix = culture.Split('-', StringSplitOptions.RemoveEmptyEntries).FirstOrDefault(); var prefix = culture.Split('-', StringSplitOptions.RemoveEmptyEntries).FirstOrDefault();
if (!string.IsNullOrEmpty(prefix) && ShortToCulture.TryGetValue(prefix, out var mapped2)) return mapped2; if (!string.IsNullOrEmpty(prefix) && ShortToCulture.TryGetValue(prefix, out var mapped2)) return mapped2;
return culture; return culture;
} }
} }
/// <summary>
/// <20><><EFBFBD><EFBFBD> ILocalizationProvider <20><> IStringLocalizer ʵ<>֣<EFBFBD>
/// ʹ<><CAB9> JSON <20>ļ<EFBFBD><C4BC>еļ<D0B5>ֵ<EFBFBD><D6B5>δ<EFBFBD>ҵ<EFBFBD><D2B5><EFBFBD><EFBFBD><EFBFBD> key <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
/// <20><><EFBFBD>Ƹ<EFBFBD>Ϊ JsonStringLocalizer <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܵ<EFBFBD> StringLocalizer <20><>ͻ<EFBFBD><CDBB>
/// </summary>
public class JsonStringLocalizer<T> : IStringLocalizer<T>
{
private readonly ILocalizationProvider _provider;
public JsonStringLocalizer(ILocalizationProvider provider)
{
_provider = provider;
}
public LocalizedString this[string name]
{
get
{
var value = _provider.GetString(name);
if (value == null)
{
// Avoid synchronous blocking during server prerender. Start background load and return key.
try
{
_ = _provider.LoadCultureAsync(_provider.CurrentCulture);
}
catch { }
}
var result = value ?? name;
return new LocalizedString(name, result, resourceNotFound: result == name);
}
}
public LocalizedString this[string name, params object[] arguments]
{
get
{
var fmt = _provider.GetString(name);
if (fmt == null)
{
try
{
_ = _provider.LoadCultureAsync(_provider.CurrentCulture);
}
catch { }
}
var format = fmt ?? name;
var value = string.Format(format, arguments);
return new LocalizedString(name, value, resourceNotFound: format == name);
}
}
public IEnumerable<LocalizedString> GetAllStrings(bool includeParentCultures)
{
var list = new List<LocalizedString>();
var providerType = _provider.GetType();
var currentProp = providerType.GetProperty("CurrentCulture");
var culture = currentProp?.GetValue(_provider) as string ?? string.Empty;
var cacheField = providerType.GetField("_cache", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
if (!string.IsNullOrEmpty(culture) && cacheField?.GetValue(_provider) is Dictionary<string, Dictionary<string, string>> cache && cache.TryGetValue(culture, out var dict))
{
foreach (var kv in dict)
{
list.Add(new LocalizedString(kv.Key, kv.Value, resourceNotFound: false));
}
}
return list;
}
public IStringLocalizer WithCulture(CultureInfo culture)
{
return this;
}
}
} }

View File

@@ -0,0 +1,11 @@
namespace Atomx.Admin.Client.Services
{
public interface INavigationService
{
}
public class NavigationService
{
}
}

View File

@@ -1,11 +1,12 @@
using Atomx.Admin.Client.Models; using Atomx.Admin.Client.Models;
using FluentValidation; using FluentValidation;
using Microsoft.Extensions.Localization;
namespace Atomx.Admin.Client.Validators namespace Atomx.Admin.Client.Validators
{ {
public class AddressModelValidator : AbstractValidator<AddressModel> public class AddressModelValidator : AbstractValidator<AddressModel>
{ {
public AddressModelValidator() public AddressModelValidator(IStringLocalizer<AddressModelValidator> localizer)
{ {
RuleFor(p => p.Name).NotEmpty().WithMessage("请填写收件人信息"); RuleFor(p => p.Name).NotEmpty().WithMessage("请填写收件人信息");
RuleFor(p => p.Email).EmailAddress().When(p => !string.IsNullOrEmpty(p.Email)).WithMessage("请填写你常用的邮箱地址"); RuleFor(p => p.Email).EmailAddress().When(p => !string.IsNullOrEmpty(p.Email)).WithMessage("请填写你常用的邮箱地址");

View File

@@ -1,11 +1,12 @@
using Atomx.Admin.Client.Models; using Atomx.Admin.Client.Models;
using FluentValidation; using FluentValidation;
using Microsoft.Extensions.Localization;
namespace Atomx.Admin.Client.Validators namespace Atomx.Admin.Client.Validators
{ {
public class AdminModelValidator : AbstractValidator<AdminModel> public class AdminModelValidator : AbstractValidator<AdminModel>
{ {
public AdminModelValidator() public AdminModelValidator(IStringLocalizer<AdminModelValidator> localizer)
{ {
RuleFor(p => p.Username).NotEmpty().WithMessage("用户名不能为空"); RuleFor(p => p.Username).NotEmpty().WithMessage("用户名不能为空");
RuleFor(p => p.Username).Length(2, 64).When(p => !string.IsNullOrEmpty(p.Username)).WithMessage("用户名长度必须再2-64个字符之间"); RuleFor(p => p.Username).Length(2, 64).When(p => !string.IsNullOrEmpty(p.Username)).WithMessage("用户名长度必须再2-64个字符之间");

View File

@@ -1,12 +1,13 @@
using Atomx.Admin.Client.Models; using Atomx.Admin.Client.Models;
using Atomx.Common.Enums; using Atomx.Common.Enums;
using FluentValidation; using FluentValidation;
using Microsoft.Extensions.Localization;
namespace Atomx.Admin.Client.Validators namespace Atomx.Admin.Client.Validators
{ {
public class AppVersionModelValidator : AbstractValidator<AppVersionModel> public class AppVersionModelValidator : AbstractValidator<AppVersionModel>
{ {
public AppVersionModelValidator() public AppVersionModelValidator(IStringLocalizer<LoginModelValidator> localizer)
{ {
RuleFor(p => p.AppName).NotEmpty().WithMessage("应用名不能为空"); RuleFor(p => p.AppName).NotEmpty().WithMessage("应用名不能为空");
RuleFor(p => p.Title).NotEmpty().WithMessage("版本标题不能为空"); RuleFor(p => p.Title).NotEmpty().WithMessage("版本标题不能为空");

View File

@@ -0,0 +1,14 @@
using Atomx.Admin.Client.Models;
using FluentValidation;
using Microsoft.Extensions.Localization;
namespace Atomx.Admin.Client.Validators
{
public class AreaModelValidator : AbstractValidator<AreaModel>
{
public AreaModelValidator(IStringLocalizer<AreaModelValidator> localizer)
{
RuleFor(p => p.Name).NotEmpty().WithMessage("请填名称信息");
}
}
}

View File

@@ -1,12 +1,12 @@
using Atomx.Admin.Client.Models; using Atomx.Admin.Client.Models;
using Atomx.Common.Enums;
using FluentValidation; using FluentValidation;
using Microsoft.Extensions.Localization;
namespace Atomx.Admin.Client.Validators namespace Atomx.Admin.Client.Validators
{ {
public class CategoryModelValidator : AbstractValidator<CategoryModel> public class CategoryModelValidator : AbstractValidator<CategoryModel>
{ {
public CategoryModelValidator() public CategoryModelValidator(IStringLocalizer<CategoryModelValidator> localizer)
{ {
RuleFor(p => p.Name).NotEmpty().WithMessage("名称不能为空"); RuleFor(p => p.Name).NotEmpty().WithMessage("名称不能为空");
RuleFor(p => p.ParentId).Must((p,id)=> ValidateParent(id,p)).WithMessage("不能选择自己做上级分类"); RuleFor(p => p.ParentId).Must((p,id)=> ValidateParent(id,p)).WithMessage("不能选择自己做上级分类");

View File

@@ -1,11 +1,12 @@
using Atomx.Admin.Client.Models; using Atomx.Admin.Client.Models;
using FluentValidation; using FluentValidation;
using Microsoft.Extensions.Localization;
namespace Atomx.Admin.Client.Validators namespace Atomx.Admin.Client.Validators
{ {
public class CorporationModelValidator : AbstractValidator<CorporationModel> public class CorporationModelValidator : AbstractValidator<CorporationModel>
{ {
public CorporationModelValidator() public CorporationModelValidator(IStringLocalizer<CorporationModelValidator> localizer)
{ {
RuleFor(p => p.Name).NotEmpty().WithMessage("公司名称不能为空"); RuleFor(p => p.Name).NotEmpty().WithMessage("公司名称不能为空");
} }

View File

@@ -1,11 +1,12 @@
using Atomx.Admin.Client.Models; using Atomx.Admin.Client.Models;
using FluentValidation; using FluentValidation;
using Microsoft.Extensions.Localization;
namespace Atomx.Admin.Client.Validators namespace Atomx.Admin.Client.Validators
{ {
public class CorporationStaffModelValidator : AbstractValidator<CorporationStaffModel> public class CorporationStaffModelValidator : AbstractValidator<CorporationStaffModel>
{ {
public CorporationStaffModelValidator() public CorporationStaffModelValidator(IStringLocalizer<CorporationStaffModelValidator> localizer)
{ {
RuleFor(p => p.Username).NotEmpty().WithMessage("用户名不能为空"); RuleFor(p => p.Username).NotEmpty().WithMessage("用户名不能为空");
RuleFor(p => p.Username).Length(2, 64).When(p => !string.IsNullOrEmpty(p.Username)).WithMessage("用户名长度必须再2-64个字符之间"); RuleFor(p => p.Username).Length(2, 64).When(p => !string.IsNullOrEmpty(p.Username)).WithMessage("用户名长度必须再2-64个字符之间");

View File

@@ -0,0 +1,14 @@
using Atomx.Admin.Client.Models;
using FluentValidation;
using Microsoft.Extensions.Localization;
namespace Atomx.Admin.Client.Validators
{
public class CountryModelValidator : AbstractValidator<CountryModel>
{
public CountryModelValidator(IStringLocalizer<CountryModelValidator> localizer)
{
RuleFor(p => p.Name).NotEmpty().WithMessage("请填名称信息");
}
}
}

View File

@@ -1,11 +1,12 @@
using Atomx.Admin.Client.Models; using Atomx.Admin.Client.Models;
using FluentValidation; using FluentValidation;
using Microsoft.Extensions.Localization;
namespace Atomx.Admin.Client.Validators namespace Atomx.Admin.Client.Validators
{ {
public class CurrencyModelValidator : AbstractValidator<CurrencyModel> public class CurrencyModelValidator : AbstractValidator<CurrencyModel>
{ {
public CurrencyModelValidator() public CurrencyModelValidator(IStringLocalizer<CurrencyModelValidator> localizer)
{ {
RuleFor(p => p.Name).NotEmpty().WithMessage("请填写货币名称"); RuleFor(p => p.Name).NotEmpty().WithMessage("请填写货币名称");
} }

View File

@@ -1,11 +1,12 @@
using Atomx.Common.Configuration; using Atomx.Common.Configuration;
using FluentValidation; using FluentValidation;
using Microsoft.Extensions.Localization;
namespace Atomx.Admin.Client.Validators namespace Atomx.Admin.Client.Validators
{ {
public class GeneralConfigValidator : AbstractValidator<GeneralConfig> public class GeneralConfigValidator : AbstractValidator<GeneralConfig>
{ {
public GeneralConfigValidator() public GeneralConfigValidator(IStringLocalizer<GeneralConfigValidator> localizer)
{ {
RuleFor(p => p.Name).NotEmpty().WithMessage("网站名称不能为空"); RuleFor(p => p.Name).NotEmpty().WithMessage("网站名称不能为空");
} }

View File

@@ -1,11 +1,12 @@
using Atomx.Admin.Client.Models; using Atomx.Admin.Client.Models;
using FluentValidation; using FluentValidation;
using Microsoft.Extensions.Localization;
namespace Atomx.Admin.Client.Validators namespace Atomx.Admin.Client.Validators
{ {
public class LanguageModelValidator : AbstractValidator<LanguageModel> public class LanguageModelValidator : AbstractValidator<LanguageModel>
{ {
public LanguageModelValidator() public LanguageModelValidator(IStringLocalizer<LanguageModelValidator> localizer)
{ {
RuleFor(p => p.Title).NotEmpty().WithMessage("请填写语言标题"); RuleFor(p => p.Title).NotEmpty().WithMessage("请填写语言标题");
RuleFor(p => p.Name).NotEmpty().WithMessage("请填写语言名称"); RuleFor(p => p.Name).NotEmpty().WithMessage("请填写语言名称");

View File

@@ -1,11 +1,12 @@
using Atomx.Admin.Client.Models; using Atomx.Admin.Client.Models;
using FluentValidation; using FluentValidation;
using Microsoft.Extensions.Localization;
namespace Atomx.Admin.Client.Validators namespace Atomx.Admin.Client.Validators
{ {
public class LocaleResourceModelValidator : AbstractValidator<LocaleResourceModel> public class LocaleResourceModelValidator : AbstractValidator<LocaleResourceModel>
{ {
public LocaleResourceModelValidator() public LocaleResourceModelValidator(IStringLocalizer<LocaleResourceModelValidator> localizer)
{ {
RuleFor(p => p.Name).NotEmpty().WithMessage("本地化多语言信息不能为空"); RuleFor(p => p.Name).NotEmpty().WithMessage("本地化多语言信息不能为空");
} }

View File

@@ -1,25 +1,36 @@
using Atomx.Admin.Client.Models; using Atomx.Admin.Client.Models;
using FluentValidation; using FluentValidation;
using Microsoft.Extensions.Localization;
namespace Atomx.Admin.Client.Validators namespace Atomx.Admin.Client.Validators
{ {
public class LoginModelValidator : AbstractValidator<LoginModel> public class LoginModelValidator : AbstractValidator<LoginModel>
{ {
public LoginModelValidator() public LoginModelValidator(IStringLocalizer<LoginModelValidator> localizer)
{ {
RuleFor(p => p.Account).NotEmpty().WithMessage("登录账号不能为空"); // helper funcs to get localized text or fallback
RuleFor(p => p.Account).Length(2, 100).When(p => !string.IsNullOrEmpty(p.Account)).WithMessage("用户名长度必须再2-100个字符之间"); string AccountEmpty() => localizer?["Login.Account.Empty"].Value ?? "登录账号不能为空";
//RuleFor(p => p.Account).EmailAddress().When(p => !p.Account.Contains("@") && !string.IsNullOrEmpty(p.Account)).WithMessage("电子邮件地址不正确"); string AccountLength() => localizer?["Login.Account.Length"].Value ?? "用户名长度必须再2-100个字符之间";
string PasswordEmpty() => localizer?["Login.Password.Empty"].Value ?? "请输入登录密码";
string PasswordLength() => localizer?["Login.Password.Length"].Value ?? "登录密码必须在6-32位长度之间";
//RuleFor(p => p.Username).NotEmpty().WithMessage("用户名不能为空"); RuleFor(p => p.Account)
//RuleFor(p => p.Username).Length(2, 50).When(p => !string.IsNullOrEmpty(p.Username)).WithMessage("用户名长度必须再2-50个字符之间"); .NotEmpty()
//RuleFor(p => p.Account).NotEmpty().WithMessage("电子邮件地址不能为空"); .WithMessage(_ => AccountEmpty());
//RuleFor(p => p.Email).EmailAddress().When(p => !string.IsNullOrEmpty(p.Email)).WithMessage(p => localizer["Form.Email.Invalid"]);
//RuleFor(p => p.Email).MaximumLength(128).When(p => !string.IsNullOrEmpty(p.Email)).WithMessage(p => localizer["Form.Email.LengthInvalid"]); RuleFor(p => p.Account)
RuleFor(p => p.Password).NotEmpty().WithMessage("请输入登录密码"); .Length(2, 100)
RuleFor(p => p.Password).Length(6, 32).When(p => !string.IsNullOrEmpty(p.Password)).WithMessage("登录密码必须在6-32位长度之间"); .When(p => !string.IsNullOrEmpty(p.Account))
//RuleFor(p => p.ConfirmPassword).NotEmpty().WithMessage(p => localizer["Form.ConfirmPassword.Empty"]); .WithMessage(_ => AccountLength());
//RuleFor(p => p.ConfirmPassword).Equal(p => p.Password).When(p => !string.IsNullOrEmpty(p.Password) && !string.IsNullOrEmpty(p.ConfirmPassword)).WithMessage(p => localizer["Form.ConfirmPassword.Different"]);
RuleFor(p => p.Password)
.NotEmpty()
.WithMessage(_ => PasswordEmpty());
RuleFor(p => p.Password)
.Length(6, 32)
.When(p => !string.IsNullOrEmpty(p.Password))
.WithMessage(_ => PasswordLength());
} }
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) => public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>

View File

@@ -1,11 +1,12 @@
using Atomx.Admin.Client.Models; using Atomx.Admin.Client.Models;
using FluentValidation; using FluentValidation;
using Microsoft.Extensions.Localization;
namespace Atomx.Admin.Client.Validators namespace Atomx.Admin.Client.Validators
{ {
public class ManufacturerModelValidator : AbstractValidator<ManufacturerModel> public class ManufacturerModelValidator : AbstractValidator<ManufacturerModel>
{ {
public ManufacturerModelValidator() public ManufacturerModelValidator(IStringLocalizer<ManufacturerModelValidator> localizer)
{ {
RuleFor(p => p.Name).NotEmpty().WithMessage("名称不能为空"); RuleFor(p => p.Name).NotEmpty().WithMessage("名称不能为空");
} }

View File

@@ -1,13 +0,0 @@
using Atomx.Common.Entities;
using FluentValidation;
namespace Atomx.Admin.Client.Validators
{
public class MaterialBatchValidator : AbstractValidator<MaterialBatch>
{
public MaterialBatchValidator()
{
RuleFor(p => p.Price).NotEmpty().WithMessage("价格不能为空");
}
}
}

View File

@@ -1,13 +0,0 @@
using Atomx.Common.Entities;
using FluentValidation;
namespace Atomx.Admin.Client.Validators
{
public class MaterialRecordValidator : AbstractValidator<MaterialRecord>
{
public MaterialRecordValidator()
{
RuleFor(p => p.UserId).NotEmpty().WithMessage("名称不能为空");
}
}
}

View File

@@ -1,13 +0,0 @@
using Atomx.Common.Entities;
using FluentValidation;
namespace Atomx.Admin.Client.Validators
{
public class MaterialValidator : AbstractValidator<Material>
{
public MaterialValidator()
{
//RuleFor(p => p.Name).NotEmpty().WithMessage("名称不能为空");
}
}
}

View File

@@ -1,12 +1,13 @@
using Atomx.Admin.Client.Models; using Atomx.Admin.Client.Models;
using Atomx.Common.Models; using Atomx.Common.Models;
using FluentValidation; using FluentValidation;
using Microsoft.Extensions.Localization;
namespace Atomx.Admin.Client.Validators namespace Atomx.Admin.Client.Validators
{ {
public class MenuModelValidator : AbstractValidator<MenuModel> public class MenuModelValidator : AbstractValidator<MenuModel>
{ {
public MenuModelValidator() public MenuModelValidator(IStringLocalizer<MenuModelValidator> localizer)
{ {
RuleFor(p => p.Name).NotEmpty().WithMessage("名称不能为空"); RuleFor(p => p.Name).NotEmpty().WithMessage("名称不能为空");
} }

View File

@@ -1,11 +1,12 @@
using Atomx.Admin.Client.Models; using Atomx.Admin.Client.Models;
using FluentValidation; using FluentValidation;
using Microsoft.Extensions.Localization;
namespace Atomx.Admin.Client.Validators namespace Atomx.Admin.Client.Validators
{ {
public class MessageTemplateModelValidator : AbstractValidator<MessageTemplateModel> public class MessageTemplateModelValidator : AbstractValidator<MessageTemplateModel>
{ {
public MessageTemplateModelValidator() public MessageTemplateModelValidator(IStringLocalizer<MessageTemplateModelValidator> localizer)
{ {
RuleFor(p => p.Name).NotEmpty().WithMessage("消息模板名称不能为空"); RuleFor(p => p.Name).NotEmpty().WithMessage("消息模板名称不能为空");
RuleFor(p => p.Title).NotEmpty().WithMessage("消息模板标题不能为空"); RuleFor(p => p.Title).NotEmpty().WithMessage("消息模板标题不能为空");

View File

@@ -1,11 +1,12 @@
using Atomx.Admin.Client.Models; using Atomx.Admin.Client.Models;
using FluentValidation; using FluentValidation;
using Microsoft.Extensions.Localization;
namespace Atomx.Admin.Client.Validators namespace Atomx.Admin.Client.Validators
{ {
public class ProductAddStockModelValidator : AbstractValidator<ProductAddStockModel> public class ProductAddStockModelValidator : AbstractValidator<ProductAddStockModel>
{ {
public ProductAddStockModelValidator() public ProductAddStockModelValidator(IStringLocalizer<ProductAddStockModelValidator> localizer)
{ {
//RuleFor(p => p.Username).NotEmpty().WithMessage("用户名不能为空"); //RuleFor(p => p.Username).NotEmpty().WithMessage("用户名不能为空");
//RuleFor(p => p.Username).Length(2, 64).When(p => !string.IsNullOrEmpty(p.Username)).WithMessage("用户名长度必须再2-64个字符之间"); //RuleFor(p => p.Username).Length(2, 64).When(p => !string.IsNullOrEmpty(p.Username)).WithMessage("用户名长度必须再2-64个字符之间");

View File

@@ -1,11 +1,12 @@
using Atomx.Admin.Client.Models; using Atomx.Admin.Client.Models;
using FluentValidation; using FluentValidation;
using Microsoft.Extensions.Localization;
namespace Atomx.Admin.Client.Validators namespace Atomx.Admin.Client.Validators
{ {
public class ProductAttributeModelValidator : AbstractValidator<ProductAttributeModel> public class ProductAttributeModelValidator : AbstractValidator<ProductAttributeModel>
{ {
public ProductAttributeModelValidator() public ProductAttributeModelValidator(IStringLocalizer<ProductAttributeModelValidator> localizer)
{ {
RuleFor(p => p.Name).NotEmpty().WithMessage("名称不能为空"); RuleFor(p => p.Name).NotEmpty().WithMessage("名称不能为空");
RuleFor(p => p.Status).GreaterThan(0).WithMessage("请设置正确的状态"); RuleFor(p => p.Status).GreaterThan(0).WithMessage("请设置正确的状态");

View File

@@ -1,11 +1,12 @@
using Atomx.Admin.Client.Models; using Atomx.Admin.Client.Models;
using FluentValidation; using FluentValidation;
using Microsoft.Extensions.Localization;
namespace Atomx.Admin.Client.Validators namespace Atomx.Admin.Client.Validators
{ {
public class ProductAttributeOptionModelValidator : AbstractValidator<ProductAttributeOptionModel> public class ProductAttributeOptionModelValidator : AbstractValidator<ProductAttributeOptionModel>
{ {
public ProductAttributeOptionModelValidator() public ProductAttributeOptionModelValidator(IStringLocalizer<ProductAttributeOptionModelValidator> localizer)
{ {
RuleFor(p => p.Value).NotEmpty().WithMessage("数值不能为空"); RuleFor(p => p.Value).NotEmpty().WithMessage("数值不能为空");
RuleFor(p => p.Status).GreaterThan(0).WithMessage("请设置正确的状态"); RuleFor(p => p.Status).GreaterThan(0).WithMessage("请设置正确的状态");

View File

@@ -1,11 +1,12 @@
using Atomx.Admin.Client.Models; using Atomx.Admin.Client.Models;
using FluentValidation; using FluentValidation;
using Microsoft.Extensions.Localization;
namespace Atomx.Admin.Client.Validators namespace Atomx.Admin.Client.Validators
{ {
public class ProductModelValidator : AbstractValidator<ProductModel> public class ProductModelValidator : AbstractValidator<ProductModel>
{ {
public ProductModelValidator() public ProductModelValidator(IStringLocalizer<ProductModelValidator> localizer)
{ {
RuleFor(p => p.Title).NotEmpty().WithMessage("商品标题不能为空"); RuleFor(p => p.Title).NotEmpty().WithMessage("商品标题不能为空");
} }

View File

@@ -1,11 +1,12 @@
using Atomx.Admin.Client.Models; using Atomx.Admin.Client.Models;
using FluentValidation; using FluentValidation;
using Microsoft.Extensions.Localization;
namespace Atomx.Admin.Client.Validators namespace Atomx.Admin.Client.Validators
{ {
public class RoleModelValidator : AbstractValidator<RoleModel> public class RoleModelValidator : AbstractValidator<RoleModel>
{ {
public RoleModelValidator() public RoleModelValidator(IStringLocalizer<RoleModelValidator> localizer)
{ {
RuleFor(p => p.Name).NotEmpty().WithMessage("角色名称不能为空"); RuleFor(p => p.Name).NotEmpty().WithMessage("角色名称不能为空");
} }

View File

@@ -1,11 +1,12 @@
using Atomx.Common.Entities; using Atomx.Common.Entities;
using FluentValidation; using FluentValidation;
using Microsoft.Extensions.Localization;
namespace Atomx.Admin.Client.Validators namespace Atomx.Admin.Client.Validators
{ {
public class RoleValidator : AbstractValidator<Role> public class RoleValidator : AbstractValidator<Role>
{ {
public RoleValidator() public RoleValidator(IStringLocalizer<RoleValidator> localizer)
{ {
RuleFor(p => p.Name).NotEmpty().WithMessage("角色名称不能为空"); RuleFor(p => p.Name).NotEmpty().WithMessage("角色名称不能为空");
} }

View File

@@ -1,11 +1,12 @@
using Atomx.Admin.Client.Models; using Atomx.Admin.Client.Models;
using FluentValidation; using FluentValidation;
using Microsoft.Extensions.Localization;
namespace Atomx.Admin.Client.Validators namespace Atomx.Admin.Client.Validators
{ {
public class SiteAppModelValidator : AbstractValidator<SiteAppModel> public class SiteAppModelValidator : AbstractValidator<SiteAppModel>
{ {
public SiteAppModelValidator() public SiteAppModelValidator(IStringLocalizer<SiteAppModelValidator> localizer)
{ {
RuleFor(p => p.Name).NotEmpty().WithMessage("请填写网站应用名称"); RuleFor(p => p.Name).NotEmpty().WithMessage("请填写网站应用名称");
} }

View File

@@ -1,11 +1,12 @@
using Atomx.Admin.Client.Models; using Atomx.Admin.Client.Models;
using FluentValidation; using FluentValidation;
using Microsoft.Extensions.Localization;
namespace Atomx.Admin.Client.Validators namespace Atomx.Admin.Client.Validators
{ {
public class SpecificationAttributeModelValidator : AbstractValidator<SpecificationAttributeModel> public class SpecificationAttributeModelValidator : AbstractValidator<SpecificationAttributeModel>
{ {
public SpecificationAttributeModelValidator() public SpecificationAttributeModelValidator(IStringLocalizer<SpecificationAttributeModelValidator> localizer)
{ {
RuleFor(p => p.Name).NotEmpty().WithMessage("名称不能为空"); RuleFor(p => p.Name).NotEmpty().WithMessage("名称不能为空");
RuleFor(p => p.Status).GreaterThan(0).WithMessage("请设置正确的状态"); RuleFor(p => p.Status).GreaterThan(0).WithMessage("请设置正确的状态");

View File

@@ -1,11 +1,12 @@
using Atomx.Admin.Client.Models; using Atomx.Admin.Client.Models;
using FluentValidation; using FluentValidation;
using Microsoft.Extensions.Localization;
namespace Atomx.Admin.Client.Validators namespace Atomx.Admin.Client.Validators
{ {
public class SpecificationAttributeOptionModelValidator : AbstractValidator<SpecificationAttributeOptionModel> public class SpecificationAttributeOptionModelValidator : AbstractValidator<SpecificationAttributeOptionModel>
{ {
public SpecificationAttributeOptionModelValidator() public SpecificationAttributeOptionModelValidator(IStringLocalizer<SpecificationAttributeOptionModelValidator> localizer)
{ {
RuleFor(p => p.Value).NotEmpty().WithMessage("数值不能为空"); RuleFor(p => p.Value).NotEmpty().WithMessage("数值不能为空");
RuleFor(p => p.Status).GreaterThan(0).WithMessage("请设置正确的状态"); RuleFor(p => p.Status).GreaterThan(0).WithMessage("请设置正确的状态");

View File

@@ -0,0 +1,14 @@
using Atomx.Admin.Client.Models;
using FluentValidation;
using Microsoft.Extensions.Localization;
namespace Atomx.Admin.Client.Validators
{
public class StateProvinceValidator : AbstractValidator<StateProvinceModel>
{
public StateProvinceValidator(IStringLocalizer<StateProvinceValidator> localizer)
{
RuleFor(p => p.Name).NotEmpty().WithMessage("请填名称信息");
}
}
}

View File

@@ -1,11 +1,12 @@
using Atomx.Admin.Client.Models; using Atomx.Admin.Client.Models;
using FluentValidation; using FluentValidation;
using Microsoft.Extensions.Localization;
namespace Atomx.Admin.Client.Validators namespace Atomx.Admin.Client.Validators
{ {
public class UploadFileModelValidator : AbstractValidator<UploadFileModel> public class UploadFileModelValidator : AbstractValidator<UploadFileModel>
{ {
public UploadFileModelValidator() public UploadFileModelValidator(IStringLocalizer<UploadFileModelValidator> localizer)
{ {
RuleFor(p => p.Name).NotEmpty().WithMessage("文件名称不能为空"); RuleFor(p => p.Name).NotEmpty().WithMessage("文件名称不能为空");
} }

View File

@@ -1,11 +1,12 @@
using Atomx.Common.Entities; using Atomx.Common.Entities;
using FluentValidation; using FluentValidation;
using Microsoft.Extensions.Localization;
namespace Atomx.Admin.Client.Validators namespace Atomx.Admin.Client.Validators
{ {
public class UserValidator : AbstractValidator<User> public class UserValidator : AbstractValidator<User>
{ {
public UserValidator() public UserValidator(IStringLocalizer<UserValidator> localizer)
{ {
RuleFor(p => p.Name).NotEmpty().WithMessage("名称不能为空"); RuleFor(p => p.Name).NotEmpty().WithMessage("名称不能为空");
} }

View File

@@ -0,0 +1,6 @@
namespace Atomx.Admin.Client.Validators
{
public sealed class ValidatorsMarker
{
}
}

View File

@@ -1,11 +1,12 @@
using Atomx.Admin.Client.Models; using Atomx.Admin.Client.Models;
using FluentValidation; using FluentValidation;
using Microsoft.Extensions.Localization;
namespace Atomx.Admin.Client.Validators namespace Atomx.Admin.Client.Validators
{ {
public class WarehouseModelValidator : AbstractValidator<WarehouseModel> public class WarehouseModelValidator : AbstractValidator<WarehouseModel>
{ {
public WarehouseModelValidator() public WarehouseModelValidator(IStringLocalizer<WarehouseModelValidator> localizer)
{ {
RuleFor(p => p.Name).NotEmpty().WithMessage("用户名不能为空"); RuleFor(p => p.Name).NotEmpty().WithMessage("用户名不能为空");
} }

View File

@@ -1,5 +1,6 @@
@using System.Net.Http @using System.Net.Http
@using System.Net.Http.Json @using System.Net.Http.Json
@using System.Text.Json
@using System.Security.Claims @using System.Security.Claims
@using Microsoft.AspNetCore.Authorization @using Microsoft.AspNetCore.Authorization
@using Microsoft.AspNetCore.Components.Authorization @using Microsoft.AspNetCore.Components.Authorization
@@ -32,8 +33,9 @@
@using Blazored.FluentValidation @using Blazored.FluentValidation
@inject IJSRuntime JS
@inject ILocalStorageService localStorage @inject ILocalStorageService localStorage
@inject ILocalizationProvider LocalizationProvider
@inject AuthenticationStateProvider AuthStateProvider @inject AuthenticationStateProvider AuthStateProvider
@inject NavigationManager Navigation @inject NavigationManager Navigation
@inject HttpService HttpService @inject HttpService HttpService

View File

@@ -1,4 +1,4 @@
window.CookieReader = { window.cookies = {
Read: function (name) { Read: function (name) {
try { try {
const match = document.cookie.match(new RegExp('(^| )' + name + '=([^;]+)')); const match = document.cookie.match(new RegExp('(^| )' + name + '=([^;]+)'));
@@ -16,6 +16,30 @@
} }
document.cookie = name + '=' + encodeURIComponent(value) + expires + '; path=/'; document.cookie = name + '=' + encodeURIComponent(value) + expires + '; path=/';
} catch (e) { } } catch (e) { }
},
Delete: function (cookie_name) {
document.cookie = cookie_name + "=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;";
}
};
window.ajax = {
Post: async function (url, data) {
try {
const res = await fetch(url, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
credentials: 'include',
body: JSON.stringify(data)
});
const text = await res.text();
try {
return JSON.parse(text);
} catch {
return { success: res.ok, message: text };
}
} catch (err) {
return { success: false, message: err?.toString() ?? 'network error' };
}
} }
}; };
@@ -32,10 +56,3 @@ window.setHtmlLang = function (lang) {
if (document && document.documentElement) document.documentElement.lang = lang || ''; if (document && document.documentElement) document.documentElement.lang = lang || '';
} catch (e) { } } catch (e) { }
}; };
// simple cookies wrapper used earlier as cookies.Write
window.cookies = {
Write: function (name, value, expiresIso) {
return window.CookieReader.Write(name, value, expiresIso);
}
};

View File

@@ -8,30 +8,34 @@
<ItemGroup> <ItemGroup>
<Compile Remove="Resources\**" /> <Compile Remove="Resources\**" />
<Compile Remove="wwwroot\js\**" />
<Content Remove="Resources\**" /> <Content Remove="Resources\**" />
<Content Remove="wwwroot\js\**" />
<EmbeddedResource Remove="Resources\**" /> <EmbeddedResource Remove="Resources\**" />
<EmbeddedResource Remove="wwwroot\js\**" />
<None Remove="Resources\**" /> <None Remove="Resources\**" />
<None Remove="wwwroot\js\**" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\..\Atomx.Core\Atomx.Core.csproj" />
<ProjectReference Include="..\..\Atomx.Data\Atomx.Data.csproj" /> <ProjectReference Include="..\..\Atomx.Data\Atomx.Data.csproj" />
<ProjectReference Include="..\..\Atomx.Utils\Atomx.Utils.csproj" /> <ProjectReference Include="..\..\Atomx.Utils\Atomx.Utils.csproj" />
<ProjectReference Include="..\Atomx.Admin.Client\Atomx.Admin.Client.csproj" /> <ProjectReference Include="..\Atomx.Admin.Client\Atomx.Admin.Client.csproj" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="10.0.0" /> <PackageReference Include="Hangfire" Version="1.8.22" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="10.0.0" /> <PackageReference Include="Hangfire.PostgreSql" Version="1.20.13" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="10.0.0" /> <PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="10.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="10.0.0"> <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="10.0.1" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="10.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="10.0.1">
<PrivateAssets>all</PrivateAssets> <PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference> </PackageReference>
<PackageReference Include="Microsoft.Extensions.Caching.StackExchangeRedis" Version="10.0.0" /> <PackageReference Include="Microsoft.Extensions.Caching.StackExchangeRedis" Version="10.0.1" />
<PackageReference Include="Scalar.AspNetCore" Version="2.11.0" /> <PackageReference Include="Scalar.AspNetCore" Version="2.11.7" />
<PackageReference Include="Serilog.Settings.Configuration" Version="10.0.0" /> <PackageReference Include="Serilog.Settings.Configuration" Version="10.0.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="6.1.1" /> <PackageReference Include="Serilog.Sinks.Console" Version="6.1.1" />
<PackageReference Include="Serilog.Sinks.Seq" Version="9.0.0" /> <PackageReference Include="Serilog.Sinks.Seq" Version="9.0.0" />
<PackageReference Include="TickerQ" Version="10.0.1" />
<PackageReference Include="TickerQ.Dashboard" Version="10.0.1" />
<PackageReference Include="TickerQ.EntityFrameworkCore" Version="10.0.1" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
@@ -43,8 +47,4 @@
</Content> </Content>
</ItemGroup> </ItemGroup>
<ItemGroup>
<Folder Include="wwwroot\js\" />
</ItemGroup>
</Project> </Project>

View File

@@ -7,10 +7,12 @@ using Atomx.Common.Models;
using Atomx.Data; using Atomx.Data;
using Atomx.Data.CacheServices; using Atomx.Data.CacheServices;
using Atomx.Data.Services; using Atomx.Data.Services;
using FluentValidation;
using MapsterMapper; using MapsterMapper;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Localization;
namespace Atomx.Admin.Controllers namespace Atomx.Admin.Controllers
{ {
@@ -25,7 +27,8 @@ namespace Atomx.Admin.Controllers
private readonly IIdentityService _identityService; private readonly IIdentityService _identityService;
private readonly IMapper _mapper; private readonly IMapper _mapper;
private readonly ICacheService _cacheService; private readonly ICacheService _cacheService;
readonly IValidator<AddressModel> _validator;
readonly IStringLocalizer<AddressController> _localizer;
/// <summary> /// <summary>
/// ///
@@ -37,7 +40,7 @@ namespace Atomx.Admin.Controllers
/// <param name="mapper"></param> /// <param name="mapper"></param>
/// <param name="jwtSettings"></param> /// <param name="jwtSettings"></param>
/// <param name="cacheService"></param> /// <param name="cacheService"></param>
public AddressController(ILogger<AddressController> logger, IIdCreatorService idCreator, IIdentityService identityService, DataContext dbContext, IMapper mapper, ICacheService cacheService) public AddressController(ILogger<AddressController> logger, IIdCreatorService idCreator, IIdentityService identityService, DataContext dbContext, IMapper mapper, ICacheService cacheService, IValidator<AddressModel> validator, IStringLocalizer<AddressController> localizer)
{ {
_logger = logger; _logger = logger;
_idCreator = idCreator; _idCreator = idCreator;
@@ -45,6 +48,8 @@ namespace Atomx.Admin.Controllers
_dbContext = dbContext; _dbContext = dbContext;
_mapper = mapper; _mapper = mapper;
_cacheService = cacheService; _cacheService = cacheService;
_validator = validator;
_localizer = localizer;
} }
/// <summary> /// <summary>
@@ -106,8 +111,7 @@ namespace Atomx.Admin.Controllers
public IActionResult AddressEdit(AddressModel model) public IActionResult AddressEdit(AddressModel model)
{ {
var result = new ApiResult<bool>(); var result = new ApiResult<bool>();
var validator = new AddressModelValidator(); var validation = _validator.Validate(model);
var validation = validator.Validate(model);
if (!validation.IsValid) if (!validation.IsValid)
{ {
result.Message = ModelState.Values.First().Errors[0].ErrorMessage; result.Message = ModelState.Values.First().Errors[0].ErrorMessage;

View File

@@ -6,10 +6,12 @@ using Atomx.Common.Models;
using Atomx.Data; using Atomx.Data;
using Atomx.Data.Services; using Atomx.Data.Services;
using Atomx.Utils.Extension; using Atomx.Utils.Extension;
using FluentValidation;
using MapsterMapper; using MapsterMapper;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Localization;
namespace Atomx.Admin.Controllers namespace Atomx.Admin.Controllers
{ {
@@ -23,6 +25,8 @@ namespace Atomx.Admin.Controllers
readonly IIdCreatorService _idCreator; readonly IIdCreatorService _idCreator;
readonly IMapper _mapper; readonly IMapper _mapper;
readonly DataContext _dbContext; readonly DataContext _dbContext;
readonly IValidator<AdminModel> _validator;
readonly IStringLocalizer<AdminController> _localizer;
/// <summary> /// <summary>
/// ///
@@ -32,13 +36,15 @@ namespace Atomx.Admin.Controllers
/// <param name="idCreator"></param> /// <param name="idCreator"></param>
/// <param name="adminService"></param> /// <param name="adminService"></param>
/// <param name="mapper"></param> /// <param name="mapper"></param>
public AdminController(ILogger<AdminController> logger, IIdentityService identityService, IIdCreatorService idCreator, IMapper mapper, DataContext dataContext) public AdminController(ILogger<AdminController> logger, IIdentityService identityService, IIdCreatorService idCreator, IMapper mapper, DataContext dataContext, IValidator<AdminModel> validator, IStringLocalizer<AdminController> localizer)
{ {
_logger = logger; _logger = logger;
_identityService = identityService; _identityService = identityService;
_idCreator = idCreator; _idCreator = idCreator;
_mapper = mapper; _mapper = mapper;
_dbContext = dataContext; _dbContext = dataContext;
_validator = validator;
_localizer = localizer;
} }
/// <summary> /// <summary>
@@ -158,8 +164,7 @@ namespace Atomx.Admin.Controllers
public IActionResult Add(AdminModel model) public IActionResult Add(AdminModel model)
{ {
var result = new ApiResult<string>(); var result = new ApiResult<string>();
var validator = new AdminModelValidator(); var validation = _validator.Validate(model);
var validation = validator.Validate(model);
if (!validation.IsValid) if (!validation.IsValid)
{ {
var message = validation.Errors.FirstOrDefault()?.ErrorMessage ?? string.Empty; var message = validation.Errors.FirstOrDefault()?.ErrorMessage ?? string.Empty;
@@ -211,8 +216,7 @@ namespace Atomx.Admin.Controllers
public IActionResult Edit(AdminModel model) public IActionResult Edit(AdminModel model)
{ {
var result = new ApiResult<string>(); var result = new ApiResult<string>();
var validator = new AdminModelValidator(); var validation = _validator.Validate(model);
var validation = validator.Validate(model);
if (!validation.IsValid) if (!validation.IsValid)
{ {
var message = validation.Errors.FirstOrDefault()?.ErrorMessage; var message = validation.Errors.FirstOrDefault()?.ErrorMessage;

View File

@@ -1,19 +1,22 @@
using Atomx.Admin.Client.Models; using Atomx.Admin.Client.Models;
using Atomx.Admin.Client.Validators;
using Atomx.Admin.Services; using Atomx.Admin.Services;
using Atomx.Common.Entities; using Atomx.Common.Entities;
using Atomx.Common.Models; using Atomx.Common.Models;
using Atomx.Data; using Atomx.Data;
using Atomx.Data.Services; using Atomx.Data.Services;
using Atomx.Utils.Extension; using Atomx.Utils.Extension;
using FluentValidation;
using MapsterMapper; using MapsterMapper;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Localization;
namespace Atomx.Admin.Controllers namespace Atomx.Admin.Controllers
{ {
[Route("api/[controller]")] [Route("api/[controller]")]
[ApiController] [ApiController]
[Authorize]
public class AppVersionController : ControllerBase public class AppVersionController : ControllerBase
{ {
readonly ILogger<AppVersionController> _logger; readonly ILogger<AppVersionController> _logger;
@@ -21,6 +24,8 @@ namespace Atomx.Admin.Controllers
readonly IIdCreatorService _idCreator; readonly IIdCreatorService _idCreator;
readonly IMapper _mapper; readonly IMapper _mapper;
readonly DataContext _dbContext; readonly DataContext _dbContext;
readonly IValidator<AppVersionModel> _validator;
readonly IStringLocalizer<AppVersionController> _localizer;
/// <summary> /// <summary>
/// ///
@@ -30,13 +35,16 @@ namespace Atomx.Admin.Controllers
/// <param name="idCreator"></param> /// <param name="idCreator"></param>
/// <param name="adminService"></param> /// <param name="adminService"></param>
/// <param name="mapper"></param> /// <param name="mapper"></param>
public AppVersionController(ILogger<AppVersionController> logger, IIdentityService identityService, IIdCreatorService idCreator, IMapper mapper, DataContext dataContext) public AppVersionController(ILogger<AppVersionController> logger, IIdentityService identityService, IIdCreatorService idCreator,
IMapper mapper, DataContext dataContext, IValidator<AppVersionModel> validator, IStringLocalizer<AppVersionController> stringLocalizer)
{ {
_logger = logger; _logger = logger;
_identityService = identityService; _identityService = identityService;
_idCreator = idCreator; _idCreator = idCreator;
_mapper = mapper; _mapper = mapper;
_dbContext = dataContext; _dbContext = dataContext;
_validator = validator;
_localizer = stringLocalizer;
} }
/// <summary> /// <summary>
@@ -81,6 +89,13 @@ namespace Atomx.Admin.Controllers
where p.AppName.Contains(search.Name) where p.AppName.Contains(search.Name)
select p; select p;
} }
if (!string.IsNullOrEmpty(search.Status))
{
var status = search.Status.ToInt();
query = from p in query
where p.Status == status
select p;
}
if (search.StartTime.HasValue) if (search.StartTime.HasValue)
{ {
query = from p in query query = from p in query
@@ -138,8 +153,7 @@ namespace Atomx.Admin.Controllers
public IActionResult Add(AppVersionModel model) public IActionResult Add(AppVersionModel model)
{ {
var result = new ApiResult<string>(); var result = new ApiResult<string>();
var validator = new AppVersionModelValidator(); var validation = _validator.Validate(model);
var validation = validator.Validate(model);
if (!validation.IsValid) if (!validation.IsValid)
{ {
var message = validation.Errors.FirstOrDefault()?.ErrorMessage ?? string.Empty; var message = validation.Errors.FirstOrDefault()?.ErrorMessage ?? string.Empty;
@@ -174,8 +188,7 @@ namespace Atomx.Admin.Controllers
public IActionResult Edit(AppVersionModel model) public IActionResult Edit(AppVersionModel model)
{ {
var result = new ApiResult<string>(); var result = new ApiResult<string>();
var validator = new AppVersionModelValidator(); var validation = _validator.Validate(model);
var validation = validator.Validate(model);
if (!validation.IsValid) if (!validation.IsValid)
{ {
var message = validation.Errors.FirstOrDefault()?.ErrorMessage; var message = validation.Errors.FirstOrDefault()?.ErrorMessage;

View File

@@ -1,10 +1,17 @@
using Atomx.Admin.Services; using Atomx.Admin.Client.Models;
using Atomx.Admin.Services;
using Atomx.Common.Constants;
using Atomx.Common.Entities;
using Atomx.Common.Models;
using Atomx.Data; using Atomx.Data;
using Atomx.Data.CacheServices; using Atomx.Data.CacheServices;
using Atomx.Data.Services; using Atomx.Data.Services;
using FluentValidation;
using MapsterMapper; using MapsterMapper;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Localization;
namespace Atomx.Admin.Controllers namespace Atomx.Admin.Controllers
{ {
@@ -13,6 +20,7 @@ namespace Atomx.Admin.Controllers
/// </summary> /// </summary>
[Route("api/[controller]")] [Route("api/[controller]")]
[ApiController] [ApiController]
[Authorize]
public class AreaController : ControllerBase public class AreaController : ControllerBase
{ {
private readonly ILogger<AreaController> _logger; private readonly ILogger<AreaController> _logger;
@@ -21,7 +29,8 @@ namespace Atomx.Admin.Controllers
private readonly IIdentityService _identityService; private readonly IIdentityService _identityService;
private readonly IMapper _mapper; private readonly IMapper _mapper;
private readonly ICacheService _cacheService; private readonly ICacheService _cacheService;
readonly IValidator<AreaModel> _validator;
readonly IStringLocalizer<AreaController> _localizer;
/// <summary> /// <summary>
/// ///
@@ -33,7 +42,7 @@ namespace Atomx.Admin.Controllers
/// <param name="mapper"></param> /// <param name="mapper"></param>
/// <param name="jwtSettings"></param> /// <param name="jwtSettings"></param>
/// <param name="cacheService"></param> /// <param name="cacheService"></param>
public AreaController(ILogger<AreaController> logger, IIdCreatorService idCreator, IIdentityService identityService, DataContext dbContext, IMapper mapper, ICacheService cacheService) public AreaController(ILogger<AreaController> logger, IIdCreatorService idCreator, IIdentityService identityService, DataContext dbContext, IMapper mapper, ICacheService cacheService, IValidator<AreaModel> validator, IStringLocalizer<AreaController> localizer)
{ {
_logger = logger; _logger = logger;
_idCreator = idCreator; _idCreator = idCreator;
@@ -41,6 +50,168 @@ namespace Atomx.Admin.Controllers
_dbContext = dbContext; _dbContext = dbContext;
_mapper = mapper; _mapper = mapper;
_cacheService = cacheService; _cacheService = cacheService;
_validator = validator;
_localizer = localizer;
}
/// <summary>
/// 数据查询
/// </summary>
/// <param name="search"></param>
/// <param name="page"></param>
/// <param name="size"></param>
/// <returns></returns>
[HttpPost("search")]
[Authorize(Policy = Permissions.User.View)]
public IActionResult AddressList(AreaSearch search, int page, int size = 20)
{
if (page < 1)
{
page = 1;
}
var result = new ApiResult<PagingList<Area>>();
var list = new PagingList<Area>() { Index = page, Size = size };
var query = from p in _dbContext.Areas
select p;
if (!string.IsNullOrEmpty(search.Name))
{
query = from p in query
where p.Name.Contains(search.Name)
select p;
}
if (search.CountryId > 0)
{
query = from p in query
where p.CountryId == search.CountryId
select p;
}
if (search.StateProvinceId > 0)
{
query = from p in query
where p.StateProvinceId == search.StateProvinceId
select p;
}
list.Count = query.Count();
list.Items = query.OrderByDescending(p => p.DisplayOrder).Skip((page - 1) * size).Take(size).ToList();
result = result.IsSuccess(list);
return new JsonResult(result);
}
/// <summary>
/// 通过ID获取数据
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[HttpGet("{id:long}")]
public IActionResult Get(long id)
{
var result = new ApiResult<Area>();
var data = _dbContext.Areas.SingleOrDefault(p => p.Id == id);
if (data == null)
{
return new JsonResult(new ApiResult<string>().IsFail("数据不存在", null));
}
result = result.IsSuccess(data);
return new JsonResult(result);
}
/// <summary>
/// 通过ID获取详情,含多语言
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[HttpGet("detail")]
public IActionResult Detail(long id)
{
var result = new ApiResult<AreaLocalizedModel>();
var data = _dbContext.Areas.SingleOrDefault(p => p.Id == id);
if (data == null)
{
return new JsonResult(new ApiResult<string>().IsFail("数据不存在", null));
}
var localizedList = _dbContext.LocalizedProperties.Where(p => p.EntityId == id).ToList();
var model = _mapper.Map<AreaLocalizedModel>(data);
model.Locales = localizedList;
result = result.IsSuccess(model);
return new JsonResult(result);
}
/// <summary>
/// 新增编辑数据
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
[HttpPost("save")]
public IActionResult AddressEdit(AreaModel model)
{
var result = new ApiResult<bool>();
var validation = _validator.Validate(model);
if (!validation.IsValid)
{
var message = validation.Errors.FirstOrDefault()?.ErrorMessage ?? string.Empty;
return new JsonResult(new ApiResult<string>().IsFail(message, null));
}
var data = _dbContext.Areas.SingleOrDefault(p => p.CountryId == model.CountryId && p.StateProvinceId == model.StateProvinceId && p.Name == model.Name && p.Id != model.Id);
if (data != null)
{
return new JsonResult(new ApiResult<string>().IsFail("当前站点语言下已经存在这个配置,请认真检查", null));
}
if (model.Id > 0)
{
data = _dbContext.Areas.SingleOrDefault(p => p.Id == model.Id);
if (data == null)
{
return new JsonResult(new ApiResult<string>().IsFail("数据不存在", null));
}
data = _mapper.Map(model, data);
_dbContext.SaveChanges();
}
else
{
data = _mapper.Map<Area>(model);
data.Id = _idCreator.CreateId();
_dbContext.Areas.Add(data);
_dbContext.SaveChanges();
}
return new JsonResult(new ApiResult<string>().IsSuccess("操作成功"));
}
/// <summary>
/// 删除数据
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
[HttpPost("delete")]
public async Task<IActionResult> DeleteAsync(long id)
{
var result = new ApiResult<string>();
try
{
Console.WriteLine($"{id} deleted");
var count = _dbContext.Areas.Where(p => p.Id == id).ExecuteDelete();
result = result.IsSuccess(count.ToString());
}
catch (Exception ex)
{
result = result.IsFail(ex.Message);
_logger.LogError(ex.Message);
}
return new JsonResult(result);
} }
} }

View File

@@ -1,13 +1,14 @@
using Atomx.Admin.Client.Models; using Atomx.Admin.Client.Models;
using Atomx.Admin.Client.Validators;
using Atomx.Admin.Services; using Atomx.Admin.Services;
using Atomx.Common.Entities; using Atomx.Common.Entities;
using Atomx.Common.Models; using Atomx.Common.Models;
using Atomx.Data; using Atomx.Data;
using Atomx.Data.CacheServices; using Atomx.Data.CacheServices;
using Atomx.Data.Services; using Atomx.Data.Services;
using FluentValidation;
using MapsterMapper; using MapsterMapper;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Localization;
namespace Atomx.Admin.Controllers namespace Atomx.Admin.Controllers
{ {
@@ -22,8 +23,10 @@ namespace Atomx.Admin.Controllers
readonly DataContext _dbContext; readonly DataContext _dbContext;
readonly JwtSetting _jwtSetting; readonly JwtSetting _jwtSetting;
readonly ICacheService _cacheService; readonly ICacheService _cacheService;
readonly IValidator<CategoryModel> _validator;
readonly IStringLocalizer<CategoryController> _localizer;
public CategoryController(ILogger<CategoryController> logger, IIdentityService identityService, IIdCreatorService idCreator, IMapper mapper, DataContext dbContext, JwtSetting jwtSetting, ICacheService cacheService) public CategoryController(ILogger<CategoryController> logger, IIdentityService identityService, IIdCreatorService idCreator, IMapper mapper, DataContext dbContext, JwtSetting jwtSetting, ICacheService cacheService, IValidator<CategoryModel> validator, IStringLocalizer<CategoryController> localizer)
{ {
_logger = logger; _logger = logger;
_identityService = identityService; _identityService = identityService;
@@ -32,6 +35,8 @@ namespace Atomx.Admin.Controllers
_dbContext = dbContext; _dbContext = dbContext;
_jwtSetting = jwtSetting; _jwtSetting = jwtSetting;
_cacheService = cacheService; _cacheService = cacheService;
_validator = validator;
_localizer = localizer;
} }
/// <summary> /// <summary>
@@ -148,8 +153,7 @@ namespace Atomx.Admin.Controllers
public IActionResult Add(CategoryModel model) public IActionResult Add(CategoryModel model)
{ {
var result = new ApiResult<string>(); var result = new ApiResult<string>();
var validator = new CategoryModelValidator(); var validation = _validator.Validate(model);
var validation = validator.Validate(model);
if (!validation.IsValid) if (!validation.IsValid)
{ {
var message = validation.Errors.FirstOrDefault()?.ErrorMessage; var message = validation.Errors.FirstOrDefault()?.ErrorMessage;
@@ -197,8 +201,7 @@ namespace Atomx.Admin.Controllers
public IActionResult Edit(CategoryModel model) public IActionResult Edit(CategoryModel model)
{ {
var result = new ApiResult<string>(); var result = new ApiResult<string>();
var validator = new CategoryModelValidator(); var validation = _validator.Validate(model);
var validation = validator.Validate(model);
if (!validation.IsValid) if (!validation.IsValid)
{ {
var message = validation.Errors.FirstOrDefault()?.ErrorMessage; var message = validation.Errors.FirstOrDefault()?.ErrorMessage;

Some files were not shown because too many files have changed in this diff Show More