Commit 12e9ee7e by fsn

日志模块完善

parent 6129ac35
package com.stylefeng.guns.common.constant.factory;
import com.baomidou.mybatisplus.plugins.Page;
import com.stylefeng.guns.core.support.HttpKit;
import javax.servlet.http.HttpServletRequest;
/**
* BootStrap Table默认的分页参数创建
*
* @author fengshuonan
* @date 2017-04-05 22:25
*/
public class PageFactory<T> {
public Page<T> defaultPage() {
HttpServletRequest request = HttpKit.getRequest();
int limit = Integer.valueOf(request.getParameter("limit"));
int offset = Integer.valueOf(request.getParameter("offset"));
return new Page<>((offset/limit + 1), limit);
}
}
...@@ -34,5 +34,5 @@ public abstract class BaseControllerWarpper { ...@@ -34,5 +34,5 @@ public abstract class BaseControllerWarpper {
} }
} }
public abstract void warpTheMap(Map<String, Object> map); protected abstract void warpTheMap(Map<String, Object> map);
} }
package com.stylefeng.guns.modular.system.controller; package com.stylefeng.guns.modular.system.controller;
import com.baomidou.mybatisplus.plugins.Page;
import com.stylefeng.guns.common.constant.factory.PageFactory;
import com.stylefeng.guns.common.controller.BaseController; import com.stylefeng.guns.common.controller.BaseController;
import com.stylefeng.guns.modular.system.warpper.LogWarpper;
import com.stylefeng.guns.persistence.dao.OperationLogMapper; import com.stylefeng.guns.persistence.dao.OperationLogMapper;
import org.apache.ibatis.session.RowBounds; import com.stylefeng.guns.persistence.model.OperationLog;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
/** /**
* 日志管理的控制器 * 日志管理的控制器
...@@ -38,6 +44,18 @@ public class LogController extends BaseController { ...@@ -38,6 +44,18 @@ public class LogController extends BaseController {
@RequestMapping("/list") @RequestMapping("/list")
@ResponseBody @ResponseBody
public Object list(){ public Object list(){
return operationLogMapper.selectPage(new RowBounds(10,2), null); Page<OperationLog> page = new PageFactory<OperationLog>().defaultPage();
List<Map<String, Object>> operationLogs = operationLogMapper.selectMapsPage(page, null);
page.setRecords((List<OperationLog>) new LogWarpper(operationLogs).warp());
return super.packForBT(page);
}
/**
* 查询操作日志详情
*/
@RequestMapping("/detail/{id}")
@ResponseBody
public Object detail(@PathVariable Integer id){
return operationLogMapper.selectById(id);
} }
} }
package com.stylefeng.guns.modular.system.warpper;
import com.stylefeng.guns.common.warpper.BaseControllerWarpper;
import com.stylefeng.guns.core.util.ToolUtil;
import java.util.List;
import java.util.Map;
/**
* 日志列表的包装类
*
* @author fengshuonan
* @date 2017年4月5日22:56:24
*/
public class LogWarpper extends BaseControllerWarpper {
public LogWarpper(List<Map<String, Object>> list) {
super(list);
}
@Override
public void warpTheMap(Map<String, Object> map) {
String message = (String) map.get("message");
if (ToolUtil.isNotEmpty(message) && message.length() >= 100) {
message = message.substring(0, 100) + "...";
} else {
message = null;
}
map.put("message", message);
}
}
/** /**
* 初始化 BootStrap Table 的封装 * 初始化 BootStrap Table 的封装
* *
* 约定:toolbar的id为 (bstableId + "Toolbar") * 约定:toolbar的id为 (bstableId + "Toolbar")
* *
* @author fengshuonan * @author fengshuonan
*/ */
(function () { (function () {
var BSTable = function (bstableId , url, columns){ var BSTable = function (bstableId, url, columns) {
this.btInstance = null; //jquery和BootStrapTable绑定的对象 this.btInstance = null; //jquery和BootStrapTable绑定的对象
this.bstableId = bstableId; this.bstableId = bstableId;
this.url = Feng.ctxPath + url; this.url = Feng.ctxPath + url;
this.method = "post"; this.method = "post";
this.paginationType = "server"; //默认分页方式是服务器分页,可选项"client" this.paginationType = "server"; //默认分页方式是服务器分页,可选项"client"
this.toolbarId = bstableId + "Toolbar"; this.toolbarId = bstableId + "Toolbar";
this.columns = columns; this.columns = columns;
this.height = 665, //默认表格高度665 this.height = 665, //默认表格高度665
this.data = {}; this.data = {};
}; };
BSTable.prototype = { BSTable.prototype = {
/** /**
* 初始化bootstrap table * 初始化bootstrap table
*/ */
init : function () { init: function () {
var tableId = this.bstableId; var tableId = this.bstableId;
this.btInstance = this.btInstance =
$('#'+tableId).bootstrapTable({ $('#' + tableId).bootstrapTable({
url: this.url, //请求地址 contentType: "application/x-www-form-urlencoded",
method: this.method, //ajax方式,post还是get url: this.url, //请求地址
ajaxOptions:{ //ajax请求的附带参数 method: this.method, //ajax方式,post还是get
data:this.data ajaxOptions: { //ajax请求的附带参数
}, data: this.data
toolbar: "#"+this.toolbarId,//顶部工具条 },
striped: true, //是否显示行间隔色 toolbar: "#" + this.toolbarId,//顶部工具条
cache: false, //是否使用缓存,默认为true striped: true, //是否显示行间隔色
pagination: true, //是否显示分页(*) cache: false, //是否使用缓存,默认为true
sortable: false, //是否启用排序 pagination: true, //是否显示分页(*)
sortOrder: "desc", //排序方式 sortable: false, //是否启用排序
pageNumber:1, //初始化加载第一页,默认第一页 sortOrder: "desc", //排序方式
pageSize: 14, //每页的记录行数(*) pageNumber: 1, //初始化加载第一页,默认第一页
pageList: [14, 50, 100], //可供选择的每页的行数(*) pageSize: 14, //每页的记录行数(*)
queryParamsType:'limit', //默认值为 'limit' ,在默认情况下 传给服务端的参数为:offset,limit,sort pageList: [14, 50, 100], //可供选择的每页的行数(*)
sidePagination: this.paginationType, //分页方式:client客户端分页,server服务端分页(*) queryParamsType: 'limit', //默认值为 'limit' ,在默认情况下 传给服务端的参数为:offset,limit,sort
search: false, //是否显示表格搜索,此搜索是客户端搜索,不会进服务端 sidePagination: this.paginationType, //分页方式:client客户端分页,server服务端分页(*)
strictSearch: true, //设置为 true启用 全匹配搜索,否则为模糊搜索 search: false, //是否显示表格搜索,此搜索是客户端搜索,不会进服务端
showColumns: true, //是否显示所有的列 strictSearch: true, //设置为 true启用 全匹配搜索,否则为模糊搜索
showRefresh: true, //是否显示刷新按钮 showColumns: true, //是否显示所有的列
minimumCountColumns: 2, //最少允许的列数 showRefresh: true, //是否显示刷新按钮
clickToSelect: true, //是否启用点击选中行 minimumCountColumns: 2, //最少允许的列数
searchOnEnterKey: true, //设置为 true时,按回车触发搜索方法,否则自动触发搜索方法 clickToSelect: true, //是否启用点击选中行
columns: this.columns, //列数组 searchOnEnterKey: true, //设置为 true时,按回车触发搜索方法,否则自动触发搜索方法
pagination:true, //是否显示分页条 columns: this.columns, //列数组
height:this.height, pagination: true, //是否显示分页条
icons : { height: this.height,
refresh : 'glyphicon-repeat', icons: {
toggle : 'glyphicon-list-alt', refresh: 'glyphicon-repeat',
columns : 'glyphicon-list' toggle: 'glyphicon-list-alt',
}, columns: 'glyphicon-list'
iconSize : 'outline' },
}); iconSize: 'outline'
return this; });
}, return this;
},
/**
* 设置分页方式:server 或者 client /**
*/ * 设置分页方式:server 或者 client
setPaginationType : function(type){ */
this.paginationType = type; setPaginationType: function (type) {
}, this.paginationType = type;
},
/**
* 设置ajax post请求时候附带的参数 /**
*/ * 设置ajax post请求时候附带的参数
set : function (key, value){ */
if (typeof key == "object") { set: function (key, value) {
for (var i in key) { if (typeof key == "object") {
if (typeof i == "function") for (var i in key) {
continue; if (typeof i == "function")
this.data[i] = key[i]; continue;
} this.data[i] = key[i];
} else { }
this.data[key] = (typeof value == "undefined") ? $("#" + key).val() : value; } else {
} this.data[key] = (typeof value == "undefined") ? $("#" + key).val() : value;
return this; }
}, return this;
},
/**
* 设置ajax post请求时候附带的参数 /**
*/ * 设置ajax post请求时候附带的参数
setData : function(data){ */
this.data = data; setData: function (data) {
return this; this.data = data;
}, return this;
},
/**
* 清空ajax post请求参数 /**
*/ * 清空ajax post请求参数
clear : function (){ */
this.data = {}; clear: function () {
return this; this.data = {};
}, return this;
},
/**
* 刷新 bootstrap 表格 /**
* Refresh the remote server data, * 刷新 bootstrap 表格
* you can set {silent: true} to refresh the data silently, * Refresh the remote server data,
* and set {url: newUrl} to change the url. * you can set {silent: true} to refresh the data silently,
* To supply query params specific to this request, set {query: {foo: 'bar'}} * and set {url: newUrl} to change the url.
*/ * To supply query params specific to this request, set {query: {foo: 'bar'}}
refresh : function(parms){ */
if(typeof parms != "undefined"){ refresh: function (parms) {
this.btInstance.bootstrapTable('refresh',parms); if (typeof parms != "undefined") {
}else{ this.btInstance.bootstrapTable('refresh', parms);
this.btInstance.bootstrapTable('refresh'); } else {
} this.btInstance.bootstrapTable('refresh');
} }
}; }
};
window.BSTable = BSTable;
window.BSTable = BSTable;
} ());
\ No newline at end of file }());
\ No newline at end of file
...@@ -2,16 +2,16 @@ ...@@ -2,16 +2,16 @@
* 日志管理初始化 * 日志管理初始化
*/ */
var OptLog = { var OptLog = {
id : "OptLogTable", //表格id id: "OptLogTable", //表格id
seItem : null, //选中的条目 seItem: null, //选中的条目
table : null, table: null,
layerIndex : -1 layerIndex: -1
}; };
/** /**
* 初始化表格的列 * 初始化表格的列
*/ */
OptLog.initColumn = function(){ OptLog.initColumn = function () {
return [ return [
{field: 'selectItem', radio: true}, {field: 'selectItem', radio: true},
{title: 'id', field: 'id', visible: false, align: 'center', valign: 'middle'}, {title: 'id', field: 'id', visible: false, align: 'center', valign: 'middle'},
...@@ -27,7 +27,7 @@ OptLog.initColumn = function(){ ...@@ -27,7 +27,7 @@ OptLog.initColumn = function(){
/** /**
* 绑定表格的事件 * 绑定表格的事件
*/ */
OptLog.bindEvent = function(){ OptLog.bindEvent = function () {
$('#' + this.id).on('click-row.bs.table', function (e, row) { $('#' + this.id).on('click-row.bs.table', function (e, row) {
OptLog.seItem = row; OptLog.seItem = row;
}); });
...@@ -36,26 +36,33 @@ OptLog.bindEvent = function(){ ...@@ -36,26 +36,33 @@ OptLog.bindEvent = function(){
/** /**
* 检查是否选中 * 检查是否选中
*/ */
OptLog.check = function(){ OptLog.check = function () {
if(this.seItem == null){ if (this.seItem == null) {
Feng.info("请先选中表格中的某一记录!"); Feng.info("请先选中表格中的某一记录!");
return false; return false;
}else{ } else {
return true; return true;
} }
}; };
/** /**
* 查看日志详情 * 查看日志详情
*/ */
OptLog.detail = function(){ OptLog.detail = function () {
if (this.check()) {
var ajax = new $ax(Feng.ctxPath + "/log/detail/" +this.seItem.id, function (data) {
}, function (data) {
});
ajax.start();
}
}; };
$(function(){ $(function () {
var defaultColunms = OptLog.initColumn(); var defaultColunms = OptLog.initColumn();
var table = new BSTable(OptLog.id,"/log/list",defaultColunms); var table = new BSTable(OptLog.id, "/log/list", defaultColunms);
table.setPaginationType("client"); table.setPaginationType("server");
table.init(); table.init();
OptLog.bindEvent(); OptLog.bindEvent();
OptLog.table = table; OptLog.table = table;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment