random / index.html
chennyhihi's picture
Update index.html
e53d7c6 verified
Raw History Blame Contribute Delete
19.2 kB
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>锐道点名系统</title>
<script src="https://cdn.tailwindcss.com"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.18.5/xlsx.full.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<style>
@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+SC:wght@400;500;700&display=swap');
body {
font-family: 'Noto Sans SC', sans-serif;
background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
min-height: 100vh;
}
.glow {
animation: glow 1.5s ease-in-out infinite alternate;
}
@keyframes glow {
from {
box-shadow: 0 0 5px rgba(99, 102, 241, 0.5);
}
to {
box-shadow: 0 0 20px rgba(99, 102, 241, 0.8);
}
}
.result-display {
font-size: 3rem;
min-height: 120px;
display: flex;
align-items: center;
justify-content: center;
}
.history-item {
transition: all 0.3s ease;
}
.history-item:hover {
transform: translateX(5px);
background-color: rgba(99, 102, 241, 0.1);
}
.file-upload {
position: relative;
overflow: hidden;
display: inline-block;
}
.file-upload input[type="file"] {
position: absolute;
left: 0;
top: 0;
opacity: 0;
width: 100%;
height: 100%;
cursor: pointer;
}
</style>
</head>
<body class="py-8 px-4">
<div class="max-w-4xl mx-auto">
<!-- 标题 -->
<div class="text-center mb-8">
<h1 class="text-4xl font-bold text-indigo-600 mb-2">锐道点名系统</h1>
<p class="text-gray-600">高效、公平、随机的课堂点名解决方案</p>
</div>
<!-- 主内容区 -->
<div class="bg-white rounded-xl shadow-lg overflow-hidden">
<!-- 上传区域 -->
<div class="p-6 border-b border-gray-200 bg-indigo-50">
<div class="flex flex-col md:flex-row items-center justify-between gap-4">
<div>
<h2 class="text-lg font-semibold text-gray-800 mb-1">导入名单</h2>
<p class="text-sm text-gray-600">支持Excel文件(.xlsx, .xls, .csv)</p>
</div>
<div class="file-upload">
<button class="bg-indigo-600 hover:bg-indigo-700 text-white font-medium py-2 px-4 rounded-lg transition duration-300 flex items-center">
<i class="fas fa-upload mr-2"></i> 选择文件
</button>
<input type="file" id="fileInput" accept=".xlsx, .xls, .csv" />
</div>
</div>
<div id="fileNameDisplay" class="mt-3 text-sm text-gray-600 hidden">
<i class="fas fa-file-excel text-green-500 mr-2"></i>
<span id="fileName"></span>
<span id="studentCount" class="ml-2 text-indigo-600"></span>
</div>
</div>
<!-- 点名显示区 -->
<div class="p-8 text-center">
<div id="resultDisplay" class="result-display bg-indigo-50 rounded-lg mb-6 text-indigo-700 font-bold">
<span id="displayText">请先导入名单</span>
</div>
<!-- 控制按钮 -->
<div class="flex justify-center space-x-4 mb-6">
<button id="startBtn" class="bg-green-600 hover:bg-green-700 text-white font-medium py-3 px-6 rounded-lg transition duration-300 flex items-center disabled:opacity-50" disabled>
<i class="fas fa-play mr-2"></i> 开始
</button>
<button id="pauseBtn" class="bg-yellow-500 hover:bg-yellow-600 text-white font-medium py-3 px-6 rounded-lg transition duration-300 flex items-center disabled:opacity-50" disabled>
<i class="fas fa-pause mr-2"></i> 暂停
</button>
<button id="resetBtn" class="bg-red-600 hover:bg-red-700 text-white font-medium py-3 px-6 rounded-lg transition duration-300 flex items-center disabled:opacity-50" disabled>
<i class="fas fa-redo mr-2"></i> 重置
</button>
</div>
<!-- 速度控制 -->
<div class="max-w-md mx-auto mb-6">
<label for="speedControl" class="block text-sm font-medium text-gray-700 mb-2">点名速度</label>
<input type="range" id="speedControl" min="50" max="500" value="150" class="w-full h-2 bg-gray-200 rounded-lg appearance-none cursor-pointer">
</div>
</div>
<!-- 历史记录 -->
<div class="border-t border-gray-200 p-6">
<h3 class="text-lg font-semibold text-gray-800 mb-4 flex items-center">
<i class="fas fa-history text-indigo-500 mr-2"></i> 点名历史
</h3>
<div id="historyList" class="space-y-2 max-h-60 overflow-y-auto">
<div class="text-center text-gray-500 py-4" id="emptyHistory">
<i class="fas fa-info-circle mr-2"></i>暂无历史记录
</div>
</div>
</div>
</div>
<!-- 统计信息 -->
<div class="mt-6 grid grid-cols-1 md:grid-cols-3 gap-4">
<div class="bg-white p-4 rounded-lg shadow text-center">
<div class="text-indigo-600 text-2xl font-bold" id="totalStudents">0</div>
<div class="text-gray-600 text-sm">总人数</div>
</div>
<div class="bg-white p-4 rounded-lg shadow text-center">
<div class="text-green-600 text-2xl font-bold" id="calledStudents">0</div>
<div class="text-gray-600 text-sm">已点名</div>
</div>
<div class="bg-white p-4 rounded-lg shadow text-center">
<div class="text-blue-600 text-2xl font-bold" id="remainingStudents">0</div>
<div class="text-gray-600 text-sm">剩余人数</div>
</div>
</div>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
// 全局变量
let studentList = [];
let calledStudents = [];
let timer = null;
let speed = 150;
// DOM元素
const fileInput = document.getElementById('fileInput');
const fileNameDisplay = document.getElementById('fileNameDisplay');
const fileName = document.getElementById('fileName');
const studentCount = document.getElementById('studentCount');
const resultDisplay = document.getElementById('resultDisplay');
const displayText = document.getElementById('displayText');
const startBtn = document.getElementById('startBtn');
const pauseBtn = document.getElementById('pauseBtn');
const resetBtn = document.getElementById('resetBtn');
const historyList = document.getElementById('historyList');
let emptyHistory = document.getElementById('emptyHistory');
const totalStudentsEl = document.getElementById('totalStudents');
const calledStudentsEl = document.getElementById('calledStudents');
const remainingStudentsEl = document.getElementById('remainingStudents');
const speedControl = document.getElementById('speedControl');
// 文件上传处理
fileInput.addEventListener('change', function(e) {
const file = e.target.files[0];
if (!file) return;
fileName.textContent = file.name;
fileNameDisplay.classList.remove('hidden');
const reader = new FileReader();
reader.onload = function(e) {
try {
const data = new Uint8Array(e.target.result);
const workbook = XLSX.read(data, { type: 'array' });
const firstSheet = workbook.Sheets[workbook.SheetNames[0]];
const jsonData = XLSX.utils.sheet_to_json(firstSheet, { header: 1 });
// 假设第一列是学生姓名
studentList = jsonData
.slice(1) // 跳过标题行
.map(row => row[0])
.filter(name => name && name.trim() !== '');
if (studentList.length === 0) {
alert('文件中没有找到有效的学生名单!');
return;
}
// 重置状态
calledStudents = [];
updateStats();
displayText.textContent = '准备就绪';
resultDisplay.classList.remove('bg-red-50', 'bg-green-50');
resultDisplay.classList.add('bg-indigo-50');
// 启用按钮
startBtn.disabled = false;
resetBtn.disabled = false;
// 更新UI
studentCount.textContent = `(${studentList.length}人)`;
historyList.innerHTML = '<div class="text-center text-gray-500 py-4" id="emptyHistory"><i class="fas fa-info-circle mr-2"></i>暂无历史记录</div>';
emptyHistory = document.getElementById('emptyHistory');
// 显示成功消息
showToast('名单导入成功!', 'success');
} catch (error) {
console.error(error);
alert('文件解析失败,请检查文件格式!');
}
};
reader.readAsArrayBuffer(file);
});
// 速度控制
speedControl.addEventListener('input', function() {
speed = 550 - this.value; // 反转值,使滑块右侧为快速
});
// 开始点名
startBtn.addEventListener('click', function() {
if (studentList.length === 0) {
showToast('请先导入名单!', 'error');
return;
}
if (calledStudents.length >= studentList.length) {
showToast('所有学生都已被点名!', 'warning');
return;
}
startBtn.disabled = true;
pauseBtn.disabled = false;
resetBtn.disabled = true;
resultDisplay.classList.remove('bg-indigo-50');
resultDisplay.classList.add('bg-indigo-100', 'glow');
// 开始随机滚动显示名字
timer = setInterval(randomDisplay, speed);
});
// 暂停点名
pauseBtn.addEventListener('click', function() {
clearInterval(timer);
timer = null;
// 获取当前显示的名字
const currentName = displayText.textContent;
// 检查是否已经点过名
if (!calledStudents.includes(currentName) && studentList.includes(currentName)) {
calledStudents.push(currentName);
addToHistory(currentName);
updateStats();
// 检查是否所有学生都已被点名
if (calledStudents.length >= studentList.length) {
displayText.textContent = '点名完成';
resultDisplay.classList.remove('glow', 'bg-indigo-100');
resultDisplay.classList.add('bg-green-50');
showToast('所有学生都已被点名!', 'success');
}
}
startBtn.disabled = false;
pauseBtn.disabled = true;
resetBtn.disabled = false;
resultDisplay.classList.remove('glow');
});
// 重置
resetBtn.addEventListener('click', function() {
clearInterval(timer);
timer = null;
calledStudents = [];
updateStats();
displayText.textContent = '准备就绪';
resultDisplay.classList.remove('bg-red-50', 'bg-green-50', 'bg-indigo-100', 'glow');
resultDisplay.classList.add('bg-indigo-50');
startBtn.disabled = false;
pauseBtn.disabled = true;
resetBtn.disabled = true;
// 清空历史记录
historyList.innerHTML = '<div class="text-center text-gray-500 py-4" id="emptyHistory"><i class="fas fa-info-circle mr-2"></i>暂无历史记录</div>';
emptyHistory = document.getElementById('emptyHistory');
});
// 随机显示名字
function randomDisplay() {
// 获取未被点名的学生
const availableStudents = studentList.filter(student => !calledStudents.includes(student));
if (availableStudents.length === 0) {
clearInterval(timer);
return;
}
// 随机选择一个名字
const randomIndex = Math.floor(Math.random() * availableStudents.length);
displayText.textContent = availableStudents[randomIndex];
}
// 添加到历史记录
function addToHistory(name) {
if (emptyHistory) {
emptyHistory.remove();
}
const now = new Date();
const timeString = now.toLocaleTimeString();
const currentEmptyHistory = historyList.querySelector('#emptyHistory');
if (currentEmptyHistory) {
currentEmptyHistory.remove();
}
const historyItem = document.createElement('div');
historyItem.className = 'history-item bg-gray-50 p-3 rounded-lg flex justify-between items-center';
historyItem.innerHTML = `
<div class="flex items-center">
<div class="w-8 h-8 rounded-full bg-indigo-100 text-indigo-600 flex items-center justify-center mr-3">
<i class="fas fa-user"></i>
</div>
<span class="font-medium">${name}</span>
</div>
<span class="text-sm text-gray-500">${timeString}</span>
`;
historyList.insertBefore(historyItem, historyList.firstChild);
}
// 更新统计信息
function updateStats() {
totalStudentsEl.textContent = studentList.length;
calledStudentsEl.textContent = calledStudents.length;
remainingStudentsEl.textContent = studentList.length - calledStudents.length;
}
// 显示Toast通知
function showToast(message, type) {
const toast = document.createElement('div');
let bgColor = 'bg-indigo-600';
if (type === 'error') bgColor = 'bg-red-600';
if (type === 'success') bgColor = 'bg-green-600';
if (type === 'warning') bgColor = 'bg-yellow-500';
toast.className = `fixed bottom-4 right-4 ${bgColor} text-white px-4 py-2 rounded-lg shadow-lg flex items-center animate-fade-in`;
toast.innerHTML = `
<i class="fas ${type === 'error' ? 'fa-exclamation-circle' : type === 'success' ? 'fa-check-circle' : 'fa-exclamation-triangle'} mr-2"></i>
${message}
`;
document.body.appendChild(toast);
setTimeout(() => {
toast.classList.remove('animate-fade-in');
toast.classList.add('animate-fade-out');
setTimeout(() => toast.remove(), 300);
}, 3000);
}
// 添加动画样式
const style = document.createElement('style');
style.textContent = `
@keyframes fade-in {
from { opacity: 0; transform: translateY(10px); }
to { opacity: 1; transform: translateY(0); }
}
@keyframes fade-out {
from { opacity: 1; transform: translateY(0); }
to { opacity: 0; transform: translateY(10px); }
}
.animate-fade-in {
animation: fade-in 0.3s ease-out forwards;
}
.animate-fade-out {
animation: fade-out 0.3s ease-out forwards;
}
`;
document.head.appendChild(style);
});
</script>
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=chennyhihi/random" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html>