joblog.index.1.js 12 KB

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