userLog.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. var pageNo = 1;
  2. var totalPages = 0;
  3. var param1 = '';
  4. var param2 = '';
  5. var param3 = '';
  6. //数据列表
  7. getListDataAjax();
  8. //获取数据列表 ajax请求
  9. function getListDataAjax(queryParam = {}, pageNo = 1) {
  10. queryParam.pageNo = pageNo;
  11. // queryParam.pageSize = 20;
  12. ajaxRequest(LOG_MANAGE_LIST, "POST", queryParam, function(result) {
  13. let data = result.RESULT.pageList;
  14. let items = '';
  15. data.forEach(function(item, key) {
  16. items += "<tr>" +
  17. "<td class='status' data-user='" + JSON.stringify(item) + "' data-id=" + item.id + "></td>" +
  18. "<td>" + item.xh + "</td>" +
  19. "<td>" + item.user_name + "</td>" +
  20. "<td>" + getFormatDate(item.creat_date.time) + "</td>" +
  21. "<td>" + item.operation + "</td>" +
  22. "<td>" + item.time + "</td>" +
  23. "<td>" + item.ip + "</td>" +
  24. "</tr>"
  25. })
  26. $('#dataList').html(items);
  27. $('#totalCount').html(result.totalCount)
  28. $('#handled').html(result.yclCount)
  29. $('#unhandle').html(result.wclCount)
  30. $('#handleRate').html(result.cll)
  31. totalPages = result.RESULT.totalPages;
  32. $('#totalPage').html(totalPages); //总共多少页
  33. $('#dataTotal').html(result.RESULT.totalCount); //总共多少条数据
  34. $('#currentPage').val(pageNo); //当前页面
  35. let pageFrom = (pageNo - 1) * result.RESULT.pageSize + 1; //开始
  36. let pageTo = result.RESULT.pageNo * result.RESULT.pageSize; //结束
  37. pageTo = pageTo > result.RESULT.totalCount ? result.RESULT.totalCount : pageTo;
  38. $('#pageFrom').html(pageFrom);
  39. $('#pageTo').html(pageTo);
  40. // 无数据时
  41. if (!data.length) {
  42. $('.pager.has-data').hide()
  43. $('.pager.no-data').show()
  44. } else {
  45. $('.pager.has-data').show()
  46. $('.pager.no-data').hide()
  47. }
  48. if (pageNo < totalPages) {
  49. $('#nextPageButton,#lastPageButton').removeClass('disabled');
  50. } else {
  51. $('#nextPageButton,#lastPageButton').addClass('disabled');
  52. }
  53. if (pageNo === 1) {
  54. $('#firstPageButton,#prevPageButton').addClass('disabled');
  55. } else {
  56. $('#firstPageButton,#prevPageButton').removeClass('disabled');
  57. }
  58. }, function(errorMsg) {
  59. alert("请求数据失败!");
  60. })
  61. }
  62. //按钮搜索
  63. $('#buttonSearch').on('click', function() {
  64. pageNo = 1
  65. getListDataAjax(getSearchParamObj());
  66. param1 = $('#user_name').val()
  67. param2 = $('#start_creat_date').val()
  68. param2 = $('#end_creat_date').val()
  69. })
  70. //拼接搜索条件
  71. function getSearchParamObj() {
  72. let queryParam = {};
  73. let start_creat_date = $('#start_creat_date').val();
  74. let end_creat_date = $('#end_creat_date').val()
  75. let user_name = $('#user_name').val()
  76. queryParam.start_creat_date = start_creat_date;
  77. queryParam.end_creat_date = end_creat_date;
  78. queryParam.user_name = user_name;
  79. return queryParam;
  80. }
  81. //重置表单
  82. $('.reset').click(resetForm);
  83. //分页刷新按钮
  84. $('.pg-refresh').click(resetForm);
  85. //重置表单
  86. function resetForm() {
  87. pageNo = 1
  88. $("#user_name").val("");
  89. $("#start_creat_date").val("");
  90. $("#end_creat_date").val("");
  91. getListDataAjax(getSearchParamObj());
  92. param1 = $('#user_name').val()
  93. param2 = $('#start_creat_date').val()
  94. param2 = $('#end_creat_date').val()
  95. }
  96. //分页操作
  97. $('#firstPageButton').on('click', function() {
  98. pageNo = 1;
  99. getListDataAjax(getSearchParamObj(), 1);
  100. })
  101. $('#lastPageButton').on('click', function() {
  102. pageNo = totalPages;
  103. getListDataAjax(getSearchParamObj(), pageNo);
  104. })
  105. $('#prevPageButton').on('click', function() {
  106. pageNo -= 1;
  107. getListDataAjax(getSearchParamObj(), pageNo);
  108. })
  109. $('#nextPageButton').on('click', function() {
  110. pageNo += 1;
  111. getListDataAjax(getSearchParamObj(), pageNo);
  112. })
  113. // 导出 start
  114. $('.export').click(function() {
  115. getDataExport({ "user_name": param1, "start_creat_date": param2, "end_creat_date": param2 })
  116. })
  117. function getDataExport(queryParam = {}) {
  118. // 输出base64编码
  119. const base64 = s => window.btoa(unescape(encodeURIComponent(s)));
  120. ajaxRequest(LOG_EXPORT, "POST", queryParam, function(result) {
  121. let data = result.RESULT.data;
  122. let newData = [];
  123. data.forEach(function(item, index) {
  124. newData.push({ xh: item.xh, user_name: item.user_name, creat_date: getFormatDate(item.creat_date.time), operation: item.operation, time: item.time, ip: item.ip })
  125. });
  126. let str = '<tr style="text-align:center"><th>序号</th><th>操作人员</th><th>操作时间</th><th>操作内容</th><th>执行时间</th><th>请求IP</th></tr>';
  127. // 循环遍历,每行加入tr标签,每个单元格加td标签
  128. for (let i = 0; i < newData.length; i++) {
  129. str += '<tr style="text-align:center">';
  130. for (const key in newData[i]) {
  131. // 增加\t为了不让表格显示科学计数法或者其他格式
  132. str += `<td x:str>${ newData[i][key] + '\t'}</td>`;
  133. }
  134. str += '</tr>';
  135. }
  136. // Worksheet名
  137. const worksheet = 'Sheet1'
  138. const uri = 'data:application/vnd.ms-excel;base64,';
  139. // 下载的表格模板数据
  140. const template = `<html xmlns:o="urn:schemas-microsoft-com:office:office"
  141. xmlns:x="urn:schemas-microsoft-com:office:excel"
  142. xmlns="http://www.w3.org/TR/REC-html40">
  143. <head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet>
  144. <x:Name>${worksheet}</x:Name>
  145. <x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet>
  146. </x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]-->
  147. </head><body><table>${str}</table></body></html>`;
  148. // 通过创建a标签实现
  149. const link = document.createElement("a");
  150. link.href = uri + base64(template);
  151. // 对下载的文件命名
  152. link.download = "日志管理数据表.xls";
  153. link.click();
  154. }, function(errorMsg) {
  155. alert("请求数据失败!");
  156. })
  157. }
  158. // 导出 end