/**
* document.js - 文件管理逻辑(表格展示 / 上传 / 删除)
*/
$(function () {
renderShell('文件管理', '系统工具 / 文件管理');
renderPage();
initPage('document', function (user) {
if (!checkPagePermission('document')) return;
loadList(1);
});
var currentPage = 1;
/** 渲染页面内容(工具栏+表格+分页) */
function renderPage() {
$('#page-content').html(
'
'
);
$('#check-all').on('change', function () { $('.row-check').prop('checked', this.checked); });
}
function loadList(page) {
currentPage = page;
var params = buildFilterParam();
params.page = page;
params.limit = PAGE_SIZE;
httpGet('document/list.php', params).then(function (data) {
var rows = data.list || [];
var html = '';
rows.forEach(function (r) {
var isLocal = (r.storage_path || '').indexOf('static/uploads/') === 0;
var link = isLocal ? r.storage_path : (r.storage_path || '#');
html += '' +
' | ' +
'' + r.id + ' | ' +
'' + escHtml(r.doc_name) + ' | ' +
'' + escHtml(r.file_type || '-') + ' | ' +
'查看/下载 | ' +
'' + (r.is_current ? '当前版本' : '历史') + ' | ' +
'' + escHtml(r.publish_date || '-') + ' | ' +
'' + fmtDate(r.created_at) + ' | ' +
'删除 |
';
});
if (!rows.length) {
html = '| 暂无文件 |
';
}
$('#doc-tbody').html(html);
renderPagination($('#pagination'), data, loadList);
});
}
$('#btn-search').on('click', function () { loadList(1); });
$('#btn-reset').on('click', function () {
$('.toolbar [data-filter]').val('');
loadList(1);
});
/* ---------- 上传 ---------- */
$('#btn-upload').on('click', function () {
triggerFileInput('.pdf,.doc,.docx,.xls,.xlsx,.ppt,.pptx,.txt,.csv,.png,.jpg,.jpeg,.gif,.zip,.rar', function (file) {
var fd = new FormData();
fd.append('file', file);
httpPost('document/upload.php', fd, true).then(function () {
Dialog.success('上传成功', function () { loadList(1); });
});
});
});
/* ---------- 删除(同时删除物理文件) ---------- */
window.delDoc = function (id) {
Dialog.confirm('确定删除该文件吗?将同时删除物理文件,不可恢复!', function () {
httpPost('document/delete.php', { id: id }).then(function () {
Dialog.success('删除成功', function () { loadList(currentPage); });
});
});
};
$('#btn-del-batch').on('click', function () {
var ids = [];
$('.row-check:checked').each(function () { ids.push($(this).val()); });
if (!ids.length) { Dialog.error('请先勾选记录'); return; }
Dialog.confirm('确定删除选中的 ' + ids.length + ' 个文件吗?将同时删除物理文件,不可恢复!', function () {
httpPost('document/delete.php', { ids: ids.join(',') }).then(function () {
Dialog.success('删除成功', function () { loadList(currentPage); });
});
});
});
});