Files
nanguaboss 71c6e8d9c1 v1.0.10
2026-08-03 00:07:01 +08:00

105 lines
4.9 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* document.js - 文件管理逻辑(表格展示 / 上传 / 删除)
*/
$(function () {
renderShell('文件管理', '系统工具 / 文件管理');
renderPage();
initPage('document', function (user) {
if (!checkPagePermission('document')) return;
loadList(1);
});
var currentPage = 1;
/** 渲染页面内容(工具栏+表格+分页) */
function renderPage() {
$('#page-content').html(
'<div class="card">' +
' <div class="toolbar">' +
' <input type="text" data-filter="keyword" placeholder="文档名称关键词">' +
' <input type="text" data-filter="file_type" placeholder="文件类型(如 application/pdf)">' +
' <button class="btn btn-primary" id="btn-search">搜索</button>' +
' <button class="btn" id="btn-reset">重置</button>' +
' <span class="spacer"></span>' +
' <button class="btn btn-success" id="btn-upload">上传文件</button>' +
' <button class="btn btn-danger" id="btn-del-batch">批量删除</button>' +
' </div>' +
' <div class="table-wrap"><table class="grid">' +
' <thead><tr><th><input type="checkbox" id="check-all"></th><th>ID</th><th>文档名称</th><th>文件类型</th><th>文件</th><th>版本</th><th>发布日期</th><th>上传时间</th><th>操作</th></tr></thead>' +
' <tbody id="doc-tbody"></tbody>' +
' </table></div>' +
' <div class="pagination" id="pagination"></div>' +
'</div>'
);
$('#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 += '<tr>' +
'<td><input type="checkbox" class="row-check" value="' + r.id + '"></td>' +
'<td>' + r.id + '</td>' +
'<td title="' + escHtml(r.doc_name) + '">' + escHtml(r.doc_name) + '</td>' +
'<td>' + escHtml(r.file_type || '-') + '</td>' +
'<td><a href="' + escHtml(link) + '" target="_blank" class="btn btn-sm">查看/下载</a></td>' +
'<td>' + (r.is_current ? '<span class="tag tag-green">当前版本</span>' : '<span class="tag tag-gray">历史</span>') + '</td>' +
'<td>' + escHtml(r.publish_date || '-') + '</td>' +
'<td>' + fmtDate(r.created_at) + '</td>' +
'<td class="ops"><a class="danger" onclick="delDoc(' + r.id + ')">删除</a></td></tr>';
});
if (!rows.length) {
html = '<tr><td colspan="9" class="empty-tip" style="padding:40px 0;">暂无文件</td></tr>';
}
$('#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); });
});
});
});
});