Files
Atomx/Atomx.Admin/Atomx.Admin.Client/Pages/Storages/UploadList.razor

303 lines
10 KiB
Plaintext

@page "/system/file/list"
@page "/{locale}/system/file/list"
@inject ILogger<UploadList> Logger
@attribute [Authorize]
<PageContainer Title="上传文件">
<Breadcrumb>
<Breadcrumb>
<BreadcrumbItem Href="/">管理后台</BreadcrumbItem>
<BreadcrumbItem Href="/admin/list">系统功能</BreadcrumbItem>
<BreadcrumbItem>上传文件</BreadcrumbItem>
</Breadcrumb>
</Breadcrumb>
<ChildContent>
<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="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.ContentType" Title="类型" Width="80px" Align="ColumnAlign.Center">
</PropertyColumn>
<PropertyColumn Property="c => c.Size" Title="文件大小" Width="100px" />
<PropertyColumn Property="c => c.Type" Title="状态" Width="80px" Align="ColumnAlign.Center">
@if (context.Type == 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.CreateTime" 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 WrapperColOffset="4">
<Button Type="ButtonType.Primary" HtmlType="submit" Style="width: 100%;">保存</Button>
</FormItem>
</Form>
</Drawer>
</ChildContent>
</PageContainer>
@code {
[SupplyParameterFromQuery]
int? Page { get; set; }
[SupplyParameterFromQuery(Name = "size")]
int? PageSize { get; set; }
[SupplyParameterFromForm]
UploadFileSearch search { get; set; } = new();
Form<UploadFileSearch> searchForm = null!;
[SupplyParameterFromForm]
UploadFileModel model { get; set; } = new();
Form<UploadFileModel> editform = null!;
PagingList<UploadFile> 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");
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/uploadfile/search";
var apiResult = await HttpService.GetPagingList<UploadFile>(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($"/system/upload/list?page={page}");
}
else
{
Navigation.NavigateTo($"/system/upload/list");
}
}
else
{
if (page > 1)
{
Navigation.NavigateTo($"/system/upload/list?page={page}&{queryString}");
}
else
{
Navigation.NavigateTo($"/system/upload/list?{queryString}");
}
}
}
void OnCreateClick()
{
model = new();
drawerVisible = true;
}
void OnEditClick(UploadFile file)
{
this.model = file.Adapt<UploadFileModel>();
drawerVisible = true;
}
async Task HandleDeleteConfirmAsync(MouseEventArgs e, long id)
{
var url = $"/api/uploadfile/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/uploadfile/edit";
result = await HttpService.Post<ApiResult<string>>(url, model);
}
else
{
var url = $"api/uploadfile/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();
}
}