$(function () {
// 文件类型图标
var images = [
'md md-image', 'md md-insert-drive-file',
'md md-headset', 'md md-local-movies',
'md md-folder-open', 'md md-sim-card-alert'
];
$('#fileTable').bootstrapTable({
url: '[[${#request.getContextPath()}]]/file/getFiles', //需要发送到后端的接口
cache: false, sidePagination: 'server', toolbar: "#toolbar", uniqueId: "id",
pagination: true, pageNumber: 1, pageSize: 10, pageList: [10, 20, 30, 40, 50],
columns: [
{checkbox: true, visible: true}, //是否显示复选框
{field: 'id', title: '文件编号', align: 'center'},
{
field: 'fileName', title: '文件名称', align: 'left', formatter: function (value, row, index) {
//展现对应的小图标
var img = '<span class="' + images[row.fileType - 1] + '" aria-hidden="true"/> ';
//如果是收藏的
if (row.isCollect == 1) {
img = img + '<span class="md md-star" aria-hidden="true"/>';
}
//如果是其他类型
if (row.fileType == 5) {
return img + '<a href="javascript:getChilden(\'' + row.id + '\', \'' + row.filePath + '\', \'' + value + '\')">' + value + '</a>';
}
//非其他
return img + '<a href="[[${#request.getContextPath()}]]/file/download?fileName=' + value + '&filePath=' + row.filePath + '">' + value + '</a>';
}
},
{
field: 'fileSize', title: '文件大小', align: 'left', formatter: function (value, row, index) {
return row.fileType == 5 ? '-' : value;
}
},
{
field: 'fileType', title: '文件类型', align: 'center',
formatter: function (value, row, index) {
var type = '';
switch (value) {
case 1 :
type = '图片';
break;
case 2 :
type = '文档';
break;
case 3 :
type = '音乐';
break;
case 4 :
type = '视频';
break;
case 5 :
type = '其他';
break;
default :
type = '未知类型';
}
return type;
}
},
{field: 'filePath', title: '文件路径', align: 'left'},
{field: 'user.username', title: '上传用户', align: 'left'},
{field: 'createTime', title: '上传时间', align: 'left'},
{
field: 'id', title: '操作', align: 'center', formatter: function (value, row, index) {
return '<a href="#" onclick="collectFile(\'' + value + '\')">收藏</a> '
+ '<a href="#" onclick="shareFile(\'' + value + '\')">分享</a>';
}
}
],
//在此处给到参数 3个
queryParams: function (params) {
//这里的键的名字和控制器的变量名必须一致,这边改动,控制器也需要改成一样的
params = {
pageNum: (params.offset / params.limit) + 1, //页码
pageSize: params.limit, //页面大小
currentUser: '[[${session.user.getId()}]]'
};
return params;
}
});
});