joblog.index.1.js 12 KB

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