seo_task.hbs
11.3 KB
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
<style type="text/css">
.task-add {
padding-top: 20px;
}
.task-add ul {
list-style: none;
}
.task-add ul li {
height: 40px;
}
.task-add select,
.task-add input {
width: 70%;
height: 30px;
padding: 5px;
}
.task-add .job-select {
margin-left: -3px;
}
.task-log {
padding: 20px;
}
.task-log table, .task-log table tr th,.task-log table tr td {
border: none;
}
.task-log tbody tr {
height: 40px;
}
.task-log table {
border-collapse: separate;
border-spacing: 0 4px;
}
.task-log tbody tr:nth-child(5n + 1) td:first-child {
border-left: 2px solid #00C656;
}
.task-log tbody tr:nth-child(5n + 2) td:first-child {
border-left: 2px solid #1e90ff;
}
.task-log tbody tr:nth-child(5n + 3) td:first-child {
border-left: 2px solid #00faff;
}
.task-log tbody tr:nth-child(5n + 4) td:first-child {
border-left: 2px solid #ee82ee;
}
.task-log tbody tr:nth-child(5n + 5) td:first-child {
border-left: 2px solid #FFFF00;
}
.task-log tbody tr.empty td {
border: none !important;
}
</style>
<div class="pageheader">
<div class="media">
<div class="pageicon pull-left">
<i class="fa fa-th-list"></i>
</div>
<div class="media-body">
<ul class="breadcrumb">
<li><a href="/"><i class="glyphicon glyphicon-home"></i></a></li>
<li>{{title}}</li>
</ul>
<h4>{{title}}</h4>
</div>
</div>
<!-- media -->
</div>
<!-- pageheader -->
<div class="contentpanel task-panel" style="padding-bottom:0;">
<div class="panel panel-default">
<div class="panel-body">
<button class="btn btn-default btn-add" >增加</button>
<button class="btn btn-default delete-all" type="submit">删除</button>
</div>
</div><!--/panel-default-->
<div class="panel panel-default">
<div class="panel-body">
<table class="table table-striped table-bordered tab-task">
<thead>
<tr>
<th width="10%">
<label><input type="checkbox" style="vertical-align: text-bottom;" onclick="javascript:$('.tab-task input[type=checkbox]').attr('checked', this.checked);" /> 全选</label>
</th>
<th class="text-center" width="20%">任务名称</th>
<th class="text-center" width="30%">链接</th>
<th class="text-center" width="10%">延迟时间</th>
<th class="text-center" width="15%">执行频率</th>
<th class="text-center" width="15%">操作</th>
</tr>
</thead>
<tbody>
{{#each tasks}}
<tr data-code="{{code}}" data-type="{{type}}">
<td> <input type="checkbox" /></td>
<td class="text-center td-name" >{{name}}</td>
<td class="text-center" >{{url}}</td>
<td class="text-center" >{{time}}</td>
<td class="text-center" >{{job_name}}</td>
<td class="text-center">
<a href="javascript:;" class="log-btn">执行日志</a>
<a href="javascript:;" class="del-btn">删除</a>
</td>
</tr>
{{/each}}
{{#unless tasks}}
<tr>
<td class="text-center" colspan="6">暂无数据</td>
</tr>
{{/unless}}
</tbody>
</table>
{{# pager}}
<div class="text-right">
{{#if pages}}
<ul class="pagination">
{{# prePage}}
<li><a href="{{url}}">上一页</a></li>
{{/ prePage}}
{{# pages}}
<li class="{{#unless url}}disabled {{/unless}}{{#if cur}}active{{/if}}"><a {{#if url}}href="{{url}}"{{^}}href="javascript:;"{{/if}}>{{num}}</a></li>
{{/ pages}}
{{# nextPage}}
<li><a href="{{url}}">下一页</a></li>
{{/ nextPage}}
</ul>
{{/if}}
</div>
{{/ pager}}
</div>
</div><!--/panel-default-->
</div><!--/contentpanel-->
<script id="task-add-tpl" type="text/tmpl">
<div class="task-add">
<ul>
<li>
执行频率:
<select class="job-select" data-placeholder="请选择..." >
<option value="-1">请选择...</option>
{{#each job}}
<option value="{{@index}}">{{info}}</option>
{{/each}}
</select>
</li>
<li>任务名称:<input type="text" class="job-name" placeholder='请输入任务名称...'></li>
<li>执行链接:<input type="text" class="job-link" placeholder='请输入执行链接...'></li>
<li>延迟时间:<input type="text" class="job-time" placeholder='请输入延迟时间...'></li>
</ul>
<p><span class="err-tip"></span></p>
</div>
</script>
<script id="task-log-tpl" type="text/tmpl">
<div class="task-log">
<table class="table table-striped table-bordered">
<thead>
<tr>
<th class="text-center" width="20%">执行时间</th>
<th class="text-center" width="20%">状态码</th>
<th class="text-center" width="50%">执行结果</th>
<th class="text-right" width="10%">
<a href="javascript:;" class="btn btn-default btn-refresh-log">刷新</a>
</th>
</tr>
</thead>
<tbody></tbody>
</table>
</div>
</script>
<script>
var tasks = {
init: function() {
var that = this;
var taskData = {};
this.$base = $('.contentpanel');
this.$base.on('click', '.btn-add', function() {
that.add();
});
// 单个删除
this.$base.on('click', '.del-btn', function() {
let $tr = $(this).closest('tr');
that.del([$tr.data()], () => $tr.remove());
});
// 日志
this.$base.on('click', '.log-btn', function() {
let $tr = $(this).closest('tr');
taskData = $tr.data();
return that.getTaskLog(taskData).then(rdata => {
layer.open({
type: 1,
area: ['800px', '500px'],
title: '《' + $tr.find('.td-name').text() + '》执行明细',
content: that.taskLogTpl
});
that.rendLog(rdata.data);
});
});
// 日志刷新
$('body').on('click', '.btn-refresh-log', function() {
var layerIndex = layer.load(1);
return that.getTaskLog(taskData).then(rdata => {
setTimeout(function() {
that.rendLog(rdata.data);
layer.close(layerIndex);
}, 800);
});
});
// 删除全部
this.$base.on('click', '.delete-all', function() {
let arr = [];
$('.tab-task input[type=checkbox]:checked').each(function(){
arr.push($(this).closest('tr').data());
});
that.del(arr, () => history.go(0));
});
this.taskAddTpl = $('#task-add-tpl').html();
this.taskLogTpl = $('#task-log-tpl').html();
},
add: function() {
var that = this;
var layerIndex = layer.open({
type: 1,
area: ['450px'],
title: '任务添加',
content: that.taskAddTpl,
btn: '添加',
yes: function() {
var data = {
type: parseInt($('.job-select').val(), 10),
name: $('.job-name').val(),
url: $('.job-link').val(),
time: parseInt($('.job-time').val() || 0),
};
if (data.type < 0) {
return that.tips('请选择执行频率...', '.job-select');
} else if (data.name === '') {
return that.tips('任务名称必填...', '.job-name');
} else if (data.url === '' || data.url.indexOf('http') === -1) {
return that.tips('请输入正确的执行链接...', '.job-link');
}
return that.ajax({
url: '/seo/task/add',
type: 'POST',
data: data,
}).then(rdata => {
if (rdata.code !== 200) {
return alert(rdata.message);
}
layer.close(layerIndex);
history.go(0)
});
}
});
},
del: function(data, callback) {
if (data.length <= 0) {
return false;
}
var that = this;
var layerIndex = layer.confirm('您确定要删除吗!!!', {
btn: ['确定', '取消']
}, function() {
return that.ajax({
url: '/seo/task/del',
type: 'POST',
data: {data: JSON.stringify(data)},
}).then(res => {
callback();
layer.close(layerIndex);
return res;
});
});
},
rendLog: function(rdata) {
var $tbody = $('.task-log tbody');
$tbody.empty();
if (rdata.length <= 0) {
$tbody.append(`<tr class="empty">
<td class="text-center" colspan="4">暂无数据</td>
</tr>`);
} else {
$.each(rdata, (key, item)=> {
$tbody.append(`<tr>
<td class="text-center" >${item.time}</td>
<td class="text-center" >${item.code}</td>
<td class="text-center" colspan="2">${item.message}</td>
</tr>`);
});
}
},
getTaskLog: function(data) {
return this.ajax({
url: '/seo/task/log',
type: 'POST',
data: data,
});
},
ajax: function(options) {
return Promise.resolve($.ajax(options));
},
tips: function(tip, dom) {
return layer.tips(tip, dom, {
tips: [1, '#000'],
time: 2000
});
}
};
$(function() {
tasks.init();
});
</script>