-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
770 lines (663 loc) · 27.6 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>课程展示与筛选</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
line-height: 1.6;
}
h1 {
color: #333;
text-align: center;
}
.filter-container {
display: flex;
flex-wrap: wrap;
gap: 10px;
padding: 15px;
background-color: #f8f9fa;
border-radius: 5px;
margin-bottom: 20px;
}
.filter-container label,
.filter-container select,
.filter-container input {
margin-bottom: 10px;
/* Add margin for better spacing in column view */
}
.filter-container select,
.filter-container input {
padding: 8px;
border: 1px solid #ddd;
border-radius: 4px;
}
button {
padding: 8px 15px;
background-color: #007bff;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
transition: background-color 0.3s;
}
button:hover {
background-color: #0056b3;
}
.error {
color: #dc3545;
padding: 10px;
margin: 10px 0;
background-color: #f8d7da;
border-radius: 4px;
text-align: center;
}
table {
width: 100%;
border-collapse: collapse;
margin-top: 20px;
font-size: 14px;
/* Slightly larger font size */
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
table-layout: fixed;
/* For fixed column widths */
}
table,
th,
td {
border: 1px solid #ddd;
}
th,
td {
padding: 12px;
text-align: left;
white-space: normal;
/* 允许文字换行 */
word-wrap: break-word;
/* 允许长单词换行 */
max-width: 150px;
/* 限制单元格最大宽度 */
}
th {
background-color: #f4f4f4;
color: #333;
cursor: pointer;
position: sticky;
/* Keep header fixed when scrolling */
top: 0;
}
tr:hover {
background-color: #f5f5f5;
}
td[data-title]:hover::after {
content: attr(data-title);
position: absolute;
left: 0;
top: 0;
z-index: 1;
background: rgba(255, 255, 255, 0.9);
padding: 5px 10px;
border-radius: 5px;
white-space: pre-wrap;
/* Allow wrapping for long tooltips */
}
.course-link {
color: #0366d6;
text-decoration: none;
cursor: pointer;
position: relative;
}
.course-link:hover {
text-decoration: underline;
}
/* 添加一个小图标表示这是外部链接 */
.course-link::after {
content: "↗️";
font-size: 0.8em;
margin-left: 4px;
opacity: 0.7;
}
#scheduleTable td.active {
background-color: #ffd700;
/* 高亮颜色 */
color: #000;
font-weight: bold;
}
#scheduleTable button {
margin-bottom: 10px;
}
#scheduleTable td {
cursor: pointer;
}
#scheduleTable td:hover {
background-color: #f0f0f0;
}
#scheduleTable td.active {
background-color: #ffd700;
color: #000;
font-weight: bold;
}
/* 在原有的style标签中添加 */
#loading-overlay {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(255, 255, 255, 0.9);
display: flex;
/* 修改这里,默认显示 */
justify-content: center;
align-items: center;
z-index: 9999;
}
.loading-content {
text-align: center;
}
.spinner {
width: 50px;
height: 50px;
border: 5px solid #f3f3f3;
border-top: 5px solid #3498db;
border-radius: 50%;
animation: spin 1s linear infinite;
margin: 0 auto 20px;
}
.loading-tip {
color: #666;
font-size: 14px;
margin-top: 10px;
}
@keyframes spin {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
@media screen and (max-width: 768px) {
.filter-container {
flex-direction: column;
}
.filter-container select,
.filter-container input,
.filter-container label {
/* Add label to responsive width adjustment */
width: calc(100% - 20px);
/* Account for padding */
box-sizing: border-box;
/* Make sure padding is within width */
}
.filter-container label {
margin-bottom: 5px;
}
}
@media (prefers-color-scheme: dark) {
body {
background-color: #1a1a1a;
color: #ffffff;
}
h1 {
color: #ffffff;
}
.filter-container {
background-color: #2d2d2d;
}
table {
border-color: #444;
}
th {
background-color: #2d2d2d;
color: #ffffff;
}
td {
border-color: #444;
}
tr:hover {
background-color: #3d3d3d;
}
select,
input {
background-color: #2d2d2d;
color: #ffffff;
border-color: #444;
}
}
</style>
</head>
<body>
<!-- 在body开始处添加 -->
<div id="loading-overlay">
<div class="loading-content">
<div class="spinner"></div>
<p>正在加载课程数据,请耐心等待...</p>
<p class="loading-tip">首次加载可能需要一分钟左右</p>
</div>
</div>
<h1>课程展示与筛选</h1>
<div class="filter-container">
<label for="courseNature" id="courseNatureLabel">课程性质:</label>
<select id="courseNature" aria-labelledby="courseNatureLabel">
<option value="">全部</option>
</select>
<label for="campus" id="campusLabel">校区:</label>
<select id="campus" aria-labelledby="campusLabel">
<option value="">全部</option>
</select>
<label for="department" id="departmentLabel">开课学院:</label>
<select id="department" aria-labelledby="departmentLabel">
<option value="">全部</option>
</select>
<label for="search" id="searchLabel">搜索:</label>
<input type="text" id="search" placeholder="搜索课程信息..." aria-labelledby="searchLabel">
<button onclick="courseManager.applyFilters()">筛选</button>
</div>
<div id="scheduleTable">
<button onclick="courseManager.resetScheduleFilter()">重置时间筛选</button>
<table border="1" style="border-collapse: collapse; text-align: center; width: 100%;">
<thead>
<tr>
<th>时间段</th>
<th>星期一</th>
<th>星期二</th>
<th>星期三</th>
<th>星期四</th>
<th>星期五</th>
<th>星期六</th>
<th>星期日</th>
</tr>
</thead>
<tbody>
<tr>
<td>1-2节</td>
<td data-day="1" data-time="1-2"></td>
<td data-day="2" data-time="1-2"></td>
<td data-day="3" data-time="1-2"></td>
<td data-day="4" data-time="1-2"></td>
<td data-day="5" data-time="1-2"></td>
<td data-day="6" data-time="1-2"></td>
<td data-day="7" data-time="1-2"></td>
</tr>
<tr>
<td>3-4节</td>
<td data-day="1" data-time="3-4"></td>
<td data-day="2" data-time="3-4"></td>
<td data-day="3" data-time="3-4"></td>
<td data-day="4" data-time="3-4"></td>
<td data-day="5" data-time="3-4"></td>
<td data-day="6" data-time="3-4"></td>
<td data-day="7" data-time="3-4"></td>
</tr>
<tr>
<td>5-6节</td>
<td data-day="1" data-time="5-6"></td>
<td data-day="2" data-time="5-6"></td>
<td data-day="3" data-time="5-6"></td>
<td data-day="4" data-time="5-6"></td>
<td data-day="5" data-time="5-6"></td>
<td data-day="6" data-time="5-6"></td>
<td data-day="7" data-time="5-6"></td>
</tr>
<tr>
<td>7-8节</td>
<td data-day="1" data-time="7-8"></td>
<td data-day="2" data-time="7-8"></td>
<td data-day="3" data-time="7-8"></td>
<td data-day="4" data-time="7-8"></td>
<td data-day="5" data-time="7-8"></td>
<td data-day="6" data-time="7-8"></td>
<td data-day="7" data-time="7-8"></td>
</tr>
<tr>
<td>10-11节</td>
<td data-day="1" data-time="10-11"></td>
<td data-day="2" data-time="10-11"></td>
<td data-day="3" data-time="10-11"></td>
<td data-day="4" data-time="10-11"></td>
<td data-day="5" data-time="10-11"></td>
<td data-day="6" data-time="10-11"></td>
<td data-day="7" data-time="10-11"></td>
</tr>
</tbody>
</table>
</div>
<table id="courseTable">
<thead>
<tr>
<th style="width: 4%;">课程序号</th>
<th style="width: 6%;">课程名称</th>
<th style="width: 1.5%;">周学时</th>
<th style="width: 1.5%;">负责人</th>
<th style="width: 3%;">授课教师</th>
<th style="width: 3%;">课程性质</th>
<th style="width: 1.5%;">授课语言</th>
<th style="width: 3%;">校区</th>
<th style="width: 4%;">开课学院</th>
<th style="width: 6%;">听课专业</th>
<th style="width: 10%;">排课信息</th>
</tr>
</thead>
<tbody>
<!-- 数据将动态填充 -->
</tbody>
</table>
<script>
class CourseManager {
constructor() {
this.originalData = [];
this.filteredData = [];
this.validCourseNatures = [
"通识选修课", "通识必修课", "社会发展与国际视野", "人文经典与审美素养",
"科学探索与生命关怀", "工程能力与创新思维", "必修课程", "公共课",
"专业基础课", "专业选修课", "专业必修课", "实践环节", "实践环节课程",
"公共基础课", "个性化课程"
];
this.validCampuses = ["四平路校区", "嘉定校区", "沪西校区", "沪北校区"];
this.currentScheduleFilter = null;
this.electiveCourseTypes = [
"人文经典与审美素养",
"工程能力与创新思维",
"社会发展与国际视野",
"科学探索与生命关怀"
];
this.loadingOverlay = document.getElementById('loading-overlay');
this.loadingOverlay.style.display = 'flex'; // 确保初始状态是显示的
}
// 显示加载提示
showLoading() {
this.loadingOverlay.style.display = 'flex';
}
// 隐藏加载提示
hideLoading() {
this.loadingOverlay.style.display = 'none';
}
init() {
this.showLoading(); // 开始加载时显示
this.loadData();
this.setupEventListeners();
}
loadData() {
this.showLoading();
fetch('source.csv')
.then(response => {
if (!response.ok) throw new Error('无法加载 source.csv 文件');
return response.text();
})
.then(csv => {
const loadingText = document.querySelector('.loading-content p:first-of-type');
loadingText.textContent = '正在处理课程数据,请耐心等待...';
// 移除 requestAnimationFrame,直接处理数据
this.processCSV(csv);
// 注意:不要在这里调用 hideLoading(),
// 让 processCSV 方法在完成时调用
})
.catch(error => {
console.error(error);
document.body.innerHTML += '<div class="error">加载数据时发生错误,请刷新页面重试。</div>';
this.hideLoading();
});
}
processCSV(csv) {
try {
const parseCSVLine = (line) => {
const result = [];
let cell = '';
let inQuotes = false;
for (let i = 0; i < line.length; i++) {
const char = line[i];
if (char === '"') {
inQuotes = !inQuotes;
continue;
}
if (char === ',' && !inQuotes) {
result.push(cell.trim());
cell = '';
} else {
cell += char;
}
}
result.push(cell.trim());
return result;
};
const rows = csv.split("\n");
const totalRows = rows.length;
let processedRows = 0;
let currentDepartment = "";
this.originalData = [];
// 更新加载进度的函数
const updateLoadingProgress = (percent) => {
const loadingText = document.querySelector('.loading-content p:first-of-type');
loadingText.textContent = `正在处理课程数据 (${percent}%),请耐心等待...`;
};
// 修改分批处理数据的逻辑
const processChunk = (startIndex) => {
this.showLoading(); // 确保处理过程中显示加载提示
const chunkSize = 100;
const endIndex = Math.min(startIndex + chunkSize, rows.length);
for (let i = startIndex; i < endIndex; i++) {
const row = parseCSVLine(rows[i]);
if (row[0] && row.slice(1).every(cell => cell === "")) {
currentDepartment = row[0];
} else if (row[0] && row[1]) {
const courseNature = row[7];
const campus = row[9];
if (!this.validCourseNatures.includes(courseNature) ||
!this.validCampuses.includes(campus)) {
continue;
}
this.originalData.push({
courseId: row[0],
courseName: row[1],
weeklyHours: row[2],
leader: row[3],
teachers: row[4],
courseNature: row[7],
language: row[8],
campus: row[9],
department: currentDepartment,
auditInfo: row[10],
schedule: row[14].replace(/\s+/g, '')
});
}
processedRows++;
}
// 更新进度
const percent = Math.round((processedRows / totalRows) * 100);
updateLoadingProgress(percent);
// 如果还有数据需要处理,继续下一批
if (endIndex < rows.length) {
setTimeout(() => processChunk(endIndex), 0);
} else {
// 所有数据处理完成
this.filteredData = [...this.originalData];
this.populateFilters();
this.renderTable();
this.addSortingFunctionality();
this.hideLoading(); // 只在所有处理完成后隐藏加载提示
}
};
// 开始处理第一批数据
processChunk(0);
} catch (error) {
console.error('处理CSV数据时出错:', error);
document.body.innerHTML += '<div class="error">处理数据时发生错误,请刷新页面重试。</div>';
this.hideLoading();
}
}
setupEventListeners() {
// 搜索框事件
const searchInput = document.getElementById('search');
searchInput.addEventListener('input',
this.debounce(() => this.applyFilters(), 300));
// 下拉框筛选事件
['courseNature', 'campus', 'department'].forEach(id => {
document.getElementById(id).addEventListener('change',
() => this.applyFilters());
});
// 课程表单元格点击事件
const scheduleCells = document.querySelectorAll('#scheduleTable td[data-day][data-time]');
scheduleCells.forEach(cell => {
cell.addEventListener('click', () => {
const day = cell.dataset.day;
const time = cell.dataset.time;
this.highlightSelectedCell(cell);
this.filterBySchedule(day, time);
});
});
}
// 修改 populateFilters 方法
populateFilters() {
const courseNatureSet = new Set();
const campusSet = new Set();
const departmentSet = new Set();
this.originalData.forEach(item => {
courseNatureSet.add(item.courseNature);
campusSet.add(item.campus);
departmentSet.add(item.department);
});
// 特殊处理课程性质下拉框
const courseNatureSelect = document.getElementById("courseNature");
courseNatureSelect.innerHTML = '<option value="">全部</option>';
courseNatureSelect.innerHTML += '<option value="选修课合集">选修课合集</option>';
// 添加其他选项
Array.from(courseNatureSet).sort().forEach(option => {
const opt = document.createElement("option");
opt.value = option;
opt.textContent = option;
courseNatureSelect.appendChild(opt);
});
// 其他下拉框保持不变
this.populateSelect("campus", campusSet);
this.populateSelect("department", departmentSet);
}
populateSelect(selectId, optionsSet) {
const select = document.getElementById(selectId);
select.innerHTML = '<option value="">全部</option>';
Array.from(optionsSet).sort().forEach(option => {
const opt = document.createElement("option");
opt.value = option;
opt.textContent = option;
select.appendChild(opt);
});
}
filterBySchedule(day, time) {
const dayMapping = {
"1": "星期一", "2": "星期二", "3": "星期三",
"4": "星期四", "5": "星期五", "6": "星期六", "7": "星期日"
};
this.currentScheduleFilter = `${dayMapping[day]}${time}`;
this.applyFilters();
}
// 修改 applyFilters 方法
applyFilters() {
this.showLoading(); // 显示加载提示
const courseNature = document.getElementById("courseNature").value;
const campus = document.getElementById("campus").value;
const department = document.getElementById("department").value;
const search = document.getElementById("search").value.toLowerCase();
setTimeout(() => {
this.filteredData = this.originalData.filter(item => {
// 处理"选修课合集"的特殊情况
const courseNatureMatch = courseNature === "" ? true :
courseNature === "选修课合集" ?
this.electiveCourseTypes.includes(item.courseNature) :
item.courseNature === courseNature;
// 其他筛选条件保持不变
const basicFilter = (
courseNatureMatch &&
(campus === "" || item.campus === campus) &&
(department === "" || item.department === department) &&
(search === "" || Object.values(item).some(value =>
String(value).toLowerCase().includes(search)))
);
// 时间筛选部分保持不变
if (!this.currentScheduleFilter) {
return basicFilter;
}
const scheduleItems = item.schedule.split(',').map(s => s.trim());
const scheduleMatch = scheduleItems.some(scheduleItem => {
const cleanScheduleItem = scheduleItem.replace(/\s+/g, '');
return cleanScheduleItem.includes(this.currentScheduleFilter);
});
return basicFilter && scheduleMatch;
});
this.renderTable();
this.hideLoading(); // 处理完成后隐藏加载提示
}, 0);
}
renderTable() {
this.showLoading();
const tbody = document.getElementById("courseTable").querySelector("tbody");
tbody.innerHTML = "";
setTimeout(() => {
this.filteredData.forEach(item => {
const row = document.createElement("tr");
// 创建一个包含所有单元格的数组,特殊处理课程名称单元格
const cells = [
`<td data-title="${item.courseId}">${item.courseId}</td>`,
`<td data-title="${item.courseName}">
<a href="https://1.tongji.icu/search?q=${encodeURIComponent(item.courseName)}"
class="course-link"
target="_blank"
title="点击查看课程详情">
${item.courseName}
</a>
</td>`,
`<td data-title="${item.weeklyHours}">${item.weeklyHours}</td>`,
`<td data-title="${item.leader}">${item.leader}</td>`,
`<td data-title="${item.teachers}">${item.teachers}</td>`,
`<td data-title="${item.courseNature}">${item.courseNature}</td>`,
`<td data-title="${item.language}">${item.language}</td>`,
`<td data-title="${item.campus}">${item.campus}</td>`,
`<td data-title="${item.department}">${item.department}</td>`,
`<td data-title="${item.auditInfo}">${item.auditInfo}</td>`,
`<td data-title="${item.schedule}">${item.schedule}</td>`
];
row.innerHTML = cells.join('');
tbody.appendChild(row);
});
this.hideLoading();
}, 0);
}
highlightSelectedCell(selectedCell) {
const scheduleCells = document.querySelectorAll('#scheduleTable td');
scheduleCells.forEach(cell => cell.classList.remove('active'));
selectedCell.classList.add('active');
}
resetScheduleFilter() {
this.currentScheduleFilter = null;
const scheduleCells = document.querySelectorAll('#scheduleTable td');
scheduleCells.forEach(cell => cell.classList.remove('active'));
this.applyFilters();
}
addSortingFunctionality() {
const headers = document.querySelectorAll('th');
headers.forEach((header, index) => {
header.addEventListener('click', () => this.sortTable(index));
});
}
sortTable(column) {
this.filteredData.sort((a, b) => {
const values = Object.values(a)[column];
const valueb = Object.values(b)[column];
return values.localeCompare(valueb);
});
this.renderTable();
}
debounce(func, wait) {
let timeout;
return (...args) => {
clearTimeout(timeout);
timeout = setTimeout(() => func.apply(this, args), wait);
};
}
}
const courseManager = new CourseManager();
window.onload = () => courseManager.init();
</script>
</body>
</html>