joblog.index.1.js 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. $(function() {
  2. // 任务组列表选中, 任务列表初始化和选中
  3. $("#jobGroup").on("change", function () {
  4. var jobGroup = $(this).children('option:selected').val();
  5. $.ajax({
  6. type : 'POST',
  7. async: false, // async, avoid js invoke pagelist before jobId data init
  8. url : base_url + '/joblog/getJobsByGroup',
  9. data : {"jobGroup":jobGroup},
  10. dataType : "json",
  11. success : function(data){
  12. if (data.code == 200) {
  13. $("#jobId").html('<option value="0" >请选择</option>');
  14. $.each(data.content, function (n, value) {
  15. $("#jobId").append('<option value="' + value.id + '" >' + value.jobDesc + '</option>');
  16. });
  17. if ($("#jobId").attr("paramVal")){
  18. $("#jobId").find("option[value='" + $("#jobId").attr("paramVal") + "']").attr("selected",true);
  19. }
  20. } else {
  21. ComAlertTec.show(data.msg);
  22. }
  23. },
  24. });
  25. });
  26. if ($("#jobGroup").attr("paramVal")){
  27. $("#jobGroup").find("option[value='" + $("#jobGroup").attr("paramVal") + "']").attr("selected",true);
  28. $("#jobGroup").change();
  29. }
  30. // 过滤时间
  31. $('#filterTime').daterangepicker({
  32. autoApply:false,
  33. singleDatePicker:false,
  34. showDropdowns:false, // 是否显示年月选择条件
  35. timePicker: true, // 是否显示小时和分钟选择条件
  36. timePickerIncrement: 10, // 时间的增量,单位为分钟
  37. timePicker24Hour : true,
  38. opens : 'left', //日期选择框的弹出位置
  39. ranges: {
  40. '最近1小时': [moment().subtract(1, 'hours'), moment()],
  41. '今日': [moment().startOf('day'), moment().endOf('day')],
  42. '昨日': [moment().subtract(1, 'days').startOf('day'), moment().subtract(1, 'days').endOf('day')],
  43. '最近7日': [moment().subtract(6, 'days'), moment()],
  44. '最近30日': [moment().subtract(29, 'days'), moment()],
  45. '本月': [moment().startOf('month'), moment().endOf('month')],
  46. '上个月': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
  47. },
  48. locale : {
  49. format: 'YYYY-MM-DD HH:mm:ss',
  50. separator : ' - ',
  51. customRangeLabel : '自定义',
  52. applyLabel : '确定',
  53. cancelLabel : '取消',
  54. fromLabel : '起始时间',
  55. toLabel : '结束时间',
  56. daysOfWeek : [ '日', '一', '二', '三', '四', '五', '六' ],
  57. monthNames : [ '一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月' ],
  58. firstDay : 1,
  59. startDate: moment().startOf('day'),
  60. endDate: moment().endOf('day')
  61. }
  62. });
  63. // init date tables
  64. var logTable = $("#joblog_list").dataTable({
  65. "deferRender": true,
  66. "processing" : true,
  67. "serverSide": true,
  68. "ajax": {
  69. url: base_url + "/joblog/pageList" ,
  70. data : function ( d ) {
  71. var obj = {};
  72. obj.jobGroup = $('#jobGroup').val();
  73. obj.jobId = $('#jobId').val();
  74. obj.filterTime = $('#filterTime').val();
  75. obj.start = d.start;
  76. obj.length = d.length;
  77. return obj;
  78. }
  79. },
  80. "searching": false,
  81. "ordering": false,
  82. //"scrollX": false,
  83. "columns": [
  84. { "data": 'id', "bSortable": false, "visible" : false},
  85. { "data": 'jobGroup', "visible" : false},
  86. { "data": 'jobId', "visible" : false},
  87. {
  88. "data": 'triggerTime',
  89. "render": function ( data, type, row ) {
  90. return data?moment(new Date(data)).format("YYYY-MM-DD HH:mm:ss"):"";
  91. }
  92. },
  93. {
  94. "data": 'triggerCode',
  95. "render": function ( data, type, row ) {
  96. return (data==200)?'<span style="color: green">成功</span>':(data==500)?'<span style="color: red">失败</span>':(data==0)?'':data;
  97. }
  98. },
  99. {
  100. "data": 'triggerMsg',
  101. "render": function ( data, type, row ) {
  102. return data?'<a class="logTips" href="javascript:;" >查看<span style="display:none;">'+ data +'</span></a>':"无";
  103. }
  104. },
  105. { "data": 'executorAddress', "visible" : true},
  106. {
  107. "data": 'executorHandler',
  108. "visible" : true,
  109. "render": function ( data, type, row ) {
  110. return (row.executorHandler)?row.executorHandler:"GLUE模式";
  111. }
  112. },
  113. { "data": 'executorParam', "visible" : true},
  114. {
  115. "data": 'handleTime',
  116. "render": function ( data, type, row ) {
  117. return data?moment(new Date(data)).format("YYYY-MM-DD HH:mm:ss"):"";
  118. }
  119. },
  120. {
  121. "data": 'handleCode',
  122. "render": function ( data, type, row ) {
  123. return (data==200)?'<span style="color: green">成功</span>':(data==500)?'<span style="color: red">失败</span>':(data==0)?'':data;
  124. }
  125. },
  126. {
  127. "data": 'handleMsg',
  128. "render": function ( data, type, row ) {
  129. return data?'<a class="logTips" href="javascript:;" >查看<span style="display:none;">'+ data +'</span></a>':"无";
  130. }
  131. },
  132. { "data": 'handleMsg' , "bSortable": false,
  133. "render": function ( data, type, row ) {
  134. // better support expression or string, not function
  135. return function () {
  136. if (row.triggerCode == 200){
  137. var temp = '<a href="javascript:;" class="logDetail" _id="'+ row.id +'">执行日志</a>';
  138. if(row.handleCode == 0){
  139. temp += '<br><a href="javascript:;" class="logKill" _id="'+ row.id +'">终止任务</a>';
  140. }
  141. return temp;
  142. }
  143. return null;
  144. }
  145. }
  146. }
  147. ],
  148. "language" : {
  149. "sProcessing" : "处理中...",
  150. "sLengthMenu" : "每页 _MENU_ 条记录",
  151. "sZeroRecords" : "没有匹配结果",
  152. "sInfo" : "第 _PAGE_ 页 ( 总共 _PAGES_ 页,_TOTAL_ 条记录 )",
  153. "sInfoEmpty" : "无记录",
  154. "sInfoFiltered" : "(由 _MAX_ 项结果过滤)",
  155. "sInfoPostFix" : "",
  156. "sSearch" : "搜索:",
  157. "sUrl" : "",
  158. "sEmptyTable" : "表中数据为空",
  159. "sLoadingRecords" : "载入中...",
  160. "sInfoThousands" : ",",
  161. "oPaginate" : {
  162. "sFirst" : "首页",
  163. "sPrevious" : "上页",
  164. "sNext" : "下页",
  165. "sLast" : "末页"
  166. },
  167. "oAria" : {
  168. "sSortAscending" : ": 以升序排列此列",
  169. "sSortDescending" : ": 以降序排列此列"
  170. }
  171. }
  172. });
  173. // 任务数据
  174. $('#joblog_list').on('click', '.logMsg', function(){
  175. var msg = $(this).find('span').html();
  176. ComAlert.show(2, msg);
  177. });
  178. // 日志弹框提示
  179. $('#joblog_list').on('click', '.logTips', function(){
  180. var msg = $(this).find('span').html();
  181. ComAlertTec.show(msg);
  182. });
  183. // 搜索按钮
  184. $('#searchBtn').on('click', function(){
  185. logTable.fnDraw();
  186. });
  187. // 查看执行器详细执行日志
  188. $('#joblog_list').on('click', '.logDetail', function(){
  189. var _id = $(this).attr('_id');
  190. window.open(base_url + '/joblog/logDetailPage?id=' + _id);
  191. return;
  192. /*
  193. $.ajax({
  194. type : 'POST',
  195. url : base_url + '/joblog/logDetail',
  196. data : {"id":_id},
  197. dataType : "json",
  198. success : function(data){
  199. if (data.code == 200) {
  200. ComAlertTec.show('<pre style="color: white;background-color: black;width2:'+ $(window).width()*2/3 +'px;" >'+ data.content +'</pre>');
  201. } else {
  202. ComAlertTec.show(data.msg);
  203. }
  204. },
  205. });
  206. */
  207. });
  208. $('#joblog_list').on('click', '.logKill', function(){
  209. var _id = $(this).attr('_id');
  210. ComConfirm.show("确认主动终止任务?", function(){
  211. $.ajax({
  212. type : 'POST',
  213. url : base_url + '/joblog/logKill',
  214. data : {"id":_id},
  215. dataType : "json",
  216. success : function(data){
  217. if (data.code == 200) {
  218. ComAlert.show(1, '操作成功');
  219. logTable.fnDraw();
  220. } else {
  221. ComAlert.show(2, data.msg);
  222. }
  223. },
  224. });
  225. });
  226. });
  227. });