parent
f940e22722
commit
06e46f5383
@ -1,86 +1,199 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<title>回答问题</title>
|
<title>回答问题</title>
|
||||||
<style>
|
<style>
|
||||||
body {
|
body {
|
||||||
font-family: 'Arial', sans-serif;
|
font-family: 'Arial', sans-serif;
|
||||||
height: 100vh;
|
height: 100vh;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
background: linear-gradient(135deg, #6e45e2, #88d3ce);
|
background: linear-gradient(135deg, #6e45e2, #88d3ce);
|
||||||
color: white;
|
color: white;
|
||||||
}
|
}
|
||||||
.container {
|
.container {
|
||||||
text-align: center;
|
text-align: center;
|
||||||
background-color: rgba(255, 255, 255, 0.1);
|
background-color: rgba(255, 255, 255, 0.1);
|
||||||
padding: 30px;
|
padding: 30px;
|
||||||
border-radius: 15px;
|
border-radius: 15px;
|
||||||
box-shadow: 0 8px 30px rgba(0, 0, 0, 0.2);
|
box-shadow: 0 8px 30px rgba(0, 0, 0, 0.2);
|
||||||
}
|
}
|
||||||
#question {
|
#question {
|
||||||
font-size: 2em;
|
font-size: 2em;
|
||||||
margin-bottom: 20px;
|
margin-bottom: 20px;
|
||||||
}
|
}
|
||||||
button {
|
button {
|
||||||
padding: 12px 30px;
|
padding: 12px 30px;
|
||||||
font-size: 1.1em;
|
font-size: 1.1em;
|
||||||
border: none;
|
border: none;
|
||||||
border-radius: 50px;
|
border-radius: 50px;
|
||||||
background-color: #ff5722;
|
background-color: #ff5722;
|
||||||
color: white;
|
color: white;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
|
box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
|
||||||
transition: background-color 0.3s ease, box-shadow 0.3s ease;
|
transition: background-color 0.3s ease, box-shadow 0.3s ease;
|
||||||
margin: 10px;
|
margin: 10px;
|
||||||
}
|
}
|
||||||
button:hover {
|
button:hover {
|
||||||
background-color: #ff3d00;
|
background-color: #ff3d00;
|
||||||
box-shadow: 0 8px 20px rgba(0, 0, 0, 0.3);
|
box-shadow: 0 8px 20px rgba(0, 0, 0, 0.3);
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<div id="question">你需要回答问题 结果是:</div>
|
<div id="question">请重复问题,选择正确或错误:</div>
|
||||||
<button id="correctButton">正确</button>
|
<button id="repeatCorrectButton">准确重复</button>
|
||||||
<button id="wrongButton">错误</button>
|
<button id="repeatWrongButton">未准确重复</button>
|
||||||
<button class="back-button" onclick="window.location.href='select.html'">返回点名页面</button>
|
|
||||||
<div id="result"></div>
|
<div id="questionResult"></div> <!-- 显示重复问题的结果 -->
|
||||||
</div>
|
|
||||||
|
<div id="answerContainer" style="display:none;">
|
||||||
<script>
|
<p>现在回答问题:</p>
|
||||||
const urlParams = new URLSearchParams(window.location.search);
|
<button id="correctButton">回答正确</button>
|
||||||
const name = urlParams.get('name');
|
<button id="partiallyCorrectButton">部分正确</button>
|
||||||
const correctButton = document.querySelector('#correctButton');
|
<button id="wrongButton">回答错误</button>
|
||||||
const wrongButton = document.querySelector('#wrongButton');
|
</div>
|
||||||
const resultDisplay = document.querySelector('#result');
|
|
||||||
|
<button class="back-button" onclick="window.location.href='select.html'">返回点名页面</button>
|
||||||
// 初始化积分
|
<div id="result"></div>
|
||||||
let userPoints = parseInt(localStorage.getItem(name));
|
<div id="studentInfo"></div> <!-- 显示学生信息 -->
|
||||||
|
</div>
|
||||||
// 正确答案处理
|
|
||||||
correctButton.addEventListener('click', () => {
|
<script>
|
||||||
userPoints += 10; // 正确回答加 10 分
|
async function updateScore(student_id, points) {
|
||||||
localStorage.setItem(name, userPoints); // 保存更新后的积分
|
try {
|
||||||
resultDisplay.textContent = `正确!${name} 的当前积分: ${userPoints}`;
|
const response = await fetch('/api/update-score', {
|
||||||
|
method: 'POST',
|
||||||
});
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
// 错误答案处理
|
},
|
||||||
wrongButton.addEventListener('click', () => {
|
body: JSON.stringify({ student_id, points }),
|
||||||
userPoints -= 5;
|
});
|
||||||
localStorage.setItem(name, userPoints); // 保存更新后的积分
|
|
||||||
resultDisplay.textContent = `错误!${name} 的当前积分: ${userPoints}`;
|
if (!response.ok) {
|
||||||
|
throw new Error('网络响应不正常');
|
||||||
});
|
}
|
||||||
|
|
||||||
</script>
|
const data = await response.text(); // 使用 text() 解析纯数字响应
|
||||||
|
console.log('更新后的分数:', data); // data 是字符串形式的分数
|
||||||
</body>
|
return data; // 返回更新后的分数字符串
|
||||||
</html>
|
} catch (error) {
|
||||||
|
console.error('分数更新失败:', error);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const urlParams = new URLSearchParams(window.location.search);
|
||||||
|
const student_name = urlParams.get('student_name');
|
||||||
|
const student_id = urlParams.get('student_id');
|
||||||
|
|
||||||
|
const repeatCorrectButton = document.querySelector('#repeatCorrectButton');
|
||||||
|
const repeatWrongButton = document.querySelector('#repeatWrongButton');
|
||||||
|
const questionResultDisplay = document.querySelector('#questionResult');
|
||||||
|
const correctButton = document.querySelector('#correctButton');
|
||||||
|
const partiallyCorrectButton = document.querySelector('#partiallyCorrectButton');
|
||||||
|
const wrongButton = document.querySelector('#wrongButton');
|
||||||
|
const resultDisplay = document.querySelector('#result');
|
||||||
|
const answerContainer = document.querySelector('#answerContainer');
|
||||||
|
const studentInfoDisplay = document.querySelector('#studentInfo');
|
||||||
|
|
||||||
|
// 显示学生姓名和学号
|
||||||
|
studentInfoDisplay.textContent = `学生: ${student_name} 学号: ${student_id}`;
|
||||||
|
|
||||||
|
// 正确重复问题处理 +0.5
|
||||||
|
repeatCorrectButton.addEventListener('click', () => {
|
||||||
|
updateScore(student_id, 0.5)
|
||||||
|
.then(newscore => {
|
||||||
|
if (newscore !== null) {
|
||||||
|
questionResultDisplay.textContent = `重复正确!${student_id} 的当前积分: ${newscore}`; // 直接使用字符串
|
||||||
|
answerContainer.style.display = 'block'; // 显示回答问题部分
|
||||||
|
} else {
|
||||||
|
console.error('更新分数失败');
|
||||||
|
questionResultDisplay.textContent = `更新分数失败,请重试。`;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
console.error('请求失败:', error);
|
||||||
|
questionResultDisplay.textContent = `更新分数失败,请重试。`;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// 未准确重复问题处理 -1
|
||||||
|
repeatWrongButton.addEventListener('click', () => {
|
||||||
|
updateScore(student_id, -1)
|
||||||
|
.then(newscore => {
|
||||||
|
if (newscore !== null) {
|
||||||
|
questionResultDisplay.textContent = `重复错误!${student_id} 的当前积分: ${newscore}`; // 直接使用字符串
|
||||||
|
answerContainer.style.display = 'block'; // 显示回答问题部分
|
||||||
|
} else {
|
||||||
|
console.error('更新分数失败');
|
||||||
|
questionResultDisplay.textContent = `更新分数失败,请重试。`;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
console.error('请求失败:', error);
|
||||||
|
questionResultDisplay.textContent = `更新分数失败,请重试。`;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// 回答问题的处理
|
||||||
|
correctButton.addEventListener('click', () => {
|
||||||
|
updateScore(student_id, 3)
|
||||||
|
.then(newscore => {
|
||||||
|
if (newscore !== null) {
|
||||||
|
resultDisplay.textContent = `回答完全正确!${student_id} 的当前积分: ${newscore}`; // 直接使用字符串
|
||||||
|
} else {
|
||||||
|
console.error('更新分数失败');
|
||||||
|
resultDisplay.textContent = `更新分数失败,请重试。`;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
console.error('请求失败:', error);
|
||||||
|
resultDisplay.textContent = `更新分数失败,请重试。`;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
partiallyCorrectButton.addEventListener('click', () => {
|
||||||
|
updateScore(student_id, 1.5)
|
||||||
|
.then(newscore => {
|
||||||
|
if (newscore !== null) {
|
||||||
|
resultDisplay.textContent = `回答部分正确!${student_id} 的当前积分: ${newscore}`; // 直接使用字符串
|
||||||
|
} else {
|
||||||
|
console.error('更新分数失败');
|
||||||
|
resultDisplay.textContent = `更新分数失败,请重试。`;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
console.error('请求失败:', error);
|
||||||
|
resultDisplay.textContent = `更新分数失败,请重试。`;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
wrongButton.addEventListener('click', () => {
|
||||||
|
updateScore(student_id, 0.5)
|
||||||
|
.then(newscore => {
|
||||||
|
if (newscore !== null) {
|
||||||
|
resultDisplay.textContent = `回答基本正确!${student_id} 的当前积分: ${newscore}`; // 直接使用字符串
|
||||||
|
} else {
|
||||||
|
console.error('更新分数失败');
|
||||||
|
resultDisplay.textContent = `更新分数失败,请重试。`;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
console.error('请求失败:', error);
|
||||||
|
resultDisplay.textContent = `更新分数失败,请重试。`;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
Loading…
Reference in new issue