xxl-job

joblog.index.1.js 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  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. layer.open({
  22. title: '系统提示',
  23. content: (data.msg || "接口异常"),
  24. icon: '2'
  25. });
  26. }
  27. },
  28. });
  29. });
  30. if ($("#jobGroup").attr("paramVal")){
  31. $("#jobGroup").find("option[value='" + $("#jobGroup").attr("paramVal") + "']").attr("selected",true);
  32. $("#jobGroup").change();
  33. }
  34. // 过滤时间
  35. $('#filterTime').daterangepicker({
  36. autoApply:false,
  37. singleDatePicker:false,
  38. showDropdowns:false, // 是否显示年月选择条件
  39. timePicker: true, // 是否显示小时和分钟选择条件
  40. timePickerIncrement: 10, // 时间的增量,单位为分钟
  41. timePicker24Hour : true,
  42. opens : 'left', //日期选择框的弹出位置
  43. ranges: {
  44. '最近1小时': [moment().subtract(1, 'hours'), moment()],
  45. '今日': [moment().startOf('day'), moment().endOf('day')],
  46. '昨日': [moment().subtract(1, 'days').startOf('day'), moment().subtract(1, 'days').endOf('day')],
  47. '最近7日': [moment().subtract(6, 'days'), moment()],
  48. '最近30日': [moment().subtract(29, 'days'), moment()],
  49. '本月': [moment().startOf('month'), moment().endOf('month')],
  50. '上个月': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
  51. },
  52. locale : {
  53. format: 'YYYY-MM-DD HH:mm:ss',
  54. separator : ' - ',
  55. customRangeLabel : '自定义',
  56. applyLabel : '确定',
  57. cancelLabel : '取消',
  58. fromLabel : '起始时间',
  59. toLabel : '结束时间',
  60. daysOfWeek : [ '日', '一', '二', '三', '四', '五', '六' ],
  61. monthNames : [ '一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月' ],
  62. firstDay : 1,
  63. startDate: moment().startOf('day'),
  64. endDate: moment().endOf('day')
  65. }
  66. });
  67. // init date tables
  68. var logTable = $("#joblog_list").dataTable({
  69. "deferRender": true,
  70. "processing" : true,
  71. "serverSide": true,
  72. "ajax": {
  73. url: base_url + "/joblog/pageList" ,
  74. data : function ( d ) {
  75. var obj = {};
  76. obj.jobGroup = $('#jobGroup').val();
  77. obj.jobId = $('#jobId').val();
  78. obj.logStatus = $('#logStatus').val();
  79. obj.filterTime = $('#filterTime').val();
  80. obj.start = d.start;
  81. obj.length = d.length;
  82. return obj;
  83. }
  84. },
  85. "searching": false,
  86. "ordering": false,
  87. //"scrollX": false,
  88. "columns": [
  89. { "data": 'id', "bSortable": false, "visible" : false},
  90. { "data": 'jobGroup', "visible" : false},
  91. { "data": 'jobId', "visible" : false},
  92. {
  93. "data": 'JobKey',
  94. "visible" : true,
  95. "render": function ( data, type, row ) {
  96. var jobKey = row.jobGroup + "_" + row.jobId;
  97. var glueTypeTitle = row.glueType;
  98. if ('GLUE_GROOVY'==row.glueType) {
  99. glueTypeTitle = "GLUE模式(Java)";
  100. } else if ('GLUE_SHELL'==row.glueType) {
  101. glueTypeTitle = "GLUE模式(Shell)";
  102. } else if ('GLUE_PYTHON'==row.glueType) {
  103. glueTypeTitle = "GLUE模式(Python)";
  104. }else if ('GLUE_NODEJS'==row.glueType) {
  105. glueTypeTitle = "GLUE模式(Nodejs)";
  106. } else if ('BEAN'==row.glueType) {
  107. glueTypeTitle = "BEAN模式:" + row.executorHandler;
  108. }
  109. var temp = '';
  110. temp += '执行器地址:' + (row.executorAddress?row.executorAddress:'');
  111. temp += '<br>运行模式:' + glueTypeTitle;
  112. temp += '<br>任务参数:' + row.executorParam;
  113. return '<a class="logTips" href="javascript:;" >'+ jobKey +'<span style="display:none;">'+ temp +'</span></a>';
  114. }
  115. },
  116. // { "data": 'executorAddress', "visible" : true},
  117. // {
  118. // "data": 'glueType',
  119. // "visible" : true,
  120. // "render": function ( data, type, row ) {
  121. // if ('GLUE_GROOVY'==row.glueType) {
  122. // return "GLUE模式(Java)";
  123. // } else if ('GLUE_SHELL'==row.glueType) {
  124. // return "GLUE模式(Shell)";
  125. // } else if ('GLUE_PYTHON'==row.glueType) {
  126. // return "GLUE模式(Python)";
  127. // } else if ('BEAN'==row.glueType) {
  128. // return "BEAN模式:" + row.executorHandler;
  129. // }
  130. // return row.executorHandler;
  131. // }
  132. // },
  133. // { "data": 'executorParam', "visible" : true},
  134. {
  135. "data": 'triggerTime',
  136. "render": function ( data, type, row ) {
  137. return data?moment(new Date(data)).format("YYYY-MM-DD HH:mm:ss"):"";
  138. }
  139. },
  140. {
  141. "data": 'triggerCode',
  142. "render": function ( data, type, row ) {
  143. var html = data;
  144. if (data == 200) {
  145. html = '<span style="color: green">成功</span>';
  146. } else if (data == 500) {
  147. html = '<span style="color: red">失败</span>';
  148. } else if (data == 0) {
  149. html = '';
  150. }
  151. return html;
  152. }
  153. },
  154. {
  155. "data": 'triggerMsg',
  156. "render": function ( data, type, row ) {
  157. return data?'<a class="logTips" href="javascript:;" >查看<span style="display:none;">'+ data +'</span></a>':"无";
  158. }
  159. },
  160. {
  161. "data": 'handleTime',
  162. "render": function ( data, type, row ) {
  163. return data?moment(new Date(data)).format("YYYY-MM-DD HH:mm:ss"):"";
  164. }
  165. },
  166. {
  167. "data": 'handleCode',
  168. "render": function ( data, type, row ) {
  169. var html = data;
  170. if (data == 200) {
  171. html = '<span style="color: green">成功</span>';
  172. } else if (data == 500) {
  173. html = '<span style="color: red">失败</span>';
  174. } else if (data == 501) {
  175. html = '<span style="color: red">失败重试</span>';
  176. } else if (data == 0) {
  177. html = '';
  178. }
  179. return html;
  180. }
  181. },
  182. {
  183. "data": 'handleMsg',
  184. "render": function ( data, type, row ) {
  185. return data?'<a class="logTips" href="javascript:;" >查看<span style="display:none;">'+ data +'</span></a>':"无";
  186. }
  187. },
  188. {
  189. "data": 'handleMsg' ,
  190. "bSortable": false,
  191. "width": "8%" ,
  192. "render": function ( data, type, row ) {
  193. // better support expression or string, not function
  194. return function () {
  195. if (row.triggerCode == 200){
  196. var temp = '<a href="javascript:;" class="logDetail" _id="'+ row.id +'">执行日志</a>';
  197. if(row.handleCode == 0){
  198. temp += '<br><a href="javascript:;" class="logKill" _id="'+ row.id +'" style="color: red;" >终止任务</a>';
  199. }
  200. return temp;
  201. }
  202. return null;
  203. }
  204. }
  205. }
  206. ],
  207. "language" : {
  208. "sProcessing" : "处理中...",
  209. "sLengthMenu" : "每页 _MENU_ 条记录",
  210. "sZeroRecords" : "没有匹配结果",
  211. "sInfo" : "第 _PAGE_ 页 ( 总共 _PAGES_ 页,_TOTAL_ 条记录 )",
  212. "sInfoEmpty" : "无记录",
  213. "sInfoFiltered" : "(由 _MAX_ 项结果过滤)",
  214. "sInfoPostFix" : "",
  215. "sSearch" : "搜索:",
  216. "sUrl" : "",
  217. "sEmptyTable" : "表中数据为空",
  218. "sLoadingRecords" : "载入中...",
  219. "sInfoThousands" : ",",
  220. "oPaginate" : {
  221. "sFirst" : "首页",
  222. "sPrevious" : "上页",
  223. "sNext" : "下页",
  224. "sLast" : "末页"
  225. },
  226. "oAria" : {
  227. "sSortAscending" : ": 以升序排列此列",
  228. "sSortDescending" : ": 以降序排列此列"
  229. }
  230. }
  231. });
  232. // 日志弹框提示
  233. $('#joblog_list').on('click', '.logTips', function(){
  234. var msg = $(this).find('span').html();
  235. ComAlertTec.show(msg);
  236. });
  237. // 搜索按钮
  238. $('#searchBtn').on('click', function(){
  239. logTable.fnDraw();
  240. });
  241. // 查看执行器详细执行日志
  242. $('#joblog_list').on('click', '.logDetail', function(){
  243. var _id = $(this).attr('_id');
  244. window.open(base_url + '/joblog/logDetailPage?id=' + _id);
  245. return;
  246. });
  247. /**
  248. * 终止任务
  249. */
  250. $('#joblog_list').on('click', '.logKill', function(){
  251. var _id = $(this).attr('_id');
  252. layer.confirm('确认主动终止任务?', {icon: 3, title:'系统提示'}, function(index){
  253. layer.close(index);
  254. $.ajax({
  255. type : 'POST',
  256. url : base_url + '/joblog/logKill',
  257. data : {"id":_id},
  258. dataType : "json",
  259. success : function(data){
  260. if (data.code == 200) {
  261. layer.open({
  262. title: '系统提示',
  263. content: '操作成功',
  264. icon: '1',
  265. end: function(layero, index){
  266. logTable.fnDraw();
  267. }
  268. });
  269. } else {
  270. layer.open({
  271. title: '系统提示',
  272. content: (data.msg || "操作失败"),
  273. icon: '2'
  274. });
  275. }
  276. },
  277. });
  278. });
  279. });
  280. /**
  281. * 清理任务Log
  282. */
  283. $('#clearLog').on('click', function(){
  284. var jobGroup = $('#jobGroup').val();
  285. var jobId = $('#jobId').val();
  286. var jobGroupText = $("#jobGroup").find("option:selected").text();
  287. var jobIdText = $("#jobId").find("option:selected").text();
  288. $('#clearLogModal input[name=jobGroup]').val(jobGroup);
  289. $('#clearLogModal input[name=jobId]').val(jobId);
  290. $('#clearLogModal .jobGroupText').val(jobGroupText);
  291. $('#clearLogModal .jobIdText').val(jobIdText);
  292. $('#clearLogModal').modal('show');
  293. });
  294. $("#clearLogModal .ok").on('click', function(){
  295. $.post(base_url + "/joblog/clearLog", $("#clearLogModal .form").serialize(), function(data, status) {
  296. if (data.code == "200") {
  297. $('#clearLogModal').modal('hide');
  298. layer.open({
  299. title: '系统提示',
  300. content: '日志清理成功',
  301. icon: '1',
  302. end: function(layero, index){
  303. logTable.fnDraw();
  304. }
  305. });
  306. } else {
  307. layer.open({
  308. title: '系统提示',
  309. content: (data.msg || "日志清理失败"),
  310. icon: '2'
  311. });
  312. }
  313. });
  314. });
  315. $("#clearLogModal").on('hide.bs.modal', function () {
  316. $("#clearLogModal .form")[0].reset();
  317. });
  318. });
  319. // 提示-科技主题
  320. var ComAlertTec = {
  321. html:function(){
  322. var html =
  323. '<div class="modal fade" id="ComAlertTec" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">' +
  324. '<div class="modal-dialog">' +
  325. '<div class="modal-content-tec">' +
  326. '<div class="modal-body"><div class="alert" style="color:#fff;"></div></div>' +
  327. '<div class="modal-footer">' +
  328. '<div class="text-center" >' +
  329. '<button type="button" class="btn btn-info ok" data-dismiss="modal" >确认</button>' +
  330. '</div>' +
  331. '</div>' +
  332. '</div>' +
  333. '</div>' +
  334. '</div>';
  335. return html;
  336. },
  337. show:function(msg, callback){
  338. // dom init
  339. if ($('#ComAlertTec').length == 0){
  340. $('body').append(ComAlertTec.html());
  341. }
  342. // 弹框初始
  343. $('#ComAlertTec .alert').html(msg);
  344. $('#ComAlertTec').modal('show');
  345. $('#ComAlertTec .ok').click(function(){
  346. $('#ComAlertTec').modal('hide');
  347. if(typeof callback == 'function') {
  348. callback();
  349. }
  350. });
  351. }
  352. };