userLog.js 5.7 KB

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