123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185 |
- var pageNo = 1;
- var totalPages = 0;
- var param1 = '';
- var param2 = '';
- var param3 = '';
- //数据列表
- getListDataAjax();
- //获取数据列表 ajax请求
- function getListDataAjax(queryParam = {}, pageNo = 1) {
- queryParam.pageNo = pageNo;
- // queryParam.pageSize = 20;
- ajaxRequest(LOG_MANAGE_LIST, "POST", queryParam, function(result) {
- let data = result.RESULT.pageList;
- let items = '';
- data.forEach(function(item, key) {
- items += "<tr>" +
- "<td class='status' data-user='" + JSON.stringify(item) + "' data-id=" + item.id + "></td>" +
- "<td>" + item.xh + "</td>" +
- "<td>" + item.user_name + "</td>" +
- "<td>" + getFormatDate(item.creat_date.time) + "</td>" +
- "<td>" + item.operation + "</td>" +
- "<td>" + item.time + "</td>" +
- "<td>" + item.ip + "</td>" +
- "</tr>"
- })
- $('#dataList').html(items);
- $('#totalCount').html(result.totalCount)
- $('#handled').html(result.yclCount)
- $('#unhandle').html(result.wclCount)
- $('#handleRate').html(result.cll)
- totalPages = result.RESULT.totalPages;
- $('#totalPage').html(totalPages); //总共多少页
- $('#dataTotal').html(result.RESULT.totalCount); //总共多少条数据
- $('#currentPage').val(pageNo); //当前页面
- let pageFrom = (pageNo - 1) * result.RESULT.pageSize + 1; //开始
- let pageTo = result.RESULT.pageNo * result.RESULT.pageSize; //结束
- pageTo = pageTo > result.RESULT.totalCount ? result.RESULT.totalCount : pageTo;
- $('#pageFrom').html(pageFrom);
- $('#pageTo').html(pageTo);
- // 无数据时
- if (!data.length) {
- $('.pager.has-data').hide()
- $('.pager.no-data').show()
- } else {
- $('.pager.has-data').show()
- $('.pager.no-data').hide()
- }
- if (pageNo < totalPages) {
- $('#nextPageButton,#lastPageButton').removeClass('disabled');
- } else {
- $('#nextPageButton,#lastPageButton').addClass('disabled');
- }
- if (pageNo === 1) {
- $('#firstPageButton,#prevPageButton').addClass('disabled');
- } else {
- $('#firstPageButton,#prevPageButton').removeClass('disabled');
- }
- }, function(errorMsg) {
- alert("请求数据失败!");
- })
- }
- //按钮搜索
- $('#buttonSearch').on('click', function() {
- pageNo = 1
- getListDataAjax(getSearchParamObj());
- param1 = $('#user_name').val()
- param2 = $('#start_creat_date').val()
- param2 = $('#end_creat_date').val()
- })
- //拼接搜索条件
- function getSearchParamObj() {
- let queryParam = {};
- let start_creat_date = $('#start_creat_date').val();
- let end_creat_date = $('#end_creat_date').val()
- let user_name = $('#user_name').val()
- queryParam.start_creat_date = start_creat_date;
- queryParam.end_creat_date = end_creat_date;
- queryParam.user_name = user_name;
- return queryParam;
- }
- //重置表单
- $('.reset').click(resetForm);
- //分页刷新按钮
- $('.pg-refresh').click(resetForm);
- //重置表单
- function resetForm() {
- pageNo = 1
- $("#user_name").val("");
- $("#start_creat_date").val("");
- $("#end_creat_date").val("");
- getListDataAjax(getSearchParamObj());
- param1 = $('#user_name').val()
- param2 = $('#start_creat_date').val()
- param2 = $('#end_creat_date').val()
- }
- //分页操作
- $('#firstPageButton').on('click', function() {
- pageNo = 1;
- getListDataAjax(getSearchParamObj(), 1);
- })
- $('#lastPageButton').on('click', function() {
- pageNo = totalPages;
- getListDataAjax(getSearchParamObj(), pageNo);
- })
- $('#prevPageButton').on('click', function() {
- pageNo -= 1;
- getListDataAjax(getSearchParamObj(), pageNo);
- })
- $('#nextPageButton').on('click', function() {
- pageNo += 1;
- getListDataAjax(getSearchParamObj(), pageNo);
- })
- // 导出 start
- $('.export').click(function() {
- getDataExport({ "user_name": param1, "start_creat_date": param2, "end_creat_date": param2 })
- })
- function getDataExport(queryParam = {}) {
- // 输出base64编码
- const base64 = s => window.btoa(unescape(encodeURIComponent(s)));
- ajaxRequest(LOG_EXPORT, "POST", queryParam, function(result) {
- let data = result.RESULT.data;
- let newData = [];
- data.forEach(function(item, index) {
- 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 })
- });
- let str = '<tr style="text-align:center"><th>序号</th><th>操作人员</th><th>操作时间</th><th>操作内容</th><th>执行时间</th><th>请求IP</th></tr>';
- // 循环遍历,每行加入tr标签,每个单元格加td标签
- for (let i = 0; i < newData.length; i++) {
- str += '<tr style="text-align:center">';
- for (const key in newData[i]) {
- // 增加\t为了不让表格显示科学计数法或者其他格式
- str += `<td x:str>${ newData[i][key] + '\t'}</td>`;
- }
- str += '</tr>';
- }
- // Worksheet名
- const worksheet = 'Sheet1'
- const uri = 'data:application/vnd.ms-excel;base64,';
- // 下载的表格模板数据
- const template = `<html xmlns:o="urn:schemas-microsoft-com:office:office"
- xmlns:x="urn:schemas-microsoft-com:office:excel"
- xmlns="http://www.w3.org/TR/REC-html40">
- <head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet>
- <x:Name>${worksheet}</x:Name>
- <x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet>
- </x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]-->
- </head><body><table>${str}</table></body></html>`;
- // 通过创建a标签实现
- const link = document.createElement("a");
- link.href = uri + base64(template);
- // 对下载的文件命名
- link.download = "日志管理数据表.xls";
- link.click();
- }, function(errorMsg) {
- alert("请求数据失败!");
- })
- }
- // 导出 end
|