-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.html
More file actions
2863 lines (2516 loc) · 118 KB
/
Copy pathtest.html
File metadata and controls
2863 lines (2516 loc) · 118 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
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
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!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>
:root {
--primary-color: #3b82f6;
--primary-hover: #2563eb;
--bg-color: #f8fafc;
--card-bg: #ffffff;
--text-main: #1e293b;
--text-sub: #64748b;
--border-color: #e2e8f0;
--shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
--radius: 12px;
--header-height: 50px;
}
* { box-sizing: border-box; margin: 0; padding: 0; outline: none; }
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
background-color: var(--bg-color);
color: var(--text-main);
display: flex;
flex-direction: column;
align-items: center;
min-height: 100vh;
padding: 20px;
}
header { text-align: center; margin-bottom: 20px; max-width: 800px; }
h1 { font-size: 1.5rem; margin-bottom: 8px; font-weight: 700; color: var(--text-main); }
p.subtitle { color: var(--text-sub); font-size: 0.9rem; line-height: 1.4; }
.app-container {
display: grid;
grid-template-columns: 300px 1fr;
gap: 20px;
width: 100%;
max-width: 1400px;
background: var(--card-bg);
border-radius: var(--radius);
box-shadow: var(--shadow);
overflow: hidden;
height: 85vh;
}
/* Sidebar (Controls) */
.sidebar {
padding: 20px;
background: #f1f5f9;
border-right: 1px solid var(--border-color);
display: flex;
flex-direction: column;
gap: 10px;
overflow-y: auto;
}
.section-title {
font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em;
color: var(--text-sub); font-weight: 700; margin-bottom: 8px;
border-bottom: 1px solid #cbd5e1; padding-bottom: 4px;
}
/* Upload Area */
.upload-area {
border: 2px dashed var(--border-color); border-radius: 8px;
padding: 20px 10px; text-align: center; cursor: pointer;
transition: all 0.2s; background: white; position: relative;
}
.upload-area:hover, .upload-area.drag-over { border-color: var(--primary-color); background: #eff6ff; }
.upload-area input {
position: absolute; top: 0; left: 0; width: 100%; height: 100%;
opacity: 0; cursor: pointer;
}
.upload-icon { font-size: 24px; margin-bottom: 8px; color: var(--primary-color); }
.upload-text { font-size: 0.85rem; color: var(--text-sub); line-height: 1.4; }
/* Buttons */
.btn {
width: 100%; padding: 10px; border: none; border-radius: 8px; font-weight: 600;
cursor: pointer; transition: all 0.2s; font-size: 0.9rem;
display: flex; align-items: center; justify-content: center; gap: 8px;
box-shadow: 0 1px 2px 0 rgb(0 0 0 / 0.05);
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--primary-color); color: white; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: white; border: 1px solid var(--border-color); color: var(--text-main); }
.btn-secondary:hover { background: #f8fafc; border-color: #cbd5e1; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
/* Offset Controls */
.offset-controls {
background: white; padding: 12px; border-radius: 8px;
border: 1px solid var(--border-color); display: flex; flex-direction: column; gap: 8px;
}
.offset-row { display: flex; align-items: center; gap: 8px; }
input[type="range"] { flex: 1; cursor: pointer; accent-color: var(--primary-color); }
input[type="number"] {
width: 70px; padding: 6px; border: 1px solid var(--border-color);
border-radius: 6px; font-size: 0.5rem; text-align: center;
}
.offset-value-text { font-size: 0.7rem; color: var(--text-sub); text-align: right; }
/* Status */
.status-bar { margin-top: auto; padding: 10px; background: #334155; color: white; border-radius: 6px; font-size: 0.8rem; text-align: center; }
/* Right Side Content Area */
.content-area {
position: relative;
display: flex;
flex-direction: column;
background-color: #e2e8f0;
background-image: radial-gradient(#cbd5e1 1px, transparent 1px);
background-size: 20px 20px;
}
/* Top Toolbar / Toggle Bar */
.view-toolbar {
height: var(--header-height);
background: rgba(255, 255, 255, 0.9);
backdrop-filter: blur(8px);
border-bottom: 1px solid var(--border-color);
display: flex;
align-items: center;
padding: 0 20px;
justify-content: space-between;
z-index: 10;
}
.toggle-group {
display: flex;
background: #e2e8f0;
padding: 4px;
border-radius: 8px;
}
.toggle-btn {
padding: 6px 16px;
border: none;
background: transparent;
font-size: 0.85rem;
font-weight: 600;
color: var(--text-sub);
border-radius: 6px;
cursor: pointer;
transition: all 0.2s;
}
.toggle-btn.active {
background: white;
color: var(--primary-color);
box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}
.toggle-btn:hover:not(.active) { color: var(--text-main); }
/* View Layers */
.view-layer {
position: absolute;
top: var(--header-height);
left: 0;
right: 0;
bottom: 0;
display: none;
flex-direction: column;
padding: 20px;
overflow-y: auto;
overflow-x: hidden;
}
.view-layer.active-view { display: flex; }
/* Main Image View */
.image-wrapper {
width: 100%; height: 100%;
display: flex; align-items: center; justify-content: center;
position: relative;
}
.image-wrapper.drag-over-main {
box-shadow: inset 0 0 0 4px var(--primary-color);
background: rgba(59, 130, 246, 0.1);
}
/* 手势方向样式 */
.image-wrapper.drag-over-gesture-ltr {
box-shadow: inset 0 0 0 4px #22c55e !important; /* 绿色 - 还原 */
background: rgba(34, 197, 94, 0.1) !important;
}
.image-wrapper.drag-over-gesture-rtl {
box-shadow: inset 0 0 0 4px #f63b44 !important; /* 红色 - 混淆 */
background: rgba(246, 59, 68, 0.1) !important;
}
.image-wrapper img {
max-width: 100%; max-height: 100%;
box-shadow: 0 20px 25px -5px rgb(0 0 0 / 0.2);
border-radius: 4px;
object-fit: contain;
}
/* Clear Button for Main Image */
.main-clear-btn {
position: absolute; top: 10px; right: 10px;
background: rgba(0,0,0,0.5); color: white;
border: none; width: 32px; height: 32px; border-radius: 50%;
cursor: pointer; display: none; align-items: center; justify-content: center;
z-index: 5; font-size: 18px; font-weight: bold; transition: background 0.2s;
}
.main-clear-btn:hover { background: #ef4444; }
/* 新增:复制按钮样式 */
.main-copy-btn {
position: absolute; top: 10px; right: 50px; /* 在清除按钮左侧 */
background: rgba(0,0,0,0.5); color: white;
border: none; width: 32px; height: 32px; border-radius: 50%;
cursor: pointer; display: none; align-items: center; justify-content: center;
z-index: 5; font-size: 14px; transition: all 0.2s;
}
.main-copy-btn:hover {
background: var(--primary-color);
transform: scale(1.1);
}
.image-wrapper:has(img[src]) .main-clear-btn { display: flex; }
.image-wrapper:has(img[src]) .main-copy-btn { display: flex; }
/* 新增:复制按钮样式 */
.main-paste-btn {
position: absolute; top: 10px; left: 10px; /* 在清除按钮左侧 */
background: rgba(0,0,0,0.5); color: white;
border: none; width: 32px; height: 32px; border-radius: 50%;
cursor: pointer; display: flex; align-items: center; justify-content: center;
z-index: 5; font-size: 14px; transition: all 0.2s;
}
.main-paste-btn:hover {
background: var(--primary-color);
transform: scale(1.1);
}
/* Waterfall View */
.waterfall-container {
position: relative;
width: 100%;
min-height: 100%;
padding-bottom: 40px;
/* 移除 column-count 相关属性 */
}
.waterfall-container.drag-over-waterfall {
background: rgba(59, 130, 246, 0.05);
border-radius: 8px;
border: dashed #7df;
}
@media (max-width: 1200px) { .waterfall-container { column-count: 3; } }
@media (max-width: 800px) { .waterfall-container { column-count: 2; } }
@media (max-width: 500px) { .waterfall-container {
column-count: auto; /* 或 initial */
display: flex;
flex-direction: column;
gap: 15px;
} }
/* Mobile */
@media (max-width: 768px) {
.app-container { grid-template-columns: 1fr; height: auto; }
.sidebar { border-right: none; border-bottom: 1px solid var(--border-color); }
.content-area { height: auto; min-height: 400px; }
.modal-nav-btn { width: 40px; height: 40px; font-size: 18px; }
#modal-prev { left: 10px; }
#modal-next { right: 10px; }
}
.waterfall-card {
position: absolute;
top: 0;
left: 0;
width: calc(25% - 11.25px); /* 默认4列,gap 15px */
background: white;
border-radius: 8px;
box-shadow: 0 2px 4px rgba(0,0,0,0.05);
transition: transform 0.2s, box-shadow 0.2s, top 0.3s, left 0.3s;
border: 1px solid var(--border-color);
cursor: pointer;
break-inside: auto; /* 移除之前的 break-inside */
margin-bottom: 0; /* 由JS控制间距 */
}
/* 响应式列宽 */
@media (max-width: 1200px) {
.waterfall-card { width: calc(33.333% - 10px); } /* 3列 */
}
@media (max-width: 800px) {
.waterfall-card { width: calc(50% - 7.5px); } /* 2列 */
}
@media (max-width: 500px) {
.waterfall-card { width: 100%; } /* 1列 */
}
.waterfall-card:hover {
transform: translateY(-2px);
box-shadow: 0 10px 15px -3px rgba(0,0,0,0.1);
border-color: var(--primary-color);
z-index: 10;
}
/* 为保持圆角效果,在内部子元素添加 overflow */
.waterfall-media {
width: 100%;
background: #f1f5f9;
border-radius: 8px 8px 0 0;
overflow: hidden;
/* 默认最小高度,加载后会被内容撑开 */
min-height: 120px;
}
.waterfall-media img, .waterfall-media video {
width: 100%;
height: auto;
display: block;
}
.waterfall-info {
padding: 10px;
background: white;
border-radius: 0 0 8px 8px;
}
.waterfall-placeholder {
height: 120px;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
background: #f1f5f9;
color: #94a3b8;
font-size: 2rem;
gap: 8px;
}
.waterfall-placeholder-size {
font-size: 12px;
color: #64748b;
font-weight: 500;
}
.waterfall-filename {
font-size: 0.8rem; font-weight: 600; color: var(--text-main);
white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.waterfall-type {
font-size: 0.7rem; color: var(--text-sub); margin-top: 2px;
}
.card-delete-btn {
position: absolute; top: 5px; right: 5px;
background: rgba(0,0,0,0.6); color: white;
border: none; width: 24px; height: 24px; border-radius: 50%;
cursor: pointer; display: flex; align-items: center; justify-content: center;
opacity: 0; transition: opacity 0.2s;
}
.waterfall-card:hover .card-delete-btn { opacity: 1; }
.card-delete-btn:hover { background: #ef4444; }
/* Empty State */
.empty-state {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
/* 保留 flex 用于图标/文本对齐 */
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
color: var(--text-sub);
}
.empty-icon { font-size: 48px; margin-bottom: 10px; opacity: 0.5; }
/* Loading */
.loading-overlay {
position: absolute; top: 0; left: 0; width: 100%; height: 100%;
background: rgba(255,255,255,0.8); z-index: 50;
display: flex; flex-direction: column; align-items: center; justify-content: center;
opacity: 0; pointer-events: none; transition: opacity 0.2s;
}
.loading-overlay.active { opacity: 1; pointer-events: all; }
.spinner { width: 32px; height: 32px; border: 3px solid #e2e8f0; border-top: 3px solid var(--primary-color); border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }
/* Modal */
.modal-overlay {
position: fixed; top: 0; left: 0; width: 100%; height: 100%;
background: rgba(0, 0, 0, 0.9); z-index: 2000;
display: none; align-items: center; justify-content: center; opacity: 0; transition: opacity 0.3s;
}
.modal-overlay.active { display: flex; opacity: 1; }
.modal-content {
width: 100%; height: 100%;
position: relative; display: flex; align-items: center; justify-content: center;
background: black; overflow: hidden;
}
/* Click-to-close layer (z-index: 1, covers everything) */
.modal-click-close-layer {
position: absolute; top: 0; left: 0; width: 100%; height: 100%;
z-index: 1;
}
.modal-body {
width: 100%; height: 100%;
overflow: hidden; display: flex; align-items: center; justify-content: center;
pointer-events: none; /* Let clicks pass to the close layer */
z-index: 2;
}
/* Re-enable pointer events for media content */
.modal-body img, .modal-body video, .modal-body pre {
pointer-events: auto;
max-width: 90%; max-height: 90%; object-fit: contain;
}
.modal-body img, .modal-body video { box-shadow: 0 0 20px rgba(0,0,0,0.5); }
.modal-body pre {
color: #ccc; font-size: 1rem; overflow: auto; white-space: pre-wrap; word-break: break-all;
background: #111; padding: 20px; border-radius: 8px;
}
/* Modal Navigation Buttons */
.modal-nav-btn {
position: absolute; top: 50%; transform: translateY(-50%);
background: rgba(255, 255, 255, 0.1);
border: 1px solid rgba(255, 255, 255, 0.2);
color: white;
font-size: 24px; width: 50px; height: 50px; border-radius: 50%;
cursor: pointer; z-index: 20; display: flex; align-items: center; justify-content: center;
transition: all 0.3s; opacity: 0;
}
.modal-nav-btn:hover { background: rgba(255, 255, 255, 0.3); transform: translateY(-50%) scale(1.1); }
.modal-nav-btn:active { transform: translateY(-50%) scale(0.95); }
.modal-content:hover .modal-nav-btn { opacity: 1; }
#modal-prev { left: 20px; }
#modal-next { right: 20px; }
.modal-close {
position: absolute; top: 20px; right: 30px;
background: rgba(0,0,0,0.5); border: none; width: 44px; height: 44px; border-radius: 50%;
color: white; font-size: 24px; cursor: pointer; z-index: 30; display: flex; align-items: center; justify-content: center;
transition: background 0.2s;
}
.modal-close:hover { background: rgba(255,255,255,0.2); transform: rotate(90deg); }
/* Mobile */
@media (max-width: 768px) {
.app-container { grid-template-columns: 1fr; height: auto; }
.sidebar { border-right: none; border-bottom: 1px solid var(--border-color); }
.content-area { height: 500px; }
.modal-nav-btn { width: 40px; height: 40px; font-size: 18px; }
#modal-prev { left: 10px; }
#modal-next { right: 10px; }
}
</style>
</head>
<body>
<header>
<h1>高级图片混淆与资源管理器</h1>
<p class="subtitle">Gilbert 像素混淆 | 拖拽式全屏瀑布流 | 智能资源打包</p>
</header>
<main class="app-container">
<!-- Sidebar Controls -->
<aside class="sidebar">
<!-- 1. Main File -->
<div>
<div class="section-title">1. 主文件 (图片/视频)</div>
<div class="upload-area" id="drop-zone">
<input type="file" id="file-input" accept="image/*,video/*">
<div class="upload-icon">📁</div>
<div class="upload-text">拖入主图片或视频<br><span style="font-size:0.75em; opacity:0.7">视频自动取第一帧</span></div>
</div>
</div>
<!-- 2. Offset Control -->
<div>
<div class="section-title">2. 偏移设置</div>
<div class="offset-controls">
<div class="offset-row">
<input type="range" id="offset-slider" min="0" max="100" value="62" disabled>
<input type="number" id="offset-input" value="0" disabled>
</div>
<div class="offset-value-text" id="offset-display">计算中...</div>
</div>
</div>
<!-- 3. Operations -->
<div>
<div class="section-title">3. 核心操作</div>
<div style="display: flex; flex-direction: column; gap: 10px;">
<button id="btn-encrypt" class="btn btn-primary" disabled>🔒 混淆图片</button>
<button id="btn-decrypt" class="btn btn-secondary" disabled>🔓 还原图片</button>
<button id="btn-download" class="btn btn-secondary" disabled>⬇️ 下载结果 (含资源)</button>
</div>
</div>
<!-- 在核心操作后面添加 -->
<div style="margin-top: 15px; padding-top: 15px; border-top: 1px solid var(--border-color);">
<label style="display: flex; align-items: center; gap: 8px; font-size: 0.85rem; cursor: pointer; user-select: none; margin-bottom: 6px;">
<input type="checkbox" id="gesture-toggle" style="width: 16px; height: 16px; accent-color: var(--primary-color);">
<span style="font-weight: 600;">使用鼠标手势拖拽</span>
</label>
<div style="font-size: 0.75rem; color: var(--text-sub); padding-left: 24px; line-height: 1.5; background: rgba(59, 130, 246, 0.05); padding: 8px; border-radius: 6px; margin-top: 4px;">
<span style="color: #22c55e; font-weight: 600;">左→右(绿色):</span>自动还原<br>
<span style="color: #f63b44; font-weight: 600;">右→左(红色):</span>自动混淆
</div>
<label style="display: flex; align-items: center; gap: 8px; font-size: 0.85rem; cursor: pointer; user-select: none; margin-bottom: 6px;">
<input type="checkbox" id="autocopy" style="width: 16px; height: 16px; accent-color: var(--primary-color);">
<span style="font-weight: 600;">混淆/还原后自动复制</span>
</label>
</div>
<!-- 4. Add Resource Button -->
<div>
<div class="section-title">4. 资源管理</div>
<label class="btn btn-secondary" style="position: relative;">
<span>+ 上传资源文件</span>
<input type="file" id="attachment-input" multiple style="position: absolute; inset: 0; opacity: 0; cursor: pointer;">
</label>
</div>
<div class="status-bar" id="status-bar">
<span id="busuanzi_container_site_pv">就绪><span id="busuanzi_value_site_pv"></span><</span>
</div>
</aside>
<!-- Right Content Area -->
<section class="content-area">
<!-- Loading Overlay -->
<div class="loading-overlay" id="loading">
<div class="spinner"></div>
<p style="margin-top: 10px; color: #64748b; font-weight: 500;">处理中...</p>
</div>
<!-- Toolbar -->
<div class="view-toolbar">
<div class="toggle-group">
<button class="toggle-btn active" data-target="view-main">主图片预览</button>
<button class="toggle-btn" data-target="view-resources">资源瀑布流</button>
</div>
</div>
<!-- View 1: Main Image -->
<div id="view-main" class="view-layer active-view">
<div class="image-wrapper" id="img-wrapper">
<button class="main-clear-btn" id="main-clear-btn" title="清空图片">×</button>
<button class="main-copy-btn" id="main-copy-btn" title="复制图片到剪贴板(不带资源)">📋</button>
<button class="main-paste-btn" id="main-paste-btn" title="粘贴图片到主窗口">🖼️</button>
<img id="display-img" alt="Main Image" style="display: none;">
<div id="main-placeholder" class="empty-state">
<div class="empty-icon">🖼️</div>
<div>拖入\粘贴图片或视频到此处</div>
</div>
</div>
</div>
<!-- View 2: Resources Waterfall -->
<div id="view-resources" class="view-layer">
<div id="waterfall-container" class="waterfall-container">
<!-- Dynamic Content -->
</div>
<div id="res-placeholder" class="empty-state">
<div class="empty-icon">📂</div>
<div>拖拽\粘贴文件到此处添加资源<br>或使用左侧 "上传资源文件"</div>
</div>
</div>
</section>
</main>
<!-- Modal -->
<div class="modal-overlay" id="modal-overlay">
<div class="modal-content">
<button class="modal-close" id="modal-close">×</button>
<div class="modal-click-close-layer" id="modal-click-close-layer" title="点击关闭"></div>
<button class="modal-nav-btn" id="modal-prev"><</button>
<button class="modal-nav-btn" id="modal-next">></button>
<div class="modal-body" id="modal-body"></div>
</div>
</div>
<script>
/**
* 高性能瀑布流实现 - 修复版
* 完整支持:图片、视频、对象文件(.7z等)、文本文件
*/
/**
* 高性能瀑布流实现 - 修复版
* 修复内容:
* 1. 修复删除卡片后瀑布流布局不更新的问题(确保DOM移除后重新布局)
* 2. 保持下载按钮调用外部 downloadAttachment 函数
*/
/**
* 高性能瀑布流实现 - 修复版
* 修复内容:
* 1. 修复删除卡片后瀑布流布局不更新的问题(关键:立即从数组移除并重新布局)
* 2. 保持下载按钮调用外部 downloadAttachment 函数
* 3. 修复删除按钮事件绑定,使用 handleDelete 分离外部回调和UI删除
*/
class HighPerformanceWaterfall {
constructor(container, options = {}) {
this.container = container;
this.columnCount = options.columnCount || 4;
this.gap = options.gap || 16;
this.cards = [];
this.visibleCards = new Set();
this.cardDataMap = new Map();
this.resizeObserver = null;
this.intersectionObserver = null;
this.columnHeights = [];
this.placeholderHeight = options.placeholderHeight || 200;
this.loadThreshold = options.loadThreshold || 0.1;
this.playThreshold = options.playThreshold || 0.6;
this.init();
}
// 获取文件图标
getFileIcon(type) {
if (type === 'image') return '🖼️';
if (type === 'video') return '🎬';
if (type === 'object') return '📦';
if (type === 'text') return '📄';
return '📎';
}
// 获取文件类型显示名称
getFileTypeLabel(type, mime) {
if (type === 'image') return 'IMAGE';
if (type === 'video') return 'VIDEO';
if (type === 'object') {
if (mime && mime !== 'app/octet-stream') {
const ext = mime.split('/').pop();
if (ext && ext.length < 10) return ext.toUpperCase();
}
return 'FILE';
}
if (type === 'text') return 'TEXT';
return 'FILE';
}
init() {
this.resizeObserver = new ResizeObserver(entries => {
requestAnimationFrame(() => this.handleResize());
});
this.resizeObserver.observe(this.container);
this.intersectionObserver = new IntersectionObserver(
(entries) => this.handleIntersection(entries),
{
root: null,
rootMargin: '100px',
threshold: [0, 0.1, 0.5, 0.6, 1]
}
);
this.updateColumnCount();
}
updateColumnCount() {
const width = this.container.clientWidth;
if (width <= 500) this.columnCount = 1;
else if (width <= 800) this.columnCount = 2;
else if (width <= 1200) this.columnCount = 3;
else this.columnCount = 4;
this.calculateLayout();
}
handleResize() {
const oldCount = this.columnCount;
this.updateColumnCount();
if (oldCount !== this.columnCount) {
this.reflowAll();
} else {
this.updateCardWidths();
}
}
calculateLayout() {
const containerWidth = this.container.clientWidth;
const totalGap = (this.columnCount - 1) * this.gap;
this.columnWidth = (containerWidth - totalGap) / this.columnCount;
this.columnHeights = new Array(this.columnCount).fill(0);
}
addCard(data) {
this.cardDataMap.set(data.id, data);
const card = this.createCardElement(data);
this.cards.push(card);
this.container.appendChild(card);
// 非媒体文件直接显示内容,不需要懒加载
if (data.type !== 'image' && data.type !== 'video') {
this.renderFileCard(card, data);
} else {
// 媒体文件先使用占位符高度
const aspectRatio = data.aspectRatio || 0;
const initialHeight = aspectRatio > 0
? this.columnWidth / aspectRatio
: this.placeholderHeight;
this.positionCard(card, initialHeight);
}
this.intersectionObserver.observe(card);
return card;
}
createCardElement(data) {
const card = document.createElement('div');
card.className = 'waterfall-card';
card.dataset.id = data.id;
card.dataset.type = data.type;
card.dataset.loaded = 'false';
card.dataset.index = data.index;
card.style.cssText = `
position: absolute;
width: ${this.columnWidth}px;
left: 0;
top: 0;
transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
will-change: transform;
contain: layout style paint;
`;
const sizeText = data.size ? `${(data.size / 1024).toFixed(1)}KB` : '';
const icon = this.getFileIcon(data.type);
const typeLabel = this.getFileTypeLabel(data.type, data.mime);
// 根据类型设置初始高度
const isMedia = data.type === 'image' || data.type === 'video';
const initialHeight = isMedia
? (data.aspectRatio > 0 ? this.columnWidth / data.aspectRatio : this.placeholderHeight)
: 160; // 固定高度给文件卡片
card.dataset.expectedHeight = initialHeight;
card.innerHTML = `
<div class="card-inner" style="
background: #f8fafc;
border-radius: 8px;
overflow: hidden;
box-shadow: 0 1px 3px rgba(0,0,0,0.1);
height: ${initialHeight}px;
position: relative;
transition: all 0.3s ease;
">
<!-- 占位符层 -->
<div class="card-placeholder" style="
position: absolute;
inset: 0;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
color: #94a3b8;
background: linear-gradient(135deg, #f1f5f9 0%, #e2e8f0 100%);
z-index: 1;
">
<div style="font-size: 2.5rem; margin-bottom: 4px;">${icon}</div>
<div style="font-size: 0.75rem; font-weight: 500;">${sizeText}</div>
<div style="font-size: 0.65rem; margin-top: 2px; opacity: 0.7;">${typeLabel}</div>
</div>
<!-- 媒体/内容层 -->
<div class="card-media" style="
position: absolute;
inset: 0;
opacity: 0;
transition: opacity 0.4s ease;
z-index: 2;
"></div>
<!-- 信息覆盖层 -->
<div class="card-overlay" style="
position: absolute;
bottom: 0;
left: 0;
right: 0;
padding: 12px;
background: linear-gradient(to top, rgba(0,0,0,0.85) 0%, rgba(0,0,0,0.4) 60%, transparent);
color: white;
font-size: 0.8rem;
opacity: 0;
transition: opacity 0.3s;
pointer-events: none;
z-index: 3;
">
<div style="font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-shadow: 0 1px 2px rgba(0,0,0,0.3);">
${data.filename}
</div>
<div style="font-size: 0.7rem; opacity: 0.9; margin-top: 3px; display: flex; align-items: center; gap: 6px;">
<span style="background: rgba(255,255,255,0.2); padding: 1px 6px; border-radius: 4px; font-size: 0.65rem;">${typeLabel}</span>
<span>${sizeText}</span>
</div>
</div>
<!-- 操作按钮 -->
<button class="card-action card-delete" style="
position: absolute;
top: 8px;
right: 8px;
width: 28px;
height: 28px;
border-radius: 50%;
background: rgba(0,0,0,0.6);
color: white;
border: none;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
opacity: 0;
transition: all 0.2s;
font-size: 18px;
z-index: 10;
backdrop-filter: blur(4px);
">×</button>
<button class="card-action card-download" style="
position: absolute;
top: 8px;
right: 40px;
width: 28px;
height: 28px;
border-radius: 50%;
background: rgba(0,0,0,0.6);
color: white;
border: none;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
opacity: 0;
transition: all 0.2s;
font-size: 12px;
z-index: 10;
backdrop-filter: blur(4px);
">⬇</button>
</div>
`;
// 悬停交互
const inner = card.querySelector('.card-inner');
const overlay = card.querySelector('.card-overlay');
const actions = card.querySelectorAll('.card-action');
card.addEventListener('mouseenter', () => {
overlay.style.opacity = '1';
actions.forEach(btn => btn.style.opacity = '1');
inner.style.transform = 'translateY(-4px)';
inner.style.boxShadow = '0 20px 25px -5px rgba(0,0,0,0.15)';
});
card.addEventListener('mouseleave', () => {
overlay.style.opacity = '0';
actions.forEach(btn => btn.style.opacity = '0');
inner.style.transform = '';
inner.style.boxShadow = '';
});
// 事件绑定 - 删除按钮(关键修复:使用箭头函数保持this上下文)
const deleteBtn = card.querySelector('.card-delete');
deleteBtn.onclick = (e) => {
e.stopPropagation();
e.preventDefault();
console.log('[Waterfall] Delete button clicked for:', data.id);
this.handleDelete(card, data);
};
// 事件绑定 - 下载按钮(调用外部 downloadAttachment 函数)
const downloadBtn = card.querySelector('.card-download');
downloadBtn.onmouseenter = () => {
downloadBtn.style.background = '#3b82f6';
};
downloadBtn.onmouseleave = () => {
downloadBtn.style.background = 'rgba(0,0,0,0.6)';
};
downloadBtn.onclick = (e) => {
e.stopPropagation();
e.preventDefault();
console.log('[Waterfall] Download button clicked for:', data.id);
// 调用外部的 downloadAttachment 函数,传入附件数据
if (typeof downloadAttachment === 'function') {
downloadAttachment(data);
} else if (data.onDownload) {
data.onDownload(data);
} else {
console.warn('[Waterfall] downloadAttachment function not found');
}
};
card.onclick = () => {
if (data.onClick) data.onClick(data);
};
return card;
}
/**
* 关键修复:处理删除操作
* 分离外部回调和UI删除,确保无论外部回调如何都会删除UI
*/
handleDelete(card, data) {
console.log('[Waterfall] handleDelete called for:', data.id, data.filename);
// 先调用外部回调(如果存在),但不依赖它来删除UI
if (data.onDelete) {
try {
data.onDelete(data);
console.log('[Waterfall] External onDelete executed');
} catch (err) {
console.error('[Waterfall] onDelete callback error:', err);
}
}
// 立即执行UI删除(关键:不等待外部回调)
console.log('[Waterfall] Calling removeCard for UI update');
this.removeCard(card);
}
// 专门处理非媒体文件(.7z, .txt 等)
renderFileCard(card, data) {
card.dataset.loaded = 'true';
const mediaContainer = card.querySelector('.card-media');
const placeholder = card.querySelector('.card-placeholder');
const inner = card.querySelector('.card-inner');
const fileIcon = this.getFileIcon(data.type);
const fileType = this.getFileTypeLabel(data.type, data.mime);
const sizeText = data.size ? `${(data.size / 1024).toFixed(1)} KB` : '';
// 文件卡片内容 - 大号图标 + 文件名
mediaContainer.innerHTML = `
<div style="
width: 100%;
height: 100%;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
background: linear-gradient(135deg, #f1f5f9 0%, #e2e8f0 100%);
color: #475569;
text-align: center;
padding: 16px;
box-sizing: border-box;
gap: 8px;
">
<div style="font-size: 3.5rem; filter: grayscale(0.2);">${fileIcon}</div>
<div style="
font-size: 0.85rem;
font-weight: 600;
color: #1e293b;
max-width: 100%;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
padding: 0 4px;
line-height: 1.3;
" title="${data.filename}">
${data.filename}
</div>
<div style="
display: flex;
align-items: center;
gap: 6px;
font-size: 0.7rem;
color: #64748b;
margin-top: 2px;
">
<span style="
background: #cbd5e1;
color: #475569;
padding: 2px 8px;
border-radius: 4px;
font-weight: 600;
font-size: 0.65rem;
text-transform: uppercase;
">${fileType}</span>
<span>${sizeText}</span>
</div>
</div>
`;
// 固定高度
const fileHeight = 160;
inner.style.height = `${fileHeight}px`;
card.dataset.expectedHeight = fileHeight;
// 直接显示,无需渐显(因为不需要加载时间)
mediaContainer.style.opacity = '1';
placeholder.style.display = 'none';