xxl-job

joblog.index.1.js 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  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. return (data==200)?'<span style="color: green">成功</span>':(data==500)?'<span style="color: red">失败</span>':(data==0)?'':data;
  144. }
  145. },
  146. {
  147. "data": 'triggerMsg',
  148. "render": function ( data, type, row ) {
  149. return data?'<a class="logTips" href="javascript:;" >查看<span style="display:none;">'+ data +'</span></a>':"无";
  150. }
  151. },
  152. {
  153. "data": 'handleTime',
  154. "render": function ( data, type, row ) {
  155. return data?moment(new Date(data)).format("YYYY-MM-DD HH:mm:ss"):"";
  156. }
  157. },
  158. {
  159. "data": 'handleCode',
  160. "render": function ( data, type, row ) {
  161. return (data==200)?'<span style="color: green">成功</span>':(data==500)?'<span style="color: red">失败</span>':(data==0)?'':data;
  162. }
  163. },
  164. {
  165. "data": 'handleMsg',
  166. "render": function ( data, type, row ) {
  167. return data?'<a class="logTips" href="javascript:;" >查看<span style="display:none;">'+ data +'</span></a>':"无";
  168. }
  169. },
  170. {
  171. "data": 'handleMsg' ,
  172. "bSortable": false,
  173. "width": "8%" ,
  174. "render": function ( data, type, row ) {
  175. // better support expression or string, not function
  176. return function () {
  177. if (row.triggerCode == 200){
  178. var temp = '<a href="javascript:;" class="logDetail" _id="'+ row.id +'">执行日志</a>';
  179. if(row.handleCode == 0){
  180. temp += '<br><a href="javascript:;" class="logKill" _id="'+ row.id +'" style="color: red;" >终止任务</a>';
  181. }
  182. return temp;
  183. }
  184. return null;
  185. }
  186. }
  187. }
  188. ],
  189. "language" : {
  190. "sProcessing" : "处理中...",
  191. "sLengthMenu" : "每页 _MENU_ 条记录",
  192. "sZeroRecords" : "没有匹配结果",
  193. "sInfo" : "第 _PAGE_ 页 ( 总共 _PAGES_ 页,_TOTAL_ 条记录 )",
  194. "sInfoEmpty" : "无记录",
  195. "sInfoFiltered" : "(由 _MAX_ 项结果过滤)",
  196. "sInfoPostFix" : "",
  197. "sSearch" : "搜索:",
  198. "sUrl" : "",
  199. "sEmptyTable" : "表中数据为空",
  200. "sLoadingRecords" : "载入中...",
  201. "sInfoThousands" : ",",
  202. "oPaginate" : {
  203. "sFirst" : "首页",
  204. "sPrevious" : "上页",
  205. "sNext" : "下页",
  206. "sLast" : "末页"
  207. },
  208. "oAria" : {
  209. "sSortAscending" : ": 以升序排列此列",
  210. "sSortDescending" : ": 以降序排列此列"
  211. }
  212. }
  213. });
  214. // 日志弹框提示
  215. $('#joblog_list').on('click', '.logTips', function(){
  216. var msg = $(this).find('span').html();
  217. ComAlertTec.show(msg);
  218. });
  219. // 搜索按钮
  220. $('#searchBtn').on('click', function(){
  221. logTable.fnDraw();
  222. });
  223. // 查看执行器详细执行日志
  224. $('#joblog_list').on('click', '.logDetail', function(){
  225. var _id = $(this).attr('_id');
  226. window.open(base_url + '/joblog/logDetailPage?id=' + _id);
  227. return;
  228. });
  229. /**
  230. * 终止任务
  231. */
  232. $('#joblog_list').on('click', '.logKill', function(){
  233. var _id = $(this).attr('_id');
  234. layer.confirm('确认主动终止任务?', {icon: 3, title:'系统提示'}, function(index){
  235. layer.close(index);
  236. $.ajax({
  237. type : 'POST',
  238. url : base_url + '/joblog/logKill',
  239. data : {"id":_id},
  240. dataType : "json",
  241. success : function(data){
  242. if (data.code == 200) {
  243. layer.open({
  244. title: '系统提示',
  245. content: '操作成功',
  246. icon: '1',
  247. end: function(layero, index){
  248. logTable.fnDraw();
  249. }
  250. });
  251. } else {
  252. layer.open({
  253. title: '系统提示',
  254. content: (data.msg || "操作失败"),
  255. icon: '2'
  256. });
  257. }
  258. },
  259. });
  260. });
  261. });
  262. /**
  263. * 清理任务Log
  264. */
  265. $('#clearLog').on('click', function(){
  266. var jobGroup = $('#jobGroup').val();
  267. var jobId = $('#jobId').val();
  268. var jobGroupText = $("#jobGroup").find("option:selected").text();
  269. var jobIdText = $("#jobId").find("option:selected").text();
  270. $('#clearLogModal input[name=jobGroup]').val(jobGroup);
  271. $('#clearLogModal input[name=jobId]').val(jobId);
  272. $('#clearLogModal .jobGroupText').val(jobGroupText);
  273. $('#clearLogModal .jobIdText').val(jobIdText);
  274. $('#clearLogModal').modal('show');
  275. });
  276. $("#clearLogModal .ok").on('click', function(){
  277. $.post(base_url + "/joblog/clearLog", $("#clearLogModal .form").serialize(), function(data, status) {
  278. if (data.code == "200") {
  279. $('#clearLogModal').modal('hide');
  280. layer.open({
  281. title: '系统提示',
  282. content: '日志清理成功',
  283. icon: '1',
  284. end: function(layero, index){
  285. logTable.fnDraw();
  286. }
  287. });
  288. } else {
  289. layer.open({
  290. title: '系统提示',
  291. content: (data.msg || "日志清理失败"),
  292. icon: '2'
  293. });
  294. }
  295. });
  296. });
  297. $("#clearLogModal").on('hide.bs.modal', function () {
  298. $("#clearLogModal .form")[0].reset();
  299. });
  300. });
  301. // 提示-科技主题
  302. var ComAlertTec = {
  303. html:function(){
  304. var html =
  305. '<div class="modal fade" id="ComAlertTec" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">' +
  306. '<div class="modal-dialog">' +
  307. '<div class="modal-content-tec">' +
  308. '<div class="modal-body"><div class="alert" style="color:#fff;"></div></div>' +
  309. '<div class="modal-footer">' +
  310. '<div class="text-center" >' +
  311. '<button type="button" class="btn btn-info ok" data-dismiss="modal" >确认</button>' +
  312. '</div>' +
  313. '</div>' +
  314. '</div>' +
  315. '</div>' +
  316. '</div>';
  317. return html;
  318. },
  319. show:function(msg, callback){
  320. // dom init
  321. if ($('#ComAlertTec').length == 0){
  322. $('body').append(ComAlertTec.html());
  323. }
  324. // 弹框初始
  325. $('#ComAlertTec .alert').html(msg);
  326. $('#ComAlertTec').modal('show');
  327. $('#ComAlertTec .ok').click(function(){
  328. $('#ComAlertTec').modal('hide');
  329. if(typeof callback == 'function') {
  330. callback();
  331. }
  332. });
  333. }
  334. };