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.
166 lines
5.8 KiB
166 lines
5.8 KiB
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<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); /* 增加模糊效果 */
|
|
}
|
|
|
|
#nameDisplay {
|
|
font-size: 2.5em;
|
|
margin-bottom: 30px;
|
|
padding: 20px;
|
|
border-radius: 10px;
|
|
background-color: rgba(255, 255, 255, 0.2);
|
|
transition: all 0.3s ease;
|
|
text-shadow: 2px 2px 5px rgba(0, 0, 0, 0.5); /* 文字阴影 */
|
|
}
|
|
|
|
#nameDisplay.active {
|
|
transform: scale(1.1);
|
|
color: #ffeb3b;
|
|
}
|
|
|
|
button {
|
|
padding: 15px 30px;
|
|
font-size: 1.2em;
|
|
border: none;
|
|
border-radius: 50px;
|
|
background: linear-gradient(45deg, #fc5c7d, #6a82fb); /* 渐变按钮 */
|
|
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);
|
|
margin: 10px;
|
|
}
|
|
|
|
button:hover {
|
|
background: linear-gradient(45deg, #e54d84, #5a72d6); /* 悬停时加深 */
|
|
transform: translateY(-3px); /* 悬停时上移效果 */
|
|
box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
|
|
}
|
|
|
|
button:disabled {
|
|
background-color: #999;
|
|
cursor: not-allowed;
|
|
}
|
|
|
|
button + button {
|
|
margin-left: 15px;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
|
|
<div class="container">
|
|
<div id="nameDisplay">准备开始提问</div>
|
|
<button id="startButton">开始</button>
|
|
<button id="stopButton" disabled>停止</button>
|
|
<button class="back-button" onclick="window.location.href='index.html'">返回主页面</button>
|
|
</div>
|
|
|
|
<script>
|
|
let names = [];
|
|
let intervalId = null;
|
|
|
|
// 获取 DOM 元素
|
|
const nameDisplay = document.querySelector('#nameDisplay');
|
|
const startButton = document.querySelector('#startButton');
|
|
const stopButton = document.querySelector('#stopButton');
|
|
|
|
// 页面加载时获取学生名单
|
|
window.addEventListener('DOMContentLoaded', fetchStudents);
|
|
|
|
// 获取学生名单
|
|
async function fetchStudents() {
|
|
try {
|
|
const response = await fetch('/api/get-students');
|
|
if (!response.ok) {
|
|
throw new Error('Network response was not ok');
|
|
}
|
|
const data = await response.json();
|
|
names = data.map(student => student.student_name);
|
|
} catch (error) {
|
|
console.error('Error fetching student list:', error);
|
|
}
|
|
}
|
|
|
|
// 动态更新显示效果
|
|
const updateNameDisplay = (name) => {
|
|
nameDisplay.textContent = `点到: ${name}`;
|
|
nameDisplay.classList.add('active');
|
|
setTimeout(() => {
|
|
nameDisplay.classList.remove('active');
|
|
}, 300);
|
|
};
|
|
|
|
// 开始滚动显示
|
|
startButton.addEventListener('click', () => {
|
|
startButton.disabled = true;
|
|
stopButton.disabled = false;
|
|
|
|
intervalId = setInterval(() => {
|
|
// 从 names 数组中随机选择一个名字进行滚动显示
|
|
const randomIndex = Math.floor(Math.random() * names.length);
|
|
const selectedName = names[randomIndex];
|
|
|
|
// 更新显示选中的名字
|
|
updateNameDisplay(selectedName);
|
|
}, 100); // 每100毫秒滚动显示一次
|
|
});
|
|
|
|
// 停止滚动并通过后端决定最终选择的学生
|
|
stopButton.addEventListener('click', async () => {
|
|
clearInterval(intervalId);
|
|
startButton.disabled = false;
|
|
stopButton.disabled = true;
|
|
|
|
try {
|
|
const response = await fetch('/api/random-call');
|
|
|
|
if (!response.ok) {
|
|
throw new Error('Network response was not ok');
|
|
}
|
|
|
|
const data = await response.json();
|
|
// 从后端返回的数据中获取学生名字
|
|
const selectedName = data.student_name; // student_name 属性
|
|
|
|
if (selectedName) {
|
|
// 更新显示选中的学生
|
|
updateNameDisplay(selectedName);
|
|
// 跳转到新页面并传递被选中的名字
|
|
window.location.href = `choice.html?student_name=${encodeURIComponent(data.student_name)}&student_id=${encodeURIComponent(data.student_id)}`;
|
|
} else {
|
|
console.error('未返回有效学生数据');
|
|
}
|
|
} catch (error) {
|
|
console.error('请求失败:', error);
|
|
}
|
|
});
|
|
|
|
</script>
|
|
|
|
</body>
|
|
</html>
|