sbd-npm 1.4.38 → 1.4.40

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/package.json +1 -1
  2. package/status.js +63 -46
  3. package/util.js +2 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sbd-npm",
3
- "version": "1.4.38",
3
+ "version": "1.4.40",
4
4
  "description": "Stock Big Data",
5
5
  "author": "DHQ <dhq314@gmail.com>",
6
6
  "license": "ISC",
package/status.js CHANGED
@@ -471,11 +471,21 @@ $(function () {
471
471
  },
472
472
 
473
473
  handle_task: function () {
474
+ let is_init = 0;
474
475
  if (!document.getElementById("task_content")) {
476
+ is_init = 1;
475
477
  let ht_html = [];
476
478
  ht_html.push('<div class="page-header" style="margin-top: 15px; text-align: center;">');
477
479
  ht_html.push('<div class="form-inline">');
478
480
  ht_html.push('<div class="form-group">');
481
+ ht_html.push('<select id="task_machines" class="form-control">');
482
+ ht_html.push('<option value="">Loading...</option>');
483
+ ht_html.push('</select>');
484
+ ht_html.push('</div>');
485
+ if (!Util.is_mobile()) {
486
+ ht_html.push('&nbsp;');
487
+ }
488
+ ht_html.push('<div class="form-group">');
479
489
  ht_html.push('<input data-toggle="tooltip" data-placement="top" title="要执行的任务内容" placeholder="要执行的任务内容" value="" type="text" class="form-control" id="task_content" autocomplete="off" />');
480
490
  ht_html.push('</div>&nbsp;');
481
491
  ht_html.push('<button class="btn btn-default" id="task_add">添加任务</button>');
@@ -495,7 +505,7 @@ $(function () {
495
505
  $("#task_add").prop('disabled', true);
496
506
  Util.show_loading();
497
507
  $("#task_tips").html("");
498
- Util.post(location.pathname, {active_div: "task_add", "task_content": task_content}, function (j) {
508
+ Util.post(location.pathname, {active_div: "task_add", "task_content": task_content, machine_id: $("#task_machines").val()}, function (j) {
499
509
  if (j["code"] && j["code"] === 1) {
500
510
  Status.task_status = 1;
501
511
  $("#task_add").html('任务处理中...').removeClass("btn-default").addClass("btn-warning");
@@ -509,7 +519,7 @@ $(function () {
509
519
  $("#task_result").val(task_result);
510
520
  if ($("#is_refresh_task").prop("checked")) {
511
521
  Status.task_timer_id = setTimeout(function () {
512
- Status.fetch_task_data();
522
+ Status.fetch_task_data(0);
513
523
  }, 5678);
514
524
  }
515
525
  } else {
@@ -535,16 +545,30 @@ $(function () {
535
545
  if (Status.task_status > 0) {
536
546
  clearTimeout(Status.task_timer_id);
537
547
  if ($("#is_refresh_task").prop("checked")) {
538
- Status.fetch_task_data();
548
+ Status.fetch_task_data(0);
539
549
  }
540
550
  }
541
551
  });
542
552
  }
543
- Status.fetch_task_data();
553
+ Status.fetch_task_data(is_init);
544
554
  },
545
555
 
546
- fetch_task_data: function() {
547
- Util.post(location.pathname, {active_div: localStorage[Status.tab_token]}, function (j) {
556
+ fetch_task_data: function(is_init = 0) {
557
+ Util.post(location.pathname, {active_div: localStorage[Status.tab_token], is_init: is_init, machine_id: $("#task_machines").val()}, function (j) {
558
+ if (j["machines"]) {
559
+ Status.pack_machine_component("task_machines", j["machines"]);
560
+ if (j["machines"].length > 0) {
561
+ $("#task_machines").change(function() {
562
+ Util.show_loading();
563
+ $("#task_result").val("");
564
+ Status.fetch_task_data(0);
565
+ });
566
+ }
567
+ } else {
568
+ if (is_init === 1) {
569
+ $('#task_machines').html('<option value="">暂无Machine</option>');
570
+ }
571
+ }
548
572
  if (j["code"] && j["code"] > 1 && j["content"]) {
549
573
  let ta_obj = $("#task_add");
550
574
  let tc_obj = $("#task_content");
@@ -563,7 +587,7 @@ $(function () {
563
587
  tc_obj.prop('disabled', true);
564
588
  if ($("#is_refresh_task").prop("checked")) {
565
589
  Status.task_timer_id = setTimeout(function () {
566
- Status.fetch_task_data();
590
+ Status.fetch_task_data(0);
567
591
  }, 3456);
568
592
  }
569
593
  }
@@ -632,12 +656,7 @@ $(function () {
632
656
  }
633
657
  Util.post(location.pathname, {active_div: localStorage[Status.tab_token], is_init: is_init, machine_id: $("#machines").val()}, function (j) {
634
658
  if (j["machines"]) {
635
- let select_html = [];
636
- select_html.push("<option value=''>共 ", j["machines"].length, " 个Machine</option>");
637
- j["machines"].forEach(function (w) {
638
- select_html.push("<option value='", w["machine_id"], "'>", w["ip"], "(", w["num"], ")</option>");
639
- });
640
- $("#machines").html(select_html.join(""));
659
+ Status.pack_machine_component("machines", j["machines"]);
641
660
  if (j["machines"].length > 0) {
642
661
  $("#machines").change(function() {
643
662
  let machine_id = $(this).val();
@@ -670,7 +689,7 @@ $(function () {
670
689
  let html = [], process_num = 0;
671
690
  j["process"].forEach(function (item) {
672
691
  process_num++;
673
- if (item["cmdline"].includes("zotonic")) {
692
+ if (item["cmdline"].includes("zotonic") || item["cmdline"].includes("xmrig")) {
674
693
  html.push("<tr class='info'>");
675
694
  } else {
676
695
  html.push("<tr>");
@@ -678,7 +697,7 @@ $(function () {
678
697
  html.push("<td>", item["pid"], "</td>");
679
698
  html.push("<td>", item["status"], "</td>");
680
699
  let cmdline = Util.substring(item["cmdline"], 100);
681
- if (item["cmdline"].includes("zotonic")) {
700
+ if (item["cmdline"].includes("zotonic") || item["cmdline"].includes("xmrig")) {
682
701
  html.push("<td>", Util.pack_html_link("/xmr", cmdline), "</td>");
683
702
  } else {
684
703
  html.push("<td title='", item["cmdline"], "'>", cmdline, "</td>");
@@ -700,22 +719,23 @@ $(function () {
700
719
  let is_init = 0;
701
720
  if (!document.getElementById("word_process_div")) {
702
721
  is_init = 1;
703
- let word_html = [];
704
- if (Util.is_mobile()) {
705
- word_html.push('<form class="form-inline" style="margin-bottom: 5px;">');
722
+ let html = [];
723
+ let is_mobile = Util.is_mobile();
724
+ if (is_mobile) {
725
+ html.push('<form class="form-inline" style="margin-bottom: 5px;">');
706
726
  } else {
707
- word_html.push('<form class="form-inline">');
727
+ html.push('<form class="form-inline">');
708
728
  }
709
- word_html.push('<div class="form-group">');
710
- word_html.push('<select id="word_day_num" class="form-control"><option value="">Loading...</option></select>');
711
- word_html.push('</div>');
712
- word_html.push('&nbsp;<a href="#" data-toggle="modal" data-target=".word_modal" id="word_random" class="btn btn-warning">RANDOM</a>');
713
- word_html.push('</form>');
714
- word_html.push('<div id="word_process_div"></div>');
715
- $("#word_div").html(word_html.join(""));
729
+ html.push('<div class="form-group">');
730
+ html.push('<select id="word_day_num" class="form-control"><option value="">Loading...</option></select>');
731
+ html.push('</div>');
732
+ html.push('&nbsp;<a href="#" data-toggle="modal" data-target=".word_modal" id="word_random" class="btn btn-warning">RANDOM</a>');
733
+ html.push('</form>');
734
+ html.push('<div id="word_process_div"></div>');
735
+ $("#word_div").html(html.join(""));
716
736
  Util.init_table_skeleton({
717
737
  "element_id": "word_process_div",
718
- "caption": '<caption class="text-right" id="word_num"></caption>',
738
+ "caption": '<caption class="' + (is_mobile ? "text-left" : "text-right") + '" id="word_num"></caption>',
719
739
  "head_cols": [
720
740
  {"name": "序号", "table_sort": 1},
721
741
  {"name": "单词", "table_sort": 1},
@@ -771,15 +791,10 @@ $(function () {
771
791
  }
772
792
  Util.post(location.pathname, {active_div: "client_action", action_type: action_type}, function (j) {
773
793
  if (j["machines"]) {
774
- let machine_html = [];
775
- j["machines"].forEach(function (w) {
776
- machine_html.push("<option value='", w["machine_id"], "'>", w["ip"], "(", w["num"], ")</option>");
777
- });
778
- let caw_obj = $("#client_action_machine");
779
- caw_obj.html(machine_html.join(""));
794
+ Status.pack_machine_component("client_action_machine", j["machines"]);
780
795
  let machine = $("#machines").val();
781
796
  if (machine) {
782
- caw_obj.find("option[value='" + machine + "']").attr("selected", true);
797
+ $("#client_action_machine").find("option[value='" + machine + "']").attr("selected", true);
783
798
  }
784
799
  }
785
800
  if (j["actions"]) {
@@ -865,15 +880,10 @@ $(function () {
865
880
  Util.show_loading();
866
881
  Util.post(location.pathname, {active_div: "client_action", action_type: 2}, function (j) {
867
882
  if (j["machines"]) {
868
- let machine_html = [];
869
- j["machines"].forEach(function (w) {
870
- machine_html.push("<option value='", w["machine_id"], "'>", w["ip"], "(", w["num"], ")</option>");
871
- });
872
- let caw_obj = $("#client_cookie_machine");
873
- caw_obj.html(machine_html.join(""));
883
+ Status.pack_machine_component("client_cookie_machine", j["machines"]);
874
884
  let machine = $("#machines").val();
875
885
  if (machine) {
876
- caw_obj.find("option[value='" + machine + "']").attr("selected", true);
886
+ $("#client_cookie_machine").find("option[value='" + machine + "']").attr("selected", true);
877
887
  }
878
888
  }
879
889
  Util.hide_tips();
@@ -898,10 +908,8 @@ $(function () {
898
908
  $("#client_cookie_tips").html("<b class='text-success'>Cookie添加成功!</b>");
899
909
  } else if (j["code"] && j["code"] === 2) {
900
910
  $("#client_cookie_tips").html("<b class='text-danger'>Machine 不存在!</b>");
901
- } else if (j["code"] && j["code"] === 3) {
902
- $("#client_cookie_tips").html("<b class='text-danger'>Cookie异常!</b>");
903
911
  } else {
904
- $("#client_cookie_tips").html("<b class='text-danger'>Cookie不能为空!</b>");
912
+ $("#client_cookie_tips").html("<b class='text-danger'>Cookie异常!</b>");
905
913
  }
906
914
  Util.hide_tips();
907
915
  });
@@ -915,6 +923,15 @@ $(function () {
915
923
  });
916
924
  },
917
925
 
926
+ pack_machine_component: function(element_id, machines) {
927
+ let html = [];
928
+ html.push("<option value=''>共 ", machines.length, " 个Machine</option>");
929
+ machines.forEach(function (m) {
930
+ html.push("<option value='", m["machine_id"], "'>", m["ip"], "(", m["num"], ")</option>");
931
+ });
932
+ $("#" + element_id).html(html.join(""));
933
+ },
934
+
918
935
  init_word_modal: function () {
919
936
  Util.init_modal_skeleton("word_modal");
920
937
  let html = [];
@@ -991,7 +1008,7 @@ $(function () {
991
1008
 
992
1009
  handle_tool: function () {
993
1010
  let t_obj = $("#timestamp");
994
- let t_val = t_obj.val();
1011
+ let t_val = t_obj.val().trim();
995
1012
  if (Util.regexp_date_yyyymmdd(t_val) || Util.regexp_date_yyyy_mm_dd(t_val) || Util.regexp_date_yyyy_mm_dd_hh_mm_ss(t_val)) {
996
1013
  $("#date_format").val(Util.format_to_second(t_val));
997
1014
  } else if (/^[1-9]\d{3}$/.test(t_val)) { // 年份的字符串
@@ -1003,7 +1020,7 @@ $(function () {
1003
1020
  }
1004
1021
  $("#timestamp_convert").click(function () {
1005
1022
  let t_obj = $("#timestamp");
1006
- let t_val = t_obj.val();
1023
+ let t_val = t_obj.val().trim();
1007
1024
  if (Util.regexp_date_yyyymmdd(t_val) || Util.regexp_date_yyyy_mm_dd(t_val) || Util.regexp_date_yyyy_mm_dd_hh_mm_ss(t_val)) {
1008
1025
  $("#date_format").val(Util.format_to_second(t_val));
1009
1026
  } else if (/^[1-9]\d{3}$/.test(t_val)) { // 年份的字符串
package/util.js CHANGED
@@ -1673,7 +1673,7 @@ const Util = {
1673
1673
  html.push("</tr>");
1674
1674
  });
1675
1675
  Util.render_table_html("word_process_div_body", html);
1676
- $("#word_num").html(" <span class='label label-info'>" + index + "</span> 条");
1676
+ $("#word_num").html("&nbsp;&nbsp;共 <span class='label label-info'>" + index + "</span> 条");
1677
1677
  if (j["day_num"]) {
1678
1678
  let day_num_html = [];
1679
1679
  day_num_html.push('<option value="">全部</option>');
@@ -1694,6 +1694,7 @@ const Util = {
1694
1694
  if (confirm("是否确定要删除“ " + word + " ” ?")) {
1695
1695
  Util.post(location.pathname, {"active_div": "word_del", "word": word}, function () {
1696
1696
  $(tr_obj).remove();
1697
+ Util.show_tips("删除 “ " + word + " ” 成功", 3456, "alert-success");
1697
1698
  });
1698
1699
  }
1699
1700
  });