151 lines
6.3 KiB
JavaScript
151 lines
6.3 KiB
JavaScript
define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
|
|
|
|
var Controller = {
|
|
index: function () {
|
|
// 初始化表格参数配置
|
|
Table.api.init({
|
|
extend: {
|
|
index_url: 'oa/doc/index' + location.search,
|
|
add_url: 'oa/doc/add',
|
|
edit_url: 'oa/doc/edit',
|
|
del_url: 'oa/doc/del',
|
|
multi_url: 'oa/doc/multi',
|
|
import_url: 'oa/doc/import',
|
|
table: 'doc',
|
|
}
|
|
});
|
|
|
|
var table = $("#table");
|
|
|
|
// 初始化表格
|
|
table.bootstrapTable({
|
|
url: $.fn.bootstrapTable.defaults.extend.index_url,
|
|
pk: 'id',
|
|
sortName: 'id',
|
|
columns: [
|
|
[
|
|
{checkbox: true},
|
|
{field: 'id', title: __('Id')},
|
|
{field: 'title', title: __('Title'), operate: 'LIKE'},
|
|
{field: 'desc', title: __('Desc'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
|
|
{field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
|
|
{field: 'update_time', title: __('Update_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
|
|
{field: 'operate', title: __('Operate'), table: table,
|
|
buttons:[
|
|
{
|
|
name: 'detail',
|
|
text: "详情",
|
|
title: __('查看详情'),
|
|
classname: 'btn btn-xs btn-primary btn-preview',
|
|
icon: 'fa fa-list',
|
|
extend: function(row) {
|
|
return 'data-filetype="' + row.filetype + '" data-fileurl="' + row.fileurl + '"';
|
|
}
|
|
},
|
|
{
|
|
name: 'edit',
|
|
text: "修改",
|
|
icon: 'fa fa-pencil',
|
|
title: __('Edit'),
|
|
extend: 'data-toggle="tooltip" data-container="body"',
|
|
classname: 'btn btn-xs btn-info btn-editone',
|
|
},
|
|
{
|
|
name: 'del',
|
|
text: "删除",
|
|
icon: 'fa fa-trash',
|
|
title: __('Delete'),
|
|
extend: 'data-toggle="tooltip"',
|
|
classname: 'btn btn-xs btn-danger btn-delone',
|
|
},
|
|
],
|
|
events: Table.api.events.operate, formatter: Table.api.formatter.operate
|
|
}
|
|
]
|
|
]
|
|
});
|
|
|
|
$(document).on('click', '.btn-preview', function (e) {
|
|
e.preventDefault();
|
|
var fileType = $(this).data('filetype'); // 自动从 data-type 获取,比如 pdf, jpg, doc
|
|
var fileUrl = $(this).data('fileurl');
|
|
|
|
if (fileType === 'pdf') {
|
|
Layer.open({
|
|
type: 2,
|
|
title: '预览PDF文件',
|
|
area: ['80%', '80%'],
|
|
content: fileUrl
|
|
});
|
|
} else if (['jpg', 'jpeg', 'png', 'gif', 'webp'].includes(fileType)) {
|
|
Layer.photos({
|
|
photos: {
|
|
"title": "图片预览",
|
|
"data": [{"src": fileUrl}]
|
|
},
|
|
anim: 5
|
|
});
|
|
} else if (['mp4', 'webm', 'ogg'].includes(fileType)) {
|
|
Layer.open({
|
|
type: 1,
|
|
title: '视频预览',
|
|
area: ['800px', '500px'],
|
|
content: `<video src="${fileUrl}" width="100%" height="100%" controls autoplay></video>`
|
|
});
|
|
} else {
|
|
window.open(fileUrl, '_blank');
|
|
}
|
|
});
|
|
|
|
// 为表格绑定事件
|
|
Table.api.bindevent(table);
|
|
},
|
|
add: function () {
|
|
Controller.api.bindevent();
|
|
},
|
|
edit: function () {
|
|
|
|
$(document).on('click', '.btn-preview', function (e) {
|
|
e.preventDefault();
|
|
var fileType = $(this).data('filetype'); // 自动从 data-type 获取,比如 pdf, jpg, doc
|
|
var fileUrl = $(this).data('fileurl');
|
|
|
|
if (fileType === 'pdf') {
|
|
Layer.open({
|
|
type: 2,
|
|
title: '预览PDF文件',
|
|
area: ['80%', '80%'],
|
|
content: fileUrl
|
|
});
|
|
} else if (['jpg', 'jpeg', 'png', 'gif', 'webp'].includes(fileType)) {
|
|
Layer.photos({
|
|
photos: {
|
|
"title": "图片预览",
|
|
"data": [{"src": fileUrl}]
|
|
},
|
|
anim: 5
|
|
});
|
|
} else if (['mp4', 'webm', 'ogg'].includes(fileType)) {
|
|
Layer.open({
|
|
type: 1,
|
|
title: '视频预览',
|
|
area: ['800px', '500px'],
|
|
content: `<video src="${fileUrl}" width="100%" height="100%" controls autoplay></video>`
|
|
});
|
|
} else {
|
|
window.open(fileUrl, '_blank');
|
|
}
|
|
});
|
|
|
|
|
|
Controller.api.bindevent();
|
|
},
|
|
api: {
|
|
bindevent: function () {
|
|
Form.api.bindevent($("form[role=form]"));
|
|
}
|
|
}
|
|
};
|
|
return Controller;
|
|
});
|