83 lines
2.6 KiB
JavaScript
83 lines
2.6 KiB
JavaScript
const BACKEND_URL = "https://rank.intcplab.cn";
|
|
const cache = {};
|
|
|
|
// 获取数据的函数
|
|
async function fetchScoresData(para, project, inject) {
|
|
try {
|
|
const response = await fetch(`${BACKEND_URL}/get_scores/${project}?sort_by=${para}`);
|
|
const data = await response.json();
|
|
|
|
const tableBody = document.getElementById(`${inject}`);
|
|
tableBody.innerHTML = ""; // 清空现有表格内容
|
|
|
|
data.forEach((item, index) => {
|
|
const row = document.createElement("tr");
|
|
|
|
row.innerHTML = `
|
|
<td>${item.time}</td>
|
|
<td>${item.id}</td>
|
|
<td>${item.name}</td>
|
|
<td>${item.score.toFixed(2)}</td>
|
|
<td>${item.running_time}</td>
|
|
<td>
|
|
<button onclick="showDetailsModal('${para}', '${project}', ${index})">查看详情</button>
|
|
</td>
|
|
`;
|
|
|
|
tableBody.appendChild(row);
|
|
});
|
|
cache[`${project}_${para}`] = data;
|
|
} catch (error) {
|
|
console.error("获取数据时发生错误:", error);
|
|
}
|
|
}
|
|
|
|
// 显示详情的函数
|
|
async function showDetailsModal(para, project, index) {
|
|
const modal = document.getElementById("detailsModal");
|
|
const modalDetails = document.getElementById("modal-details");
|
|
|
|
let data;
|
|
if (cache[`${project}_${para}`]) {
|
|
data = cache[`${project}_${para}`];
|
|
} else {
|
|
try {
|
|
const response = await fetch(`${BACKEND_URL}/get_scores/${project}?sort_by=${para}`);
|
|
data = await response.json();
|
|
// 缓存数据
|
|
cache[`${project}_${para}`] = data;
|
|
} catch (error) {
|
|
console.error("Failed to fetch data:", error);
|
|
return;
|
|
}
|
|
}
|
|
|
|
const details = data[index].details;
|
|
const hashLink = data[index].hash ? `若<b>仓库设置</b>为公开,则可<a href="${data[index].hash}" target="_blank">点击查看</a>评测所对应提交<br><br>` : "";
|
|
|
|
modalDetails.innerHTML = details + "<br><br>" + hashLink;
|
|
modal.style.display = "block";
|
|
}
|
|
|
|
// 关闭模态框
|
|
window.onclick = function (event) {
|
|
const modal = document.getElementById("detailsModal");
|
|
if (event.target === modal || event.target === document.getElementsByClassName("close")[0]) {
|
|
modal.style.display = "none";
|
|
}
|
|
};
|
|
|
|
// 当页面加载时默认加载
|
|
window.onload = () => {
|
|
fetchScoresData("score", "challenge_knn", "top-data-table-body");
|
|
fetchScoresData("time", "challenge_knn", "recent-data-table-body");
|
|
};
|
|
|
|
// 监听下拉框
|
|
document.getElementById("projectSelect").addEventListener("change", function () {
|
|
const selectedProject = this.value;
|
|
// 根据选择的项目加载
|
|
fetchScoresData("score", selectedProject, "top-data-table-body");
|
|
fetchScoresData("time", selectedProject, "recent-data-table-body");
|
|
});
|