const API_HISTORY = "http://app.wisdompulse.cn/api/v1/doc/fetch-os-upload-history";
const API_DELETE = "http://app.wisdompulse.cn/api/v1/doc/batch-delete-os-upload"; // 假设后端支持 recordId 数组删除
const tableBody = document.getElementById("historyTableBody");
const pagination = document.getElementById("pagination");
const pageSizeSelect = document.getElementById("pageSizeSelect");
const deleteBtn = document.getElementById("deleteSelectedBtn");
const selectAllCheckbox = document.getElementById("selectAll");
let currentPage = 1;
let total = 0;
let pageSize = parseInt(pageSizeSelect.value);
function loadUploadHistory(page = 1, size = 10) {
const url = `${API_HISTORY}?page=${page}&size=${size}`;
fetch(url)
.then(res => res.json())
.then(data => {
renderTable(data.records || []);
renderPagination(data.total || 0, page, size);
})
.catch(err => {
console.error("加载上传记录失败:", err);
});
}
function renderTable(records) {
tableBody.innerHTML = "";
if (!records.length) {
const tr = document.createElement("tr");
tr.innerHTML = `
暂无记录 | `;
tableBody.appendChild(tr);
return;
}
records.forEach((rec) => {
const statusText = rec.searchableStatus === 1 ? "可检索" : "不可检索";
const tr = document.createElement("tr");
tr.innerHTML = `
|
${rec.fileName} |
${rec.uploadTime} |
${rec.daysRemaining} |
${statusText} |
`;
tableBody.appendChild(tr);
});
// 全选功能
selectAllCheckbox.checked = false;
selectAllCheckbox.onclick = () => {
const checkboxes = document.querySelectorAll(".recordCheckbox");
checkboxes.forEach(cb => cb.checked = selectAllCheckbox.checked);
};
}
function renderPagination(totalCount, current, size) {
pagination.innerHTML = "";
total = totalCount;
const totalPages = Math.ceil(totalCount / size);
if (totalPages <= 1) return;
for (let i = 1; i <= totalPages; i++) {
const btn = document.createElement("button");
btn.textContent = i;
if (i === current) btn.classList.add("active");
btn.onclick = () => {
currentPage = i;
loadUploadHistory(currentPage, pageSize);
};
pagination.appendChild(btn);
}
}
deleteBtn.onclick = () => {
const selected = Array.from(document.querySelectorAll(".recordCheckbox:checked"));
if (!selected.length) {
alert("请选择要删除的记录");
return;
}
const recordIds = selected.map(cb => parseInt(cb.getAttribute("data-id")));
if (!confirm("删除后文件将无法访问或检索,是否确认删除?")) return;
fetch(API_DELETE, {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({ recordIds })
})
.then(res => {
if (!res.ok) throw new Error("删除失败");
return res.json();
})
.then(() => {
alert("删除成功");
loadUploadHistory(currentPage, pageSize);
})
.catch(err => {
console.error("删除出错:", err);
alert("删除失败,请稍后重试");
});
};
pageSizeSelect.addEventListener("change", () => {
pageSize = parseInt(pageSizeSelect.value);
currentPage = 1;
loadUploadHistory(currentPage, pageSize);
});
window.addEventListener("DOMContentLoaded", () => {
loadUploadHistory(currentPage, pageSize);
});