sbd-npm 1.4.5 → 1.4.7
Sign up to get free protection for your applications and to get access to all the features.
- package/package.json +1 -1
- package/status.js +119 -0
package/package.json
CHANGED
package/status.js
CHANGED
@@ -3,6 +3,8 @@ $(function () {
|
|
3
3
|
let Status = {
|
4
4
|
|
5
5
|
tab_token: "status_nav",
|
6
|
+
task_status: 0,
|
7
|
+
task_timer_id: 0,
|
6
8
|
data: {},
|
7
9
|
|
8
10
|
fetch_data: function () {
|
@@ -33,6 +35,9 @@ $(function () {
|
|
33
35
|
case "environment":
|
34
36
|
Status.handle_environment();
|
35
37
|
break;
|
38
|
+
case "task":
|
39
|
+
Status.handle_task();
|
40
|
+
break;
|
36
41
|
case "tool":
|
37
42
|
Status.handle_tool();
|
38
43
|
break;
|
@@ -385,6 +390,120 @@ $(function () {
|
|
385
390
|
});
|
386
391
|
},
|
387
392
|
|
393
|
+
handle_task: function () {
|
394
|
+
if (!document.getElementById("task_content")) {
|
395
|
+
let ht_html =[];
|
396
|
+
ht_html.push('<div class="page-header" style="margin-top: 15px; text-align: center;">');
|
397
|
+
ht_html.push('<div class="form-inline">');
|
398
|
+
ht_html.push('<div class="form-group">');
|
399
|
+
ht_html.push('<input data-toggle="tooltip" data-placement="top" title="要执行的任务内容" placeholder="要执行的任务内容" value="" type="text" class="form-control" id="task_content" autocomplete="off" />');
|
400
|
+
ht_html.push('</div> ');
|
401
|
+
ht_html.push('<button class="btn btn-default" id="task_add">添加任务</button>');
|
402
|
+
ht_html.push('<input type="checkbox" id="is_refresh_task"> 定时刷新数据');
|
403
|
+
ht_html.push(' <span id="task_tips"></span>');
|
404
|
+
ht_html.push('</div>');
|
405
|
+
ht_html.push('<form class="form-horizontal" style="margin-top: 10px;">');
|
406
|
+
ht_html.push('<div class="form-group" id="task_result_zone"></div>');
|
407
|
+
ht_html.push('</form>');
|
408
|
+
ht_html.push('</div>');
|
409
|
+
$("#task_div").html(ht_html.join(""));
|
410
|
+
$("#task_add").click(function() {
|
411
|
+
let task_content = $("#task_content").val();
|
412
|
+
if (task_content) {
|
413
|
+
$("#task_content").prop('disabled', true);
|
414
|
+
$("#task_add").prop('disabled', true);
|
415
|
+
Util.show_loading();
|
416
|
+
$("#task_tips").html("");
|
417
|
+
Util.post(location.pathname, {active_div: "task_add", "task_content": task_content}, function (j) {
|
418
|
+
if (j["code"] && j["code"] === 1) {
|
419
|
+
Status.task_status = 1;
|
420
|
+
$("#task_add").html('任务处理中...').removeClass("btn-default").addClass("btn-warning");
|
421
|
+
if (!document.getElementById("task_result")) {
|
422
|
+
$("#task_result_zone").html('<textarea rows="20" id="task_result" class="form-control"></textarea>');
|
423
|
+
}
|
424
|
+
$("#task_result").val("任务 `" + task_content + "` 处理中...");
|
425
|
+
if ($("#is_refresh_task").prop("checked")) {
|
426
|
+
Status.task_timer_id = setTimeout(function () {
|
427
|
+
Status.fetch_task_data();
|
428
|
+
}, 3456);
|
429
|
+
}
|
430
|
+
} else {
|
431
|
+
Status.task_status = 0;
|
432
|
+
if (j["code"] && j["code"] === 2) {
|
433
|
+
$("#task_tips").html("<b class='text-danger'>已添加新任务在处理中!</b>");
|
434
|
+
} else if (j["code"] && j["code"] === 3) {
|
435
|
+
$("#task_tips").html("<b class='text-danger'>有任务在执行中!</b>");
|
436
|
+
} else {
|
437
|
+
$("#task_tips").html("<b class='text-danger'>参数异常!</b>");
|
438
|
+
}
|
439
|
+
$("#task_content").prop('disabled', false);
|
440
|
+
$("#task_add").prop('disabled', false);
|
441
|
+
}
|
442
|
+
Util.hide_tips();
|
443
|
+
});
|
444
|
+
} else {
|
445
|
+
$("#task_tips").html("<b class='text-danger'>任务内容不能为空!</b>");
|
446
|
+
}
|
447
|
+
return false;
|
448
|
+
});
|
449
|
+
$("#is_refresh_task").click(function() {
|
450
|
+
if (Status.task_status > 0) {
|
451
|
+
clearTimeout(Status.task_timer_id);
|
452
|
+
if ($("#is_refresh_task").prop("checked")) {
|
453
|
+
Status.fetch_task_data();
|
454
|
+
}
|
455
|
+
}
|
456
|
+
});
|
457
|
+
}
|
458
|
+
Status.fetch_task_data();
|
459
|
+
},
|
460
|
+
|
461
|
+
fetch_task_data: function() {
|
462
|
+
Util.post(location.pathname, {active_div: localStorage[Status.tab_token]}, function (j) {
|
463
|
+
if (j["code"] && j["code"] > 1 && j["content"]) {
|
464
|
+
let ta_obj = $("#task_add");
|
465
|
+
let tc_obj = $("#task_content");
|
466
|
+
tc_obj.val(j["content"]);
|
467
|
+
if (j["code"] === 4) {
|
468
|
+
if (Status.task_status > 0) {
|
469
|
+
clearTimeout(Status.task_timer_id);
|
470
|
+
}
|
471
|
+
Status.task_status = 0;
|
472
|
+
ta_obj.html('添加任务').prop('disabled', false).removeClass("btn-warning").addClass("btn-default");
|
473
|
+
tc_obj.prop('disabled', false);
|
474
|
+
$("#task_tips").html("<b class='text-success'>任务 `" + j["content"] + "` 已经完成!</b>");
|
475
|
+
} else {
|
476
|
+
Status.task_status = 1;
|
477
|
+
ta_obj.html('任务处理中...').prop('disabled', true).removeClass("btn-default").addClass("btn-warning");
|
478
|
+
tc_obj.prop('disabled', true);
|
479
|
+
if ($("#is_refresh_task").prop("checked")) {
|
480
|
+
Status.task_timer_id = setTimeout(function () {
|
481
|
+
Status.fetch_task_data();
|
482
|
+
}, 3456);
|
483
|
+
}
|
484
|
+
}
|
485
|
+
if (!document.getElementById("task_result")) {
|
486
|
+
$("#task_result_zone").html('<textarea rows="20" id="task_result" class="form-control"></textarea>');
|
487
|
+
}
|
488
|
+
let tr_obj = $("#task_result");
|
489
|
+
if (j["result"]) {
|
490
|
+
tr_obj.val(j["result"]);
|
491
|
+
tr_obj.scrollTop(tr_obj[0].scrollHeight);
|
492
|
+
} else {
|
493
|
+
if (j["code"] !== 4) {
|
494
|
+
tr_obj.val("任务 `" + j["content"] + "` 处理中...");
|
495
|
+
}
|
496
|
+
}
|
497
|
+
} else {
|
498
|
+
if (Status.task_status > 0) {
|
499
|
+
clearTimeout(Status.task_timer_id);
|
500
|
+
}
|
501
|
+
Status.task_status = 0;
|
502
|
+
}
|
503
|
+
Util.hide_tips();
|
504
|
+
});
|
505
|
+
},
|
506
|
+
|
388
507
|
handle_tool: function () {
|
389
508
|
let t_obj = $("#timestamp");
|
390
509
|
let t_val = t_obj.val();
|