joblog.index.1.js 11 KB

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