-
Notifications
You must be signed in to change notification settings - Fork 312
Expand file tree
/
Copy pathindex.html
More file actions
6604 lines (5923 loc) · 290 KB
/
index.html
File metadata and controls
6604 lines (5923 loc) · 290 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>
<script src="./static/tailwindcss.js"></script>
<script src="./static/xlsx.full.min.js"></script>
<script src="./static/crypto-js.min.js"></script>
<link href="./static/mermaid.min.css" rel="stylesheet" />
<link href="./static/remixicon.css" rel="stylesheet" />
<script src="./static/gridjs.umd.js"></script>
<script src="./static/pdf-lib.min.js"></script>
<script src="./static/fontkit.umd.min.js"></script>
<script src="./static/GiftListPDFGenerator.js"></script>
<link rel="preload" href="./static/bg.jpg" as="image" type="image/jpeg" />
<link rel="preload" href="./static/cover1.jpg" as="image" type="image/jpeg" />
<link rel="preload" href="./static/cover2.jpg" as="image" type="image/jpeg" />
<style>
/* ==================== 字体定义 ==================== */
@font-face {
font-family: "Source Han Serif CN Heavy";
src: url("./static/SourceHanSerifCN-Heavy.ttf") format("truetype");
font-weight: 900;
font-style: normal;
font-display: swap;
}
/* ==================== 主题变量 ==================== */
:root,
.theme-festive {
--primary-color: #c00;
--primary-color-hover: #a00;
--primary-text-color: #c00;
--primary-bg-light: #fff2f2;
--primary-border-color: #ffaaaa;
--primary-ring-color: #ef4444;
--header-text-color: #b91c1c;
--button-bg-color: #dc2626;
--button-bg-hover: #b91c1c;
--button-border-color: #dc2626;
--button-text-color: #dc2626;
--link-hover-bg: #fee2e2;
--total-text-color: #ef4444;
/* 默认自定义变量 */
--name-font-size: var(--custom-name-size, 25px);
--name-color: var(--custom-name-color, #333);
--name-font-family: var(--custom-name-font, "KaiTi", "楷体", serif);
--type-font-size: var(--custom-type-size, 22px);
--type-color: var(--custom-type-color, #c00);
--type-font-family: var(--custom-type-font, "Source Han Serif CN Heavy", serif);
--amount-chinese-font-size: var(--custom-amount-chinese-size, 25px);
--amount-chinese-color: var(--custom-amount-chinese-color, #333);
--amount-chinese-font-family: var(--custom-amount-chinese-font, "KaiTi", "楷体", serif);
--cover-text-font-size: var(--custom-cover-text-size, 30px);
--cover-text-color: var(--custom-cover-text-color, #f5d4ab);
--cover-text-font-family: var(--custom-cover-text-font, "KaiTi", "楷体", serif);
--page-info-color: var(--custom-page-info-color, var(--primary-color));
--page-info-font-family: var(--custom-page-info-font, inherit);
}
.theme-solemn {
--primary-color: #374151;
--primary-color-hover: #1f2937;
--primary-text-color: #111827;
--primary-bg-light: #f3f4f6;
--primary-border-color: #d1d5db;
--primary-ring-color: #4b5563;
--header-text-color: #1f2937;
--button-bg-color: #4b5563;
--button-bg-hover: #374151;
--button-border-color: #4b5563;
--button-text-color: #4b5563;
--link-hover-bg: #e5e7eb;
--total-text-color: #374151;
--type-color: var(--custom-type-color, #374151);
}
/* ==================== 基础样式 ==================== */
body {
font-family: "Inter", "Microsoft YaHei", sans-serif;
}
/* ==================== 礼簿样式 (屏幕显示) ==================== */
.gift-book-frame {
border: 4px solid var(--primary-color);
padding: 22px;
border-radius: 10px;
background-color: var(--primary-bg-light);
position: relative;
display: grid;
grid-template-rows: auto 1fr;
height: 100%;
cursor: default;
min-height: 450px;
}
#gift-book-content {
display: grid;
grid-template-rows: 3fr 1fr 3fr;
border-top: 2px solid var(--primary-border-color);
min-height: 0;
}
.print-book-content {
display: flex;
flex-direction: column;
border-top: 2px solid var(--primary-border-color);
flex: 1;
}
.print-book-content > .gift-book-row:first-child,
.print-book-content > .gift-book-row:last-child {
flex: 1;
min-height: 0;
}
.gift-book-row {
width: 100%;
display: grid;
grid-template-columns: repeat(var(--gift-grid-columns, 12), minmax(0, 1fr));
}
.gift-book-row:nth-child(1),
.gift-book-row:nth-child(3) {
min-height: 33.3%;
}
.gift-book-row > .book-cell {
min-width: 0;
position: relative;
line-height: 1.2;
}
.book-cell {
border-right: 2px solid var(--primary-border-color);
border-bottom: 2px solid var(--primary-border-color);
display: grid;
place-items: center;
writing-mode: vertical-lr;
text-orientation: mixed;
font-weight: bold;
font-size: clamp(16px, 1.6vw, 25px);
letter-spacing: 7px;
font-family: "KaiTi", "楷体", serif;
padding: 10px 0;
overflow: hidden;
text-align: center;
}
.book-cell:first-child {
border-left: 2px solid var(--primary-border-color);
}
.book-cell:hover {
background-color: var(--link-hover-bg);
}
.name-cell .name {
color: var(--name-color);
padding: 15px 0;
cursor: pointer;
text-align: center;
white-space: nowrap;
min-height: 8em;
font-size: var(--name-font-size);
font-family: var(--name-font-family);
}
.type-cell {
color: var(--type-color);
font-size: var(--type-font-size);
padding: 10px 4px;
font-family: var(--type-font-family);
font-weight: bold;
}
.amount-cell {
color: #333;
cursor: pointer;
grid-template-columns: 1fr auto;
column-gap: clamp(8px, 1.5vw, 18px);
justify-content: center;
}
.amount-chinese {
letter-spacing: 1.5px;
text-align: center;
padding: 15px 0;
flex: 1;
overflow: hidden;
font-size: var(--amount-chinese-font-size);
color: var(--amount-chinese-color);
font-family: var(--amount-chinese-font-family);
}
.amount-numeric {
color: #555;
letter-spacing: 1px;
writing-mode: horizontal-tb;
line-height: 3;
font-size: clamp(10px, 1.3vw, 14px);
}
.mark {
font-size: clamp(10px, 1.3vw, 14px);
letter-spacing: 1px;
color: var(--primary-color);
white-space: nowrap;
line-height: 1.2;
height: 2.5em;
display: flex;
flex-direction: column;
justify-content: center;
position: absolute;
bottom: 1vw;
writing-mode: lr;
}
/* ==================== 主题组件 ==================== */
.themed-edit-area {
background-color: var(--primary-bg-light);
border: 1px solid var(--primary-border-color);
padding: 1rem;
border-radius: 0.5rem;
width: 100%;
}
input[type="checkbox"] {
accent-color: var(--button-bg-color);
}
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
-webkit-appearance: none;
margin: 0;
}
input[type="number"] {
-moz-appearance: textfield;
}
.themed-header {
color: var(--header-text-color);
}
.themed-button-primary {
background-color: var(--button-bg-color);
color: white;
}
.themed-button-primary:hover {
background-color: var(--button-bg-hover);
}
.themed-button-secondary {
border-color: var(--button-border-color);
color: var(--button-text-color);
}
.themed-button-secondary:hover {
background-color: var(--link-hover-bg);
}
.themed-ring:focus {
--tw-ring-color: var(--primary-ring-color) !important;
}
.themed-text-radio {
color: var(--button-text-color);
}
.themed-peer-checked {
--tw-bg-opacity: 1;
background-color: var(--button-bg-color);
}
.themed-text {
color: var(--total-text-color);
}
.themed-link-hover:hover {
background-color: var(--link-hover-bg);
}
.themed-dropdown-text {
color: var(--primary-text-color);
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
.themed-dropdown-text:hover {
color: var(--primary-color-hover);
}
.peer:checked ~ .toggle-bg {
background-color: var(--button-bg-color);
}
.remark-preset-btn.themed-button-primary {
background-color: var(--primary-bg-light);
color: var(--primary-text-color);
}
/* ==================== 弹窗和打印容器 ==================== */
#modal {
display: flex;
flex-direction: column;
max-height: 90vh;
margin: 0 10px;
position: relative;
}
#modal-content {
flex: 1;
overflow-y: auto;
padding-right: 0.5rem;
}
#modal-close-btn {
position: absolute;
top: 0.75rem;
right: 0.75rem;
color: #9ca3af;
transition: color 0.2s ease-in-out;
}
#modal-close-btn:hover,
#modal-close-btn:focus {
color: #4b5563;
}
#modal-close-btn:focus-visible {
outline: 2px solid var(--primary-ring-color);
outline-offset: 2px;
}
body.printing #app-container {
display: none;
}
#modal.modal-large {
max-width: 1200px;
width: 95vw;
}
td.gridjs-td,
th.gridjs-th {
padding: 6px;
}
#print-view {
visibility: hidden;
}
/* ==================== 缩放样式 ==================== */
.amount-chinese.scale,
.name.scale {
font-size: 14pt;
letter-spacing: -2px;
padding: 5px 0;
}
.amount-numeric.scale {
letter-spacing: 0.5px;
writing-mode: vertical-rl;
}
/* ==================== 响应式 ==================== */
@media (max-width: 700px) {
.amount-numeric,
.mark {
position: relative;
writing-mode: vertical-rl;
}
.gridjs-wrapper {
overflow-x: auto;
height: 30vh !important;
}
}
/* ==================== 打印样式 ==================== */
@media print {
:root {
/* 打印物理尺寸设置 */
--print-page-width: 210mm;
--print-page-height: 297mm;
--print-content-height: 188mm;
--print-padding-top: 9mm;
--print-padding-side: 9.5mm;
--print-footer-bottom: 12px;
--print-theme-color: var(--custom-print-theme-color, #ec403c);
--print-base-color: var(--custom-print-base-color, #1f2937);
--print-base-font: var(--custom-print-base-font, "KaiTi", "楷体", serif);
}
/* 页面重置 */
@page {
size: var(--print-page-height) var(--print-page-width);
margin: 0;
}
/* 隐藏屏幕元素,显示打印视图 */
body * {
visibility: hidden;
}
#print-view,
#print-view * {
visibility: visible;
}
#print-view {
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
}
/* --- 容器与背景 --- */
/* 外框:统一使用主题色 */
.gift-book-frame {
background-color: transparent;
border-color: var(--print-theme-color) !important;
}
.print-page {
page-break-after: always;
width: 100%;
height: 100%;
padding: var(--print-padding-top) var(--print-padding-side) 0;
box-sizing: border-box;
display: flex;
flex-direction: column;
background: var(--custom-bg-image, url("./static/bg.jpg")) center/contain no-repeat, var(--primary-bg-light);
overflow: hidden;
position: relative;
font-family: var(--print-base-font);
color: var(--print-base-color);
-webkit-print-color-adjust: exact;
print-color-adjust: exact;
}
/* --- 封面页 --- */
.print-cover-page {
padding: 0;
background: none;
justify-content: center;
align-items: center;
}
.print-cover {
display: flex;
flex-direction: column;
justify-content: flex-end;
align-items: center;
text-align: center;
width: 100%;
height: 100%;
background: var(--custom-cover-image, url("./static/cover1.jpg")) center/contain no-repeat, var(--primary-bg-light);
/* 封面独立变量 */
color: var(--cover-text-color);
font-family: var(--cover-text-font-family);
padding-bottom: 20mm;
box-sizing: border-box;
position: relative;
}
.print-cover p {
font-size: var(--cover-text-font-size);
letter-spacing: 4px;
}
/* --- 礼簿表格核心样式 --- */
.book-cell {
font-size: 18pt !important;
border-color: var(--print-theme-color) !important; /* 边框跟随主题色 */
font-family: var(--print-base-font) !important; /* 字体跟随基础设置 */
color: var(--print-base-color); /* 颜色跟随基础设置 */
}
.type-cell {
color: var(--custom-type-color, var(--type-color)) !important;
font-family: var(--custom-type-font, var(--type-font-family)) !important;
font-size: var(--custom-type-size, 18pt) !important;
font-weight: bold;
}
.name-cell .name {
color: var(--custom-name-color, var(--name-color)) !important;
font-family: var(--custom-name-font, var(--name-font-family)) !important;
font-size: var(--custom-name-size, 18pt) !important;
padding: 0;
}
.name-cell:hover {
background-color: transparent;
}
.amount-chinese {
color: var(--custom-amount-chinese-color, var(--amount-chinese-color)) !important;
font-family: var(--custom-amount-chinese-font, var(--amount-chinese-font-family)) !important;
font-size: var(--custom-amount-chinese-size, 18pt) !important;
}
.amount-numeric {
display: block;
color: var(--print-base-color, #333) !important;
}
.print-book-content {
border-top-color: var(--print-theme-color) !important;
height: var(--print-content-height) !important;
flex: none !important;
overflow: hidden !important;
}
/* --- 页头与页脚 --- */
.print-header {
text-align: center;
margin: 35px 0 0;
color: var(--print-theme-color);
font-family: var(--print-base-font);
font-weight: bold;
font-size: 38px;
}
.print-footer {
flex: 1;
display: flex;
justify-content: space-between;
align-items: flex-end;
font-size: 17px;
padding: 0 0 var(--print-footer-bottom);
color: var(--print-base-color);
font-family: var(--print-base-font);
margin-top: auto;
}
.print-footer p {
margin: 3px 0;
flex: 1;
}
.print-footer-totals {
flex: 1;
text-align: right;
}
.print-footer .total-amount-print {
font-weight: bold;
}
.print-footer-totals .total-amount-print:not(:last-child) {
margin-right: 25px;
}
.print-page-number {
text-align: center;
}
/* --- 附录表格样式 --- */
.print-appendix-table {
width: 90%;
margin: 20px auto 0 auto;
text-align: center;
box-sizing: border-box;
line-height: 4.5em;
}
.print-appendix-table th,
.print-appendix-table td {
border: 2px solid var(--print-theme-color);
padding: 8px;
word-break: break-word;
font-family: var(--print-base-font);
font-weight: bold;
letter-spacing: 2px;
}
#print-view .print-appendix-table th {
color: var(--print-theme-color);
text-align: center !important;
}
/* 附录内容:基础字色 */
#print-view .print-appendix-table td {
color: var(--print-base-color);
}
.print-appendix-table th:nth-child(3) {
width: 60%;
}
/* 兼容性与杂项 */
.theme-solemn #print-view {
filter: grayscale(100%);
}
.mark {
display: none;
}
}
</style>
</head>
<body class="bg-gray-100 flex items-center justify-center min-h-screen theme-festive">
<div id="app-container" class="w-full max-w-7xl mx-auto p-4">
<!-- 设置界面 -->
<div id="setup-screen" class="bg-white p-8 rounded-lg shadow-xl max-w-2xl mx-auto hidden">
<h1 class="text-3xl font-bold text-center themed-header mb-6">电子礼簿系统</h1>
<div id="select-event-section" class="mb-8 hidden">
<h2 class="text-xl font-semibold mb-4 border-b pb-2">选择事项</h2>
<div class="flex items-center space-x-4">
<select id="event-selector" class="flex-1 p-3 border rounded-lg focus:ring-2 themed-ring">
<option value="">请选择一个事项</option>
</select>
<button id="unlock-event-btn" class="themed-button-primary px-6 py-3 rounded-lg transition duration-300">进入</button>
</div>
</div>
<div>
<h2 class="text-xl font-semibold mb-4 border-b pb-2"><span id="or-text">或 </span>创建新事项</h2>
<form id="create-event-form" class="space-y-4">
<input type="text" id="event-name" placeholder="事项名称 (例如: 张三李四新婚之喜)" required class="w-full p-3 border rounded-lg focus:ring-2 themed-ring" />
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
<div>
<label class="block text-sm font-medium text-gray-700">开始时间</label>
<div class="flex gap-2">
<input type="date" id="start-date" required class="w-full p-3 border rounded-lg focus:ring-2 themed-ring" />
<input type="time" id="start-time" required class="w-full p-3 border rounded-lg focus:ring-2 themed-ring" />
</div>
</div>
<div>
<label class="block text-sm font-medium text-gray-700">结束时间</label>
<div class="flex gap-2">
<input type="date" id="end-date" required class="w-full p-3 border rounded-lg focus:ring-2 themed-ring" />
<input type="time" id="end-time" required class="w-full p-3 border rounded-lg focus:ring-2 themed-ring" />
</div>
</div>
</div>
<input type="text" id="admin-password" placeholder="设置管理密码 (请牢记)" required class="w-full p-3 border rounded-lg focus:ring-2 themed-ring" />
<details class="group">
<summary class="cursor-pointer text-sm font-medium text-gray-600 group-hover:text-gray-900 list-none">
<div class="flex items-center">
<span>更多设置</span>
<i class="ri-arrow-down-s-line text-lg ml-1 transition-transform transform group-open:rotate-180"></i>
</div>
</summary>
<div class="mt-4 p-4 bg-gray-50 rounded-lg border">
<div>
<label for="event-theme" class="block text-sm font-medium text-gray-700">界面风格</label>
<select id="event-theme" class="mt-1 w-full p-3 border rounded-lg focus:ring-2 themed-ring">
<option value="theme-festive" selected>喜庆红 (喜事)</option>
<option value="theme-solemn">肃穆灰 (白事)</option>
</select>
<p class="text-xs text-gray-500 mt-2">为不同性质的事项选择合适的界面配色风格。</p>
</div>
<div class="mt-4">
<label for="event-voice" class="block text-sm font-medium text-gray-700">语音播报音色</label>
<div class="flex items-center gap-2 mt-1">
<select id="event-voice" class="text-sm flex-grow w-full p-3 border rounded-lg focus:ring-2 themed-ring">
<option value="">默认音色</option>
</select>
<button type="button" id="preview-create-voice-btn" class="themed-button-secondary border p-3 rounded-lg whitespace-nowrap text-xl"><i class="ri-volume-up-line"></i> 预览</button>
</div>
<p class="text-xs text-gray-500 mt-2">选择一个喜欢的播报声音。</p>
</div>
<div class="mt-4">
<label class="block text-sm font-medium text-gray-700">记账人</label>
<input type="text" id="event-recorder" placeholder="记账人 (例如: 王五,选填)" class="w-full mt-1 p-3 border rounded-lg focus:ring-2 themed-ring" />
</div>
</div>
</details>
<button type="submit" class="w-full themed-button-primary p-3 rounded-lg transition duration-300 font-bold">创建并进入</button>
</form>
</div>
</div>
<!-- 主界面 -->
<div id="main-screen" class="hidden">
<div class="flex justify-between items-center mb-4">
<div class="flex items-center gap-4">
<div class="relative">
<div id="event-switcher-trigger" class="flex items-center gap-2 cursor-pointer group">
<h1 id="current-event-title" class="text-2xl font-bold themed-dropdown-text max-sm:text-2xl"></h1>
<i class="ri-arrow-down-s-line text-2xl themed-dropdown-text"></i>
</div>
<div id="event-dropdown" class="absolute top-full left-0 mt-2 w-72 bg-white rounded-md shadow-lg z-10 hidden"></div>
</div>
</div>
</div>
<div class="grid grid-cols-1 lg:grid-cols-3 gap-6">
<!-- 左侧录入区 -->
<div class="lg:col-span-1 bg-white p-6 rounded-lg shadow-lg">
<h2 class="text-2xl font-bold mb-4 text-center border-b pb-2">礼金录入</h2>
<form id="add-gift-form" class="space-y-4">
<input type="text" id="guest-name" placeholder="姓名" required class="w-full p-3 border rounded-lg focus:ring-2 themed-ring" />
<input type="number" id="gift-amount" placeholder="金额 (元)" required min="0" max="999999999999" step="0.01" class="w-full p-3 border rounded-lg focus:ring-2 themed-ring" />
<div class="flex flex-wrap items-center gap-x-2 gap-y-2">
<label class="text-sm font-medium text-gray-700 whitespace-nowrap">收款类型:</label>
<div class="flex flex-wrap gap-x-3 gap-y-2">
<label class="flex items-center space-x-2 cursor-pointer"><input type="radio" name="payment-type" value="现金" class="themed-text-radio themed-ring" checked /><span>现金</span></label>
<label class="flex items-center space-x-2 cursor-pointer"><input type="radio" name="payment-type" value="微信" class="themed-text-radio themed-ring" /><span>微信</span></label>
<label class="flex items-center space-x-2 cursor-pointer"><input type="radio" name="payment-type" value="支付宝" class="themed-text-radio themed-ring" /><span>支付宝</span></label>
<label class="flex items-center space-x-2 cursor-pointer"><input type="radio" name="payment-type" value="其他" class="themed-text-radio themed-ring" /><span>其他</span></label>
</div>
</div>
<textarea id="guest-remark-custom" class="w-full p-3 border rounded-lg focus:ring-2 themed-ring" rows="2" placeholder="备注内容(选填)" data-remark-type="custom"></textarea>
<div class="flex flex-wrap items-center gap-x-1 gap-y-2">
<label class="text-sm font-medium text-gray-700 whitespace-nowrap">更多备注:</label>
<div class="flex flex-wrap gap-2">
<button type="button" class="remark-preset-btn px-3 py-1.5 text-xs border rounded-lg themed-ring" data-preset="gift">礼品</button>
<button type="button" class="remark-preset-btn px-3 py-1.5 text-xs border rounded-lg themed-ring" data-preset="relation">关系</button>
<button type="button" class="remark-preset-btn px-3 py-1.5 text-xs border rounded-lg themed-ring" data-preset="phone">电话</button>
<button type="button" class="remark-preset-btn px-3 py-1.5 text-xs border rounded-lg themed-ring" data-preset="address">住址</button>
</div>
</div>
<!-- 用于动态添加“礼品”、“关系”等输入框的容器 -->
<div id="remark-inputs-container" class="space-y-2"></div>
<button type="submit" class="w-full themed-button-primary font-bold p-4 rounded-lg transition duration-300 text-lg">确认录入</button>
</form>
<div class="mt-6 pt-6 border-t">
<h3 class="text-xl font-semibold mb-3">功能区</h3>
<div class="space-y-3">
<div class="relative">
<input type="text" id="search-name" placeholder="按姓名查找..." class="w-full p-3 border rounded-lg focus:ring-2 themed-ring pr-10" />
<i id="search-icon" class="ri-search-line text-xl absolute right-3 top-3 text-gray-400 cursor-pointer"></i>
</div>
<button id="print-btn" class="w-full themed-button-primary p-3 rounded-lg">打印/另存为PDF</button>
<button id="export-excel-btn" class="w-full border themed-button-secondary p-3 rounded-lg">导出为 Excel</button>
<button id="stats-btn" class="w-full themed-button-primary p-3 rounded-lg">查看统计</button>
<div class="flex items-center justify-between bg-gray-100 p-3 rounded-lg">
<span class="font-medium text-gray-700">语音播报</span>
<label for="speech-toggle" class="relative inline-flex items-center cursor-pointer">
<input type="checkbox" id="speech-toggle" class="sr-only peer" checked />
<div
class="toggle-bg w-11 h-6 bg-gray-300 peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-5 after:w-5 after:transition-all"
></div>
</label>
</div>
</div>
</div>
</div>
<!-- 右侧展示区 -->
<div class="lg:col-span-2">
<div id="book-container-wrapper" class="gift-book-frame">
<div id="book-footer" class="flex justify-between items-center mb-4 flex-wrap gap-y-2">
<div class="flex items-center flex-wrap gap-x-4">
<div><span class="font-bold text-md">本页小计:</span> <span id="page-subtotal" class="text-xl font-bold themed-text">¥0.00</span></div>
<div><span class="font-bold text-md">总金额:</span> <span id="total-amount" class="text-xl font-bold themed-text">¥0.00</span></div>
<div><span class="font-bold text-md">总人数:</span> <span id="total-givers" class="text-xl font-bold themed-text">0</span></div>
</div>
<div class="flex items-center space-x-2 text-lg">
<button id="prev-page-btn" class="themed-button-primary p-2 disabled:bg-gray-300 rounded-full w-8 h-8 flex items-center justify-center">
<i class="ri-arrow-left-s-line"></i>
</button>
<div id="page-info" class="font-bold flex items-center">第 1 / 1 页</div>
<button id="next-page-btn" class="themed-button-primary p-2 disabled:bg-gray-300 rounded-full w-8 h-8 flex items-center justify-center">
<i class="ri-arrow-right-s-line"></i>
</button>
</div>
</div>
<div id="gift-book-content"></div>
</div>
</div>
</div>
</div>
</div>
<div class="absolute lg:fixed top-5 right-5 flex gap-3 z-40">
<button id="support-btn" class="bg-white/80 backdrop-blur rounded-full p-2 shadow-sm hover:shadow-md transition-all group" title="联系/支持作者">
<i class="ri-heart-3-line text-2xl text-red-500 group-hover:scale-110 transition-transform block"></i>
</button>
<button id="fullscreen-btn" class="bg-white/80 backdrop-blur rounded-full p-2 shadow-sm hover:shadow-md transition-all" title="全屏/退出全屏">
<i id="fullscreen-icon" class="ri-fullscreen-line text-2xl themed-text themed-dropdown-text"></i>
</button>
</div>
<!-- 模态框 -->
<div id="modal-container" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center hidden z-50">
<div id="modal" class="bg-white p-6 rounded-lg shadow-xl w-full max-w-md">
<button id="modal-close-btn" type="button" aria-label="关闭弹窗" class="w-10 h-10 flex items-center justify-center rounded-full hover:bg-gray-100 transition focus:outline-none">
<i class="ri-close-line text-2xl"></i>
</button>
<h3 id="modal-title" class="text-xl font-bold mb-4 text-center"></h3>
<div id="modal-content"></div>
<div id="modal-actions" class="mt-6 flex justify-end space-x-3"></div>
</div>
</div>
<script type="module">
/**
* 应用配置常量
* 集中管理所有全局配置参数,便于统一维护和调整
*/
const CONFIG = {
/**
* 每页显示的礼金记录数量
* 影响:
* - 主界面礼簿显示
* - 打印PDF每页容量
* - 分页导航计算
*/
ITEMS_PER_PAGE: 12,
/**
* 礼簿封面图最大文件大小(2MB)
* 超过此大小的图片将被拒绝上传
* 原因:避免 IndexedDB 存储压力和打印性能问题
*/
MAX_COVER_SIZE: 2 * 1024 * 1024,
/**
* 打印分批阈值(1008 条记录 = 84 页)
* 超过此数量将启用分批打印模式
* 原因:
* - 防止浏览器渲染大量 DOM 导致卡死
* - 避免内存溢出
* - 提高打印成功率
* 同时用于 GridJS 表格分页判断
*/
PRINT_SPLIT_THRESHOLD: 1008,
APP_NAME: "电子礼簿系统 - 专业版",
DB_NAME: "GiftRegistryDB",
DB_VERSION: 1,
/**
* 宾客等级系统配置
* 使用数组存储等级名称,索引即为等级权重(用于排序)
* 索引越大,等级越高,在打印/导出时排名越靠前
* 索引范围:0-4
*/
GUEST_LEVELS: ["普宾", ...Array.from({ length: 100 }, (_, index) => `排序${100 - index}`)],
PASSWORD_CACHE_DURATION: 5,
};
const DEFAULT_PRINT_OPTIONS = Object.freeze({
printCover: true,
printEndPage: true,
printAppendix: true,
printSummary: true,
printAbolished: true,
showCoverTitle: true,
pdfEngine: "browser",
});
/**
* 工具类 - 提供通用工具方法
* 集中管理数据格式化、转换等通用功能
*/
class Utils {
/**
* 格式化金额为人民币格式
* @param {number} amount - 金额数值
* @returns {string} 格式化后的字符串,如 "¥1,234.56"
*/
static formatCurrency(amount) {
return new Intl.NumberFormat("zh-CN", {
style: "currency",
currency: "CNY",
}).format(amount || 0);
}
/**
* 将数字金额转换为中文大写金额
* @param {number|string} n - 要转换的金额
* @returns {string} 中文大写金额字符串
* @example
*/
static amountToChinese(n) {
if (typeof n !== "number" && typeof n !== "string") return "";
n = parseFloat(n);
if (isNaN(n) || n === null) return "";
if (n === 0) return "零元整";
let unit = "京亿万仟佰拾兆万仟佰拾亿仟佰拾万仟佰拾元角分";
let str = "";
let s = n.toString();
if (s.indexOf(".") > -1) s = (n * 100).toFixed(0);
else s += "00";
if (s.length > unit.length) return "金额过大";
unit = unit.substr(unit.length - s.length);
for (let i = 0; i < s.length; i++) {
str += "零壹贰叁肆伍陆柒捌玖".charAt(s.charAt(i)) + unit.charAt(i);
}
return str
.replace(/零(仟|佰|拾|角)/g, "零")
.replace(/(零)+/g, "零")
.replace(/零(兆|万|亿|元)/g, "$1")
.replace(/(兆|亿)万/g, "$1")
.replace(/(京|兆)亿/g, "$1")
.replace(/(京)兆/g, "$1")
.replace(/(亿)万/g, "$1")
.replace(/(京|兆|亿|仟|佰|拾)(万?)(.)/g, "$1$2$3")
.replace(/零元/g, "元")
.replace(/零分/g, "")
.replace(/零角/g, "零")
.replace(/元$/g, "元整")
.replace(/角$/g, "角整");
}
/**
* 将文件读取为 Base64 编码字符串
* @param {File} file - 要读取的文件对象
* @returns {Promise<string>} Base64 编码的数据 URL(包含 data:image/...;base64, 前缀)
* @throws {Error} 文件读取失败时抛出错误
* 用途:将礼簿封面图存储到 IndexedDB
*/
static async readFileAsBase64(file) {
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.onload = () => resolve(reader.result);
reader.onerror = reject;
reader.readAsDataURL(file);
});
}
/**
* 获取当前日期时间的格式化字符串
* @returns {{date: string, time: string}} 包含 date 和 time 的对象
* @example
* Utils.getCurrentDateTime()
* // => { date: "2025-10-12", time: "14:30" }
* 用途:为创建事项表单设置默认时间
*/
static getCurrentDateTime() {
const now = new Date();
const pad = (num) => num.toString().padStart(2, "0");
const date = `${now.getFullYear()}-${pad(now.getMonth() + 1)}-${pad(now.getDate())}`;
const time = `${pad(now.getHours())}:${pad(now.getMinutes())}`;
return { date, time };
}
/**
*/
static getEventDateInfo(dateInput) {
const date = new Date(dateInput);
if (Number.isNaN(date.getTime())) {
return { date, formattedDisplay: "", localeDate: "" };
}
const formattedDisplay = `${date.getFullYear()}年${date.getMonth() + 1}月${date.getDate()}日`;
return {
date,
formattedDisplay,
localeDate: date.toLocaleDateString("zh-CN"),
};
}
/**
* 生成用于文件名的时间戳
* @param {Date} date
* @returns {string} yyyy-mm-dd hh:mm:ss
*/
static formatTimestampForFilename(date = new Date()) {
const pad = (num) => num.toString().padStart(2, "0");
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())} ${pad(date.getHours())}:${pad(date.getMinutes())}:${pad(date.getSeconds())}`;
}
/**
* @returns {boolean}
*/
static isMobile() {
// 一个通用且可靠的移动设备检测方法
return /Mobi|Android|iPhone|iPad|iPod/i.test(navigator.userAgent);
}
}
/**
* 加密管理器 - 处理所有加密相关操作
* 使用 CryptoJS 库实现 AES 加密和 SHA-256 哈希
* 用途:保护礼金数据的隐私性和完整性
*/
class CryptoService {
/**
* 加密数据 - 使用 AES 对称加密算法
* @param {Object} data - 要加密的数据对象(会先转为JSON字符串)
* @param {string} key - 加密密钥(用户输入的密码)
* @returns {string} 加密后的密文字符串
*/
static encrypt(data, key) {
return CryptoJS.AES.encrypt(JSON.stringify(data), key).toString();
}
/**
* 解密数据 - 使用 AES 对称解密算法
* @param {string} ciphertext - 密文字符串
* @param {string} key - 解密密钥(必须与加密时的密钥一致)
* @returns {Object|null} 解密后的数据对象,失败时返回 null
*/
static decrypt(ciphertext, key) {
try {
const bytes = CryptoJS.AES.decrypt(ciphertext, key);
return JSON.parse(bytes.toString(CryptoJS.enc.Utf8));
} catch (e) {
console.error("解密失败:", e);
return null; // 密钥错误或数据损坏时返回null
}
}
/**
* 哈希密码 - 使用 SHA-256 单向哈希算法
* @param {string} password - 原始密码
* @returns {string} 哈希值(用于密码验证,不可逆)
* 注意:哈希值存储在数据库中,用于验证密码而不存储明文
*/
static hash(password) {
return CryptoJS.SHA256(password).toString();
}
}
/**
* 数据库管理器 - IndexedDB 封装
* 提供对浏览器本地数据库的统一操作接口
* 存储结构:
* - events: 事项信息(包含名称、时间、密码哈希、主题等)
* - gifts: 礼金记录(包含加密数据和关联的事项ID)
*/