|
|
<!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 {
|
|
|
text-align: center;
|
|
|
background: rgba(50, 50, 70, 0.9); /* 更深的背景色 */
|
|
|
padding: 40px;
|
|
|
border-radius: 20px;
|
|
|
box-shadow: 0 15px 30px rgba(0, 0, 0, 0.5);
|
|
|
border: 1px solid rgba(255, 255, 255, 0.2);
|
|
|
backdrop-filter: blur(10px); /* 增加模糊效果 */
|
|
|
}
|
|
|
|
|
|
h1 {
|
|
|
margin-bottom: 40px;
|
|
|
font-size: 2.5em;
|
|
|
color: #ffffff;
|
|
|
text-shadow: 2px 2px 5px rgba(0, 0, 0, 0.5); /* 文字阴影 */
|
|
|
}
|
|
|
|
|
|
#studentNameDisplay {
|
|
|
font-size: 1.8em;
|
|
|
margin-bottom: 30px;
|
|
|
min-height: 50px;
|
|
|
}
|
|
|
|
|
|
.button-group {
|
|
|
display: flex;
|
|
|
justify-content: center;
|
|
|
gap: 20px;
|
|
|
flex-wrap: wrap;
|
|
|
}
|
|
|
|
|
|
button {
|
|
|
padding: 15px 30px;
|
|
|
font-size: 1.2em;
|
|
|
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;
|
|
|
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
|
|
|
}
|
|
|
|
|
|
button:hover {
|
|
|
background: linear-gradient(45deg, #5a72d6, #e54d84); /* 悬停时加深 */
|
|
|
transform: translateY(-3px); /* 悬停时上移效果 */
|
|
|
box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
|
|
|
}
|
|
|
|
|
|
#absentButton {
|
|
|
background: linear-gradient(45deg, #f44336, #e53935); /* 渐变红色按钮 */
|
|
|
}
|
|
|
|
|
|
#absentButton:hover {
|
|
|
background: linear-gradient(45deg, #d32f2f, #c62828); /* 悬停时加深 */
|
|
|
}
|
|
|
|
|
|
.back-button {
|
|
|
margin-top: 30px;
|
|
|
background: linear-gradient(45deg, #2196F3, #1e88e5); /* 渐变蓝色按钮 */
|
|
|
}
|
|
|
|
|
|
.back-button:hover {
|
|
|
background: linear-gradient(45deg, #1976d2, #1565c0); /* 悬停时加深 */
|
|
|
}
|
|
|
</style>
|
|
|
</head>
|
|
|
|
|
|
<body>
|
|
|
|
|
|
<div class="container">
|
|
|
<h1>课堂点名</h1>
|
|
|
<div id="studentNameDisplay">请点击“随机点名”按钮</div>
|
|
|
<div class="button-group">
|
|
|
<button id="startAttendance">随机点名</button>
|
|
|
<button id="presentButton" style="display:none;">到</button>
|
|
|
<button id="absentButton" style="display:none;">没到</button>
|
|
|
</div>
|
|
|
<button class="back-button" onclick="window.location.href='index.html'">返回主页面</button>
|
|
|
</div>
|
|
|
|
|
|
<script>
|
|
|
const studentNameDisplay = document.getElementById('studentNameDisplay');
|
|
|
const startAttendanceButton = document.getElementById('startAttendance');
|
|
|
const presentButton = document.getElementById('presentButton');
|
|
|
const absentButton = document.getElementById('absentButton');
|
|
|
let currentStudent = null;
|
|
|
|
|
|
// 随机点名按钮点击事件
|
|
|
startAttendanceButton.addEventListener('click', async () => {
|
|
|
try {
|
|
|
// 向后端请求随机学生
|
|
|
const response = await fetch('http://localhost:3000/api/random-call');
|
|
|
const data = await response.json();
|
|
|
|
|
|
if (data.student_id && data.student_name) {
|
|
|
currentStudent = data;
|
|
|
studentNameDisplay.textContent = `当前学生: ${currentStudent.student_name}`;
|
|
|
presentButton.style.display = 'inline-block';
|
|
|
absentButton.style.display = 'inline-block';
|
|
|
startAttendanceButton.disabled = true;
|
|
|
} else {
|
|
|
alert('无法获取学生数据');
|
|
|
}
|
|
|
} catch (error) {
|
|
|
console.error('获取学生失败', error);
|
|
|
alert('获取学生失败,请重试');
|
|
|
}
|
|
|
});
|
|
|
|
|
|
// 到场按钮点击事件
|
|
|
presentButton.addEventListener('click', async () => {
|
|
|
if (currentStudent) {
|
|
|
await updatePoints(currentStudent.student_id, 0.5); // 到场加0.5分
|
|
|
alert(`${currentStudent.student_name} 已到,加0.5分`);
|
|
|
resetAttendance();
|
|
|
}
|
|
|
});
|
|
|
|
|
|
// 没到按钮点击事件
|
|
|
absentButton.addEventListener('click', async () => {
|
|
|
if (currentStudent) {
|
|
|
await updatePoints(currentStudent.student_id, -1); // 未到减1分
|
|
|
alert(`${currentStudent.student_name} 未到,减1分`);
|
|
|
resetAttendance();
|
|
|
}
|
|
|
});
|
|
|
|
|
|
// 更新分数的函数
|
|
|
async function updatePoints(studentId, points) {
|
|
|
try {
|
|
|
// 发送请求更新分数
|
|
|
const response = await fetch('http://localhost:3000/api/update-score', {
|
|
|
method: 'POST',
|
|
|
headers: {
|
|
|
'Content-Type': 'application/json',
|
|
|
},
|
|
|
body: JSON.stringify({ student_id: studentId, points }),
|
|
|
});
|
|
|
|
|
|
if (!response.ok) {
|
|
|
throw new Error('更新分数失败');
|
|
|
}
|
|
|
} catch (error) {
|
|
|
console.error('更新分数失败', error);
|
|
|
alert('更新分数失败,请重试');
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 重置点名的函数
|
|
|
function resetAttendance() {
|
|
|
studentNameDisplay.textContent = '请点击“随机点名”按钮';
|
|
|
presentButton.style.display = 'none';
|
|
|
absentButton.style.display = 'none';
|
|
|
startAttendanceButton.disabled = false;
|
|
|
}
|
|
|
|
|
|
</script>
|
|
|
|
|
|
</body>
|
|
|
</html>
|