[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>
<style>
[url=home.php?mod=space&uid=476974]@import[/url] url('https://fonts.googleapis.com/css2?family=Noto+Sans+SC:wght@400;500;600;700&family=Comic+Neue:wght@400;700&display=swap');
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
:root {
--blue-light: #E0F7FA;
--blue-medium: #80DEEA;
--blue-dark: #26C6DA;
--cyan-light: #B2EBF2;
--cyan-medium: #4DD0E1;
--text-dark: #263238;
--text-light: #546E7A;
--white: #FFFFFF;
--shadow: 0 8px 32px rgba(38, 198, 218, 0.2);
--shadow-hover: 0 12px 48px rgba(38, 198, 218, 0.3);
}
body {
font-family: 'Noto Sans SC', 'Comic Neue', sans-serif;
background: linear-gradient(135deg, #E0F7FA 0%, #B2EBF2 50%, #80DEEA 100%);
color: var(--text-dark);
line-height: 1.6;
min-height: 100vh;
position: relative;
overflow-x: hidden;
}
/* 装饰元素样式 */
.decoration {
position: fixed;
pointer-events: none;
z-index: 0;
}
.butterfly { font-size: 2rem; animation: float 6s ease-in-out infinite; }
.flower { font-size: 1.5rem; animation: spin 20s linear infinite; }
.star { font-size: 1.2rem; animation: twinkle 2s ease-in-out infinite; }
.butterfly:nth-child(1) { top: 10%; left: 5%; animation-delay: 0s; }
.butterfly:nth-child(2) { top: 20%; right: 8%; animation-delay: 1s; }
.butterfly:nth-child(3) { bottom: 15%; left: 10%; animation-delay: 2s; }
.butterfly:nth-child(4) { bottom: 25%; right: 5%; animation-delay: 3s; }
.flower:nth-child(5) { top: 30%; left: 3%; }
.flower:nth-child(6) { top: 60%; right: 4%; }
.flower:nth-child(7) { bottom: 10%; left: 15%; }
.star:nth-child(8) { top: 15%; left: 20%; animation-delay: 0.5s; }
.star:nth-child(9) { top: 50%; right: 15%; animation-delay: 1s; }
.star:nth-child(10) { bottom: 20%; right: 20%; animation-delay: 1.5s; }
@keyframes float { 0%,100% { transform: translateY(0) rotate(0deg); } 50% { transform: translateY(-20px) rotate(10deg); } }
@keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }
@keyframes twinkle { 0%,100% { opacity: 1; transform: scale(1); } 50% { opacity: 0.5; transform: scale(1.2); } }
.container {
max-width: 1400px;
margin: 0 auto;
padding: 2rem;
position: relative;
z-index: 1;
}
.header {
text-align: center;
margin-bottom: 1rem;
animation: fadeInDown 0.8s ease;
background: linear-gradient(135deg, rgba(255,255,255,0.9) 0%, rgba(224,247,250,0.9) 100%);
padding: 1rem;
border-radius: 30px;
box-shadow: var(--shadow);
border: 3px solid var(--blue-medium);
}
.header h1 {
font-size: 2.5rem;
font-weight: 700;
background: linear-gradient(135deg, #26C6DA 0%, #4DD0E1 50%, #26C6DA 100%);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-clip: text;
margin-bottom: 0.5rem;
font-family: 'Comic Neue', 'Noto Sans SC', sans-serif;
}
.title-edit {
margin-top: 1rem;
}
.title-edit input {
padding: 0.5rem;
border: 2px solid var(--blue-medium);
border-radius: 15px;
font-size: 1rem;
width: 200px;
text-align: center;
}
.title-edit button {
margin-left: 0.5rem;
padding: 0.5rem 1rem;
background-color: var(--blue-dark);
color: white;
border: none;
border-radius: 15px;
cursor: pointer;
}
.subtitle {
color: var(--text-light);
font-size: 1rem;
}
.main-content {
display: grid;
grid-template-columns: 420px 1fr;
gap: 2rem;
animation: fadeInUp 0.8s ease;
}
/* 配置面板 */
.config-panel {
background: linear-gradient(135deg, rgba(255,255,255,0.95) 0%, rgba(224,247,250,0.95) 100%);
border: 3px solid var(--blue-medium);
border-radius: 30px;
padding: 2rem;
box-shadow: var(--shadow);
transition: all 0.3s ease;
}
.config-panel:hover {
box-shadow: var(--shadow-hover);
transform: translateY(-2px);
}
.config-panel h2 {
font-size: 1.5rem;
margin-bottom: 1.5rem;
color: var(--blue-dark);
font-family: 'Comic Neue', 'Noto Sans SC', sans-serif;
text-align: center;
}
.class-count-control {
margin-bottom: 1.5rem;
text-align: center;
}
.class-count-control button {
padding: 0.5rem 1rem;
background-color: var(--blue-medium);
color: var(--text-dark);
border: none;
border-radius: 15px;
cursor: pointer;
margin: 0 0.5rem;
transition: all 0.2s ease;
font-size: 1.2rem;
width: 40px;
height: 40px;
display: inline-flex;
align-items: center;
justify-content: center;
}
.class-count-control button:hover {
background-color: var(--blue-dark);
color: white;
}
.class-count-display {
font-size: 1.2rem;
font-weight: bold;
margin: 0 1rem;
}
.day-selector {
display: grid;
grid-template-columns: repeat(5, 1fr); /* 修改为5列(周一到周五) */
gap: 0.5rem;
margin-bottom: 2rem;
}
.day-btn {
padding: 0.8rem 0.3rem;
border: 2px solid var(--blue-medium);
background: white;
color: var(--text-dark);
border-radius: 15px;
cursor: pointer;
font-size: 0.85rem;
font-weight: 600;
transition: all 0.3s ease;
position: relative;
}
.day-btn:hover {
background: var(--blue-light);
border-color: var(--blue-dark);
transform: translateY(-3px) scale(1.05);
box-shadow: 0 5px 15px rgba(38,198,218,0.3);
}
.day-btn.active {
background: linear-gradient(135deg, var(--blue-dark) 0%, var(--cyan-medium) 100%);
border-color: var(--blue-dark);
color: white;
box-shadow: 0 5px 20px rgba(38,198,218,0.4);
transform: scale(1.1);
}
.day-btn.active::after {
content: '💖';
position: absolute;
top: -10px;
right: -5px;
font-size: 1rem;
}
.form-section {
margin-bottom: 2rem;
background: rgba(255,255,255,0.6);
padding: 1.5rem;
border-radius: 20px;
border: 2px dashed var(--blue-medium);
}
.form-section h3 {
font-size: 1.2rem;
margin-bottom: 1rem;
color: var(--blue-dark);
font-family: 'Comic Neue', 'Noto Sans SC', sans-serif;
text-align: center;
}
.course-input {
margin-bottom: 1rem;
position: relative;
}
/* 时间段切换按钮样式 */
.time-switch {
position: absolute;
top: 0;
right: 10px;
display: flex;
gap: 0.3rem;
}
.time-switch-btn {
padding: 0.3rem 0.6rem;
border: 1px solid var(--blue-medium);
border-radius: 8px;
background: white;
color: var(--text-dark);
font-size: 0.75rem;
cursor: pointer;
transition: all 0.2s ease;
}
.time-switch-btn.active {
background: var(--blue-dark);
color: white;
border-color: var(--blue-dark);
}
.course-input label {
display: block;
margin-bottom: 0.5rem;
color: var(--text-dark);
font-size: 0.9rem;
font-weight: 600;
}
.course-input input {
width: 100%;
padding: 0.9rem 1rem;
background: white;
border: 2px solid var(--blue-medium);
border-radius: 15px;
color: var(--text-dark);
font-size: 0.95rem;
transition: all 0.3s ease;
font-family: 'Noto Sans SC', sans-serif;
}
.course-input input:focus {
outline: none;
border-color: var(--blue-dark);
box-shadow: 0 0 0 4px rgba(38,198,218,0.2);
}
/* 按钮样式 */
.action-buttons {
display: flex;
gap: 1rem;
margin-top: 2rem;
}
.btn {
flex: 1;
padding: 1rem 1.5rem;
border: none;
border-radius: 20px;
font-size: 1rem;
font-weight: 700;
cursor: pointer;
transition: all 0.3s ease;
display: flex;
align-items: center;
justify-content: center;
gap: 0.5rem;
font-family: 'Noto Sans SC', sans-serif;
}
.btn-save {
background: linear-gradient(135deg, #26C6DA 0%, #00BCD4 100%);
color: white;
box-shadow: 0 5px 20px rgba(38,198,218,0.4);
}
.btn-clear {
background: linear-gradient(135deg, #4DD0E1 0%, #00ACC1 100%);
color: white;
box-shadow: 0 5px 20px rgba(77,208,225,0.4);
}
.btn-print {
background: linear-gradient(135deg, #80DEEA 0%, #26C6DA 100%);
color: white;
box-shadow: 0 5px 20px rgba(128,222,234,0.4);
padding: 1rem 2rem;
border: none;
border-radius: 20px;
font-size: 1rem;
font-weight: 700;
cursor: pointer;
transition: all 0.3s ease;
}
/* 预览面板 */
.preview-panel {
background: linear-gradient(135deg, rgba(255,255,255,0.95) 0%, rgba(229,212,255,0.95) 100%);
border: 3px solid var(--cyan-medium);
border-radius: 30px;
padding: 2rem;
box-shadow: var(--shadow);
}
.preview-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 2rem;
}
.preview-header h2 {
font-size: 1.5rem;
color: var(--cyan-medium);
font-family: 'Comic Neue', 'Noto Sans SC', sans-serif;
}
/* 课程表样式 */
.schedule-table {
width: 100%;
border-collapse: separate;
border-spacing: 0;
background: white;
border-radius: 20px;
overflow: hidden;
box-shadow: 0 5px 20px rgba(0,0,0,0.1);
}
.schedule-table th, .schedule-table td {
padding: 1rem;
text-align: center;
border: 2px solid var(--blue-light);
}
.schedule-table th {
background: linear-gradient(135deg, var(--blue-medium) 0%, var(--cyan-light) 100%);
font-weight: 700;
color: var(--text-dark);
font-size: 1rem;
}
.schedule-table td {
background: white;
color: var(--text-dark);
transition: all 0.3s ease;
font-size: 0.95rem;
font-weight: 500;
cursor: pointer; /* 添加鼠标指针样式 */
}
.schedule-table td:hover {
background: var(--blue-light);
transform: scale(1.05);
box-shadow: 0 3px 10px rgba(38,198,218,0.2);
}
.schedule-table td.rest-cell {
background: linear-gradient(135deg, #E0F7FA 0%, #80DEEA 100%);
color: var(--blue-dark);
font-weight: 700;
}
.schedule-table td.course-cell {
background: linear-gradient(135deg, #B2EBF2 0%, #4DD0E1 100%);
color: var(--text-dark);
font-weight: 600;
}
.schedule-table td.empty-cell {
color: var(--text-light);
font-style: italic;
}
/* 上午/下午节次样式(仅背景色区分,无文字) */
.morning-slot {
background: linear-gradient(135deg, #FFF8E1 0%, #FFECB3 100%);
font-weight: bold;
color: #FF8F00;
cursor: default; /* 节次单元格不响应点击 */
}
.afternoon-slot {
background: linear-gradient(135deg, #E1F5FE 0%, #B3E5FC 100%);
font-weight: bold;
color: #0288D1;
cursor: default; /* 节次单元格不响应点击 */
}
.time-divider {
background: linear-gradient(135deg, var(--blue-dark) 0%, var(--cyan-medium) 100%);
color: white;
font-weight: bold;
font-size: 1.1rem;
cursor: default; /* 分割线不响应点击 */
}
/* 弹窗样式 */
.course-modal-overlay {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0,0,0,0.5);
display: flex;
align-items: center;
justify-content: center;
z-index: 9999;
opacity: 0;
visibility: hidden;
transition: all 0.3s ease;
}
.course-modal-overlay.active {
opacity: 1;
visibility: visible;
}
.course-modal {
background: linear-gradient(135deg, rgba(255,255,255,0.98) 0%, rgba(224,247,250,0.98) 100%);
border: 3px solid var(--blue-medium);
border-radius: 30px;
padding: 2rem;
max-width: 500px;
width: 90%;
max-height: 80vh;
overflow-y: auto;
box-shadow: 0 20px 60px rgba(38,198,218,0.4);
transform: scale(0.8) translateY(-20px);
transition: all 0.3s ease;
position: relative;
}
.course-modal-overlay.active .course-modal {
transform: scale(1) translateY(0);
}
.course-options {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 0.8rem;
margin-bottom: 1.5rem;
}
.course-option {
padding: 0.8rem 0.5rem;
background: white;
border: 2px solid var(--blue-light);
border-radius: 15px;
cursor: pointer;
font-size: 0.9rem;
font-weight: 600;
color: var(--text-dark);
transition: all 0.3s ease;
text-align: center;
}
.course-option:hover {
background: var(--blue-light);
border-color: var(--blue-medium);
transform: translateY(-3px);
box-shadow: 0 5px 15px rgba(38,198,218,0.2);
}
.course-option.rest-option {
background: linear-gradient(135deg, #E0F7FA 0%, #80DEEA 100%);
border-color: var(--blue-medium);
}
.course-option.rest-option:hover {
background: linear-gradient(135deg, #80DEEA 0%, #4DD0E1 100%);
}
.custom-course-input {
margin-top: 1rem;
display: none;
}
.custom-course-input.active {
display: block;
}
.custom-course-input input {
width: 100%;
padding: 0.8rem 1rem;
border: 2px solid var(--blue-medium);
border-radius: 15px;
font-size: 1rem;
margin-bottom: 1rem;
}
.custom-course-input button {
padding: 0.8rem 2rem;
background: var(--blue-dark);
color: white;
border: none;
border-radius: 15px;
cursor: pointer;
font-weight: 600;
}
.modal-close {
position: absolute;
top: 20px;
right: 20px;
background: none;
border: none;
font-size: 1.5rem;
cursor: pointer;
color: var(--text-light);
}
.modal-close:hover {
color: #ff4444;
}
/* 打印样式 */
.print-only {
display: none;
}
[url=home.php?mod=space&uid=945662]@media[/url] print {
body { background: white; color: black; }
.container, .decoration { display: none; }
.print-only { display: block; padding: 15mm; }
.print-header {
text-align: center;
margin-bottom: 20px;
border-bottom: 3px solid #26C6DA;
padding-bottom: 15px;
position: relative;
}
.print-header h1 {
font-size: 26pt;
color: #26C6DA;
margin-bottom: 8px;
font-family: 'Comic Neue', 'Noto Sans SC', sans-serif;
}
.print-owner {
font-size: 14pt;
color: #4DD0E1;
font-weight: bold;
margin: 8px 0;
}
.schedule-table {
width: 100%;
border-collapse: collapse;
margin-top: 10px;
page-break-inside: avoid;
}
.schedule-table th, .schedule-table td {
border: 2px solid #80DEEA;
padding: 10px 5px;
text-align: center;
}
.morning-slot {
background: #FFF8E1 !important;
color: #FF8F00 !important;
}
.afternoon-slot {
background: #E1F5FE !important;
color: #0288D1 !important;
}
.time-divider {
background: #26C6DA !important;
color: white !important;
}
.print-footer {
margin-top: 15px;
text-align: center;
font-size: 11pt;
color: #26C6DA;
border-top: 2px solid #80DEEA;
padding-top: 10px;
font-weight: bold;
}
}
/* 响应式 */
@media (max-width: 1200px) {
.main-content { grid-template-columns: 1fr; }
.config-panel { max-width: 600px; margin: 0 auto; }
}
@media (max-width: 768px) {
.container { padding: 1rem; }
.header h1 { font-size: 2rem; }
.day-selector { grid-template-columns: repeat(5, 1fr); } /* 保持5列 */
.action-buttons { flex-direction: column; }
.preview-header { flex-direction: column; gap: 1rem; align-items: stretch; }
.time-switch { position: static; margin-bottom: 0.5rem; }
}
/* 通知动画 */
@keyframes fadeInDown {
from { opacity: 0; transform: translateY(-20px); }
to { opacity: 1; transform: translateY(0); }
}
@keyframes fadeInUp {
from { opacity: 0; transform: translateY(20px); }
to { opacity: 1; transform: translateY(0); }
}
@keyframes fadeIn {
from { opacity: 0; }
to { opacity: 1; }
}
@keyframes pulse {
0% { transform: scale(1); }
50% { transform: scale(1.05); }
100% { transform: scale(1); }
}
/* 通知样式 */
.notification {
position: fixed;
bottom: 20px;
right: 20px;
background: linear-gradient(135deg, var(--blue-dark) 0%, var(--cyan-medium) 100%);
color: white;
padding: 1rem 1.5rem;
border-radius: 15px;
box-shadow: 0 5px 20px rgba(38,198,218,0.4);
z-index: 9999;
opacity: 0;
transform: translateY(20px);
transition: all 0.3s ease;
display: flex;
align-items: center;
gap: 0.5rem;
}
.notification.show {
opacity: 1;
transform: translateY(0);
animation: pulse 1s ease-in-out;
}
</style>
</head>
<body>
<!-- 装饰元素 -->
<div class="decoration butterfly">🎖️</div>
<div class="decoration butterfly">🎖️</div>
<div class="decoration butterfly">🎖️</div>
<div class="decoration butterfly">🎖️</div>
<div class="decoration flower">🌸</div>
<div class="decoration flower">🌼</div>
<div class="decoration flower">💐</div>
<div class="decoration star">✨</div>
<div class="decoration star">🌟</div>
<div class="decoration star">💫</div>
<div class="container">
<div class="header">
<h1 id="mainTitle">🎖️ 课程表 🎖️</h1>
<p class="subtitle">记录每日学习计划,让学习更有条理</p>
<div class="title-edit">
<input type="text" id="titleInput" placeholder="输入课程表标题">
<button>保存标题</button>
</div>
</div>
<div class="main-content">
<div class="config-panel">
<h2>课程设置</h2>
<div class="class-count-control">
<button id="decreaseBtn">-</button>
<span class="class-count-display">上午 <span id="morningClassCount">4</span> 节 | 下午 <span id="afternoonClassCount">3</span> 节</span>
<button id="increaseBtn">+</button>
</div>
<div class="day-selector">
<button class="day-btn active" data-day="monday">周一</button>
<button class="day-btn" data-day="tuesday">周二</button>
<button class="day-btn" data-day="wednesday">周三</button>
<button class="day-btn" data-day="thursday">周四</button>
<button class="day-btn" data-day="friday">周五</button>
<!-- 移除周六周日按钮 -->
</div>
<div class="form-section">
<h3>上午课程</h3>
<div id="morningCourses">
<!-- 上午课程输入框将通过JS动态生成 -->
</div>
</div>
<div class="form-section">
<h3>下午课程</h3>
<div id="afternoonCourses">
<!-- 下午课程输入框将通过JS动态生成 -->
</div>
</div>
<div class="action-buttons">
<button class="btn btn-save">
<span>💾 保存课程表</span>
</button>
<button class="btn btn-clear">
<span>🧹 清空当前天</span>
</button>
</div>
</div>
<div class="preview-panel">
<div class="preview-header">
<h2 id="previewTitle">课程表预览</h2>
<button class="btn-print">
<span>🖨️ 打印课程表</span>
</button>
</div>
<table class="schedule-table" id="scheduleTable">
<!-- 课程表内容将通过JS动态生成 -->
</table>
</div>
</div>
</div>
<!-- 打印专用区域 -->
<div class="print-only">
<div class="print-header">
<h1 id="printMainTitle">🎖️ 课程表 🎖️</h1>
<div class="print-owner" id="printOwner">—— 学习计划 ——</div>
<div id="printDate"></div>
</div>
<table class="schedule-table" id="printTable">
<!-- 打印用课程表内容将通过JS动态生成 -->
</table>
<div class="print-footer">
祝学习愉快,天天进步!😊
</div>
</div>
<!-- 课程选择弹窗 -->
<div class="course-modal-overlay" id="courseModal">
<div class="course-modal">
<button class="modal-close">×</button>
<h3 style="text-align: center; margin-bottom: 1.5rem; color: var(--blue-dark);">选择课程</h3>
<div class="course-options">
<div class="course-option">✏️ 语文</div>
<div class="course-option">🔢 数学</div>
<div class="course-option">🔤 英语</div>
<div class="course-option">🤾🏻 体育</div>
<div class="course-option">🎼 音乐</div>
<div class="course-option">🎨 美术</div>
<div class="course-option">⚖ 道法</div>
<div class="course-option rest-option">🕮 自习</div>
<div class="course-option rest-option">💤 午休</div>
<div class="course-option">自定义...</div>
</div>
<div class="custom-course-input" id="customCourseInput">
<input type="text" id="customCourseText" placeholder="输入课程名称">
<button>添加</button>
</div>
</div>
</div>
<!-- 通知组件 -->
<div class="notification" id="notification"></div>
<script>
// 全局变量
let currentDay = 'monday';
let currentInputId = '';
// 新增:存储预览表格点击的位置信息
let previewClickInfo = {
day: '', // 星期(monday/tuesday等)
timeSlot: '', // 时间段(morning/afternoon)
index: -1 // 节次索引
};
// 修改:移除周六周日的数据结构
let scheduleData = {
monday: { morning: [], afternoon: [], morningSort: [1, 2, 3, 4], afternoonSort: [5, 6, 7] },
tuesday: { morning: [], afternoon: [], morningSort: [1, 2, 3, 4], afternoonSort: [5, 6, 7] },
wednesday: { morning: [], afternoon: [], morningSort: [1, 2, 3, 4], afternoonSort: [5, 6, 7] },
thursday: { morning: [], afternoon: [], morningSort: [1, 2, 3, 4], afternoonSort: [5, 6, 7] },
friday: { morning: [], afternoon: [], morningSort: [1, 2, 3, 4], afternoonSort: [5, 6, 7] }
// 移除周六周日数据
};
// 初始化
document.addEventListener('DOMContentLoaded', function() {
// 加载保存的数据
loadScheduleData();
// 加载自定义标题
loadTitle();
// 渲染课程输入框
renderClassInputs();
// 渲染课程表
renderSchedule();
// 设置日期显示
updatePrintDate();
// 绑定日期选择事件
document.querySelectorAll('.day-btn').forEach(btn => {
btn.addEventListener('click', function() {
document.querySelectorAll('.day-btn').forEach(b => b.classList.remove('active'));
this.classList.add('active');
currentDay = this.dataset.day;
renderClassInputs();
});
});
// 绑定时间段切换事件(事件委托)
document.addEventListener('click', function(e) {
if (e.target.classList.contains('time-switch-btn')) {
const time = e.target.dataset.time;
const classNum = parseInt(e.target.dataset.classnum);
const parent = e.target.parentElement;
// 更新按钮状态
parent.querySelectorAll('.time-switch-btn').forEach(btn => {
btn.classList.remove('active');
});
e.target.classList.add('active');
// 移动课程
moveClassBetweenTimeSlots(classNum, time);
}
});
// 绑定预览表格点击事件
document.getElementById('scheduleTable').addEventListener('click', function(e) {
handlePreviewTableClick(e);
});
});
// 处理预览表格点击事件
function handlePreviewTableClick(e) {
const td = e.target.closest('td');
if (!td) return;
// 跳过节次单元格和分割线
if (td.classList.contains('morning-slot') ||
td.classList.contains('afternoon-slot') ||
td.classList.contains('time-divider')) {
return;
}
const tr = td.parentElement;
const rowIndex = Array.from(tr.parentElement.children).indexOf(tr);
const cellIndex = Array.from(tr.children).indexOf(td);
// 跳过表头和节次列
if (cellIndex === 0) return;
// 修改:只保留周一到周五
const days = ['monday', 'tuesday', 'wednesday', 'thursday', 'friday'];
// 检查单元格索引是否有效(1-5对应周一到周五)
if (cellIndex < 1 || cellIndex > 5) return;
const targetDay = days[cellIndex - 1];
// 确定时间段和节次索引
const morningRows = scheduleData[currentDay].morningSort.length;
let timeSlot, sectionIndex;
if (rowIndex <= morningRows) {
// 上午时间段
timeSlot = 'morning';
sectionIndex = rowIndex - 1; // 减1是因为表头占了一行
} else if (rowIndex > morningRows + 1) { // +1是因为午休分割线占了一行
// 下午时间段
timeSlot = 'afternoon';
sectionIndex = rowIndex - morningRows - 2; // 减2是因为表头+午休分割线
} else {
// 午休分割线
return;
}
// 验证索引有效性
if (sectionIndex < 0 ||
(timeSlot === 'morning' && sectionIndex >= scheduleData[targetDay].morningSort.length) ||
(timeSlot === 'afternoon' && sectionIndex >= scheduleData[targetDay].afternoonSort.length)) {
return;
}
// 存储点击位置信息
previewClickInfo = {
day: targetDay,
timeSlot: timeSlot,
index: sectionIndex
};
// 打开选课弹窗
openCourseModal('preview_' + targetDay + '_' + timeSlot + '_' + sectionIndex);
}
// 保存自定义标题
function saveTitle() {
const title = document.getElementById('titleInput').value.trim();
if (title) {
// 更新页面标题
document.title = `🎖️ ${title} 🎖️`;
// 更新主标题
document.getElementById('mainTitle').textContent = `🎖️ ${title} 🎖️`;
// 更新预览标题
document.getElementById('previewTitle').textContent = `${title}预览`;
// 更新打印标题
document.getElementById('printMainTitle').textContent = `🎖️ ${title} 🎖️`;
// 保存到本地存储
localStorage.setItem('scheduleTitle', title);
showNotification(`标题已设置为:${title}`);
} else {
// 恢复默认标题
document.title = '🎖️ 课程表 🎖️';
document.getElementById('mainTitle').textContent = '🎖️ 课程表 🎖️';
document.getElementById('previewTitle').textContent = '课程表预览';
document.getElementById('printMainTitle').textContent = '🎖️ 课程表 🎖️';
// 清除本地存储
localStorage.removeItem('scheduleTitle');
showNotification('标题已恢复为默认值');
}
}
// 加载自定义标题
function loadTitle() {
const title = localStorage.getItem('scheduleTitle');
if (title) {
document.title = `🎖️ ${title} 🎖️`;
document.getElementById('mainTitle').textContent = `🎖️ ${title} 🎖️`;
document.getElementById('previewTitle').textContent = `${title}预览`;
document.getElementById('printMainTitle').textContent = `🎖️ ${title} 🎖️`;
document.getElementById('titleInput').value = title;
}
}
// 更改课程节数
function changeClassCount(delta) {
const morningCount = scheduleData[currentDay].morningSort.length;
const afternoonCount = scheduleData[currentDay].afternoonSort.length;
// 限制课程节数在1-10之间
if (delta > 0) {
// 增加课程节数
const newClassNum = morningCount + afternoonCount + 1;
if (morningCount <= afternoonCount && morningCount < 10) {
scheduleData[currentDay].morningSort.push(newClassNum);
} else if (afternoonCount < 10) {
scheduleData[currentDay].afternoonSort.push(newClassNum);
}
} else {
// 减少课程节数
if (morningCount > afternoonCount && morningCount > 1) {
scheduleData[currentDay].morningSort.pop();
} else if (afternoonCount > 1) {
scheduleData[currentDay].afternoonSort.pop();
}
}
// 更新所有天的节数配置(保持一致)
Object.keys(scheduleData).forEach(day => {
scheduleData[day].morningSort = [...scheduleData[currentDay].morningSort];
scheduleData[day].afternoonSort = [...scheduleData[currentDay].afternoonSort];
});
// 更新显示并保存
updateClassCountDisplay();
renderClassInputs();
renderSchedule();
saveScheduleData();
showNotification(`课程节数已调整:上午${scheduleData[currentDay].morningSort.length}节,下午${scheduleData[currentDay].afternoonSort.length}节`);
}
// 更新课程节数显示
function updateClassCountDisplay() {
document.getElementById('morningClassCount').textContent = scheduleData[currentDay].morningSort.length;
document.getElementById('afternoonClassCount').textContent = scheduleData[currentDay].afternoonSort.length;
}
// 渲染课程输入框
function renderClassInputs() {
const morningContainer = document.getElementById('morningCourses');
const afternoonContainer = document.getElementById('afternoonCourses');
morningContainer.innerHTML = '';
afternoonContainer.innerHTML = '';
// 渲染上午课程输入框(上午从第1节开始编号)
scheduleData[currentDay].morningSort.forEach((classNum, index) => {
morningContainer.innerHTML += `
<div class="course-input">
<label>上午第${index + 1}节 📖</label>
<div class="time-switch">
<button class="time-switch-btn active" data-time="morning" data-classnum="${classNum}">上午</button>
<button class="time-switch-btn" data-time="afternoon" data-classnum="${classNum}">下午</button>
</div>
<input type="text" id="morning${index}" list="courseList"
placeholder="例如:语文" value="${scheduleData[currentDay].morning[index] || ''}"
>
</div>
`;
});
// 渲染下午课程输入框(下午从第1节开始编号)
scheduleData[currentDay].afternoonSort.forEach((classNum, index) => {
afternoonContainer.innerHTML += `
<div class="course-input">
<label>下午第${index + 1}节 🌙</label>
<div class="time-switch">
<button class="time-switch-btn" data-time="morning" data-classnum="${classNum}">上午</button>
<button class="time-switch-btn active" data-time="afternoon" data-classnum="${classNum}">下午</button>
</div>
<input type="text" id="afternoon${index}" list="courseList"
placeholder="例如:数学" value="${scheduleData[currentDay].afternoon[index] || ''}"
>
</div>
`;
});
}
// 渲染课程表
function renderSchedule() {
const table = document.getElementById('scheduleTable');
const printTable = document.getElementById('printTable');
// 修改:表头只保留周一到周五
let tableHtml = `
<tr>
<th>节次/星期</th>
<th>周一</th>
<th>周二</th>
<th>周三</th>
<th>周四</th>
<th>周五</th>
<!-- 移除周六周日列 -->
</tr>
`;
// 生成上午课程行(从第1节开始)
// 修改:只遍历周一到周五
const days = ['monday', 'tuesday', 'wednesday', 'thursday', 'friday'];
scheduleData[currentDay].morningSort.forEach((classNum, index) => {
tableHtml += '<tr>';
// 上午节次单元格(只显示第X节)
tableHtml += `<td class="morning-slot"><strong>第${index + 1}节</strong></td>`;
// 遍历星期
days.forEach(day => {
// 找到对应的索引
const idx = scheduleData[day].morningSort.indexOf(classNum);
// 获取课程名称
const course = idx !== -1 ? scheduleData[day].morning[idx] : '';
// 根据课程内容设置单元格样式
if (course === '休息' || course === '午休') {
tableHtml += `<td class="rest-cell">${course}</td>`;
} else if (course) {
tableHtml += `<td class="course-cell">${course}</td>`;
} else {
tableHtml += `<td class="empty-cell">--</td>`;
}
});
tableHtml += '</tr>';
});
// 添加午休分割线
// 修改:分割线列数改为6(节次列+5个星期列)
tableHtml += `
<tr>
<td class="time-divider" colspan="6">—— 午休分割线 ——</td>
</tr>
`;
// 生成下午课程行(从第1节开始)
scheduleData[currentDay].afternoonSort.forEach((classNum, index) => {
tableHtml += '<tr>';
// 下午节次单元格(只显示第X节)
tableHtml += `<td class="afternoon-slot"><strong>第${index + 1}节</strong></td>`;
// 遍历星期
days.forEach(day => {
// 找到对应的索引
const idx = scheduleData[day].afternoonSort.indexOf(classNum);
// 获取课程名称
const course = idx !== -1 ? scheduleData[day].afternoon[idx] : '';
// 根据课程内容设置单元格样式
if (course === '休息' || course === '午休') {
tableHtml += `<td class="rest-cell">${course}</td>`;
} else if (course) {
tableHtml += `<td class="course-cell">${course}</td>`;
} else {
tableHtml += `<td class="empty-cell">--</td>`;
}
});
tableHtml += '</tr>';
});
// 更新表格内容
table.innerHTML = tableHtml;
printTable.innerHTML = tableHtml;
}
// 在上午和下午之间移动课程
function moveClassBetweenTimeSlots(classNum, targetTime) {
// 从原时间段移除
let sourceTime = targetTime === 'morning' ? 'afternoon' : 'morning';
let sourceIndex = scheduleData[currentDay][`${sourceTime}Sort`].indexOf(classNum);
if (sourceIndex !== -1) {
// 获取课程内容
let courseContent = scheduleData[currentDay][sourceTime][sourceIndex];
// 从源数组移除
scheduleData[currentDay][`${sourceTime}Sort`].splice(sourceIndex, 1);
scheduleData[currentDay][sourceTime].splice(sourceIndex, 1);
// 添加到目标数组
scheduleData[currentDay][`${targetTime}Sort`].push(classNum);
scheduleData[currentDay][targetTime].push(courseContent);
// 对目标数组排序
scheduleData[currentDay][`${targetTime}Sort`].sort((a, b) => a - b);
// 更新所有天的节数配置(保持一致)
Object.keys(scheduleData).forEach(day => {
scheduleData[day].morningSort = [...scheduleData[currentDay].morningSort];
scheduleData[day].afternoonSort = [...scheduleData[currentDay].afternoonSort];
});
// 重新渲染
updateClassCountDisplay();
renderClassInputs();
renderSchedule();
saveScheduleData();
showNotification(`课程已移动到${targetTime === 'morning' ? '上午' : '下午'}`);
}
}
// 打开课程选择弹窗
function openCourseModal(inputId) {
currentInputId = inputId;
document.getElementById('courseModal').classList.add('active');
document.getElementById('customCourseInput').classList.remove('active');
document.getElementById('customCourseText').value = '';
}
// 关闭课程选择弹窗
function closeCourseModal() {
document.getElementById('courseModal').classList.remove('active');
// 重置预览点击信息
previewClickInfo = { day: '', timeSlot: '', index: -1 };
}
// 选择课程
function selectCourse(courseName) {
if (currentInputId) {
// 判断是配置面板输入还是预览表格点击
if (currentInputId.startsWith('preview_')) {
// 预览表格点击更新
if (previewClickInfo.day && previewClickInfo.timeSlot && previewClickInfo.index >= 0) {
// 更新对应位置的课程数据
scheduleData[previewClickInfo.day][previewClickInfo.timeSlot][previewClickInfo.index] = courseName;
// 重新渲染课程表
renderSchedule();
// 如果当前编辑的就是这个天,同步更新输入框
if (previewClickInfo.day === currentDay) {
renderClassInputs();
}
// 保存数据
saveScheduleData();
showNotification(`${previewClickInfo.day === currentDay ? '本周' : getDayName(previewClickInfo.day)}${previewClickInfo.timeSlot === 'morning' ? '上午' : '下午'}第${previewClickInfo.index + 1}节已设置为:${courseName}`);
}
} else {
// 配置面板输入更新
const input = document.getElementById(currentInputId);
if (input) {
input.value = courseName;
realTimeUpdateSchedule();
}
}
}
closeCourseModal();
}
// 获取星期名称
function getDayName(dayKey) {
const dayMap = {
'monday': '周一',
'tuesday': '周二',
'wednesday': '周三',
'thursday': '周四',
'friday': '周五'
// 移除周六周日映射
};
return dayMap[dayKey] || dayKey;
}
// 显示自定义课程输入框
function showCustomCourseInput() {
document.getElementById('customCourseInput').classList.add('active');
document.getElementById('customCourseText').focus();
}
// 添加自定义课程
function addCustomCourse() {
const courseName = document.getElementById('customCourseText').value.trim();
if (courseName) {
selectCourse(courseName);
}
}
// 实时更新课程表
function realTimeUpdateSchedule() {
// 获取当前输入的时间段和索引
const isMorning = currentInputId.startsWith('morning');
const index = parseInt(currentInputId.replace(isMorning ? 'morning' : 'afternoon', ''));
// 更新数据
if (isMorning) {
scheduleData[currentDay].morning[index] = document.getElementById(currentInputId).value.trim();
} else {
scheduleData[currentDay].afternoon[index] = document.getElementById(currentInputId).value.trim();
}
// 重新渲染课程表
renderSchedule();
}
// 保存课程表
function saveSchedule() {
// 收集所有输入框的值
document.querySelectorAll('#morningCourses input, #afternoonCourses input').forEach(input => {
const isMorning = input.id.startsWith('morning');
const index = parseInt(input.id.replace(isMorning ? 'morning' : 'afternoon', ''));
if (isMorning) {
scheduleData[currentDay].morning[index] = input.value.trim();
} else {
scheduleData[currentDay].afternoon[index] = input.value.trim();
}
});
// 保存数据
saveScheduleData();
// 更新课程表
renderSchedule();
// 显示通知
showNotification('课程表已保存成功!');
}
// 清空当前天的课程
function clearSchedule() {
if (confirm('确定要清空当前天的所有课程吗?')) {
scheduleData[currentDay].morning = Array(scheduleData[currentDay].morningSort.length).fill('');
scheduleData[currentDay].afternoon = Array(scheduleData[currentDay].afternoonSort.length).fill('');
// 保存数据
saveScheduleData();
// 重新渲染
renderClassInputs();
renderSchedule();
// 显示通知
showNotification('当前天的课程已清空');
}
}
// 保存课程表数据到本地存储
function saveScheduleData() {
localStorage.setItem('scheduleData', JSON.stringify(scheduleData));
}
// 从本地存储加载课程表数据
function loadScheduleData() {
const savedData = localStorage.getItem('scheduleData');
if (savedData) {
// 加载数据时过滤掉周六周日(如果有)
const loadedData = JSON.parse(savedData);
scheduleData = {
monday: loadedData.monday || { morning: [], afternoon: [], morningSort: [1,2,3,4], afternoonSort: [5,6,7] },
tuesday: loadedData.tuesday || { morning: [], afternoon: [], morningSort: [1,2,3,4], afternoonSort: [5,6,7] },
wednesday: loadedData.wednesday || { morning: [], afternoon: [], morningSort: [1,2,3,4], afternoonSort: [5,6,7] },
thursday: loadedData.thursday || { morning: [], afternoon: [], morningSort: [1,2,3,4], afternoonSort: [5,6,7] },
friday: loadedData.friday || { morning: [], afternoon: [], morningSort: [1,2,3,4], afternoonSort: [5,6,7] }
};
}
updateClassCountDisplay();
}
// 更新打印日期
function updatePrintDate() {
const now = new Date();
const options = { year: 'numeric', month: 'long', day: 'numeric', weekday: 'long' };
document.getElementById('printDate').textContent = `更新于:${now.toLocaleDateString('zh-CN', options)}`;
}
// 显示通知
function showNotification(message) {
const notification = document.getElementById('notification');
notification.textContent = message;
notification.classList.add('show');
setTimeout(() => {
notification.classList.remove('show');
}, 3000);
}
</script>
</body>
</html>