添加项目文件。

This commit is contained in:
2025-12-02 13:10:10 +08:00
parent 93a2382a16
commit 289aa4cbe7
400 changed files with 91177 additions and 0 deletions

View File

@@ -0,0 +1,347 @@
@page "/admin/list"
@inject ILogger<AdminList> Logger
@* @attribute [Authorize] *@
<PageTitle>管理员账号管理</PageTitle>
<Title Level="4">管理员帐号</Title>
<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.Username" Placeholder="帐号" AllowClear />
</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="OnSearchReset">重置</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>
<AuthorizeView Policy="@Permissions.Admin.Edit">
<Authorized>
<Button Class="me-3" OnClick="OnCreateClick" Type="ButtonType.Primary">新增</Button>
</Authorized>
<NotAuthorized>
没有权限
</NotAuthorized>
</AuthorizeView>
</div>
</Flex>
</TitleTemplate>
<ColumnDefinitions>
<PropertyColumn Property="c => c.Username" Title="帐号">
</PropertyColumn>
<PropertyColumn Property="c => c.Email" Title="邮件" Width="80px" Align="ColumnAlign.Center">
</PropertyColumn>
<PropertyColumn Property="c => c.Mobile" Title="手机号" Width="100px" />
<PropertyColumn Property="c => c.Status" Title="状态" Width="80px" Align="ColumnAlign.Center">
@if (context.Status == 1)
{
<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.LastLogin" Title="最后登录" Width="190px" />
<PropertyColumn Property="c => c.UpdateTime" Title="最后更新" Width="190px" />
<ActionColumn Title="操作" Align="ColumnAlign.Right" Width="160px">
<Space>
<SpaceItem>
<Dropdown Trigger="@(new Trigger[] { Trigger.Click })">
<Overlay>
<Menu>
<MenuItem>
<a @onclick="(e) => OnEditClick(context)"> <Icon Type="@IconType.Outline.Edit" /> 编辑</a>
</MenuItem>
<MenuDivider />
<MenuItem>
<Popconfirm Placement="@Placement.Left" Title="@("删除这条数据无法恢复,您确定要删除吗?")"
OnConfirm="@(e=>HandleDeleteConfirmAsync(e,context.Id))"
OkText="确定"
CancelText="取消">
<a> <Icon Type="@IconType.Outline.Delete" /> 删除</a>
</Popconfirm>
</MenuItem>
</Menu>
</Overlay>
<ChildContent>
<a class="ant-dropdown-link" @onclick:preventDefault>
<Icon Type="@IconType.Outline.Menu" />
</a>
</ChildContent>
</Dropdown>
</SpaceItem>
</Space>
</ActionColumn>
</ColumnDefinitions>
</Table>
</Card>
<Drawer Closable="true" Width="520" Visible="drawerVisible" Title='(model.Id == 0 ? "新增帐号" : "编辑帐号")' OnClose="_ => CloseDrawer()">
<Form LabelColSpan="5" @ref="@editform" Model="@model" OnFinish="OnFormFinish">
<FluentValidationValidator />
<FormItem Label="帐号名称">
<Input @bind-Value="model.Username" For="(()=>model.Username)" Placeholder="帐号名称" />
</FormItem>
<FormItem Label="电子邮件">
<Input @bind-Value="model.Email" For="(()=>model.Email)" Placeholder="电子邮件" />
</FormItem>
<FormItem Label="手机号码">
<Input @bind-Value="model.Mobile" For="(()=>model.Mobile)" Placeholder="手机号码" />
</FormItem>
@if (context.Id > 0)
{
<FormItem Label="密码设置">
<Checkbox @bind-Value="@context.SetPassword" Disabled=false>
重置密码
</Checkbox>
</FormItem>
}
@if (context.Id == 0)
{
<FormItem Label="登录密码">
<Input @bind-Value="@context.Password" Placeholder="登录密码" />
</FormItem>
}
@if ((context.Id > 0 && context.SetPassword) || context.Id == 0)
{
<FormItem Label="新密码">
<Input @bind-Value="@context.NewPassword" Placeholder="新登录密码" />
</FormItem>
}
@if ((context.Id > 0 && context.SetPassword) || context.Id == 0)
{
<FormItem Label="确认密码">
<Input @bind-Value="@context.RePassword" Placeholder="确认密码" />
</FormItem>
}
<FormItem Label="可用状态">
<RadioGroup @bind-Value="@context.Status">
<Radio RadioButton Value=0>禁用</Radio>
<Radio RadioButton Value=1>启用</Radio>
</RadioGroup>
</FormItem>
<FormItem WrapperColOffset="4">
<Button Type="ButtonType.Primary" HtmlType="submit" Style="width: 100%;">保存</Button>
</FormItem>
</Form>
</Drawer>
@code {
[SupplyParameterFromQuery]
int? Page { get; set; }
[SupplyParameterFromQuery(Name = "size")]
int? PageSize { get; set; }
[SupplyParameterFromForm]
AdminSearch search { get; set; } = new();
Form<AdminSearch> searchForm = null!;
[SupplyParameterFromForm]
AdminModel model { get; set; } = new();
Form<AdminModel> editform = null!;
PagingList<Admin> 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.Username = query.GetQueryString("Username");
search.Mobile = query.GetQueryString("Mobile");
search.Email = query.GetQueryString("Email");
search.RealName = query.GetQueryString("RealName");
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 void LoadList()
{
loading = true;
var url = "/api/admin/search";
var apiResult = await HttpService.GetPagingList<Admin>(url, search, Page.GetValueOrDefault(1), PageSize.GetValueOrDefault(20));
if (apiResult.Success)
{
if (apiResult.Data != null)
{
PagingList = apiResult.Data;
}
}
loading = false;
StateHasChanged();
}
private void OnReset()
{
search = new();
LoadList();
}
void OnSearchReset()
{
search = new();
searchForm?.Reset();
OnSearchFinish();
}
void OnSearchFinish()
{
Page = Page.GetValueOrDefault(1) - 1;
OnSearch(Page.Value);
}
private void OnSearch(int page)
{
var queryString = search.BuildQueryString();
if (string.IsNullOrEmpty(queryString))
{
if (page > 1)
{
Navigation.NavigateTo($"/admin/list?page={page}");
}
else
{
Navigation.NavigateTo($"/admin/list");
}
}
else
{
if (page > 1)
{
Navigation.NavigateTo($"/admin/list?page={page}&{queryString}");
}
else
{
Navigation.NavigateTo($"/admin/list?{queryString}");
}
}
}
void OnCreateClick()
{
model = new();
drawerVisible = true;
}
void OnEditClick(Admin admin)
{
this.model = admin.Adapt<AdminModel>();
this.model.Password = string.Empty;
drawerVisible = true;
}
async Task HandleDeleteConfirmAsync(MouseEventArgs e, long id)
{
var url = $"/api/admin/delete/{id}";
var apiResult = await HttpService.Post<ApiResult<string>>(url, new());
if (apiResult.Success)
{
LoadList();
await ModalService.InfoAsync(new ConfirmOptions() { Title = "操作提示", Content = "删除数据成功" });
}
else
{
await ModalService.ErrorAsync(new ConfirmOptions() { Title = "操作提示", Content = $"数据删除失败.{apiResult.Message}" });
}
}
async Task OnFormFinish()
{
if (editform.Validate())
{
var result = new ApiResult<string>();
if (model.Id > 0)
{
var url = $"api/admin/edit";
result = await HttpService.Post<ApiResult<string>>(url, model);
}
else
{
var url = $"api/admin/add";
result = await HttpService.Post<ApiResult<string>>(url, model);
}
if (result.Code == (int)ResultCode.Success)
{
CloseDrawer();
LoadList();
await ModalService.InfoAsync(new ConfirmOptions() { Title = "提示", Content = "数据提交成功!" });
}
else
{
await ModalService.ErrorAsync(new ConfirmOptions() { Title = "服务异常", Content = result.Message });
}
}
}
private void OnPageChanged(int args)
{
OnSearch(args);
}
void CloseDrawer()
{
drawerVisible = false;
editform.Reset();
}
}

View File

@@ -0,0 +1,7 @@
@page "/system/currency/list"
<h3>CurrencyList</h3>
@code {
}

View File

@@ -0,0 +1,238 @@
@page "/system/language/list"
@inject ILogger<LanguageList> Logger
<PageTitle>语言管理</PageTitle>
<Title Level="4">多语言</Title>
<Card Class="mt-3">
<Table DataSource="PagingList.Items" PageSize="100" HidePagination="true" Resizable>
<TitleTemplate>
<Flex Justify="FlexJustify.SpaceBetween">
多语言列表
<div>
<Button Class="me-3" OnClick="OnCreateClick" Type="ButtonType.Primary">新增</Button>
</div>
</Flex>
</TitleTemplate>
<ColumnDefinitions>
<PropertyColumn Property="c => c.Name" Title="帐号">
</PropertyColumn>
<PropertyColumn Property="c => c.Title" Title="邮件" Width="80px" Align="ColumnAlign.Center">
</PropertyColumn>
<PropertyColumn Property="c => c.Culture" Title="手机号" Width="100px" />
<PropertyColumn Property="c => c.Enabled" Title="状态" Width="80px" Align="ColumnAlign.Center">
@if (context.Enabled)
{
<AntDesign.Text Type="TextElementType.Success"><Icon Type="check" Theme=" IconThemeType.Outline" Width="1.3em" Height="1.3em" /></AntDesign.Text>
}
else
{
<Icon Type="close" Theme="IconThemeType.Outline" Width="1.3em" Height="1.3em" />
}
</PropertyColumn>
<PropertyColumn Property="c => c.ResourceVersion" Title="最后登录" Width="190px" />
<PropertyColumn Property="c => c.UpdateTime" Title="最后更新" Width="190px" />
<ActionColumn Title="操作" Align="ColumnAlign.Right" Width="160px">
<Space>
<SpaceItem>
<Dropdown Trigger="@(new Trigger[] { Trigger.Click })">
<Overlay>
<Menu>
<MenuItem>
<a @onclick="(e) => OnEditClick(context)"> <Icon Type="@IconType.Outline.Edit" /> 编辑</a>
</MenuItem>
<MenuDivider />
<MenuItem>
<Popconfirm Placement="@Placement.Left" Title="@("删除这条数据无法恢复,您确定要删除吗?")"
OnConfirm="@(e=>HandleDeleteConfirmAsync(e,context.Id))"
OkText="确定"
CancelText="取消">
<a> <Icon Type="@IconType.Outline.Delete" /> 删除</a>
</Popconfirm>
</MenuItem>
</Menu>
</Overlay>
<ChildContent>
<a class="ant-dropdown-link" @onclick:preventDefault>
<Icon Type="@IconType.Outline.Menu" />
</a>
</ChildContent>
</Dropdown>
</SpaceItem>
</Space>
</ActionColumn>
</ColumnDefinitions>
</Table>
</Card>
<Drawer Closable="true" Width="520" Visible="drawerVisible" Title='(model.Id == 0 ? "新增帐号" : "编辑帐号")' OnClose="_ => CloseDrawer()">
<Form LabelColSpan="5" @ref="@editform" Model="@model" OnFinish="OnFormFinish">
<FluentValidationValidator />
<FormItem Label="语言名称">
<Input @bind-Value="model.Name" For="(()=>model.Name)" Placeholder="语言名称" />
</FormItem>
<FormItem Label="语言标题">
<Input @bind-Value="model.Culture" For="(()=>model.Culture)" Placeholder="语言标题" />
</FormItem>
<FormItem Label="手机号码">
<Input @bind-Value="model.FlagImage" For="(()=>model.FlagImage)" Placeholder="手机号码" />
</FormItem>
@* <FormItem Label="可用状态">
<Checkbox T="bool" Label="启用" @bind-value="model.Enabled" Size="InputSize.Small" Class="ps-0" />
</FormItem> *@
<FormItem WrapperColOffset="4">
<Button Type="ButtonType.Primary" HtmlType="submit" Style="width: 100%;">保存</Button>
</FormItem>
</Form>
</Drawer>
@code {
[SupplyParameterFromQuery]
int? Page { get; set; }
[SupplyParameterFromQuery(Name = "size")]
int? PageSize { get; set; }
[SupplyParameterFromForm]
LanguageSearch search { get; set; } = new();
[SupplyParameterFromForm]
LanguageModel model { get; set; } = new();
Form<LanguageModel> editform = null!;
PagingList<Language> PagingList = new();
bool loading { get; set; } = true;
bool drawerVisible;
protected override void OnInitialized()
{
base.OnInitialized();
}
protected override void OnParametersSet()
{
LoadList();
base.OnParametersSet();
}
private async void LoadList()
{
loading = true;
var url = "/api/language/search";
var apiResult = await HttpService.GetPagingList<Language>(url, search, Page.GetValueOrDefault(1), PageSize.GetValueOrDefault(20));
if (apiResult.Success)
{
if (apiResult.Data != null)
{
PagingList = apiResult.Data;
}
}
loading = false;
StateHasChanged();
}
private void OnSearch(int page)
{
var queryString = search.BuildQueryString();
if (string.IsNullOrEmpty(queryString))
{
if (page > 1)
{
Navigation.NavigateTo($"/system/language/list?page={page}");
}
else
{
Navigation.NavigateTo($"/system/language/list");
}
}
else
{
if (page > 1)
{
Navigation.NavigateTo($"/system/language/list?page={page}&{queryString}");
}
else
{
Navigation.NavigateTo($"/system/language/list?{queryString}");
}
}
}
void OnCreateClick()
{
model = new();
drawerVisible = true;
}
void OnEditClick(Language admin)
{
this.model = admin.Adapt<LanguageModel>();
drawerVisible = true;
}
async Task HandleDeleteConfirmAsync(MouseEventArgs e, long id)
{
var url = $"/api/language/delete/{id}";
var apiResult = await HttpService.Post<ApiResult<string>>(url, new());
if (apiResult.Success)
{
LoadList();
await ModalService.InfoAsync(new ConfirmOptions() { Title = "操作提示", Content = "删除数据成功" });
}
else
{
await ModalService.ErrorAsync(new ConfirmOptions() { Title = "操作提示", Content = $"数据删除失败.{apiResult.Message}" });
}
}
async Task OnFormFinish()
{
if (editform.Validate())
{
var result = new ApiResult<string>();
if (model.Id > 0)
{
var url = $"api/language/edit";
result = await HttpService.Post<ApiResult<string>>(url, model);
}
else
{
var url = $"api/language/add";
result = await HttpService.Post<ApiResult<string>>(url, model);
}
if (result.Code == (int)ResultCode.Success)
{
CloseDrawer();
LoadList();
await ModalService.InfoAsync(new ConfirmOptions() { Title = "提示", Content = "数据提交成功!" });
}
else
{
await ModalService.ErrorAsync(new ConfirmOptions() { Title = "服务异常", Content = result.Message });
}
}
}
private void OnPageChanged(int args)
{
OnSearch(args);
}
void CloseDrawer()
{
drawerVisible = false;
editform.Reset();
}
}

View File

@@ -0,0 +1,6 @@
@page "/system/locale/resource/list/{culture}"
@inject ILogger<LocaleResourceList> Logger
@code {
}

View File

@@ -0,0 +1,350 @@
@page "/system/menu/list"
@inject ILogger<MenuList> Logger
@using MenuItem = Atomx.Admin.Client.Models.MenuItem
@using Menu = Atomx.Common.Entities.Menu
@* @attribute [Authorize] *@
<PageTitle>菜单管理</PageTitle>
<Title Level="4">菜单管理</Title>
<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" style="width:200px;display:flex;">
<Button Type="ButtonType.Primary" HtmlType="submit">查询</Button>
<Button Style="margin: 0 8px;" OnClick="OnSearchReset">重置</Button>
</div>
</Col>
</Row>
</Form>
</Card>
<Card Class="mt-3">
<Table DataSource="Menus" PageSize="100" HidePagination="true" Resizable>
<TitleTemplate>
<Flex Justify="FlexJustify.SpaceBetween">
菜单列表
<div>
<Button Class="me-3" OnClick="OnCreateClick" Type="ButtonType.Primary">新增</Button>
</div>
</Flex>
</TitleTemplate>
<ColumnDefinitions>
<PropertyColumn Property="c=>c.Name" Title="名称">
<AntDesign.Text>@GetName(context)</AntDesign.Text>
</PropertyColumn>
<PropertyColumn Property="c=>c.Icon" Title="图标" Width="60px" Align="ColumnAlign.Center">
@if (!string.IsNullOrEmpty(context.Icon)) {
<Icon Type="@context.Icon" Theme="IconThemeType.Outline" Width="1.3em" Height="1.3em" />
}
</PropertyColumn>
<PropertyColumn Property="c=>c.Key" Title="分组标识" Ellipsis/>
<PropertyColumn Property="c=>c.Url" Title="链接" />
<PropertyColumn Property="c=>c.DisplayOrder" Title="排序" Width="80px" Align="ColumnAlign.Center" />
<PropertyColumn Property="c=>c.Enabled" Title="状态" Width="80px" Align="ColumnAlign.Center">
@if (context.Enabled)
{
<AntDesign.Text Type="TextElementType.Success"><Icon Type="check" Theme=" IconThemeType.Outline" Width="1.3em" Height="1.3em" /></AntDesign.Text>
}
else
{
<Icon Type="close" Theme="IconThemeType.Outline" Width="1.3em" Height="1.3em" />
}
</PropertyColumn>
<PropertyColumn Property="c=>c.CreateTime" Title="时间" Width="150px" />
<ActionColumn Title="操作" Align="ColumnAlign.Right" Width="120px">
<Space>
<SpaceItem>
<a @onclick="(e)=>OnEditClick(context)">编辑</a>
</SpaceItem>
<SpaceItem>
<Popconfirm Placement="@Placement.Left" Title="@("删除这条数据无法恢复,您确定要删除吗?")"
OnConfirm="@(e=>HandleDeleteConfirmAsync(e,context.Id))"
OkText="确定"
CancelText="取消">
<a>删除</a>
</Popconfirm>
</SpaceItem>
</Space>
</ActionColumn>
</ColumnDefinitions>
</Table>
</Card>
<Drawer Closable="true" Width="520" Visible="drawerVisible" Title='("设置菜单")' OnClose="_=>CloseDrawer()">
<Form LabelColSpan="4" @ref="@editform" Model="@menu" Class="px-5" OnFinish="OnFormFinish">
<FluentValidationValidator />
<FormItem Label="名称">
<Input @bind-Value="menu.Name" For="(()=>menu.Name)" />
</FormItem>
<FormItem Label="分组标识">
<Input @bind-Value="menu.Key" For="(()=>menu.Key)" />
</FormItem>
<FormItem Label="链接">
<Input @bind-Value="menu.Url" For="(()=>menu.Url)" />
</FormItem>
<FormItem Label="上级分类">
<Select @bind-Value="@menu.ParentId" TItemValue="long" TItem="string" Placeholder="请选择上级分类">
<SelectOptions>
<SelectOption Value="0L" Label="无" />
@foreach(var item in Menus)
{
<SelectOption Value="@item.Id" Label="@GetName(item)" />
}
</SelectOptions>
</Select>
</FormItem>
@if (menu.ParentId == 0)
{
<FormItem Label="图标">
<Select ItemValue="c=>c"
ItemLabel="c=>c"
DataSource="IconsExtension.IconList()"
@bind-Value="@menu.Icon">
<ItemTemplate Context="Icon">
<p class="mt-2"><Icon Type="@Icon" /> @Icon</p>
</ItemTemplate>
<LabelTemplate Context="Icon">
<p class="mt-1"><Icon Type="@Icon" /> @Icon</p>
</LabelTemplate>
</Select>
</FormItem>
}
<FormItem Label="显示排序">
<Input @bind-Value="menu.DisplayOrder" For="(()=>menu.DisplayOrder)" />
</FormItem>
<FormItem Label="状态">
<Checkbox T="bool" Label="启用" @bind-value="menu.Enabled" Size="InputSize.Small" Class="ps-0" />
</FormItem>
<FormItem WrapperColOffset="4">
<Button Type="ButtonType.Primary" HtmlType="submit" Class="mt-5" Style="width: 100%;">保存</Button>
</FormItem>
</Form >
</Drawer>
@code {
[SupplyParameterFromQuery]
int? Page { get; set; }
[SupplyParameterFromForm]
MenuSearch search { get; set; } = new();
Form<MenuSearch> searchForm = null!;
[SupplyParameterFromForm]
MenuModel menu { get; set; } = new();
Form<MenuModel> editform = null!;
List<MenuItem> Menus = new();
private 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");
}
private async void LoadList()
{
var url = "/api/menu/list";
var apiResult = await HttpService.Get<ApiResult<List<MenuItem>>>(url);
if (apiResult.Success)
{
if (apiResult.Data != null)
{
Menus = apiResult.Data;
StateHasChanged();
}
}
}
void OnSearchFinish()
{
Page = Page.GetValueOrDefault(1) - 1;
OnSearch(Page.Value);
}
void OnSearchReset()
{
search = new();
searchForm?.Reset();
OnSearchFinish();
}
private void OnReset()
{
search = new();
LoadList();
}
private void OnSearch(int page)
{
var queryString = search.BuildQueryString();
if (string.IsNullOrEmpty(queryString))
{
if (page > 1)
{
Navigation.NavigateTo($"/system/menu/list?page={page}");
}
else
{
Navigation.NavigateTo($"/system/menu/list");
}
}
else
{
if (page > 1)
{
Navigation.NavigateTo($"/system/menu/list?page={page}&{queryString}");
}
else
{
Navigation.NavigateTo($"/system/menu/list?{queryString}");
}
}
LoadList();
}
async Task HandleDeleteConfirmAsync(MouseEventArgs e, long id)
{
var url = $"/api/menu/delete/{id}";
var apiResult = await HttpService.Post<ApiResult<string>>(url, new());
if (apiResult.Success)
{
LoadList();
ModalService.Info(new ConfirmOptions() { Title = "操作提示", Content = "删除数据成功" });
}
else
{
ModalService.Error(new ConfirmOptions() { Title = "操作提示", Content = $"数据删除失败.{apiResult.Message}" });
}
}
void OnCreateClick()
{
menu = new();
drawerVisible = true;
}
void OnEditClick(Common.Entities.Menu model)
{
menu = model.Adapt<MenuModel>();
drawerVisible = true;
}
async Task OnFormFinish()
{
if (editform.Validate())
{
var result = new ApiResult<string>();
var data = menu.Adapt<Menu>();
if (menu.Id > 0)
{
var url = $"api/menu/edit";
result = await HttpService.Post<ApiResult<string>>(url, data);
}
else
{
var url = $"api/menu/add";
result = await HttpService.Post<ApiResult<string>>(url, data);
}
if (result.Code == (int)ResultCode.Success)
{
CloseDrawer();
LoadList();
await ModalService.InfoAsync(new ConfirmOptions() { Title="提示", Content="数据提交成功!" });
}
else
{
await ModalService.ErrorAsync(new ConfirmOptions() { Title = "服务异常", Content = result.Message });
}
}
}
private string GetPath(string path)
{
var array = path.Split(",").ToList();
var pathText = string.Empty;
foreach (var item in array)
{
var name = Menus.Where(p => p.Id == item.ToLong()).Select(p => p.Name).SingleOrDefault();
if (string.IsNullOrEmpty(pathText))
{
pathText = name;
}
else
{
pathText = $"{pathText}>{name}";
}
}
return pathText ?? string.Empty;
}
private string GetName(MenuItem menu)
{
string name = string.Empty;
if (menu.Depth > 0)
{
var symbol = " ";
for (var i = 0; i < menu.Depth; i++)
{
symbol = $"{symbol}├ ";
}
name = $"{symbol}{menu.Name}";
}
else
{
name = menu.Name;
}
return name;
}
private void OpenDrawer()
{
drawerVisible = true;
}
private void CloseDrawer()
{
menu = new();
drawerVisible = false;
}
}

View File

@@ -0,0 +1,186 @@
@page "/system/role/permission/{RoleId:long}"
@inject ILogger<RoleList> Logger
<PageTitle>权限设置</PageTitle>
<Spin Spinning="loading">
<Title Level="4">编辑角色权限</Title>
<Card>
<Form @ref="editForm" Model="model" LabelColSpan="2" WrapperColSpan="22" Class="search-form" OnFinish="OnFormFinishAsync">
<FormItem Label="角色">
为角色 <Text>@role?.Name</Text> 设置权限
</FormItem>
<FormItem Label="权限">
<div class="ant-form-item-control-input-content">
@if (!PermissionGroups.Any())
{
<div>
<p>暂无权限可设置</p>
</div>
}
else
{
@foreach (var group in PermissionGroups)
{
<GridRow Style="padding-top:10px;">
<GridCol Span="24">
<label class="ant-checkbox-wrapper">
<span class="ant-checkbox @((@group.PermissionItems.Count(p => p.IsSelected) > 0 && @group.PermissionItems.Count(p => p.IsSelected) < @group.PermissionItems.Count) ? "ant-checkbox-indeterminate" : "")">
<input class="ant-checkbox-input" type="checkbox"
@onchange="(e) => ToggleAllPermissions(group, (bool)e.Value!)"
checked="@group.PermissionItems.All(p => p.IsSelected)" />
<span class="ant-checkbox-inner"></span>
</span>
<span>
<span class="form-check-label fw-bold">
@group.CategoryName
</span>
<small class="text-muted ms-2">
(@group.PermissionItems.Count(p => p.IsSelected)/@group.PermissionItems.Count)
</small>
</span>
</label>
</GridCol>
</GridRow>
<GridRow Style="margin-left:20px;margin-right:20px;">
@foreach (var permission in group.PermissionItems)
{
<GridCol Span="6">
<label class="ant-checkbox-wrapper">
<span class="ant-checkbox">
<input class="ant-checkbox-input" type="checkbox"
@bind="permission.IsSelected"
id="perm_@permission.Name" />
<span class="ant-checkbox-inner"></span>
</span>
<span class="form-check-label" for="perm_@permission.Name">
@permission.Description
<small class="text-muted d-block">@permission.Name</small>
</span>
</label>
</GridCol>
}
</GridRow>
}
}
</div>
</FormItem>
<FormItem WrapperCol="new ColLayoutParam { Span = 24, Offset = 2 }">
<Button Type="@ButtonType.Primary" HtmlType="submit" Loading="@isSaving">
@if (isSaving)
{
<span>保存中...</span>
}
else
{
<span>保存权限设置</span>
}
</Button>
</FormItem>
</Form>
</Card>
</Spin>
@code {
[Parameter]
public long RoleId { get; set; }
bool loading = false;
bool isSaving = false;
Role role;
List<RolePermissionGroup> PermissionGroups = new List<RolePermissionGroup>();
[SupplyParameterFromForm]
RoleModel model { get; set; } = new();
Form<RoleModel> editForm = null!;
protected override void OnInitialized()
{
base.OnInitialized();
}
protected override async Task OnParametersSetAsync()
{
loading = true;
await LoadRoleAndPermission();
loading = false;
base.OnParametersSet();
}
async Task LoadRoleAndPermission()
{
var roleResult = await HttpService.Get<ApiResult<Role>>($"/api/role/{RoleId}");
if (roleResult.Success)
{
if (roleResult.Data != null)
{
role = roleResult.Data;
StateHasChanged();
}
}
var apiResult = await HttpService.Get<ApiResult<List<RolePermissionGroup>>>($"/api/role/permission/{RoleId}");
if (apiResult.Success)
{
if (apiResult.Data != null)
{
PermissionGroups = apiResult.Data;
StateHasChanged();
}
}
}
private void ToggleAllPermissions(RolePermissionGroup group, bool isSelected)
{
foreach (var permission in group.PermissionItems)
{
permission.IsSelected = isSelected;
}
StateHasChanged();
}
async void OnFormFinishAsync()
{
isSaving = true;
StateHasChanged();
try
{
var selectedPermissions = PermissionGroups!
.SelectMany(g => g.PermissionItems)
.Where(p => p.IsSelected)
.Select(p => p.Name)
.ToList();
model = role.Adapt<RoleModel>();
model.Permission = string.Join(",", selectedPermissions);
var url = $"api/role/edit";
var result = await HttpService.Post<ApiResult<string>>(url, model);
if (result.Success)
{
await ModalService.InfoAsync(new ConfirmOptions() { Title = "提示", Content = "权限设置保存成功!" });
}
else
{
await ModalService.InfoAsync(new ConfirmOptions() { Title = "提示", Content = "服务异常!" });
}
Navigation.NavigateTo("/system/role/list");
}
catch (Exception ex)
{
await ModalService.InfoAsync(new ConfirmOptions() { Title = "提示", Content = "保存权限设置失败!" });
}
finally
{
isSaving = false;
StateHasChanged();
}
}
}

View File

@@ -0,0 +1,259 @@
@page "/system/role/list"
@inject ILogger<RoleList> Logger
<PageTitle>角色管理</PageTitle>
<Title Level="4">角色管理</Title>
<Card Class="mt-3">
<Table DataSource="PagingList.Items" PageSize="100" HidePagination="true" Resizable>
<TitleTemplate>
<Flex Justify="FlexJustify.SpaceBetween">
角色列表
<div>
<Button Class="me-3" OnClick="OnCreateClick" Type="ButtonType.Primary">新增</Button>
</div>
</Flex>
</TitleTemplate>
<ColumnDefinitions>
<PropertyColumn Property="c => c.Name" Title="角色">
</PropertyColumn>
<PropertyColumn Property="c => c.Description" Title="说明" />
<PropertyColumn Property="c => c.IsSystemRole" Title="系统" Width="80px" Align="ColumnAlign.Center">
@if (context.IsSystemRole)
{
<AntDesign.Text Type="TextElementType.Success"><Icon Type="check" Theme=" IconThemeType.Outline" Width="1.3em" Height="1.3em" /></AntDesign.Text>
}
else
{
<AntDesign.Text Type="TextElementType.Secondary"><Icon Type="minus" Theme="IconThemeType.Outline" Width="1.3em" Height="1.3em" /></AntDesign.Text>
}
</PropertyColumn>
<PropertyColumn Property="c => c.Count" Title="用户数" Width="100px" />
<PropertyColumn Property="c => c.Enabled" Title="状态" Width="80px" Align="ColumnAlign.Center">
@if (context.Enabled)
{
<AntDesign.Text Type="TextElementType.Success"><Icon Type="check" Theme=" IconThemeType.Outline" Width="1.3em" Height="1.3em" /></AntDesign.Text>
}
else
{
<Icon Type="close" Theme="IconThemeType.Outline" Width="1.3em" Height="1.3em" />
}
</PropertyColumn>
<PropertyColumn Property="c => c.UpdateTime" Title="最后更新" Width="190px" />
<ActionColumn Title="操作" Align="ColumnAlign.Right" Width="160px">
<Space>
<SpaceItem>
<Button Type="ButtonType.Link" OnClick="() => OnEditPermissionClick(context)">权限管理</Button>
</SpaceItem>
<SpaceItem>
<Dropdown Trigger="@(new Trigger[] { Trigger.Click })">
<Overlay>
<Menu>
<MenuItem>
<a @onclick="(e) => OnEditClick(context)"> <Icon Type="@IconType.Outline.Edit" /> 编辑</a>
</MenuItem>
@if (!context.IsSystemRole)
{
<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">
<Pagination PageIndex="pager.Index" Total="PagingList.Count" PageSize="PagingList.Size" ShowSizeChanger="false" OnChange="OnPageChanged"></Pagination>
</Row>
</Card>
<Drawer Closable="true" Width="520" Visible="drawerVisible" Title='(model.Id == 0 ? "新增角色" : "编辑角色")' OnClose="_ => CloseDrawer()">
<Form LabelColSpan="5" @ref="@editform" Model="@model" OnFinish="OnFormFinish">
<FluentValidationValidator />
<FormItem Label="角色名称">
<Input @bind-Value="model.Name" For="(()=>model.Name)" Placeholder="角色名称" />
</FormItem>
<FormItem Label="角色说明">
<Input @bind-Value="model.Description" For="(()=>model.Culture)" Placeholder="角色说明" />
</FormItem>
<FormItem Label="可用状态">
<Checkbox T="bool" Label="启用" @bind-value="model.Enabled" Size="InputSize.Small" Class="ps-0" />
</FormItem>
<FormItem WrapperColOffset="4">
<Button Type="ButtonType.Primary" HtmlType="submit" Style="width: 100%;">保存</Button>
</FormItem>
</Form>
</Drawer>
@code {
[SupplyParameterFromQuery]
int? Page { get; set; }
[SupplyParameterFromQuery(Name = "size")]
int? PageSize { get; set; }
[SupplyParameterFromForm]
RoleSearch search { get; set; } = default!;
[SupplyParameterFromForm]
RoleModel model { get; set; } = default!;
Form<RoleModel> editform = null!;
PagingList<Role> PagingList = new();
bool loading { get; set; } = true;
bool drawerVisible;
bool isSave = false;
protected override void OnInitialized()
{
search ??= new RoleSearch();
model ??= new RoleModel();
base.OnInitialized();
}
protected override async Task OnParametersSetAsync()
{
await LoadList();
}
private async Task LoadList()
{
loading = true;
var url = "/api/role/search";
var apiResult = await HttpService.GetPagingList<Role>(url, search ?? new RoleSearch(), Page.GetValueOrDefault(1), PageSize.GetValueOrDefault(20));
if (apiResult.Success)
{
if (apiResult.Data != null)
{
PagingList = apiResult.Data;
}
}
loading = false;
StateHasChanged();
}
private void OnSearch(int page)
{
var queryString = search.BuildQueryString();
if (string.IsNullOrEmpty(queryString))
{
if (page > 1)
{
Navigation.NavigateTo($"/system/role/list?page={page}");
}
else
{
Navigation.NavigateTo($"/system/role/list");
}
}
else
{
if (page > 1)
{
Navigation.NavigateTo($"/system/role/list?page={page}&{queryString}");
}
else
{
Navigation.NavigateTo($"/system/role/list?{queryString}");
}
}
}
void OnCreateClick()
{
model = new();
drawerVisible = true;
}
void OnEditPermissionClick(Role role)
{
Navigation.NavigateTo($"/system/role/permission/{role.Id}");
}
void OnEditClick(Role role)
{
model = role.Adapt<RoleModel>();
drawerVisible = true;
}
async Task HandleDeleteConfirmAsync(MouseEventArgs e, long id)
{
var url = $"/api/role/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}" });
}
}
async Task OnFormFinish()
{
if (editform.Validate())
{
var apiResult = new ApiResult<string>();
if (model != null)
{
if (model.Id > 0)
{
var url = $"api/role/edit";
apiResult = await HttpService.Post<ApiResult<string>>(url, model);
}
else
{
var url = $"api/role/add";
apiResult = await HttpService.Post<ApiResult<string>>(url, model);
}
if (apiResult.Success)
{
ModalService.Success(new ConfirmOptions() { Title = "提示", Content = "数据提交成功!" });
CloseDrawer();
await LoadList();
}
else
{
await ModalService.ErrorAsync(new ConfirmOptions() { Title = "服务异常", Content = apiResult.Message });
}
}
}
StateHasChanged();
}
private void OnPageChanged(PaginationEventArgs args)
{
OnSearch(args.Page);
}
void CloseDrawer()
{
drawerVisible = false;
editform.Reset();
}
}