xxl-job

joblog.index.1.js 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. $(function() {
  2. // jobGroup change, job list init and select
  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" >'+ I18n.system_all +'</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. layer.open({
  22. title: I18n.system_tips ,
  23. btn: [ I18n.system_ok ],
  24. content: (data.msg || I18n.system_api_error ),
  25. icon: '2'
  26. });
  27. }
  28. },
  29. });
  30. });
  31. if ($("#jobGroup").attr("paramVal")){
  32. $("#jobGroup").find("option[value='" + $("#jobGroup").attr("paramVal") + "']").attr("selected",true);
  33. $("#jobGroup").change();
  34. }
  35. // filter Time
  36. var rangesConf = {};
  37. rangesConf[I18n.daterangepicker_ranges_recent_hour] = [moment().subtract(1, 'hours'), moment()];
  38. rangesConf[I18n.daterangepicker_ranges_today] = [moment().startOf('day'), moment().endOf('day')];
  39. rangesConf[I18n.daterangepicker_ranges_yesterday] = [moment().subtract(1, 'days').startOf('day'), moment().subtract(1, 'days').endOf('day')];
  40. rangesConf[I18n.daterangepicker_ranges_this_month] = [moment().startOf('month'), moment().endOf('month')];
  41. rangesConf[I18n.daterangepicker_ranges_last_month] = [moment().subtract(1, 'months').startOf('month'), moment().subtract(1, 'months').endOf('month')];
  42. rangesConf[I18n.daterangepicker_ranges_recent_week] = [moment().subtract(1, 'weeks').startOf('day'), moment().endOf('day')];
  43. rangesConf[I18n.daterangepicker_ranges_recent_month] = [moment().subtract(1, 'months').startOf('day'), moment().endOf('day')];
  44. $('#filterTime').daterangepicker({
  45. autoApply:false,
  46. singleDatePicker:false,
  47. showDropdowns:false, // 是否显示年月选择条件
  48. timePicker: true, // 是否显示小时和分钟选择条件
  49. timePickerIncrement: 10, // 时间的增量,单位为分钟
  50. timePicker24Hour : true,
  51. opens : 'left', //日期选择框的弹出位置
  52. ranges: rangesConf,
  53. locale : {
  54. format: 'YYYY-MM-DD HH:mm:ss',
  55. separator : ' - ',
  56. customRangeLabel : I18n.daterangepicker_custom_name ,
  57. applyLabel : I18n.system_ok ,
  58. cancelLabel : I18n.system_cancel ,
  59. fromLabel : I18n.daterangepicker_custom_starttime ,
  60. toLabel : I18n.daterangepicker_custom_endtime ,
  61. daysOfWeek : I18n.daterangepicker_custom_daysofweek.split(',') , // '日', '一', '二', '三', '四', '五', '六'
  62. monthNames : I18n.daterangepicker_custom_monthnames.split(',') , // '一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'
  63. firstDay : 1
  64. },
  65. startDate: rangesConf[I18n.daterangepicker_ranges_today][0],
  66. endDate: rangesConf[I18n.daterangepicker_ranges_today][1]
  67. });
  68. // init date tables
  69. var logTable = $("#joblog_list").dataTable({
  70. "deferRender": true,
  71. "processing" : true,
  72. "serverSide": true,
  73. "ajax": {
  74. url: base_url + "/joblog/pageList" ,
  75. type:"post",
  76. data : function ( d ) {
  77. var obj = {};
  78. obj.jobGroup = $('#jobGroup').val();
  79. obj.jobId = $('#jobId').val();
  80. obj.logStatus = $('#logStatus').val();
  81. obj.filterTime = $('#filterTime').val();
  82. obj.start = d.start;
  83. obj.length = d.length;
  84. return obj;
  85. }
  86. },
  87. "searching": false,
  88. "ordering": false,
  89. //"scrollX": false,
  90. "columns": [
  91. {
  92. "data": 'jobId',
  93. "visible" : true,
  94. "width":'10%',
  95. "render": function ( data, type, row ) {
  96. var jobhandler = '';
  97. if (row.executorHandler) {
  98. jobhandler = "<br>JobHandler:" + row.executorHandler;
  99. }
  100. var temp = '';
  101. temp += I18n.joblog_field_executorAddress + ':' + (row.executorAddress?row.executorAddress:'');
  102. temp += jobhandler;
  103. temp += '<br>'+ I18n.jobinfo_field_executorparam +':' + row.executorParam;
  104. return '<a class="logTips" href="javascript:;" >'+ row.jobId +'<span style="display:none;">'+ temp +'</span></a>';
  105. }
  106. },
  107. { "data": 'jobGroup', "visible" : false},
  108. {
  109. "data": 'triggerTime',
  110. "width":'16%',
  111. "render": function ( data, type, row ) {
  112. return data?moment(new Date(data)).format("YYYY-MM-DD HH:mm:ss"):"";
  113. }
  114. },
  115. {
  116. "data": 'triggerCode',
  117. "width":'12%',
  118. "render": function ( data, type, row ) {
  119. var html = data;
  120. if (data == 200) {
  121. html = '<span style="color: green">'+ I18n.system_success +'</span>';
  122. } else if (data == 500) {
  123. html = '<span style="color: red">'+ I18n.system_fail +'</span>';
  124. } else if (data == 0) {
  125. html = '';
  126. }
  127. return html;
  128. }
  129. },
  130. {
  131. "data": 'triggerMsg',
  132. "width":'12%',
  133. "render": function ( data, type, row ) {
  134. return data?'<a class="logTips" href="javascript:;" >'+ I18n.system_show +'<span style="display:none;">'+ data +'</span></a>':I18n.system_empty;
  135. }
  136. },
  137. {
  138. "data": 'handleTime',
  139. "width":'16%',
  140. "render": function ( data, type, row ) {
  141. return data?moment(new Date(data)).format("YYYY-MM-DD HH:mm:ss"):"";
  142. }
  143. },
  144. {
  145. "data": 'handleCode',
  146. "width":'12%',
  147. "render": function ( data, type, row ) {
  148. var html = data;
  149. if (data == 200) {
  150. html = '<span style="color: green">'+ I18n.joblog_handleCode_200 +'</span>';
  151. } else if (data == 500) {
  152. html = '<span style="color: red">'+ I18n.joblog_handleCode_500 +'</span>';
  153. } else if (data == 502) {
  154. html = '<span style="color: red">'+ I18n.joblog_handleCode_502 +'</span>';
  155. } else if (data == 0) {
  156. html = '';
  157. }
  158. return html;
  159. }
  160. },
  161. {
  162. "data": 'handleMsg',
  163. "width":'12%',
  164. "render": function ( data, type, row ) {
  165. return data?'<a class="logTips" href="javascript:;" >'+ I18n.system_show +'<span style="display:none;">'+ data +'</span></a>':I18n.system_empty;
  166. }
  167. },
  168. {
  169. "data": 'handleMsg' ,
  170. "bSortable": false,
  171. "width":'10%',
  172. "render": function ( data, type, row ) {
  173. // better support expression or string, not function
  174. return function () {
  175. if (row.triggerCode == 200 || row.handleCode != 0){
  176. var temp = '<a href="javascript:;" class="logDetail" _id="'+ row.id +'">'+ I18n.joblog_rolling_log +'</a>';
  177. if(row.handleCode == 0){
  178. temp += '<br><a href="javascript:;" class="logKill" _id="'+ row.id +'" style="color: red;" >'+ I18n.joblog_kill_log +'</a>';
  179. }
  180. return temp;
  181. }
  182. return null;
  183. }
  184. }
  185. }
  186. ],
  187. "language" : {
  188. "sProcessing" : I18n.dataTable_sProcessing ,
  189. "sLengthMenu" : I18n.dataTable_sLengthMenu ,
  190. "sZeroRecords" : I18n.dataTable_sZeroRecords ,
  191. "sInfo" : I18n.dataTable_sInfo ,
  192. "sInfoEmpty" : I18n.dataTable_sInfoEmpty ,
  193. "sInfoFiltered" : I18n.dataTable_sInfoFiltered ,
  194. "sInfoPostFix" : "",
  195. "sSearch" : I18n.dataTable_sSearch ,
  196. "sUrl" : "",
  197. "sEmptyTable" : I18n.dataTable_sEmptyTable ,
  198. "sLoadingRecords" : I18n.dataTable_sLoadingRecords ,
  199. "sInfoThousands" : ",",
  200. "oPaginate" : {
  201. "sFirst" : I18n.dataTable_sFirst ,
  202. "sPrevious" : I18n.dataTable_sPrevious ,
  203. "sNext" : I18n.dataTable_sNext ,
  204. "sLast" : I18n.dataTable_sLast
  205. },
  206. "oAria" : {
  207. "sSortAscending" : I18n.dataTable_sSortAscending ,
  208. "sSortDescending" : I18n.dataTable_sSortDescending
  209. }
  210. }
  211. });
  212. // logTips alert
  213. $('#joblog_list').on('click', '.logTips', function(){
  214. var msg = $(this).find('span').html();
  215. ComAlertTec.show(msg);
  216. });
  217. // search Btn
  218. $('#searchBtn').on('click', function(){
  219. logTable.fnDraw();
  220. });
  221. // logDetail look
  222. $('#joblog_list').on('click', '.logDetail', function(){
  223. var _id = $(this).attr('_id');
  224. window.open(base_url + '/joblog/logDetailPage?id=' + _id);
  225. return;
  226. });
  227. /**
  228. * log Kill
  229. */
  230. $('#joblog_list').on('click', '.logKill', function(){
  231. var _id = $(this).attr('_id');
  232. layer.confirm( (I18n.system_ok + I18n.joblog_kill_log + '?'), {
  233. icon: 3,
  234. title: I18n.system_tips ,
  235. btn: [ I18n.system_ok, I18n.system_cancel ]
  236. }, function(index){
  237. layer.close(index);
  238. $.ajax({
  239. type : 'POST',
  240. url : base_url + '/joblog/logKill',
  241. data : {"id":_id},
  242. dataType : "json",
  243. success : function(data){
  244. if (data.code == 200) {
  245. layer.open({
  246. title: I18n.system_tips,
  247. btn: [ I18n.system_ok ],
  248. content: I18n.system_opt_suc ,
  249. icon: '1',
  250. end: function(layero, index){
  251. logTable.fnDraw();
  252. }
  253. });
  254. } else {
  255. layer.open({
  256. title: I18n.system_tips,
  257. btn: [ I18n.system_ok ],
  258. content: (data.msg || I18n.system_opt_fail ),
  259. icon: '2'
  260. });
  261. }
  262. },
  263. });
  264. });
  265. });
  266. /**
  267. * clear Log
  268. */
  269. $('#clearLog').on('click', function(){
  270. var jobGroup = $('#jobGroup').val();
  271. var jobId = $('#jobId').val();
  272. var jobGroupText = $("#jobGroup").find("option:selected").text();
  273. var jobIdText = $("#jobId").find("option:selected").text();
  274. $('#clearLogModal input[name=jobGroup]').val(jobGroup);
  275. $('#clearLogModal input[name=jobId]').val(jobId);
  276. $('#clearLogModal .jobGroupText').val(jobGroupText);
  277. $('#clearLogModal .jobIdText').val(jobIdText);
  278. $('#clearLogModal').modal('show');
  279. });
  280. $("#clearLogModal .ok").on('click', function(){
  281. $.post(base_url + "/joblog/clearLog", $("#clearLogModal .form").serialize(), function(data, status) {
  282. if (data.code == "200") {
  283. $('#clearLogModal').modal('hide');
  284. layer.open({
  285. title: I18n.system_tips ,
  286. btn: [ I18n.system_ok ],
  287. content: (I18n.joblog_clean_log + I18n.system_success) ,
  288. icon: '1',
  289. end: function(layero, index){
  290. logTable.fnDraw();
  291. }
  292. });
  293. } else {
  294. layer.open({
  295. title: I18n.system_tips ,
  296. btn: [ I18n.system_ok ],
  297. content: (data.msg || (I18n.joblog_clean_log + I18n.system_fail) ),
  298. icon: '2'
  299. });
  300. }
  301. });
  302. });
  303. $("#clearLogModal").on('hide.bs.modal', function () {
  304. $("#clearLogModal .form")[0].reset();
  305. });
  306. });
  307. // Com Alert by Tec theme
  308. var ComAlertTec = {
  309. html:function(){
  310. var html =
  311. '<div class="modal fade" id="ComAlertTec" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">' +
  312. '<div class="modal-dialog">' +
  313. '<div class="modal-content-tec">' +
  314. '<div class="modal-body"><div class="alert" style="color:#fff;"></div></div>' +
  315. '<div class="modal-footer">' +
  316. '<div class="text-center" >' +
  317. '<button type="button" class="btn btn-info ok" data-dismiss="modal" >'+ I18n.system_ok +'</button>' +
  318. '</div>' +
  319. '</div>' +
  320. '</div>' +
  321. '</div>' +
  322. '</div>';
  323. return html;
  324. },
  325. show:function(msg, callback){
  326. // dom init
  327. if ($('#ComAlertTec').length == 0){
  328. $('body').append(ComAlertTec.html());
  329. }
  330. // init com alert
  331. $('#ComAlertTec .alert').html(msg);
  332. $('#ComAlertTec').modal('show');
  333. $('#ComAlertTec .ok').click(function(){
  334. $('#ComAlertTec').modal('hide');
  335. if(typeof callback == 'function') {
  336. callback();
  337. }
  338. });
  339. }
  340. };