|
|
@ -118,35 +118,35 @@
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// 停止滚动并通过后端决定最终选择的学生
|
|
|
|
// 停止滚动并通过后端决定最终选择的学生
|
|
|
|
stopButton.addEventListener('click', () => {
|
|
|
|
stopButton.addEventListener('click', async () => {
|
|
|
|
clearInterval(intervalId);
|
|
|
|
clearInterval(intervalId);
|
|
|
|
startButton.disabled = false;
|
|
|
|
startButton.disabled = false;
|
|
|
|
stopButton.disabled = true;
|
|
|
|
stopButton.disabled = true;
|
|
|
|
|
|
|
|
|
|
|
|
// 调用后端接口获取最终选中的学生
|
|
|
|
try {
|
|
|
|
fetch('/api/random-call')
|
|
|
|
const response = await fetch('/api/random-call');
|
|
|
|
.then(response => {
|
|
|
|
|
|
|
|
if (!response.ok) {
|
|
|
|
if (!response.ok) {
|
|
|
|
throw new Error('Network response was not ok');
|
|
|
|
throw new Error('Network response was not ok');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return response.json();
|
|
|
|
|
|
|
|
})
|
|
|
|
const data = await response.json();
|
|
|
|
.then(data => {
|
|
|
|
|
|
|
|
// 从后端返回的数据中获取学生名字
|
|
|
|
// 从后端返回的数据中获取学生名字
|
|
|
|
if (data.student && data.student.name) {
|
|
|
|
const selectedName = data.student_name; // student_name 属性
|
|
|
|
const selectedName = data.student.name;
|
|
|
|
|
|
|
|
|
|
|
|
if (selectedName) {
|
|
|
|
// 更新显示选中的学生
|
|
|
|
// 更新显示选中的学生
|
|
|
|
updateNameDisplay(selectedName);
|
|
|
|
updateNameDisplay(selectedName);
|
|
|
|
// 跳转到新页面并传递被选中的名字
|
|
|
|
// 跳转到新页面并传递被选中的名字
|
|
|
|
window.location.href = `choice.html?name=${encodeURIComponent(selectedName)}`;
|
|
|
|
window.location.href = `choice.html?student_name=${encodeURIComponent(data.student_name)}&student_id=${encodeURIComponent(data.student_id)}`;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
console.error('未返回有效学生数据');
|
|
|
|
console.error('未返回有效学生数据');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
} catch (error) {
|
|
|
|
.catch(error => {
|
|
|
|
|
|
|
|
console.error('请求失败:', error);
|
|
|
|
console.error('请求失败:', error);
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
</script>
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
</body>
|
|
|
|
</body>
|
|
|
|