userLog.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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. })
  67. //拼接搜索条件
  68. function getSearchParamObj() {
  69. let queryParam = {};
  70. let start_creat_date = $('#start_creat_date').val();
  71. let end_creat_date = $('#end_creat_date').val()
  72. let user_name = $('#user_name').val()
  73. queryParam.start_creat_date = start_creat_date;
  74. queryParam.end_creat_date = end_creat_date;
  75. queryParam.user_name = user_name;
  76. return queryParam;
  77. }
  78. //重置表单
  79. $('.reset').click(resetForm)
  80. //重置表单
  81. function resetForm() {
  82. pageNo = 1
  83. $("#user_name").val("");
  84. $("#start_creat_date").val("");
  85. $("#end_creat_date").val("");
  86. getListDataAjax(getSearchParamObj());
  87. }
  88. //分页操作
  89. $('#firstPageButton').on('click', function() {
  90. pageNo = 1;
  91. getListDataAjax(getSearchParamObj(), 1);
  92. })
  93. $('#lastPageButton').on('click', function() {
  94. pageNo = totalPages;
  95. getListDataAjax(getSearchParamObj(), pageNo);
  96. })
  97. $('#prevPageButton').on('click', function() {
  98. pageNo -= 1;
  99. getListDataAjax(getSearchParamObj(), pageNo);
  100. })
  101. $('#nextPageButton').on('click', function() {
  102. pageNo += 1;
  103. getListDataAjax(getSearchParamObj(), pageNo);
  104. })
  105. // 导出 start
  106. $('.export').click(getDataExport)
  107. function getDataExport() {
  108. // 输出base64编码
  109. const base64 = s => window.btoa(unescape(encodeURIComponent(s)));
  110. ajaxRequest(LOG_EXPORT, "POST", {}, function(result) {
  111. let data = result.RESULT.data;
  112. let newData = [];
  113. data.forEach(function(item, index) {
  114. 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 })
  115. });
  116. let str = '<tr style="text-align:center"><th>序号</th><th>操作人员</th><th>操作时间</th><th>操作内容</th><th>执行时间</th><th>请求IP</th></tr>';
  117. // 循环遍历,每行加入tr标签,每个单元格加td标签
  118. for (let i = 0; i < newData.length; i++) {
  119. str += '<tr style="text-align:center">';
  120. for (const key in newData[i]) {
  121. // 增加\t为了不让表格显示科学计数法或者其他格式
  122. str += `<td>${ newData[i][key] + '\t'}</td>`;
  123. }
  124. str += '</tr>';
  125. }
  126. // Worksheet名
  127. const worksheet = 'Sheet1'
  128. const uri = 'data:application/vnd.ms-excel;base64,';
  129. // 下载的表格模板数据
  130. const template = `<html xmlns:o="urn:schemas-microsoft-com:office:office"
  131. xmlns:x="urn:schemas-microsoft-com:office:excel"
  132. xmlns="http://www.w3.org/TR/REC-html40">
  133. <head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet>
  134. <x:Name>${worksheet}</x:Name>
  135. <x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet>
  136. </x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]-->
  137. </head><body><table>${str}</table></body></html>`;
  138. // 通过创建a标签实现
  139. const link = document.createElement("a");
  140. link.href = uri + base64(template);
  141. // 对下载的文件命名
  142. link.download = "日志管理数据表.xls";
  143. link.click();
  144. }, function(errorMsg) {
  145. alert("请求数据失败!");
  146. })
  147. }
  148. // 导出 end