HTML<!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>
<link href="https://cdn.jsdelivr.net/npm/font-awesome@4.7.0/css/font-awesome.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/html2canvas@1.4.1/dist/html2canvas.min.js"></script>
<link href="https://fonts.googleapis.com/css2?family=Orbitron:wght@400;500;600;700;800;900&family=Rajdhani:wght@300;400;500;600;700&display=swap" rel="stylesheet">
<script>
tailwind.config = {
theme: {
extend: {
colors: {
primary: '#00f5ff',
secondary: '#ff00ff',
danger: '#ff3366',
success: '#33ff99',
neutral: '#1a1a2e',
dark: '#0f0f1e',
accent1: '#ff00ff',
accent2: '#00ffff',
accent3: '#ffff00',
accent4: '#ff6600'
},
fontFamily: {
sans: ['Orbitron', 'Rajdhani', 'Inter', 'system-ui', 'sans-serif']
},
animation: {
'fade-in': 'fadeIn 0.5s ease-in-out',
'slide-in': 'slideIn 0.5s ease-in-out',
'pulse-light': 'pulseLight 1.5s infinite',
'firework': 'firework 1s ease-out forwards',
'firework-particle': 'fireworkParticle 1s ease-out forwards',
'glow': 'glow 2s ease-in-out infinite alternate',
'float': 'float 3s ease-in-out infinite',
'scan': 'scan 2s linear infinite',
'rotate': 'rotate 10s linear infinite',
'hologram': 'hologram 2s ease-in-out infinite'
},
keyframes: {
fadeIn: {
'0%': { opacity: 0 },
'100%': { opacity: 1 }
},
slideIn: {
'0%': { transform: 'translateY(20px)', opacity: 0 },
'100%': { transform: 'translateY(0)', opacity: 1 }
},
pulseLight: {
'0%, 100%': { opacity: 1 },
'50%': { opacity: 0.7 }
},
glow: {
'0%': { boxShadow: '0 0 5px theme(colors.primary), 0 0 10px theme(colors.primary)' },
'100%': { boxShadow: '0 0 10px theme(colors.primary), 0 0 20px theme(colors.primary), 0 0 30px theme(colors.primary)' }
},
float: {
'0%, 100%': { transform: 'translateY(0px)' },
'50%': { transform: 'translateY(-10px)' }
},
scan: {
'0%': { backgroundPosition: '0 -100%' },
'100%': { backgroundPosition: '0 200%' }
},
rotate: {
'0%': { transform: 'rotate(0deg)' },
'100%': { transform: 'rotate(360deg)' }
},
hologram: {
'0%': {
boxShadow: '0 0 5px theme(colors.accent1), 0 0 10px theme(colors.accent1)',
transform: 'translateY(0) rotate(0deg)'
},
'25%': {
boxShadow: '0 0 10px theme(colors.accent2), 0 0 20px theme(colors.accent2)',
transform: 'translateY(-2px) rotate(0.5deg)'
},
'50%': {
boxShadow: '0 0 5px theme(colors.accent1), 0 0 10px theme(colors.accent1)',
transform: 'translateY(0) rotate(0deg)'
},
'75%': {
boxShadow: '0 0 10px theme(colors.accent2), 0 0 20px theme(colors.accent2)',
transform: 'translateY(2px) rotate(-0.5deg)'
},
'100%': {
boxShadow: '0 0 5px theme(colors.accent1), 0 0 10px theme(colors.accent1)',
transform: 'translateY(0) rotate(0deg)'
}
}
}
}
}
}
</script>
<style type="text/tailwindcss">
@layer utilities {
.seat-transition {
@apply transition-all duration-300 ease-in-out;
}
.glass-effect {
@apply bg-black bg-opacity-30 backdrop-blur-lg border border-white border-opacity-20;
}
.btn-primary {
@apply bg-gradient-to-r from-accent1 to-accent2 text-white font-medium py-2 px-6 rounded-lg transition-all duration-300 transform hover:scale-105 focus:outline-none focus:ring-2 focus:ring-accent1 focus:ring-opacity-50 shadow-lg animate-glow;
}
.btn-secondary {
@apply bg-gradient-to-r from-gray-800 to-gray-900 text-gray-200 font-medium py-2 px-6 rounded-lg transition-all duration-300 transform hover:scale-105 focus:outline-none focus:ring-2 focus:ring-gray-400 focus:ring-opacity-50 shadow-md border border-gray-700;
}
.input-field {
@apply bg-black bg-opacity-50 border-2 border-accent1 rounded-lg px-4 py-2 text-white focus:outline-none focus:ring-2 focus:ring-accent1 focus:border-transparent transition-all duration-300 animate-pulse-light;
}
.step-container {
@apply animate-fade-in;
}
.click-effect {
position: absolute;
border-radius: 50%;
background-color: rgba(0, 245, 255, 0.5);
transform: scale(0);
pointer-events: none;
z-index: 50;
}
.firework {
position: absolute;
transform-origin: center;
pointer-events: none;
z-index: 50;
}
.firework-particle {
position: absolute;
width: 4px;
height: 4px;
border-radius: 50%;
pointer-events: none;
}
.sci-fi-border {
@apply border-2 border-accent1 relative overflow-hidden;
}
.sci-fi-border::before {
content: '';
position: absolute;
top: 0;
left: -100%;
width: 100%;
height: 100%;
background: linear-gradient(90deg, transparent, rgba(0, 245, 255, 0.4), transparent);
animation: scan 2s linear infinite;
}
.sci-fi-text {
@apply text-transparent bg-clip-text bg-gradient-to-r from-accent1 to-accent2 font-bold;
}
.sci-fi-seat {
@apply border-2 border-accent1 hover:border-accent2 hover:shadow-lg hover:shadow-accent1 hover:shadow-opacity-50 transition-all duration-300;
}
.sci-fi-desk {
@apply bg-gradient-to-b from-gray-900 to-black border-2 border-accent1 relative overflow-hidden;
}
.sci-fi-desk::after {
content: '';
position: absolute;
top: 0;
left: 0;
right: 0;
height: 2px;
background: linear-gradient(90deg, transparent, theme(colors.accent1), transparent);
animation: scan 3s linear infinite;
}
.particle {
position: absolute;
border-radius: 50%;
pointer-events: none;
opacity: 0.5;
animation: float 4s infinite ease-in-out;
}
}
</style>
</head>
<body class="bg-gradient-to-br from-dark to-neutral min-h-screen font-sans text-gray-200 overflow-x-hidden">
<!-- 粒子背景 -->
<div id="particles" class="fixed inset-0 z-0"></div>
<div class="container mx-auto px-4 py-8 max-w-6xl">
<header class="text-center mb-8 animate-fade-in relative z-10">
<h1 class="text-5xl font-bold sci-fi-text mb-2 animate-float">随机机房座位表生成器</h1>
<p class="text-xl text-gray-300 animate-pulse-light">未来科技 · 智能排座系统</p>
</header>
<!-- 进度指示器 -->
<div class="flex justify-center mb-8 animate-fade-in">
<div class="flex items-center space-x-4">
<div id="step1-indicator" class="flex flex-col items-center">
<div class="w-12 h-12 rounded-full bg-gradient-to-r from-accent1 to-accent2 text-white flex items-center justify-center font-bold shadow-lg animate-glow">1</div>
<span class="mt-2 text-sm font-medium text-accent1">标记坏座位</span>
</div>
<div class="w-16 h-1 bg-gray-300 rounded-full">
<div id="progress-1-2" class="h-full bg-primary rounded-full transition-all duration-500" style="width: 0%"></div>
</div>
<div id="step2-indicator" class="flex flex-col items-center">
<div class="w-12 h-12 rounded-full bg-gray-800 text-gray-400 flex items-center justify-center font-bold border border-gray-700">2</div>
<span class="mt-2 text-sm font-medium text-gray-400">输入学号</span>
</div>
<div class="w-16 h-1 bg-gray-300 rounded-full">
<div id="progress-2-3" class="h-full bg-primary rounded-full transition-all duration-500" style="width: 0%"></div>
</div>
<div id="step3-indicator" class="flex flex-col items-center">
<div class="w-12 h-12 rounded-full bg-gray-800 text-gray-400 flex items-center justify-center font-bold border border-gray-700">3</div>
<span class="mt-2 text-sm font-medium text-gray-400">生成座位表</span>
</div>
</div>
</div>
<!-- 步骤1:标记坏座位 -->
<div id="step1" class="step-container glass-effect rounded-xl shadow-xl p-6 mb-8 border border-accent1 border-opacity-30 animate-hologram">
<h2 class="text-2xl font-bold mb-4 text-center sci-fi-text">步骤1:标记坏座位</h2>
<p class="text-center mb-6 text-gray-300">点击座位标记为坏座位(红色),再次点击取消标记</p>
<div class="overflow-x-auto">
<div class="min-w-[900px]">
<!-- 讲台 -->
<div class="flex justify-center mb-8">
<div class="w-3/4 h-32 sci-fi-desk rounded-lg flex items-center justify-center px-8 animate-glow relative overflow-hidden">
<!-- 木鱼居中 -->
<div class="relative flex flex-col items-center">
<img src="https://cdn.luogu.com.cn/upload/usericon/338284.png" alt="木鱼" class="h-20 w-20 object-cover rounded-full border-2 border-accent1 animate-float z-10 cursor-pointer hover:scale-110 transition-transform duration-300" id="wooden-fish">
<div class="absolute -inset-2 rounded-full border-2 border-accent2 animate-ping opacity-75"></div>
<div class="mt-2 text-accent1 font-bold" id="merit-counter">功德: 0</div>
</div>
<div class="absolute inset-0 bg-gradient-to-r from-accent1 to-accent2 opacity-10 animate-scan"></div>
</div>
</div>
<!-- 座位区域 -->
<div class="flex justify-center">
<!-- 左侧座位 -->
<div class="grid grid-cols-4 gap-2 mr-12">
<!-- 动态生成左侧座位 -->
</div>
<!-- 中间走廊 -->
<div class="w-12"></div>
<!-- 右侧座位 -->
<div class="grid grid-cols-4 gap-2 ml-12">
<!-- 动态生成右侧座位 -->
</div>
</div>
</div>
</div>
<div class="mt-8 flex justify-center">
<button id="step1-next" class="btn-primary flex items-center">
<span>确定并继续</span>
<i class="fa fa-arrow-right ml-2"></i>
</button>
</div>
</div>
<!-- 步骤2:输入学号范围 -->
<div id="step2" class="step-container glass-effect rounded-xl shadow-xl p-6 mb-8 hidden border border-accent1 border-opacity-30 animate-hologram">
<h2 class="text-2xl font-bold mb-4 text-center sci-fi-text">步骤2:输入学号信息</h2>
<p class="text-center mb-6 text-gray-300">请输入学号范围和需要排除的学号</p>
<div class="max-w-md mx-auto">
<div class="mb-6">
<label for="start-id" class="block text-accent1 font-medium mb-2">起始学号</label>
<input type="number" id="start-id" class="input-field w-full" placeholder="例如:001" required>
</div>
<div class="mb-6">
<label for="end-id" class="block text-accent1 font-medium mb-2">结束学号</label>
<input type="number" id="end-id" class="input-field w-full" placeholder="例如:040" required>
</div>
<div class="mb-6">
<label for="exclude-ids" class="block text-accent1 font-medium mb-2">排除学号(用逗号分隔)</label>
<input type="text" id="exclude-ids" class="input-field w-full" placeholder="例如:005,010,015">
<p class="mt-2 text-sm text-gray-400">请输入不参与排座的学生学号,多个学号用逗号分隔</p>
</div>
<div class="mt-8 flex justify-center">
<button id="step2-back" class="btn-secondary mr-4 flex items-center">
<i class="fa fa-arrow-left mr-2"></i>
<span>返回</span>
</button>
<button id="step2-next" class="btn-primary flex items-center">
<span>生成座位表</span>
<i class="fa fa-arrow-right ml-2"></i>
</button>
</div>
</div>
</div>
<!-- 步骤3:生成座位表 -->
<div id="step3" class="step-container glass-effect rounded-xl shadow-xl p-6 mb-8 hidden border border-accent1 border-opacity-30 animate-hologram">
<h2 class="text-2xl font-bold mb-4 text-center sci-fi-text">步骤3:随机座位表</h2>
<p class="text-center mb-6 text-gray-300">以下是随机生成的座位表</p>
<div class="overflow-x-auto">
<div class="min-w-[900px]">
<!-- 讲台 -->
<div class="flex justify-center mb-8">
<div class="w-3/4 h-32 sci-fi-desk rounded-lg flex items-center justify-center px-8 animate-glow relative overflow-hidden">
<!-- 木鱼居中 -->
<div class="relative flex flex-col items-center">
<img src="https://cdn.luogu.com.cn/upload/usericon/338284.png" alt="木鱼" class="h-20 w-20 object-cover rounded-full border-2 border-accent1 animate-float z-10 cursor-pointer hover:scale-110 transition-transform duration-300" id="wooden-fish-step3">
<div class="absolute -inset-2 rounded-full border-2 border-accent2 animate-ping opacity-75"></div>
<div class="mt-2 text-accent1 font-bold" id="merit-counter-step3">功德: 0</div>
</div>
<div class="absolute inset-0 bg-gradient-to-r from-accent1 to-accent2 opacity-10 animate-scan"></div>
</div>
</div>
<!-- 座位区域 -->
<div class="flex justify-center">
<!-- 左侧座位 -->
<div id="step3-left-seats" class="grid grid-cols-4 gap-2 mr-12">
<!-- 动态生成左侧座位 -->
</div>
<!-- 中间走廊 -->
<div class="w-12"></div>
<!-- 右侧座位 -->
<div id="step3-right-seats" class="grid grid-cols-4 gap-2 ml-12">
<!-- 动态生成右侧座位 -->
</div>
</div>
</div>
</div>
<div class="mt-8 flex justify-center space-x-4">
<button id="step3-back" class="btn-secondary flex items-center">
<i class="fa fa-arrow-left mr-2"></i>
<span>重新设置</span>
</button>
<button id="step3-save" class="btn-primary flex items-center">
<i class="fa fa-download mr-2"></i>
<span>保存座位表</span>
</button>
<button id="step3-swap" class="btn-primary flex items-center">
<i class="fa fa-exchange mr-2"></i>
<span>交换位置</span>
</button>
<button id="step3-regenerate" class="btn-secondary flex items-center">
<i class="fa fa-refresh mr-2"></i>
<span>重新生成</span>
</button>
</div>
</div>
<!-- 交换位置模态框 -->
<div id="swap-modal" class="fixed inset-0 bg-black bg-opacity-70 flex items-center justify-center z-50 hidden">
<div class="glass-effect rounded-xl shadow-2xl p-8 max-w-md w-full border border-accent1 animate-fade-in">
<div class="flex justify-between items-center mb-6">
<h3 class="text-2xl font-bold sci-fi-text">交换学生位置</h3>
<button id="close-modal" class="text-gray-400 hover:text-white text-2xl">
<i class="fa fa-times"></i>
</button>
</div>
<div class="space-y-6">
<div>
<label for="student1" class="block text-accent1 font-medium mb-2">学生1学号</label>
<input type="number" id="student1" class="input-field w-full" placeholder="请输入学号" required>
</div>
<div>
<label for="student2" class="block text-accent1 font-medium mb-2">学生2学号</label>
<input type="number" id="student2" class="input-field w-full" placeholder="请输入学号" required>
</div>
<div class="flex justify-center space-x-4 mt-8">
<button id="cancel-swap" class="btn-secondary flex items-center">
<i class="fa fa-times mr-2"></i>
<span>取消</span>
</button>
<button id="confirm-swap" class="btn-primary flex items-center">
<i class="fa fa-check mr-2"></i>
<span>确认交换</span>
</button>
</div>
</div>
</div>
</div>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
// 全局变量
const totalRows = 8;
const seatsPerSide = 4;
const totalSeats = totalRows * seatsPerSide * 2; // 左右两侧
let brokenSeats = new Set(); // 存储坏座位的索引
let studentIds = []; // 存储生成的学号列表
let currentSeatMap = {}; // 存储当前座位映射关系
// 步骤控制
const steps = ['step1', 'step2', 'step3'];
let currentStep = 0;
// 初始化座位图
function initializeSeats() {
const leftSeatsContainer = document.querySelector('.grid-cols-4.mr-12');
const rightSeatsContainer = document.querySelector('.grid-cols-4.ml-12');
leftSeatsContainer.innerHTML = '';
rightSeatsContainer.innerHTML = '';
// 生成左侧座位
for (let row = 0; row < totalRows; row++) {
for (let col = 0; col < seatsPerSide; col++) {
const seatIndex = row * seatsPerSide + col;
const seat = createSeat(seatIndex, row, col);
leftSeatsContainer.appendChild(seat);
}
}
// 生成右侧座位
for (let row = 0; row < totalRows; row++) {
for (let col = 0; col < seatsPerSide; col++) {
const seatIndex = totalRows * seatsPerSide + row * seatsPerSide + col;
const seat = createSeat(seatIndex, row, col);
rightSeatsContainer.appendChild(seat);
}
}
}
// 创建单个座位元素
function createSeat(index, row, col) {
const seat = document.createElement('div');
seat.className = 'w-16 h-16 bg-gradient-to-br from-gray-900 to-black border-2 border-accent1 rounded-lg flex items-center justify-center cursor-pointer seat-transition hover:shadow-lg hover:shadow-accent1 hover:shadow-opacity-50 animate-pulse-light';
seat.dataset.index = index;
seat.dataset.row = row;
seat.dataset.col = col;
// 添加电脑图标和座位号
const seatContent = document.createElement('div');
seatContent.className = 'flex flex-col items-center justify-center';
// 电脑图标
const computerIcon = document.createElement('i');
computerIcon.className = 'fa fa-desktop text-accent1 mb-1';
seatContent.appendChild(computerIcon);
// 座位号
const seatNumber = document.createElement('span');
seatNumber.className = 'text-xs font-medium text-accent2';
seatNumber.textContent = `${row + 1}-${col + 1}`;
seatContent.appendChild(seatNumber);
seat.appendChild(seatContent);
// 添加点击事件
seat.addEventListener('click', function(e) {
// 创建点击特效
createClickEffect(e);
// 切换座位状态
toggleSeatStatus(this);
});
return seat;
}
// 切换座位状态(好/坏)
function toggleSeatStatus(seatElement) {
const index = parseInt(seatElement.dataset.index);
// 添加点击动画效果
seatElement.classList.add('scale-95', 'opacity-80');
setTimeout(() => {
seatElement.classList.remove('scale-95', 'opacity-80');
}, 150);
if (brokenSeats.has(index)) {
// 如果是坏座位,则恢复为好座位
brokenSeats.delete(index);
seatElement.classList.remove('bg-gradient-to-br', 'from-danger', 'to-red-800', 'border-danger', 'animate-pulse');
seatElement.classList.add('bg-gradient-to-br', 'from-gray-900', 'to-black', 'border-accent1', 'animate-pulse-light');
seatElement.querySelector('i').classList.remove('fa-exclamation-triangle', 'text-danger');
seatElement.querySelector('i').classList.add('fa-desktop', 'text-accent1');
seatElement.querySelector('span').classList.remove('text-white');
seatElement.querySelector('span').classList.add('text-accent2');
seatElement.querySelector('span').textContent = seatElement.dataset.row + '-' + (parseInt(seatElement.dataset.col) + 1);
} else {
// 如果是好座位,则标记为坏座位
brokenSeats.add(index);
seatElement.classList.remove('bg-gradient-to-br', 'from-gray-900', 'to-black', 'border-accent1', 'animate-pulse-light');
seatElement.classList.add('bg-gradient-to-br', 'from-danger', 'to-red-800', 'border-danger', 'animate-pulse');
seatElement.querySelector('i').classList.remove('fa-desktop', 'text-accent1');
seatElement.querySelector('i').classList.add('fa-exclamation-triangle', 'text-danger');
seatElement.querySelector('span').classList.remove('text-accent2');
seatElement.querySelector('span').classList.add('text-white');
seatElement.querySelector('span').textContent = '故障';
}
}
// 创建科幻风格的爆炸特效
function createClickEffect(event) {
// 确保在鼠标点击精确位置
const x = event.clientX;
const y = event.clientY;
// 创建烟花容器
const firework = document.createElement('div');
firework.className = 'firework';
firework.style.left = `${x}px`;
firework.style.top = `${y}px`;
// 确保容器在最顶层
firework.style.zIndex = '9999';
// 添加到文档中
document.body.appendChild(firework);
// 生成大量大尺寸烟花粒子
const particleCount = 60;
const colors = ['#00f5ff', '#ff00ff', '#33ff99', '#ffff00', '#ff6600', '#ffffff'];
for (let i = 0; i < particleCount; i++) {
// 创建粒子
const particle = document.createElement('div');
particle.className = 'firework-particle';
// 显著增大粒子尺寸
const size = 6 + Math.random() * 8;
particle.style.width = `${size}px`;
particle.style.height = `${size}px`;
// 随机颜色
const color = colors[Math.floor(Math.random() * colors.length)];
particle.style.backgroundColor = color;
// 增强发光效果
particle.style.boxShadow = `0 0 ${size * 2}px ${color}, 0 0 ${size * 3}px ${color}, 0 0 ${size * 4}px ${color}`;
// 更随机的角度和更大的爆炸距离
const angle = (Math.PI * 2 * i) / particleCount + Math.random() * 0.5;
const distance = 100 + Math.random() * 80;
// 设置初始位置(精确在点击中心)
particle.style.left = '0';
particle.style.top = '0';
particle.style.transform = 'translate(-50%, -50%)';
// 添加到烟花容器
firework.appendChild(particle);
// 动画
setTimeout(() => {
particle.style.transition = 'all 1.5s ease-out';
particle.style.left = `${Math.cos(angle) * distance}px`;
particle.style.top = `${Math.sin(angle) * distance}px`;
particle.style.opacity = '0';
particle.style.transform = 'translate(-50%, -50%) scale(0.2) rotate(360deg)';
}, 10);
}
// 添加二次爆炸效果
setTimeout(() => {
for (let i = 0; i < 30; i++) {
const particle = document.createElement('div');
particle.className = 'firework-particle';
const size = 3 + Math.random() * 4;
particle.style.width = `${size}px`;
particle.style.height = `${size}px`;
const color = colors[Math.floor(Math.random() * colors.length)];
particle.style.backgroundColor = color;
particle.style.boxShadow = `0 0 ${size * 2}px ${color}, 0 0 ${size * 3}px ${color}`;
const angle = Math.random() * Math.PI * 2;
const distance = 50 + Math.random() * 60;
particle.style.left = `${Math.cos(angle) * (60 + Math.random() * 40)}px`;
particle.style.top = `${Math.sin(angle) * (60 + Math.random() * 40)}px`;
particle.style.transform = 'translate(-50%, -50%)';
firework.appendChild(particle);
setTimeout(() => {
particle.style.transition = 'all 1s ease-out';
particle.style.left = `${parseInt(particle.style.left) + Math.cos(angle) * distance}px`;
particle.style.top = `${parseInt(particle.style.top) + Math.sin(angle) * distance}px`;
particle.style.opacity = '0';
particle.style.transform = 'translate(-50%, -50%) scale(0) rotate(720deg)';
}, 10);
}
}, 400);
// 添加电磁脉冲效果
const pulse = document.createElement('div');
pulse.style.position = 'absolute';
pulse.style.left = '-50px';
pulse.style.top = '-50px';
pulse.style.width = '100px';
pulse.style.height = '100px';
pulse.style.border = '2px solid #00f5ff';
pulse.style.borderRadius = '50%';
pulse.style.transform = 'scale(0)';
pulse.style.opacity = '1';
firework.appendChild(pulse);
setTimeout(() => {
pulse.style.transition = 'all 0.8s ease-out';
pulse.style.transform = 'scale(3)';
pulse.style.opacity = '0';
}, 10);
// 延长移除时间
setTimeout(() => {
document.body.removeChild(firework);
}, 2000);
}
// 生成学号列表
function generateStudentIds(startId, endId, excludeIds) {
const ids = [];
// 生成学号范围
for (let id = startId; id <= endId; id++) {
ids.push(id);
}
// 排除指定学号
if (excludeIds && excludeIds.length > 0) {
return ids.filter(id => !excludeIds.includes(id));
}
return ids;
}
// 生成随机座位表 - 修复核心问题1
function generateRandomSeating() {
// 获取可用座位(排除坏座位)并按行排序
const availableSeats = [];
for (let i = 0; i < totalSeats; i++) {
if (!brokenSeats.has(i)) {
availableSeats.push(i);
}
}
// 按行排序,确保前排优先
availableSeats.sort((a, b) => {
// 计算行号
const rowA = Math.floor(a / seatsPerSide) % totalRows;
const rowB = Math.floor(b / seatsPerSide) % totalRows;
// 先按行排序
if (rowA !== rowB) {
return rowA - rowB;
}
// 行内随机排序
return Math.random() - 0.5;
});
// 打乱学号顺序
const shuffledIds = [...studentIds];
shuffleArray(shuffledIds);
// 初始化座位映射
currentSeatMap = {};
const maxAssignments = Math.min(availableSeats.length, shuffledIds.length);
for (let i = 0; i < maxAssignments; i++) {
currentSeatMap[availableSeats[i]] = shuffledIds[i];
}
// 修复:传递正确的参数
initializeStep3Seats(currentSeatMap);
}
// 初始化步骤3的座位图 - 修复核心问题1
function initializeStep3Seats(seatMap) {
const leftSeatsContainer = document.getElementById('step3-left-seats');
const rightSeatsContainer = document.getElementById('step3-right-seats');
leftSeatsContainer.innerHTML = '';
rightSeatsContainer.innerHTML = '';
// 生成左侧座位
for (let row = 0; row < totalRows; row++) {
for (let col = 0; col < seatsPerSide; col++) {
const seatIndex = row * seatsPerSide + col;
const seat = createStep3Seat(seatIndex, row, col, seatMap);
leftSeatsContainer.appendChild(seat);
}
}
// 生成右侧座位
for (let row = 0; row < totalRows; row++) {
for (let col = 0; col < seatsPerSide; col++) {
const seatIndex = totalRows * seatsPerSide + row * seatsPerSide + col;
const seat = createStep3Seat(seatIndex, row, col, seatMap);
rightSeatsContainer.appendChild(seat);
}
}
}
// 创建步骤3的座位元素
function createStep3Seat(index, row, col, seatMap) {
const seat = document.createElement('div');
// 检查是否是坏座位
if (brokenSeats.has(index)) {
seat.className = 'w-16 h-16 bg-gradient-to-br from-danger to-red-800 border-2 border-danger rounded-lg flex flex-col items-center justify-center seat-transition animate-pulse';
const seatContent = document.createElement('div');
seatContent.className = 'flex flex-col items-center justify-center';
// 损坏电脑图标
const computerIcon = document.createElement('i');
computerIcon.className = 'fa fa-exclamation-triangle text-white mb-1';
seatContent.appendChild(computerIcon);
const seatText = document.createElement('span');
seatText.className = 'text-xs font-medium text-white';
seatText.textContent = '故障';
seatContent.appendChild(seatText);
seat.appendChild(seatContent);
}
// 检查是否有分配学号
else if (seatMap[index]) {
seat.className = 'w-16 h-16 bg-gradient-to-br from-gray-900 to-black border-2 border-accent1 rounded-lg flex flex-col items-center justify-center seat-transition hover:shadow-lg hover:shadow-accent1 hover:shadow-opacity-50 animate-hologram';
const seatContent = document.createElement('div');
seatContent.className = 'flex flex-col items-center justify-center';
// 电脑图标
const computerIcon = document.createElement('i');
computerIcon.className = 'fa fa-desktop text-accent1 mb-1';
seatContent.appendChild(computerIcon);
const studentId = document.createElement('span');
studentId.className = 'text-xs font-bold text-accent2';
studentId.textContent = seatMap[index];
seatContent.appendChild(studentId);
seat.appendChild(seatContent);
}
// 空座位
else {
seat.className = 'w-16 h-16 bg-gradient-to-br from-gray-800 to-gray-900 border-2 border-gray-700 rounded-lg flex flex-col items-center justify-center seat-transition';
const seatContent = document.createElement('div');
seatContent.className = 'flex flex-col items-center justify-center';
// 灰色电脑图标
const computerIcon = document.createElement('i');
computerIcon.className = 'fa fa-desktop text-gray-500 mb-1';
seatContent.appendChild(computerIcon);
const seatText = document.createElement('span');
seatText.className = 'text-xs font-medium text-gray-500';
seatText.textContent = '空闲';
seatContent.appendChild(seatText);
seat.appendChild(seatContent);
}
return seat;
}
// 打乱数组顺序
function shuffleArray(array) {
for (let i = array.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[array[i], array[j]] = [array[j], array[i]];
}
return array;
}
// 更新进度指示器 - 修复核心问题2
function updateProgressIndicators() {
// 重置所有指示器
for (let i = 1; i <= 3; i++) {
const indicator = document.getElementById(`step${i}-indicator`);
const circle = indicator.querySelector('div');
const text = indicator.querySelector('span');
if (i <= currentStep + 1) {
// 当前步骤及之前的步骤 - 修复样式类名匹配
circle.classList.remove('bg-gray-800', 'text-gray-400', 'border-gray-700');
circle.classList.add('bg-gradient-to-r', 'from-accent1', 'to-accent2', 'text-white', 'animate-glow');
text.classList.remove('text-gray-400');
text.classList.add('text-accent1');
} else {
// 之后的步骤
circle.classList.remove('bg-gradient-to-r', 'from-accent1', 'to-accent2', 'text-white', 'animate-glow');
circle.classList.add('bg-gray-800', 'text-gray-400', 'border-gray-700');
text.classList.remove('text-accent1');
text.classList.add('text-gray-400');
}
}
// 更新进度条
if (currentStep >= 1) {
document.getElementById('progress-1-2').style.width = '100%';
} else {
document.getElementById('progress-1-2').style.width = '0%';
}
if (currentStep >= 2) {
document.getElementById('progress-2-3').style.width = '100%';
} else {
document.getElementById('progress-2-3').style.width = '0%';
}
}
// 切换步骤
function goToStep(stepIndex) {
// 隐藏所有步骤
steps.forEach(step => {
document.getElementById(step).classList.add('hidden');
});
// 显示目标步骤
document.getElementById(steps[stepIndex]).classList.remove('hidden');
// 更新当前步骤
currentStep = stepIndex;
// 更新进度指示器
updateProgressIndicators();
}
// 步骤1 -> 步骤2
document.getElementById('step1-next').addEventListener('click', function(event) {
// 创建点击特效
createClickEffect(event);
// 切换到步骤2
goToStep(1);
});
// 步骤2 -> 步骤1
document.getElementById('step2-back').addEventListener('click', function(event) {
// 创建点击特效
createClickEffect(event);
// 切换到步骤1
goToStep(0);
});
// 步骤2 -> 步骤3
document.getElementById('step2-next').addEventListener('click', function(event) {
// 创建点击特效
createClickEffect(event);
// 获取学号范围
const startId = parseInt(document.getElementById('start-id').value);
const endId = parseInt(document.getElementById('end-id').value);
const excludeIdsInput = document.getElementById('exclude-ids').value;
// 验证输入
if (!startId || !endId) {
alert('请输入起始和结束学号');
return;
}
if (startId > endId) {
alert('起始学号不能大于结束学号');
return;
}
// 解析排除学号
let excludeIds = [];
if (excludeIdsInput.trim() !== '') {
excludeIds = excludeIdsInput.split(',')
.map(id => parseInt(id.trim()))
.filter(id => !isNaN(id));
}
// 生成学号列表
studentIds = generateStudentIds(startId, endId, excludeIds);
// 检查学号数量是否超过可用座位数
const availableSeatsCount = totalSeats - brokenSeats.size;
if (studentIds.length > availableSeatsCount) {
alert(`学号数量(${studentIds.length})超过可用座位数(${availableSeatsCount}),将只安排${availableSeatsCount}个学号`);
}
// 生成随机座位表
generateRandomSeating();
// 切换到步骤3
goToStep(2);
});
// 步骤3 -> 步骤1
document.getElementById('step3-back').addEventListener('click', function(event) {
// 创建点击特效
createClickEffect(event);
// 切换到步骤1
goToStep(0);
});
// 保存座位表为图片
document.getElementById('step3-save').addEventListener('click', function(event) {
// 创建点击特效
createClickEffect(event);
// 获取座位表容器
const container = document.querySelector('#step3 .overflow-x-auto');
// 创建canvas用于截图
html2canvas(container).then(canvas => {
// 创建下载链接
const link = document.createElement('a');
link.download = '机房座位表.png';
link.href = canvas.toDataURL('image/png');
link.click();
});
});
// 重新生成座位表
document.getElementById('step3-regenerate').addEventListener('click', function(event) {
// 创建点击特效
createClickEffect(event);
// 重新生成随机座位表
generateRandomSeating();
});
// 交换位置功能
document.getElementById('step3-swap').addEventListener('click', function(event) {
// 创建点击特效
createClickEffect(event);
// 显示交换位置模态框
document.getElementById('swap-modal').classList.remove('hidden');
});
// 关闭模态框
document.getElementById('close-modal').addEventListener('click', function() {
document.getElementById('swap-modal').classList.add('hidden');
clearSwapInputs();
});
document.getElementById('cancel-swap').addEventListener('click', function() {
document.getElementById('swap-modal').classList.add('hidden');
clearSwapInputs();
});
// 确认交换位置
document.getElementById('confirm-swap').addEventListener('click', function(event) {
// 创建点击特效
createClickEffect(event);
const student1 = parseInt(document.getElementById('student1').value);
const student2 = parseInt(document.getElementById('student2').value);
if (!student1 || !student2) {
alert('请输入两个学号');
return;
}
if (student1 === student2) {
alert('不能交换同一个学生的位置');
return;
}
if (swapStudentPositions(student1, student2)) {
// 交换成功,重新渲染座位表
initializeStep3Seats(currentSeatMap);
// 显示成功动画效果
showSwapSuccessEffect();
// 关闭模态框
setTimeout(() => {
document.getElementById('swap-modal').classList.add('hidden');
clearSwapInputs();
}, 1000);
}
});
// 交换学生位置
function swapStudentPositions(student1, student2) {
let seat1 = null;
let seat2 = null;
// 查找两个学生的座位位置
for (const [seat, student] of Object.entries(currentSeatMap)) {
if (student === student1) {
seat1 = parseInt(seat);
}
if (student === student2) {
seat2 = parseInt(seat);
}
}
if (!seat1 && !seat2) {
alert('两个学生都不在座位表中');
return false;
} else if (!seat1) {
alert(`学号 ${student1} 不在座位表中`);
return false;
} else if (!seat2) {
alert(`学号 ${student2} 不在座位表中`);
return false;
}
// 交换位置
currentSeatMap[seat1] = student2;
currentSeatMap[seat2] = student1;
return true;
}
// 显示交换成功特效
function showSwapSuccessEffect() {
const successEffect = document.createElement('div');
successEffect.className = 'fixed top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2 z-50 text-center';
successEffect.innerHTML = `
<div class="bg-black bg-opacity-80 border-2 border-success rounded-lg p-8 animate-fade-in">
<i class="fa fa-check-circle text-success text-6xl mb-4"></i>
<h3 class="text-2xl font-bold text-success mb-2">交换成功</h3>
<p class="text-gray-300">学生位置已成功交换</p>
</div>
`;
document.body.appendChild(successEffect);
setTimeout(() => {
successEffect.remove();
}, 2000);
}
// 清空交换输入框
function clearSwapInputs() {
document.getElementById('student1').value = '';
document.getElementById('student2').value = '';
}
// 创建粒子背景
function createParticleBackground() {
const particleContainer = document.getElementById('particles');
const particleCount = 50;
for (let i = 0; i < particleCount; i++) {
const particle = document.createElement('div');
particle.className = 'particle';
// 随机大小
const size = 2 + Math.random() * 4;
particle.style.width = `${size}px`;
particle.style.height = `${size}px`;
// 随机位置
particle.style.left = `${Math.random() * 100}vw`;
particle.style.top = `${Math.random() * 100}vh`;
// 随机颜色
const colors = ['#00f5ff', '#ff00ff', '#33ff99', '#ffff00'];
const color = colors[Math.floor(Math.random() * colors.length)];
particle.style.backgroundColor = color;
particle.style.boxShadow = `0 0 ${size * 2}px ${color}`;
// 随机动画延迟和持续时间
particle.style.animationDelay = `${Math.random() * 4}s`;
particle.style.animationDuration = `${2 + Math.random() * 4}s`;
particleContainer.appendChild(particle);
}
}
// 添加木鱼点击事件处理
function setupWoodenFishClick() {
let meritCount = 0;
const woodenFishElements = document.querySelectorAll('#wooden-fish, #wooden-fish-step3');
const meritCounters = document.querySelectorAll('#merit-counter, #merit-counter-step3');
woodenFishElements.forEach(fish => {
fish.addEventListener('click', function(event) {
// 创建点击特效
createClickEffect(event);
// 增加功德计数
meritCount++;
// 更新所有功德计数器显示
meritCounters.forEach(counter => {
counter.textContent = `功德: ${meritCount}`;
});
// 显示功德+1效果
showMeritPlusOne(event);
// 播放木鱼音效(模拟)
playWoodenFishSound();
});
});
}
// 显示功德+1效果
function showMeritPlusOne(event) {
const meritText = document.createElement('div');
meritText.className = 'absolute pointer-events-none z-9999 font-bold';
meritText.style.fontSize = '60px';
// 使用金色作为功德文字颜色
const goldColor = '#ffd700';
meritText.style.color = goldColor;
meritText.style.textShadow = `0 0 10px ${goldColor}, 0 0 20px ${goldColor}, 0 0 30px ${goldColor}, 0 0 40px ${goldColor}`;
// 设置初始位置(点击位置)
const rect = event.currentTarget.getBoundingClientRect();
const x = rect.left + rect.width / 2;
const y = rect.top + rect.height / 2;
meritText.style.left = `${x}px`;
meritText.style.top = `${y}px`;
meritText.style.position = 'fixed';
meritText.style.transform = 'translate(-50%, -50%) scale(0.5)';
meritText.style.opacity = '1';
meritText.style.pointerEvents = 'none';
meritText.style.zIndex = '9999';
meritText.style.fontWeight = 'bold';
meritText.style.textAlign = 'center';
meritText.style.whiteSpace = 'nowrap';
meritText.style.userSelect = 'none';
// 设置内容
meritText.textContent = '功德+1';
// 添加到文档中
document.body.appendChild(meritText);
// 动画效果
meritText.style.transition = 'all 2s ease-out';
setTimeout(() => {
meritText.style.transform = 'translate(-50%, -150px) scale(2)';
meritText.style.opacity = '0';
meritText.style.fontSize = '80px';
}, 10);
// 移除元素
setTimeout(() => {
if (document.body.contains(meritText)) {
document.body.removeChild(meritText);
}
}, 2000);
}
// 播放木鱼音效(模拟)
function playWoodenFishSound() {
try {
// 创建音频上下文
const audioContext = new (window.AudioContext || window.webkitAudioContext)();
// 创建振荡器
const oscillator = audioContext.createOscillator();
const gainNode = audioContext.createGain();
// 连接节点
oscillator.connect(gainNode);
gainNode.connect(audioContext.destination);
// 设置音频参数(木鱼声音频率范围)
oscillator.type = 'sine';
oscillator.frequency.setValueAtTime(800, audioContext.currentTime);
oscillator.frequency.exponentialRampToValueAtTime(400, audioContext.currentTime + 0.2);
// 设置音量包络
gainNode.gain.setValueAtTime(0, audioContext.currentTime);
gainNode.gain.linearRampToValueAtTime(0.3, audioContext.currentTime + 0.01);
gainNode.gain.exponentialRampToValueAtTime(0.01, audioContext.currentTime + 0.2);
// 播放声音
oscillator.start(audioContext.currentTime);
oscillator.stop(audioContext.currentTime + 0.2);
} catch (error) {
console.log('无法播放音效:', error);
}
}
// 初始化
createParticleBackground();
initializeSeats();
goToStep(0);
setupWoodenFishClick();
});
</script>
</body>
</html>