parent
f223c74b0f
commit
281cb915dc
@ -1,98 +1,98 @@
|
|||||||
// 返回上一页
|
// 返回上一页
|
||||||
function goBack() {
|
function goBack() {
|
||||||
window.history.back();
|
window.history.back();
|
||||||
}
|
}
|
||||||
|
|
||||||
function showMessage(text) {
|
function showMessage(text) {
|
||||||
const messageDiv = document.getElementById("message");
|
const messageDiv = document.getElementById("message");
|
||||||
messageDiv.textContent = text;
|
messageDiv.textContent = text;
|
||||||
messageDiv.style.display = "block"; // 显示消息
|
messageDiv.style.display = "block"; // 显示消息
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
messageDiv.style.display = "none"; // 1秒后隐藏消息
|
messageDiv.style.display = "none"; // 1秒后隐藏消息
|
||||||
}, 1000);
|
}, 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 加载学生名单
|
// 加载学生名单
|
||||||
function loadStudentList() {
|
function loadStudentList() {
|
||||||
// 注册工具提示事件
|
// 注册工具提示事件
|
||||||
registerTooltipEvents();
|
registerTooltipEvents();
|
||||||
const students = JSON.parse(localStorage.getItem('students')) || [];
|
const students = JSON.parse(localStorage.getItem('students')) || [];
|
||||||
const list = document.getElementById('studentList');
|
const list = document.getElementById('studentList');
|
||||||
list.innerHTML = '';
|
list.innerHTML = '';
|
||||||
|
|
||||||
if (students.length === 0) {
|
if (students.length === 0) {
|
||||||
list.innerHTML = '<div>尚未导入任何学生名单。</div>';
|
list.innerHTML = '<div>尚未导入任何学生名单。</div>';
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 积分从大到小排序学生
|
// 积分从大到小排序学生
|
||||||
students.sort((a, b) => b.points - a.points);
|
students.sort((a, b) => b.points - a.points);
|
||||||
|
|
||||||
students.forEach((student, index) => {
|
students.forEach((student, index) => {
|
||||||
list.innerHTML += `
|
list.innerHTML += `
|
||||||
<div>
|
<div>
|
||||||
${student.id} - ${student.name} - 积分: ${student.points}
|
${student.id} - ${student.name} - 积分: ${student.points}
|
||||||
<button
|
<button
|
||||||
data-tooltip="清除积分"
|
data-tooltip="清除积分"
|
||||||
onclick="clearStudentPoints(${index})"
|
onclick="clearStudentPoints(${index})"
|
||||||
style="background: none; border: none; padding: 0; cursor: pointer;">
|
style="background: none; border: none; padding: 0; cursor: pointer;">
|
||||||
<img src="clear-icon.svg" alt="清除" style="width: 40px; height: 40px;" />
|
<img src="clear-icon.svg" alt="清除" style="width: 40px; height: 40px;" />
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
data-tooltip="删除学生"
|
data-tooltip="删除学生"
|
||||||
onclick="deleteStudent(${index})"
|
onclick="deleteStudent(${index})"
|
||||||
style="background: none; border: none; padding: 0; cursor: pointer;">
|
style="background: none; border: none; padding: 0; cursor: pointer;">
|
||||||
<img src="delete-icon.svg" alt="删除" style="width: 40px; height: 40px;" />
|
<img src="delete-icon.svg" alt="删除" style="width: 40px; height: 40px;" />
|
||||||
</button>
|
</button>
|
||||||
</div>`;
|
</div>`;
|
||||||
});
|
});
|
||||||
registerTooltipEvents();
|
registerTooltipEvents();
|
||||||
}
|
}
|
||||||
|
|
||||||
function registerTooltipEvents() {
|
function registerTooltipEvents() {
|
||||||
const buttons = document.querySelectorAll('button[data-tooltip]');
|
const buttons = document.querySelectorAll('button[data-tooltip]');
|
||||||
const tooltip = document.getElementById('tooltip');
|
const tooltip = document.getElementById('tooltip');
|
||||||
|
|
||||||
buttons.forEach(button => {
|
buttons.forEach(button => {
|
||||||
button.addEventListener('mouseenter', function(event) {
|
button.addEventListener('mouseenter', function(event) {
|
||||||
tooltip.textContent = button.getAttribute('data-tooltip');
|
tooltip.textContent = button.getAttribute('data-tooltip');
|
||||||
tooltip.style.display = 'block';
|
tooltip.style.display = 'block';
|
||||||
tooltip.style.left = event.pageX + 'px';
|
tooltip.style.left = event.pageX + 'px';
|
||||||
tooltip.style.top = (event.pageY + 20) + 'px'; // 鼠标下方略微偏移
|
tooltip.style.top = (event.pageY + 20) + 'px'; // 鼠标下方略微偏移
|
||||||
});
|
});
|
||||||
|
|
||||||
button.addEventListener('mouseleave', function() {
|
button.addEventListener('mouseleave', function() {
|
||||||
tooltip.style.display = 'none';
|
tooltip.style.display = 'none';
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// 清除单个学生积分
|
// 清除单个学生积分
|
||||||
function clearStudentPoints(index) {
|
function clearStudentPoints(index) {
|
||||||
const students = JSON.parse(localStorage.getItem('students')) || [];
|
const students = JSON.parse(localStorage.getItem('students')) || [];
|
||||||
students[index].points = 0; // 清除该学生的积分
|
students[index].points = 0; // 清除该学生的积分
|
||||||
localStorage.setItem('students', JSON.stringify(students)); // 更新本地存储
|
localStorage.setItem('students', JSON.stringify(students)); // 更新本地存储
|
||||||
loadStudentList(); // 重新加载学生列表
|
loadStudentList(); // 重新加载学生列表
|
||||||
showMessage("已清除该学生积分。");
|
showMessage("已清除该学生积分。");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 删除单个学生
|
// 删除单个学生
|
||||||
function deleteStudent(index) {
|
function deleteStudent(index) {
|
||||||
let students = JSON.parse(localStorage.getItem('students')) || [];
|
let students = JSON.parse(localStorage.getItem('students')) || [];
|
||||||
students.splice(index, 1); // 删除该学生
|
students.splice(index, 1); // 删除该学生
|
||||||
localStorage.setItem('students', JSON.stringify(students)); // 更新本地存储
|
localStorage.setItem('students', JSON.stringify(students)); // 更新本地存储
|
||||||
loadStudentList(); // 重新加载学生列表
|
loadStudentList(); // 重新加载学生列表
|
||||||
showMessage("已删除该学生。");
|
showMessage("已删除该学生。");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 一键清除所有学生的积分
|
// 一键清除所有学生的积分
|
||||||
function resetAllPoints() {
|
function resetAllPoints() {
|
||||||
let students = JSON.parse(localStorage.getItem('students')) || [];
|
let students = JSON.parse(localStorage.getItem('students')) || [];
|
||||||
students.forEach(student => student.points = 0); // 清除所有学生的积分
|
students.forEach(student => student.points = 0); // 清除所有学生的积分
|
||||||
localStorage.setItem('students', JSON.stringify(students)); // 更新本地存储
|
localStorage.setItem('students', JSON.stringify(students)); // 更新本地存储
|
||||||
loadStudentList(); // 重新加载学生列表
|
loadStudentList(); // 重新加载学生列表
|
||||||
showMessage("所有学生的积分已清除。");
|
showMessage("所有学生的积分已清除。");
|
||||||
}
|
}
|
||||||
|
|
||||||
window.onload = loadStudentList; // 页面加载时调用
|
window.onload = loadStudentList; // 页面加载时调用
|
Loading…
Reference in new issue