log.js 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. /**
  2. * 引入toaster方法
  3. */
  4. document.write("<script language=javascript src='static/js/common/toastr.js'></script>");
  5. /**
  6. * 引入分页
  7. */
  8. document.write("<script language=javascript src='static/lib/jquery/jquery.pagination.js'></script>");
  9. /**
  10. * 引入base方法
  11. */
  12. document.write("<script language=javascript src='static/js/common/base.js'></script>");
  13. var logList = [];
  14. /**
  15. * 获取日志列表
  16. */
  17. function getLogList(count, page, keyword, fromDate, endDate) {
  18. $('#loadingDiv').show();
  19. $("#logList-body").empty();
  20. logList = [];
  21. $.get('log/errPage', {
  22. count: count,
  23. page: page,
  24. keyword: keyword,
  25. fromDate: fromDate,
  26. endDate: endDate
  27. }, function (data) {
  28. $('#loadingDiv').hide();
  29. logList = data.data;
  30. var pageNumber = data.page;
  31. var pageSize = data.size;
  32. var total = data.totalElements;
  33. var totalPage = data.totalPages;
  34. var tbody = document.getElementById("logList-body");
  35. var page = document.getElementById("page");
  36. //noinspection JSAnnotator
  37. $('#logList-total').val('共 ' + total + ' 条');
  38. if (logList.length > 0) {
  39. for (var i = 0; i < logList.length; i++) {
  40. var trow = getDataRow(logList[i], i); //定义一个方法,返回tr数据
  41. tbody.appendChild(trow);
  42. // 查询错误详情
  43. (function(i) {
  44. $("#para_detail_" + logList[i].id ).click(function () {
  45. getPara(logList[i].id, logList[i].enName, logList[i].url);
  46. $('#loadingDiv').show();
  47. });
  48. })(i);
  49. // 查询参数详情
  50. (function(i) {
  51. $("#pa_detail_" + logList[i].id ).click(function () {
  52. getDetail(logList[i].detail, logList[i].enName);
  53. });
  54. })(i);
  55. // 查询错误列表
  56. (function(i) {
  57. if (logList[i].uuid != null && logList[i].uuid != "") {
  58. $("#not_exit_data_" + logList[i].id ).click(function () {
  59. getNotExistData(logList[i].uuid, logList[i].msg, logList[i].enName);
  60. $('#loadingDiv').show();
  61. });
  62. }
  63. })(i);
  64. }
  65. // 点击搜索
  66. $('#p_search').unbind('click').click(function () {// 每次先解除上次绑定的事件,防止重复发送请求
  67. $("#logList-body").load(location.href + " #logList-body");
  68. getLogList(count, 1, $('#keyword').val());
  69. });
  70. // 键盘确认按钮搜索
  71. document.onkeydown = function(event) {
  72. var e = event || window.event;
  73. if (e && e.keyCode == 13) { // enter 键
  74. $("#logList-body").load(location.href + " #logList-body");
  75. getLogList(count, 1, $('#keyword').val());
  76. }
  77. };
  78. }
  79. $('#m-page').pagination({
  80. pageCount: totalPage,
  81. totalData: total,
  82. current: pageNumber,
  83. showData: pageSize,
  84. coping: true,
  85. homePage: '首页',
  86. endPage: '末页',
  87. prevContent: '<<',
  88. nextContent: '>>',
  89. jump: true,
  90. jumpBtn: '跳转',
  91. callback: function (api) {
  92. $('.now').text(api.getCurrent());
  93. $("#logList-body").load(location.href + " #logList-body");
  94. getLogList(count, api.getCurrent(), $('#keyword').val());
  95. }
  96. }, function (api) {
  97. $('.now').text(api.getCurrent());
  98. });
  99. })
  100. }
  101. /**
  102. * 获取参数详情
  103. *
  104. * @param id 主表id
  105. */
  106. function getPara(id, name, url) {
  107. $.get('log/para', {id: id}, function (data) {
  108. $('#para-content').empty();
  109. $('#para-title').empty();
  110. $("<p style='font-size: 16px; font-weight: bold'>").text(name).appendTo("#para-title");
  111. var result = JSON.stringify(JSON.parse(data.content), null, 4);
  112. $("<pre>").html(syntaxHighlight(result)).appendTo("#para-content");
  113. $('#loadingDiv').hide();
  114. $('#paraDetail').modal('show');
  115. });
  116. }
  117. /**
  118. * 获取详情
  119. */
  120. function getDetail(detail, name) {
  121. $('#para-content').empty();
  122. $('#para-title').empty();
  123. $("<p style='font-size: 16px; font-weight: bold'>").text(name).appendTo("#para-title");
  124. var result = JSON.stringify(JSON.parse(detail), null, 4);
  125. $("<pre>").html(syntaxHighlight(result)).appendTo("#para-content");
  126. $('#loadingDiv').hide();
  127. $('#paraDetail').modal('show');
  128. }
  129. /**
  130. * 获取错误列表
  131. */
  132. function getNotExistData(uuid, msg, name) {
  133. $.get('log/notExistData', {sign: uuid, msg: msg}, function (data) {
  134. $('#para-content').empty();
  135. $('#para-title').empty();
  136. $("<p style='font-size: 16px; font-weight: bold'>").text(name).appendTo("#para-title");
  137. var result = JSON.stringify(JSON.parse(data.content), null, 4);
  138. $("<pre>").html(syntaxHighlight(result)).appendTo("#para-content");
  139. $('#loadingDiv').hide();
  140. $('#paraDetail').modal('show');
  141. });
  142. }
  143. /**
  144. * 建立表格数据
  145. *
  146. * @param log 日志
  147. * @param i 行号
  148. * @returns {Element}
  149. */
  150. function getDataRow(log, i) {
  151. var keyword = $('#keyword').val();
  152. var row = document.createElement('tr'); //创建行
  153. var indexCell = document.createElement('td'); //序号
  154. indexCell.setAttribute("class", "text-center");
  155. indexCell.innerHTML = i + 1; //填充数据
  156. row.appendChild(indexCell);
  157. var dateCell = document.createElement('td'); //时间
  158. dateCell.setAttribute("class", "text-center");
  159. dateCell.innerHTML = formatDateTime(log.date); //填充数据
  160. row.appendChild(dateCell);
  161. var uuCell = document.createElement('td'); //enUU
  162. uuCell.setAttribute("class", "text-center");
  163. uuCell.innerHTML = highLightKeywords(log.enUU, keyword, null); //填充数据
  164. row.appendChild(uuCell);
  165. var nameCell = document.createElement('td'); //enName
  166. nameCell.setAttribute("class", "text-center");
  167. nameCell.innerHTML = highLightKeywords(log.enName, keyword, null); //填充数据
  168. row.appendChild(nameCell);
  169. var urlCell = document.createElement('td'); //enName
  170. urlCell.setAttribute("class", "text-center");
  171. urlCell.innerHTML = log.url; //填充数据
  172. row.appendChild(urlCell);
  173. var msgCell = document.createElement('td'); //msg
  174. msgCell.setAttribute("class", "text-center");
  175. msgCell.setAttribute("style", "max-height: 400px; overflow-y: auto;");
  176. msgCell.innerHTML = log.msg; //填充数据
  177. if (log.uuid != null && log.uuid != "") {
  178. msgCell.setAttribute("title", "查看详情");
  179. msgCell.setAttribute("id", "not_exit_data_" + log.id);
  180. var button = "<a style='color: red'><i class='icon-edit'>more>></i></a>";
  181. msgCell.innerHTML += button;
  182. }
  183. row.appendChild(msgCell);
  184. var detailCell = document.createElement('td'); //detail
  185. detailCell.setAttribute("class", "text-center");
  186. detailCell.setAttribute("title", log.detail);
  187. detailCell.setAttribute("id", "pa_detail_" + log.id);
  188. detailCell.setAttribute("title", "查看详情");
  189. detailCell.innerHTML = "详情"; //填充数据
  190. row.appendChild(detailCell);
  191. var paraCell = document.createElement('td'); //parameters
  192. paraCell.setAttribute("class", "text-center");
  193. paraCell.setAttribute("title", "查看参数详情");
  194. paraCell.innerHTML = "详情"; //填充数据
  195. paraCell.setAttribute("id", "para_detail_" + log.id)
  196. row.appendChild(paraCell);
  197. return row;
  198. }
  199. $(function() {
  200. 'use strict';
  201. // 监听页面滚动
  202. $(window).scroll(function() {
  203. if($(window).scrollTop() >= 400) {
  204. $('#nav').addClass('on');
  205. } else {
  206. $('#nav').removeClass('on');
  207. }
  208. });
  209. // 设置分页大小
  210. var count = 20;
  211. getLogList(count, 1, null);
  212. });