feat: 增加任务管理界面
This commit is contained in:
parent
97503e4a81
commit
6703d510b2
|
@ -3,6 +3,10 @@
|
|||
<PropertyGroup>
|
||||
<IsWebProject>true</IsWebProject>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Longbow.Tasks" Version="5.2.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\BootstrapAdmin.DataAccess.PetaPoco\BootstrapAdmin.DataAccess.PetaPoco.csproj" />
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
using BootstrapAdmin.Web.Models;
|
||||
using Longbow.Tasks;
|
||||
|
||||
namespace BootstrapAdmin.Web.Extensions;
|
||||
|
||||
public static class TasksExtensions
|
||||
{
|
||||
public static List<TasksModel> ToTasksModelList(this IEnumerable<IScheduler> schedulers) => schedulers.Select(i => new TasksModel
|
||||
{
|
||||
Name = i.Name,
|
||||
CreateTime = i.CreatedTime,
|
||||
LastRuntime = i.LastRuntime,
|
||||
NextRuntime = i.NextRuntime,
|
||||
LastRunResult = i.LastRunResult,
|
||||
Status = i.Status,
|
||||
Trigger = i.Triggers.First().ToString()
|
||||
|
||||
}).ToList();
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
using Longbow.Tasks;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace BootstrapAdmin.Web.Models;
|
||||
|
||||
public class TasksModel
|
||||
{
|
||||
[Display(Name = "任务名称")]
|
||||
[NotNull]
|
||||
public string? Name { get; set; }
|
||||
|
||||
[Display(Name = "创建时间")]
|
||||
public DateTimeOffset CreateTime { get; set; }
|
||||
|
||||
[Display(Name = "上次运行时间")]
|
||||
public DateTimeOffset? LastRuntime { get; set; }
|
||||
|
||||
[Display(Name = "下次运行时间")]
|
||||
public DateTimeOffset? NextRuntime { get; set; }
|
||||
|
||||
[Display(Name = "触发条件")]
|
||||
[NotNull]
|
||||
public string? Trigger { get; set; }
|
||||
|
||||
[Display(Name = "执行结果")]
|
||||
[NotNull]
|
||||
public TriggerResult LastRunResult { get; set; }
|
||||
|
||||
[Display(Name = "任务状态")]
|
||||
[NotNull]
|
||||
public SchedulerStatus Status { get; set; }
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
@page "/Admin/Tasks"
|
||||
|
||||
<Card IsCollapsible="true" HeaderText="任务介绍">
|
||||
<Card IsCollapsible="true" HeaderText="任务介绍" class="mb-3">
|
||||
<CardBody>
|
||||
<Alert class="mb-0">
|
||||
<p class="font-weight-bold">后台任务说明:</p>
|
||||
|
@ -27,3 +27,20 @@
|
|||
</Alert>
|
||||
</CardBody>
|
||||
</Card>
|
||||
|
||||
<AdminTable TItem="TasksModel" ExtendButtonColumnWidth="270" OnQueryAsync="OnQueryAsync">
|
||||
<ColumnsTemplete>
|
||||
<TableColumn @bind-Field="@context.Name" Sortable="true" Filterable="true" Searchable="true" Width="180"></TableColumn>
|
||||
<TableColumn @bind-Field="@context.CreateTime" Sortable="true" Filterable="true" Searchable="true"></TableColumn>
|
||||
<TableColumn @bind-Field="@context.LastRuntime" Sortable="true" Filterable="true" Searchable="true"></TableColumn>
|
||||
<TableColumn @bind-Field="@context.NextRuntime" Sortable="true" Filterable="true" Searchable="true"></TableColumn>
|
||||
<TableColumn @bind-Field="@context.Trigger" Sortable="true" Filterable="true" Searchable="true"></TableColumn>
|
||||
<TableColumn @bind-Field="@context.LastRunResult" Sortable="true" Filterable="true" Searchable="true"></TableColumn>
|
||||
<TableColumn @bind-Field="@context.Status" Sortable="true" Filterable="true" Searchable="true"></TableColumn>
|
||||
</ColumnsTemplete>
|
||||
<RowButtonTemplate>
|
||||
<TableCellButton Size="Size.ExtraSmall" Color="Color.Warning" Icon="fa fa-pause-circle" Text="暂停" OnClick="() => OnPause(context)" />
|
||||
<TableCellButton Size="Size.ExtraSmall" Color="Color.Success" Icon="fa fa-play-circle" Text="运行" OnClick="() => OnRun(context)" />
|
||||
<TableCellButton Size="Size.ExtraSmall" Color="Color.Info" Icon="fa fa-info-circle" Text="日志" OnClick="() => OnLog(context)" />
|
||||
</RowButtonTemplate>
|
||||
</AdminTable>
|
||||
|
|
|
@ -1,6 +1,33 @@
|
|||
namespace BootstrapAdmin.Web.Pages.Admin;
|
||||
using BootstrapAdmin.DataAccess.Models;
|
||||
using BootstrapAdmin.Web.Extensions;
|
||||
using BootstrapAdmin.Web.Models;
|
||||
using Longbow.Tasks;
|
||||
|
||||
namespace BootstrapAdmin.Web.Pages.Admin;
|
||||
|
||||
public partial class Tasks
|
||||
{
|
||||
private Task<QueryData<TasksModel>> OnQueryAsync(QueryPageOptions options)
|
||||
{
|
||||
var tasks = TaskServicesManager.ToList().ToTasksModelList();
|
||||
return Task.FromResult(new QueryData<TasksModel>()
|
||||
{
|
||||
Items = tasks
|
||||
});
|
||||
}
|
||||
|
||||
private Task OnPause(TasksModel model)
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
private Task OnRun(TasksModel model)
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
private Task OnLog(TasksModel model)
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue