-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
505 lines (433 loc) · 16.1 KB
/
index.html
File metadata and controls
505 lines (433 loc) · 16.1 KB
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
<!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>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Segoe UI', 'Microsoft YaHei', sans-serif;
background: linear-gradient(135deg, #6a11cb 0%, #2575fc 100%);
color: #333;
min-height: 100vh;
padding: 40px 20px;
display: flex;
flex-direction: column;
align-items: center;
}
.container {
width: 100%;
max-width: 1200px;
text-align: center;
}
header {
margin-bottom: 40px;
color: white;
text-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
}
h1 {
font-size: 2.8rem;
margin-bottom: 15px;
}
.subtitle {
font-size: 1.2rem;
opacity: 0.9;
max-width: 600px;
margin: 0 auto;
}
.upload-section {
background-color: rgba(255, 255, 255, 0.15);
backdrop-filter: blur(10px);
border-radius: 20px;
padding: 40px 30px;
margin: 30px auto;
max-width: 600px;
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
border: 2px dashed rgba(255, 255, 255, 0.3);
transition: all 0.3s ease;
}
.upload-section:hover {
background-color: rgba(255, 255, 255, 0.2);
}
.file-drop-area {
padding: 50px 30px;
background-color: rgba(255, 255, 255, 0.1);
border-radius: 16px;
cursor: pointer;
transition: all 0.3s ease;
position: relative;
}
.file-drop-area:hover {
background-color: rgba(255, 255, 255, 0.2);
}
.file-drop-area.highlight {
background-color: rgba(255, 255, 255, 0.3);
}
.upload-icon {
font-size: 60px;
margin-bottom: 20px;
color: white;
}
.file-input {
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
opacity: 0;
cursor: pointer;
}
.btn {
background: #ff4081;
color: white;
border: none;
padding: 12px 30px;
font-size: 1.1rem;
border-radius: 50px;
cursor: pointer;
transition: all 0.3s ease;
font-weight: 600;
box-shadow: 0 5px 15px rgba(255, 64, 129, 0.4);
}
.btn:hover {
background: #f50057;
transform: translateY(-2px);
box-shadow: 0 7px 18px rgba(255, 64, 129, 0.5);
}
.btn:active {
transform: translateY(1px);
}
.btn-secondary {
background: transparent;
border: 2px solid white;
color: white;
box-shadow: none;
margin-top: 15px;
}
.btn-secondary:hover {
background: rgba(255, 255, 255, 0.1);
}
.cards-container {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
gap: 30px;
width: 100%;
margin: 40px 0;
padding: 10px;
}
.card {
aspect-ratio: 2/1.5;
perspective: 1500px;
cursor: pointer;
}
.card-inner {
position: relative;
width: 100%;
height: 100%;
text-align: center;
transition: transform 0.8s;
transform-style: preserve-3d;
border-radius: 20px;
box-shadow: 0 15px 35px rgba(0, 0, 0, 0.25);
}
.card.flipped .card-inner {
transform: rotateY(180deg);
}
.card-front, .card-back {
position: absolute;
width: 100%;
height: 100%;
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
padding: 20px;
border-radius: 20px;
}
.card-front {
background: linear-gradient(135deg, #ffffff 0%, #f8f9fa 100%);
color: #333;
}
.card-back {
background: linear-gradient(135deg, #3a1c71 0%, #d76d77 100%);
color: white;
transform: rotateY(180deg);
}
.card-number {
position: absolute;
top: 15px;
right: 15px;
background: rgba(0, 0, 0, 0.1);
border-radius: 50%;
width: 30px;
height: 30px;
display: flex;
align-items: center;
justify-content: center;
font-size: 0.9rem;
}
.card-front .card-number {
background: rgba(0, 0, 0, 0.05);
color: rgba(0, 0, 0, 0.5);
}
.card-title {
font-size: 1.5rem;
font-weight: 600;
margin-bottom: 20px;
}
.card-content {
font-size: 1.2rem;
line-height: 1.6;
}
.flip-notice {
position: absolute;
bottom: 15px;
font-size: 0.9rem;
color: rgba(0, 0, 0, 0.5);
font-style: italic;
}
.hidden {
display: none;
}
.error-message {
background-color: #ffebee;
color: #c62828;
padding: 15px;
border-radius: 10px;
margin-top: 20px;
max-width: 600px;
}
.instruction {
color: white;
margin-top: 30px;
max-width: 700px;
text-align: left;
background: rgba(0, 0, 0, 0.1);
padding: 20px;
border-radius: 15px;
}
code {
background: rgba(0, 0, 0, 0.2);
padding: 2px 6px;
border-radius: 5px;
font-family: monospace;
}
.card-counter {
background: white;
color: #3a1c71;
padding: 10px 20px;
border-radius: 50px;
font-weight: bold;
margin-top: 20px;
display: inline-block;
}
@media (max-width: 768px) {
.cards-container {
grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
}
h1 {
font-size: 2.2rem;
}
}
</style>
</head>
<body>
<div class="container">
<header>
<h1>闪记</h1>
<p class="subtitle">导入TXT文件,一键生成可翻转的记忆卡片,高效学习、轻松记忆</p>
</header>
<div class="upload-section" id="uploadSection">
<div class="file-drop-area" id="dropArea">
<div class="upload-icon">📁</div>
<h3>点击或拖拽文件到此处</h3>
<p>支持格式:TXT (格式:序号¥问题¥答案)</p>
<input type="file" class="file-input" id="fileInput" accept=".txt">
</div>
<div class="hidden" id="statusMessage"></div>
<div class="instruction">
<p><strong>使用说明:</strong></p>
<p>1. 创建符合格式的TXT文件:每行内容格式为 <code>序号¥问题¥答案</code></p>
<p>2. 示例:<code>1¥什么是HTML?¥超文本标记语言</code></p>
<p>3. 点击上方区域选择文件或直接拖拽文件到此处</p>
<p>4. 点击卡片翻转查看答案,再次点击翻转回问题</p>
</div>
</div>
<div class="hidden" id="cardsContainer">
<div class="card-counter">已生成 <span id="cardCount">0</span> 张卡片</div>
<div class="cards-container" id="cardsGrid">
<!-- 卡片将通过JS动态生成 -->
</div>
</div>
</div>
<script>
// DOM元素
const dropArea = document.getElementById('dropArea');
const fileInput = document.getElementById('fileInput');
const cardsGrid = document.getElementById('cardsGrid');
const uploadSection = document.getElementById('uploadSection');
const cardsContainer = document.getElementById('cardsContainer');
const cardCount = document.getElementById('cardCount');
const statusMessage = document.getElementById('statusMessage');
// 防止默认拖放行为
['dragenter', 'dragover', 'dragleave', 'drop'].forEach(eventName => {
document.addEventListener(eventName, preventDefaults, false);
});
function preventDefaults(e) {
e.preventDefault();
e.stopPropagation();
}
// 拖放区域高亮
['dragenter', 'dragover'].forEach(eventName => {
dropArea.addEventListener(eventName, highlight, false);
});
['dragleave', 'drop'].forEach(eventName => {
dropArea.addEventListener(eventName, unhighlight, false);
});
function highlight() {
dropArea.classList.add('highlight');
}
function unhighlight() {
dropArea.classList.remove('highlight');
}
// 处理文件拖放
dropArea.addEventListener('drop', handleDrop, false);
function handleDrop(e) {
const dt = e.dataTransfer;
const files = dt.files;
if (files.length) {
processFile(files[0]);
}
}
// 处理文件输入
fileInput.addEventListener('change', function() {
if (this.files.length) {
processFile(this.files[0]);
}
});
// 处理文件
function processFile(file) {
statusMessage.classList.add('hidden');
// 检查文件类型
if (file.type !== 'text/plain') {
showMessage('错误:请选择TXT文本文件', 'error');
return;
}
const reader = new FileReader();
reader.onload = function(e) {
const content = e.target.result;
try {
const cards = parseFileContent(content);
if (cards.length > 0) {
generateCards(cards);
uploadSection.classList.add('hidden');
cardsContainer.classList.remove('hidden');
} else {
showMessage('未在文件中找到任何卡片数据', 'error');
}
} catch (error) {
showMessage('解析错误: ' + error.message, 'error');
}
};
reader.onerror = function() {
showMessage('读取文件出错', 'error');
};
reader.readAsText(file);
}
// 解析文件内容
function parseFileContent(content) {
const lines = content.split('\n');
const cards = [];
lines.forEach((line, index) => {
line = line.trim();
if (!line) return;
const parts = line.split('¥');
if (parts.length < 3) {
throw new Error(`第${index+1}行格式错误:缺少分隔符`);
}
// 移除首尾空白
const number = parts[0].trim();
const question = parts[1].trim();
const answer = parts.slice(2).join('¥').trim();
cards.push({ number, question, answer });
});
return cards;
}
// 生成卡片
function generateCards(cards) {
cardsGrid.innerHTML = '';
cardCount.textContent = cards.length;
cards.forEach((cardData, index) => {
const cardElement = document.createElement('div');
cardElement.className = 'card';
cardElement.dataset.index = index;
cardElement.innerHTML = `
<div class="card-inner">
<div class="card-front">
<span class="card-number">${cardData.number}</span>
<div class="card-title">问题</div>
<div class="card-content">${cardData.question}</div>
<div class="flip-notice">点击卡片查看答案</div>
</div>
<div class="card-back">
<span class="card-number">${cardData.number}</span>
<div class="card-title">答案</div>
<div class="card-content">${cardData.answer}</div>
<div class="flip-notice">点击返回问题</div>
</div>
</div>
`;
cardElement.addEventListener('click', function() {
this.classList.toggle('flipped');
});
cardsGrid.appendChild(cardElement);
});
}
// 显示消息
function showMessage(message, type = 'info') {
statusMessage.className = type === 'error' ? 'error-message' : 'status-message';
statusMessage.textContent = message;
statusMessage.classList.remove('hidden');
}
// 生成示例数据
function loadSampleData() {
const sampleData = `
1¥HTML是什么?¥超文本标记语言(Hyper Text Markup Language)
2¥CSS的主要作用是什么?¥用于描述网页的表现样式
3¥JavaScript是什么类型的语言?¥解释型或即时编译型的编程语言
4¥什么是响应式设计?¥网页能够根据屏幕大小自动调整布局
5¥HTTP和HTTPS的主要区别?¥HTTPS在HTTP基础上增加了SSL/TLS加密
6¥什么是闭包?¥有权访问另一个函数作用域中变量的函数
7¥CSS中,em和rem的区别是什么?¥em相对于父元素,rem相对于根元素
8¥let和var的区别是什么?¥let有块级作用域,var是函数作用域
9¥什么是Flex布局?¥CSS3的一种弹性盒布局模型
10¥AJAX全称是什么?¥Asynchronous JavaScript And XML
`;
try {
const cards = parseFileContent(sampleData);
generateCards(cards);
uploadSection.classList.add('hidden');
cardsContainer.classList.remove('hidden');
} catch (e) {
showMessage('加载示例数据出错: ' + e.message, 'error');
}
}
// 页面加载时添加示例数据按钮(用于演示)
document.addEventListener('DOMContentLoaded', function() {
const sampleButton = document.createElement('button');
sampleButton.className = 'btn btn-secondary';
sampleButton.textContent = '加载示例数据';
sampleButton.onclick = loadSampleData;
const buttonsContainer = document.querySelector('.upload-section');
buttonsContainer.appendChild(sampleButton);
});
</script>
</body>
</html>