You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
243 lines
8.4 KiB
243 lines
8.4 KiB
2 months ago
|
<!DOCTYPE html>
|
||
|
<html lang="zh-CN">
|
||
|
<head>
|
||
|
<meta charset="UTF-8">
|
||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||
|
<title>积分显示</title>
|
||
|
<style>
|
||
|
body {
|
||
|
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
||
|
background: linear-gradient(135deg, #283c86, #45a247); /* 深蓝到绿色的渐变 */
|
||
|
height: 100vh;
|
||
|
margin: 0;
|
||
|
display: flex;
|
||
|
justify-content: center;
|
||
|
align-items: center;
|
||
|
color: #ffffff; /* 白色字体 */
|
||
|
}
|
||
|
.container {
|
||
|
width: 90%;
|
||
|
max-width: 800px;
|
||
|
background: rgba(50, 50, 70, 0.9); /* 更深的背景色 */
|
||
|
padding: 40px;
|
||
|
border-radius: 20px;
|
||
|
box-shadow: 0 15px 30px rgba(0, 0, 0, 0.5);
|
||
|
backdrop-filter: blur(10px); /* 增加模糊效果 */
|
||
|
border: 1px solid rgba(255, 255, 255, 0.2);
|
||
|
text-align: center;
|
||
|
}
|
||
|
h1 {
|
||
|
margin-bottom: 30px;
|
||
|
font-size: 2em;
|
||
|
color: #ff5722; /* 标题颜色 */
|
||
|
text-shadow: 2px 2px 5px rgba(0, 0, 0, 0.5); /* 文字阴影 */
|
||
|
}
|
||
|
#sortButton {
|
||
|
padding: 15px 30px;
|
||
|
font-size: 1.1em;
|
||
|
border: none;
|
||
|
border-radius: 50px;
|
||
|
background: linear-gradient(45deg, #6a82fb, #fc5c7d); /* 渐变按钮 */
|
||
|
color: white;
|
||
|
cursor: pointer;
|
||
|
transition: transform 0.2s, background 0.3s, box-shadow 0.3s;
|
||
|
margin-bottom: 20px;
|
||
|
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
|
||
|
}
|
||
|
#sortButton:hover {
|
||
|
background: linear-gradient(45deg, #5a72d6, #e54d84); /* 悬停时加深 */
|
||
|
transform: translateY(-3px); /* 悬停时上移效果 */
|
||
|
box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
|
||
|
}
|
||
|
table {
|
||
|
width: 100%;
|
||
|
border-collapse: collapse;
|
||
|
margin-top: 10px;
|
||
|
}
|
||
|
th, td {
|
||
|
padding: 12px 15px;
|
||
|
border-bottom: 1px solid rgba(255, 255, 255, 0.2); /* 边框颜色 */
|
||
|
font-size: 1em;
|
||
|
color: #ffffff; /* 字体颜色 */
|
||
|
}
|
||
|
th {
|
||
|
background-color: #4CAF50; /* 表头背景颜色 */
|
||
|
color: white;
|
||
|
}
|
||
|
tr:hover {
|
||
|
background-color: rgba(255, 255, 255, 0.1); /* 悬停行的颜色 */
|
||
|
}
|
||
|
.button-group {
|
||
|
margin-top: 30px;
|
||
|
display: flex;
|
||
|
justify-content: space-between;
|
||
|
gap: 10px;
|
||
|
}
|
||
|
.back-button, .clear-button {
|
||
|
padding: 15px 30px;
|
||
|
font-size: 1.1em;
|
||
|
border: none;
|
||
|
border-radius: 50px;
|
||
|
color: white;
|
||
|
cursor: pointer;
|
||
|
transition: background-color 0.3s, transform 0.2s, box-shadow 0.3s;
|
||
|
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
|
||
|
}
|
||
|
.back-button {
|
||
|
background: linear-gradient(45deg, #6a82fb, #fc5c7d); /* 渐变背景 */
|
||
|
}
|
||
|
.back-button:hover {
|
||
|
background: linear-gradient(45deg, #5a72d6, #e54d84); /* 悬停时加深 */
|
||
|
transform: translateY(-3px); /* 悬停时上移效果 */
|
||
|
box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
|
||
|
}
|
||
|
.clear-button {
|
||
|
background: linear-gradient(45deg, #f44336, #e53935); /* 渐变背景 */
|
||
|
}
|
||
|
.clear-button:hover {
|
||
|
background: linear-gradient(45deg, #d32f2f, #c62828); /* 悬停时加深 */
|
||
|
transform: translateY(-3px); /* 悬停时上移效果 */
|
||
|
box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
|
||
|
}
|
||
|
@media (max-width: 600px) {
|
||
|
th, td {
|
||
|
padding: 8px 10px;
|
||
|
}
|
||
|
#sortButton, .button-group button {
|
||
|
width: 100%;
|
||
|
margin: 10px 0;
|
||
|
}
|
||
|
}
|
||
|
</style>
|
||
|
</head>
|
||
|
|
||
|
<body>
|
||
|
|
||
|
<div class="container">
|
||
|
<h1>2024K班积分排名</h1>
|
||
|
<button id="sortButton">切换排序 (降序)</button>
|
||
|
<table>
|
||
|
<thead>
|
||
|
<tr>
|
||
|
<th>姓名</th>
|
||
|
<th>学号</th>
|
||
|
<th>积分</th>
|
||
|
</tr>
|
||
|
</thead>
|
||
|
<tbody id="studentList">
|
||
|
<!-- 学生积分将在此处显示 -->
|
||
|
</tbody>
|
||
|
</table>
|
||
|
<div class="button-group">
|
||
|
<button class="back-button" onclick="window.location.href='index.html'">返回主页面</button>
|
||
|
<button class="clear-button" id="clearButton">清除所有数据</button>
|
||
|
</div>
|
||
|
</div>
|
||
|
|
||
|
<script>
|
||
|
const studentList = document.getElementById('studentList');
|
||
|
const sortButton = document.getElementById('sortButton');
|
||
|
const clearButton = document.getElementById('clearButton');
|
||
|
let ascend = false; // 默认降序
|
||
|
|
||
|
|
||
|
//删除表
|
||
|
async function deleteTable(tableName) {
|
||
|
try {
|
||
|
const response = await fetch('/api/delete-table', {
|
||
|
method: 'POST',
|
||
|
headers: {
|
||
|
'Content-Type': 'application/json',
|
||
|
},
|
||
|
body: JSON.stringify({ tableName }),
|
||
|
});
|
||
|
|
||
|
if (!response.ok) {
|
||
|
throw new Error('删除表失败');
|
||
|
}
|
||
|
|
||
|
const data = await response.json();
|
||
|
alert(data.message); // 成功后显示消息
|
||
|
} catch (error) {
|
||
|
console.error('删除表操作失败:', error);
|
||
|
alert('删除表失败');
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
// 获取按分数降序排列的学生排名
|
||
|
async function fetchDescendRanking() {
|
||
|
try {
|
||
|
const response = await fetch('/api/descend_ranking');
|
||
|
if (!response.ok) {
|
||
|
return null;
|
||
|
}
|
||
|
|
||
|
const ranking = await response.json(); // 获取并解析为JSON数组
|
||
|
return ranking; // 返回排名数组
|
||
|
} catch (error) {
|
||
|
console.error('请求失败:', error);
|
||
|
return null;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// 获取按分数升序排列的学生排名
|
||
|
async function fetchAscendRanking() {
|
||
|
try {
|
||
|
const response = await fetch('/api/ascend_ranking');
|
||
|
if (!response.ok) {
|
||
|
return null;
|
||
|
}
|
||
|
|
||
|
const ranking = await response.json(); // 获取并解析为JSON数组
|
||
|
return ranking; // 返回排名数组
|
||
|
} catch (error) {
|
||
|
console.error('请求失败:', error);
|
||
|
return null;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
async function displayStudents() {
|
||
|
let ranking; // 声明 ranking 变量
|
||
|
if (ascend) {
|
||
|
ranking = await fetchAscendRanking(); // 获取升序排名
|
||
|
} else {
|
||
|
ranking = await fetchDescendRanking(); // 获取降序排名
|
||
|
}
|
||
|
|
||
|
studentList.innerHTML = ''; // 清空表格内容
|
||
|
// 只显示前10名学生
|
||
|
ranking.slice(0, 10).forEach(student => {
|
||
|
studentList.innerHTML += `
|
||
|
<tr>
|
||
|
<td>${student.student_name}</td> <!-- 学生姓名 -->
|
||
|
<td>${student.student_id}</td> <!-- 学生ID -->
|
||
|
<td>${student.score}</td> <!-- 学生分数 -->
|
||
|
</tr>
|
||
|
`;
|
||
|
});
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
sortButton.addEventListener('click', () => {
|
||
|
ascend = !ascend;
|
||
|
sortButton.textContent = `切换排序 (${ascend ? '升序' : '降序'})`;
|
||
|
displayStudents();
|
||
|
});
|
||
|
|
||
|
clearButton.addEventListener('click', () => {
|
||
|
const confirmation = confirm("确定要清除所有学生数据吗?此操作无法撤销!");
|
||
|
if (confirmation) {
|
||
|
deleteTable('students');
|
||
|
displayStudents(); // 重新显示清空后的数据
|
||
|
}
|
||
|
});
|
||
|
|
||
|
displayStudents();
|
||
|
</script>
|
||
|
|
||
|
</body>
|
||
|
</html>
|