fix(#I12DUB): 任务管理界面重新布局

#Issue
close https://gitee.com/LongbowEnterprise/dashboard/issues?id=I12DUB
This commit is contained in:
Argo Window10 2019-11-14 21:37:40 +08:00
parent 6909d1cb19
commit 624f584072
8 changed files with 175 additions and 62 deletions

View File

@ -611,6 +611,30 @@
"IsResource": NumberInt(0),
"Application": "BA"
},
{
"_id": ObjectId("1bd7b8445fa31256f77e4b9c"),
"ParentId": "5bd7b8445fa31256f77e4b9a",
"Name": "暂停",
"Order": NumberInt(20),
"Icon": "fa fa-fa",
"Url": "pause",
"Category": "0",
"Target": "_self",
"IsResource": NumberInt(2),
"Application": "BA"
},
{
"_id": ObjectId("1bd7b8445fa31256f77e4b9d"),
"ParentId": "5bd7b8445fa31256f77e4b9a",
"Name": "日志",
"Order": NumberInt(30),
"Icon": "fa fa-fa",
"Url": "info",
"Category": "0",
"Target": "_self",
"IsResource": NumberInt(2),
"Application": "BA"
},
{
"_id": ObjectId("5bd7b8445fa31256f77e4b9b"),
"ParentId": "0",

View File

@ -110,6 +110,8 @@ INSERT INTO Navigations (ParentId, Name, `Order`, Icon, Url, Category, IsResourc
INSERT INTO Navigations (ParentId, Name, `Order`, Icon, Url, Category, IsResource) VALUES (@@identity - 2, '删除', 30, 'fa fa-fa', 'del', '0', 2);
INSERT INTO Navigations (ParentId, Name, `Order`, Icon, Url, Category) VALUES (0, '站内消息', 100, 'fa fa-envelope', '~/Admin/Messages', '0');
INSERT INTO Navigations (ParentId, Name, `Order`, Icon, Url, Category) VALUES (0, '任务管理', 110, 'fa fa fa-tasks', '~/Admin/Tasks', '0');
INSERT INTO Navigations (ParentId, Name, `Order`, Icon, Url, Category, IsResource) VALUES (@@identity, '暂停', 10, 'fa fa-fa', 'pause', '0', 2);
INSERT INTO Navigations (ParentId, Name, `Order`, Icon, Url, Category, IsResource) VALUES (@@identity - 1, '日志', 20, 'fa fa-fa', 'info', '0', 2);
INSERT INTO Navigations (ParentId, Name, `Order`, Icon, Url, Category) VALUES (0, '通知管理', 120, 'fa fa-bell', '~/Admin/Notifications', '0');
INSERT INTO Navigations (ParentId, Name, `Order`, Icon, Url, Category) VALUES (0, '系统日志', 130, 'fa fa-gears', '#', '0');
INSERT INTO Navigations (ParentId, Name, `Order`, Icon, Url, Category) VALUES (@@identity, '操作日志', 10, 'fa fa-edit', '~/Admin/Logs', '0');

View File

@ -111,6 +111,8 @@ INSERT INTO [Navigations] ([ParentId], [Name], [Order], [Icon], [Url], [Category
INSERT INTO [Navigations] ([ParentId], [Name], [Order], [Icon], [Url], [Category], IsResource) VALUES (currval('navigations_id_seq') - 3, '删除', 30, 'fa fa-fa', 'del', '0', 2);
INSERT INTO Navigations (ParentId, Name, "order", Icon, Url, Category) VALUES (0, '站内消息', 100, 'fa fa-envelope', '~/Admin/Messages', '0');
INSERT INTO Navigations (ParentId, Name, "order", Icon, Url, Category) VALUES (0, '任务管理', 110, 'fa fa fa-tasks', '~/Admin/Tasks', '0');
INSERT INTO [Navigations] ([ParentId], [Name], [Order], [Icon], [Url], [Category], IsResource) VALUES (currval('navigations_id_seq') - 1, '暂停', 10, 'fa fa-fa', 'pause', '0', 2);
INSERT INTO [Navigations] ([ParentId], [Name], [Order], [Icon], [Url], [Category], IsResource) VALUES (currval('navigations_id_seq') - 2, '日志', 20, 'fa fa-fa', 'info', '0', 2);
INSERT INTO Navigations (ParentId, Name, "order", Icon, Url, Category) VALUES (0, '通知管理', 120, 'fa fa-bell', '~/Admin/Notifications', '0');
INSERT INTO Navigations (ParentId, Name, "order", Icon, Url, Category) VALUES (0, '系统日志', 130, 'fa fa-gears', '#', '0');
INSERT INTO Navigations (ParentId, Name, "order", Icon, Url, Category) VALUES (currval('navigations_id_seq') - 1, 0, '操作日志', 10, 'fa fa-edit', '~/Admin/Logs', '0');

View File

@ -110,6 +110,8 @@ INSERT INTO [Navigations] ([ParentId], [Name], [Order], [Icon], [Url], [Category
INSERT INTO [Navigations] ([ParentId], [Name], [Order], [Icon], [Url], [Category], IsResource) VALUES (last_insert_rowid() - 2, '删除', 30, 'fa fa-fa', 'del', '0', 2);
INSERT INTO [Navigations] ([ParentId], [Name], [Order], [Icon], [Url], [Category]) VALUES (0, '站内消息', 100, 'fa fa-envelope', '~/Admin/Messages', '0');
INSERT INTO [Navigations] ([ParentId], [Name], [Order], [Icon], [Url], [Category]) VALUES (0, '任务管理', 110, 'fa fa fa-tasks', '~/Admin/Tasks', '0');
INSERT INTO [Navigations] ([ParentId], [Name], [Order], [Icon], [Url], [Category], IsResource) VALUES (last_insert_rowid(), '暂停', 10, 'fa fa-fa', 'pause', '0', 2);
INSERT INTO [Navigations] ([ParentId], [Name], [Order], [Icon], [Url], [Category], IsResource) VALUES (last_insert_rowid() - 1, '日志', 20, 'fa fa-fa', 'info', '0', 2);
INSERT INTO [Navigations] ([ParentId], [Name], [Order], [Icon], [Url], [Category]) VALUES (0, '通知管理', 120, 'fa fa-bell', '~/Admin/Notifications', '0');
INSERT INTO [Navigations] ([ParentId], [Name], [Order], [Icon], [Url], [Category]) VALUES (0, '系统日志', 130, 'fa fa-gears', '#', '0');
INSERT INTO [Navigations] ([ParentId], [Name], [Order], [Icon], [Url], [Category]) VALUES (last_insert_rowid(), '操作日志', 10, 'fa fa-edit', '~/Admin/Logs', '0');

View File

@ -113,6 +113,8 @@ INSERT INTO [Navigations] ([ParentId], [Name], [Order], [Icon], [Url], [Category
INSERT INTO [Navigations] ([ParentId], [Name], [Order], [Icon], [Url], [Category], IsResource) VALUES (@@Identity - 2, N'删除', 30, 'fa fa-fa', 'del', '0', 2);
INSERT INTO [Navigations] ([ParentId], [Name], [Order], [Icon], [Url], [Category]) VALUES (0, N'站内消息', 100, N'fa fa-envelope', N'~/Admin/Messages', N'0')
INSERT INTO [Navigations] ([ParentId], [Name], [Order], [Icon], [Url], [Category]) VALUES (0, N'任务管理', 110, N'fa fa fa-tasks', N'~/Admin/Tasks', N'0')
INSERT INTO [Navigations] ([ParentId], [Name], [Order], [Icon], [Url], [Category], IsResource) VALUES (@@Identity, N'暂停', 10, 'fa fa-fa', 'pause', '0', 2);
INSERT INTO [Navigations] ([ParentId], [Name], [Order], [Icon], [Url], [Category], IsResource) VALUES (@@Identity - 1, N'日志', 20, 'fa fa-fa', 'info', '0', 2);
INSERT INTO [Navigations] ([ParentId], [Name], [Order], [Icon], [Url], [Category]) VALUES (0, N'通知管理', 120, N'fa fa-bell', N'~/Admin/Notifications', N'0')
INSERT INTO [Navigations] ([ParentId], [Name], [Order], [Icon], [Url], [Category]) VALUES (0, N'日志管理', 130, N'fa fa-gears', N'#', N'0')
INSERT INTO [Navigations] ([ParentId], [Name], [Order], [Icon], [Url], [Category]) VALUES (@@Identity, N'操作日志', 10, N'fa fa-edit', N'~/Admin/Logs', N'0')

View File

@ -23,5 +23,18 @@ namespace Bootstrap.Admin.Controllers.Api
{
return TaskServicesManager.ToList().Select(s => new { s.Name, Status = s.Status.ToString(), s.LastRuntime, s.CreatedTime, s.NextRuntime, LastRunResult = s.Triggers.First().LastResult.ToString(), TriggerExpression = s.Triggers.FirstOrDefault().ToString() }).OrderBy(s => s.Name);
}
/// <summary>
/// 任务相关操作
/// </summary>
/// <param name="scheName">调度名称</param>
/// <param name="operType">操作方式 pause run</param>
[HttpPut("{scheName}")]
public bool Put(string scheName, [FromQuery]string operType)
{
var sche = TaskServicesManager.Get(scheName);
if (sche != null) sche.Status = operType == "pause" ? SchedulerStatus.Disabled : SchedulerStatus.Running;
return true;
}
}
}

View File

@ -1,80 +1,86 @@
@model TaskModel
@{
ViewBag.Title = "任务管理";
Layout = "_Default";
Layout = "_Admin";
}
@section css {
<environment include="Development">
<link href="~/lib/bootstrap-table/bootstrap-table.css" rel="stylesheet" />
</environment>
<environment exclude="Development">
<link href="~/lib/bootstrap-table/bootstrap-table.min.css" rel="stylesheet" />
</environment>
<link href="~/lib/longbow-select/longbow-select.css" rel="stylesheet" />
<link href="~/css/tasks.css" rel="stylesheet" asp-append-version="true" />
}
@section javascript {
<environment include="Development">
<script src="~/lib/bootstrap-table/bootstrap-table.js"></script>
<script src="~/lib/bootstrap-table/extensions/export/bootstrap-table-export.js"></script>
<script src="~/lib/bootstrap-table/locale/bootstrap-table-zh-CN.js"></script>
<script src="~/lib/tablexport/tableExport.js"></script>
<script src="~/lib/validate/jquery.validate.js"></script>
<script src="~/lib/validate/localization/messages_zh.js"></script>
</environment>
<environment exclude="Development">
<script src="~/lib/bootstrap-table/bootstrap-table.min.js"></script>
<script src="~/lib/bootstrap-table/extensions/export/bootstrap-table-export.min.js"></script>
<script src="~/lib/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>
<script src="~/lib/tablexport/tableExport.min.js"></script>
<script src="~/lib/validate/jquery.validate.min.js"></script>
<script src="~/lib/validate/localization/messages_zh.min.js"></script>
</environment>
<script src="~/lib/longbow-checkbox/longbow-checkbox.js"></script>
<script src="~/lib/longbow-select/longbow-select.js"></script>
<script src="~/lib/longbow/longbow.dataentity.js" asp-append-version="true"></script>
<script src="~/lib/longbow/longbow.validate.js" asp-append-version="true"></script>
<script src="~/js/tasks.js" asp-append-version="true"></script>
}
@section tableButtons {
<button class='info btn btn-sm btn-info' asp-auth="info"><i class='fa fa-info'></i><span>日志</span></button>
}
@section cardbody {
<div class="alert alert-danger" role="alert" asp-condition="@Model.IsDemo">
<span>演示系统禁止修改定时后台任务</span>
</div>
}
@section query {
<div class="alert alert-info">
<p class="font-weight-bold">后台任务说明:</p>
<p>1. 默认任务 (立即执行,仅执行一次)</p>
<p>
<code>
TaskServicesManager.GetOrAdd("简单任务", token => Task.Delay(1000));
</code>
</p>
<p>2. 周期性任务 (1 分钟后间隔 5 秒执行 2 次任务)</p>
<p>
<code>
var trigger = TriggerBuilder.Default.WithInterval(TimeSpan.FromSeconds(5)).WithRepeatCount(2).WithStartTime(DateTimeOffset.Now.AddMinutes(1)).Build();
<br />
TaskServicesManager.GetOrAdd("测试任务", token => Task.Delay(1000), trigger);
</code>
</p>
<p>3. Cron 表达式任务 (间隔 5 秒循环执行任务)</p>
<p>
<code>
TaskServicesManager.GetOrAdd("Cron 表达式任务", token => Task.Delay(1000), TriggerBuilder.Build("*/5 * * * * *"));
</code>
</p>
</div>
}
@section modal {
<div class="modal-header">
<h5 class="modal-title" id="myModalLabel">任务编辑窗口</h5>
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
</div>
<div class="modal-body">
<form class="form-inline">
<div class="row">
<input type="hidden" id="taskID" />
<div class="form-group col-12">
<label class="control-label" for="taskName">任务名称</label>
<input type="text" class="form-control flex-sm-fill" id="taskName" placeholder="不可为空50字以内" maxlength="50" data-valid="true" />
<div class="modal fade" id="dialogNew" tabindex="-1" role="dialog" data-backdrop="static" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered modal-lg" role="document">
<div class="modal-content" data-toggle="LgbValidate" data-valid-button="#btnSubmit" data-valid-modal="#dialogNew">
<div class="modal-header">
<h5 class="modal-title" id="myModalLabel">任务编辑窗口</h5>
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
</div>
<div class="form-group col-12">
<label class="control-label" for="taskCron">Cron表达式</label>
<input type="text" class="form-control flex-sm-fill" id="taskCron" placeholder="不可为空2000字以内" maxlength="2000" data-valid="true" />
<div class="modal-body">
<form class="form-inline">
<div class="row">
<input type="hidden" id="taskID" />
<div class="form-group col-12">
<label class="control-label" for="taskName">任务名称</label>
<input type="text" class="form-control flex-sm-fill" id="taskName" placeholder="不可为空50字以内" maxlength="50" data-valid="true" />
</div>
<div class="form-group col-12">
<label class="control-label" for="taskCron">Cron表达式</label>
<input type="text" class="form-control flex-sm-fill" id="taskCron" placeholder="不可为空2000字以内" maxlength="2000" data-valid="true" />
</div>
<div class="form-group col-12">
<label class="control-label" for="taskContent">内置任务</label>
<select id="taskList" data-toggle="lgbSelect">
@foreach (var name in Model.Tasks)
{
<option value="@name">@name</option>
}
</select>
</div>
</div>
</form>
</div>
<div class="form-group col-12">
<label class="control-label" for="taskContent">内置任务</label>
<select id="taskList" data-toggle="lgbSelect">
@foreach (var name in Model.Tasks)
{
<option value="@name">@name</option>
}
</select>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">
<i class="fa fa-times"></i>
<span>关闭</span>
</button>
<button type="button" class="btn btn-primary" id="btnSubmit">
<i class="fa fa-save"></i>
<span>保存</span>
</button>
</div>
</div>
</form>
</div>
</div>
}
@section customModal {
<div class="modal fade" id="dialogLog" tabindex="-1" role="dialog" data-backdrop="static" aria-labelledby="taskModalLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered modal-lg" role="document">
<div class="modal-content">
@ -97,4 +103,50 @@
</div>
</div>
</div>
}
}
<div class="card">
<div class="card-header">任务介绍</div>
<div class="card-body">
<div class="alert alert-info">
<p class="font-weight-bold">后台任务说明:</p>
<p>1. 默认任务 (立即执行,仅执行一次)</p>
<p>
<code>
TaskServicesManager.GetOrAdd("简单任务", token => Task.Delay(1000));
</code>
</p>
<p>2. 周期性任务 (1 分钟后间隔 5 秒执行 2 次任务)</p>
<p>
<code>
var trigger = TriggerBuilder.Default.WithInterval(TimeSpan.FromSeconds(5)).WithRepeatCount(2).WithStartTime(DateTimeOffset.Now.AddMinutes(1)).Build();
<br />
TaskServicesManager.GetOrAdd("测试任务", token => Task.Delay(1000), trigger);
</code>
</p>
<p>3. Cron 表达式任务 (间隔 5 秒循环执行任务)</p>
<div>
<code>
TaskServicesManager.GetOrAdd("Cron 表达式任务", token => Task.Delay(1000), TriggerBuilder.Build("*/5 * * * * *"));
</code>
</div>
</div>
</div>
</div>
<div class="card">
<div class="card-header">
查询结果
</div>
<div class="card-body">
<div class="alert alert-danger" role="alert" asp-condition="@Model.IsDemo">
<span>演示系统禁止修改定时后台任务</span>
</div>
<table></table>
</div>
</div>
<div id="tableButtons" class="d-none">
<div class='btn-group'>
<button class='pause btn btn-sm btn-danger' asp-auth="pause"><i class='fa fa-pause-circle'></i><span>暂停</span></button>
<button class='run btn btn-sm btn-success' asp-auth="pause"><i class='fa fa-play-circle'></i><span>运行</span></button>
<button class='info btn btn-sm btn-info' asp-auth="info"><i class='fa fa-info-circle'></i><span>日志</span></button>
</div>
</div>

View File

@ -11,7 +11,7 @@
content = $.format(template, 'success', 'play-circle', '运行中');
}
else if (value === "Disabled") {
content = $.format(template, 'danger', 'times-circle', '已禁用');
content = $.format(template, 'danger', 'times-circle', '已停止');
}
return content;
};
@ -33,7 +33,7 @@
return content;
};
$('.card-body table').lgbTable({
var $task = $('.card-body table').lgbTable({
url: Tasks.url,
dataBinder: {
map: {
@ -95,6 +95,22 @@
console.log(error);
}
});
},
'click .pause': function (e, value, row, index) {
$.bc({
url: 'api/Tasks/' + row.Name + "?operType=" + "pause", method: 'put',
callback: function (result) {
if (result) $task.bootstrapTable('refresh');
}
});
},
'click .run': function (e, value, row, index) {
$.bc({
url: 'api/Tasks/' + row.Name + "?operType=" + "run", method: 'put',
callback: function (result) {
if (result) $task.bootstrapTable('refresh');
}
});
}
}
}