zhaolei
2020-11-20 4a2e5b9a21940f11757be37d99f0944e240e908b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
@model TaskModel
@{
    ViewBag.Title = "任务管理";
}
@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-checkbox/longbow-checkbox.css" rel="stylesheet" />
    <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/longbow.dataentity.js" asp-append-version="true"></script>
    <script src="~/lib/longbow/longbow.validate.js" asp-append-version="true"></script>
    <script src="~/lib/longbow-select/longbow-select.js"></script>
    <script src="~/js/tasks.js" asp-append-version="true"></script>
}
<div id="toolbar" class="d-none">
    <div class="gear btn-group">
        <button class="btn btn-secondary dropdown-toggle" data-toggle="dropdown" type="button"><i class="fa fa-gear"></i></button>
        <div class="dropdown-menu">
            <a id="tb_add" href="#" title="新增" asp-auth="add"><i class="fa fa-plus"></i></a>
            <a id="tb_delete" href="#" title="删除" asp-auth="del"><i class="fa fa-remove"></i></a>
            <a id="tb_edit" href="#" title="编辑" asp-auth="edit"><i class="fa fa-pencil"></i></a>
        </div>
    </div>
    <div class="toolbar btn-group">
        <button id="btn_add" type="button" class="btn btn-success" asp-auth="add"><i class="fa fa-plus" aria-hidden="true"></i><span>新增</span></button>
        <button id="btn_delete" type="button" class="btn btn-danger" asp-auth="del"><i class="fa fa-remove" aria-hidden="true"></i><span>删除</span></button>
        <button id="btn_edit" type="button" class="btn btn-primary" asp-auth="edit"><i class="fa fa-pencil" aria-hidden="true"></i><span>编辑</span></button>
    </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 id='table'></table>
    </div>
</div>
<div id="tableButtons" class="d-none">
    <div class='btn-group'>
        <button class='edit btn btn-sm btn-success' asp-auth="edit"><i class='fa fa-edit'></i><span>编辑</span></button>
        <button class='del btn btn-sm btn-danger' asp-auth="del"><i class='fa fa-remove'></i><span>删除</span></button>
        <button class='pause btn btn-sm btn-warning' 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>
<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="modal-body">
                <div class="alert alert-danger" role="alert" asp-condition="@Model.IsDemo">
                    <span>演示系统禁止修改内置后台任务</span>
                </div>
                <form class="form-inline">
                    <div class="row">
                        <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 class="form-control" data-toggle="lgbSelect" />
                            <select data-toggle="lgbSelect" class="d-none" id="taskCron" data-default-val="*/5 * * * * *">
                                @foreach (var task in Model.TaskTriggers)
                                {
                                    <option value="@task.Value">@task.Key</option>
                                }
                            </select>
                        </div>
                        <div class="form-group col-12">
                            <label class="control-label" for="taskContent">内置任务</label>
                            <input class="form-control" data-toggle="lgbSelect" />
                            <select data-toggle="lgbSelect" class="d-none" id="taskExecutor" data-default-val="Bootstrap.Admin.DefaultTaskExecutor">
                                @foreach (var task in Model.TaskExecutors)
                                {
                                    <option value="@task.Value">@task.Key</option>
                                }
                            </select>
                        </div>
                    </div>
                </form>
            </div>
            <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>
    </div>    
</div>
<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">
            <div class="modal-header">
                <h5 class="modal-title" id="taskModalLabel">任务日志窗口</h5>
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
            </div>
            <div class="modal-body" style="background-color: #174482; color: #fff;">
                <div id="taskMsg" class="form-group" style="height: 500px; overflow: auto;">
                    <div></div>
                </div>
            </div>
            <div class="modal-footer">
                <a class="btn"><i class="fa fa-check-square-o" style="width: 13px;"></i><span>自动滚屏</span></a>
                <button type="button" class="btn btn-secondary" data-dismiss="modal">
                    <i class="fa fa-times"></i>
                    <span>关闭</span>
                </button>
            </div>
        </div>
    </div>
</div>