-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
842 lines (771 loc) · 32.5 KB
/
index.html
File metadata and controls
842 lines (771 loc) · 32.5 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
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title>像素工卡生成器</title>
<link href="https://fonts.googleapis.com/css2?family=VT323&display=swap" rel="stylesheet">
<script src="https://cdnjs.cloudflare.com/ajax/libs/qrcodejs/1.0.0/qrcode.min.js"></script>
<style>
@font-face {
font-family: 'Friends Z';
src: url('./FriendsZ-Regular.ttf') format('truetype');
font-weight: normal;
font-style: normal;
}
@font-face {
font-family: 'Birthlong';
src: url('./Birthlong.ttf') format('truetype');
font-weight: normal;
font-style: normal;
}
@font-face {
font-family: 'BreezyBolton';
src: url('./BreezyBolton.ttf') format('truetype');
font-weight: normal;
font-style: normal;
}
@font-face {
font-family: 'Vegabond';
src: url('./Vegabond.ttf') format('truetype');
font-weight: normal;
font-style: normal;
}
@font-face {
font-family: 'Patung';
src: url('./Patung.ttf') format('truetype');
font-weight: normal;
font-style: normal;
}
:root {
--bg-color: #222;
--card-bg: #fff;
--ink-color: #000;
--accent-gray: #ccc;
}
body {
font-family: 'VT323', monospace; /* 使用像素字体 */
background-color: var(--bg-color);
margin: 0;
padding: 20px;
color: #fff;
display: flex;
flex-direction: column;
align-items: center;
}
h2 { text-align: center; margin-bottom: 10px; letter-spacing: 2px; }
/* --- 工卡主体样式 (预览区) --- */
#card-capture-area {
width: 324px;
height: 490px;
background-color: var(--card-bg);
border: 0px solid var(--ink-color);
border-radius: 0px;
position: relative;
color: var(--ink-color);
overflow: hidden;
/* 模拟电路板背景纹理 */
background-image:
linear-gradient(var(--ink-color) 3px, transparent 3px),
linear-gradient(90deg, var(--ink-color) 3px, transparent 3px);
background-size: 40px 40px;
background-color: #cfcfcf;
box-shadow: 0 0 1px rgba(0,0,0,0.8);
}
/* 覆盖一层白色遮罩让背景只在特定区域显示,或者我们直接用块级元素堆叠 */
.card-layer {
position: absolute;
top: 0; left: 0; right: 0; bottom: 0;
z-index: 1;
/* 复杂的CSS电路背景模拟比较难,这里用简单的SVG图或者CSS遮罩模拟 */
background:
radial-gradient(circle at 10% 20%, transparent 0%, transparent 0%),
#fff;
/* 这里为了简化,我们把背景设为白色,只在边缘留一点缝隙 */
margin: 4px;
border: 2px solid var(--ink-color);
}
/* 真正的布局容器 */
.card-content {
position: relative;
z-index: 10;
height: 100%;
display: flex;
flex-direction: column;
padding: 15px;
box-sizing: border-box;
background:
radial-gradient(circle, transparent 20%, #fff 20%) 0 0/10px 10px;
/* 简单的点阵背景 */
}
/* 头部: 部门信息 */
.header-box {
background: var(--ink-color);
color: #fff;
padding: 10px;
border-radius: 5px;
display: flex;
align-items: center;
border: 2px solid var(--ink-color);
margin-bottom: 10px;
}
.header-logo {
width: 40px;
height: 40px;
filter: invert(1); /* 反色,因为背景是黑的 */
margin-right: 10px;
image-rendering: pixelated;
}
.header-text h3 { margin: 0; font-size: 22px; text-transform: uppercase; line-height: 1; }
.header-text span { font-size: 14px; opacity: 0.8; }
/* 中部: 头像和信息 */
.main-section {
display: flex;
gap: 10px;
margin-bottom: 8px;
align-items: center;
}
.photo-frame {
width: 120px;
height: 160px;
border: 4px solid var(--ink-color);
border-radius: 8px;
padding: 4px;
background: #fff;
box-shadow: 4px 4px 0px rgba(0,0,0,0.2);
}
.photo-img {
width: 100%;
height: 100%;
object-fit: cover;
border: 0px solid var(--ink-color);
border-radius: 4px;
/*filter: grayscale(100%) contrast(120%); 强制黑白高对比 */
image-rendering: pixelated;
}
.info-block {
flex: 1;
background: var(--ink-color);
color: #fff;
padding: 10px;
border-radius: 4px;
height: 150px;
display: flex;
flex-direction: column;
justify-content: center;
}
.info-label {
font-size: 18px;
margin-bottom: 2px;
}
.info-value {
font-size: 28px;
font-weight: bold;
line-height: 1;
margin-bottom: 10px;
}
/* 签名区域容器 */
.signature-container {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 6px;
width: 100%;
}
/* 签名区域 */
.signature-area {
height: 50px;
flex: 1;
border: 2px dashed var(--ink-color);
border-radius: 4px;
background: #fff;
display: flex;
align-items: center;
justify-content: center;
position: relative;
overflow: hidden;
padding: 0 10px;
box-sizing: border-box;
}
.signature-text {
font-family: 'Friends Z', cursive;
font-size: 40px;
color: var(--ink-color);
text-align: center;
transform: translateY(4px);
}
.qr-code {
width: 50px;
height: 50px;
border: 0.5px solid var(--ink-color);
background: #fff;
display: flex;
align-items: center;
justify-content: center;
position: relative;
margin-right: 3px;
flex-shrink: 0;
}
.qr-code img {
width: 100%;
height: 100%;
object-fit: cover;
}
.qr-code-placeholder {
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
font-size: 8px;
color: var(--ink-color);
text-align: center;
background: repeating-linear-gradient(
45deg,
#000,
#000 2px,
#fff 2px,
#fff 4px
);
color: #fff;
}
/* 底部: 权限和条码 */
.footer-box {
background: #fff;
border: 3px solid var(--ink-color);
border-radius: 8px;
padding: 10px;
text-align: center;
margin-top: auto;
position: relative;
}
.security-level {
font-size: 20px;
font-weight: bold;
margin-bottom: 5px;
border-bottom: 2px dashed var(--ink-color);
padding-bottom: 5px;
display: block;
}
.access-badge {
background: var(--ink-color);
color: #fff;
display: inline-block;
padding: 5px 20px;
border-radius: 20px;
font-size: 24px;
margin: 5px 0;
width: 80%;
}
.access-badge svg {
fill: #fff;
vertical-align: middle;
margin-bottom: 4px;
}
/* 动态条形码样式 */
.barcode {
height: 15px;
width: 90%;
margin: 0 auto;
background: var(--barcode-gradient, repeating-linear-gradient(
to right,
#000 0px, #000 2px,
transparent 2px, transparent 4px,
#000 4px, #000 7px,
transparent 7px, transparent 9px
));
background-size: 100% 100%;
}
.id-number {
margin-top: 5px;
font-size: 18px;
letter-spacing: 2px;
}
/* --- 控制面板样式 --- */
.controls {
width: 100%;
max-width: 320px;
margin-top: 20px;
background: #333;
padding: 15px;
border-radius: 10px;
box-sizing: border-box;
}
.control-group { margin-bottom: 15px; }
label { display: block; margin-bottom: 5px; color: #aaa; font-size: 14px;}
input[type="text"] {
width: 100%;
padding: 8px;
background: #222;
border: 1px solid #555;
color: #fff;
font-family: inherit;
font-size: 16px;
box-sizing: border-box;
}
input[type="range"] {
width: 100%;
height: 6px;
background: #222;
border: 1px solid #555;
outline: none;
-webkit-appearance: none;
appearance: none;
cursor: pointer;
margin-top: 5px;
}
input[type="range"]::-webkit-slider-thumb {
-webkit-appearance: none;
appearance: none;
width: 20px;
height: 20px;
background: #fff;
border: 2px solid #000;
cursor: pointer;
border-radius: 3px;
}
input[type="range"]::-moz-range-thumb {
width: 20px;
height: 20px;
background: #fff;
border: 2px solid #000;
cursor: pointer;
border-radius: 3px;
}
.control-group span[id$="-value"] {
color: #fff;
font-weight: bold;
font-size: 14px;
}
input[type="checkbox"] {
width: 20px;
height: 20px;
background: #222;
border: 2px solid #555;
cursor: pointer;
vertical-align: middle;
}
input[type="checkbox"]:checked {
background: #fff;
border-color: #000;
}
.upload-btn {
display: inline-block;
background: #555;
padding: 5px 10px;
border-radius: 4px;
cursor: pointer;
font-size: 14px;
margin-top: 5px;
}
input[type="file"] { display: none; }
/* 预设选择器 */
.preset-list { display: flex; gap: 5px; margin-top: 5px; }
.preset-item {
width: 40px;
height: 40px;
border: 2px solid #555;
cursor: pointer;
object-fit: cover;
}
.preset-item:hover, .preset-item.active { border-color: #fff; }
/* 生成按钮 */
.action-btn {
width: 100%;
padding: 15px;
background: #fff;
color: #000;
border: none;
font-family: inherit;
font-size: 20px;
font-weight: bold;
cursor: pointer;
margin-top: 10px;
border: 4px solid #000;
box-shadow: 4px 4px 0 #888;
}
.action-btn:active {
transform: translate(2px, 2px);
box-shadow: 2px 2px 0 #888;
}
/* 模式切换按钮样式 */
.mode-switch {
display: flex;
gap: 10px;
margin: 15px 0;
justify-content: center;
}
.mode-btn {
padding: 8px 20px;
background: #333;
color: #fff;
border: 2px solid #555;
border-radius: 5px;
cursor: pointer;
font-family: 'VT323', monospace;
font-size: 18px;
transition: all 0.3s ease;
}
.mode-btn:hover {
background: #444;
border-color: #fff;
}
.mode-btn.active {
background: #fff;
color: #000;
border-color: #000;
box-shadow: 3px 3px 0 rgba(0,0,0,0.5);
}
/* 过渡动画效果 */
#card-capture-area,
.main-section,
.signature-container,
.barcode {
transition: all 0.3s ease-in-out;
}
</style>
</head>
<body>
<h2>像素工卡生成器</h2>
<!-- 模式切换按钮 -->
<div class="mode-switch">
<button class="mode-btn active" onclick="switchMode('X3')">X3</button>
<button class="mode-btn" onclick="switchMode('X4')">X4</button>
</div>
<div id="card-capture-area">
<div class="card-content">
<div class="header-box">
<img src="https://img.icons8.com/ios-filled/100/000000/united-nations.png" class="header-logo" id="preview-logo">
<div class="header-text">
<h3 id="preview-dept">THE NAVIGATOR PROJECT</h3>
<span id="preview-sub-dept">ORGANIZATION</span>
</div>
</div>
<div class="main-section">
<div class="photo-frame" onclick="setRandomAvatar()" style="cursor: pointer;" title="点击随机生成头像">
<img src="Avatar-1.jpg" class="photo-img" id="preview-avatar">
</div>
<div class="info-block">
<div class="info-label">POSITION</div>
<div class="info-value" id="preview-position">DATA CLEANER</div>
<div class="info-label">NAME</div>
<div class="info-value" id="preview-name">Steven</div>
</div>
</div>
<div class="signature-container">
<div class="signature-area">
<div class="signature-text" id="preview-signature">Steven Evens</div>
</div>
<div class="qr-code" id="preview-qr">
<div class="qr-code-placeholder">QR</div>
</div>
</div>
<div class="footer-box">
<span class="security-level" id="preview-level">SECURITY CLEARANCE: LEVEL 5</span>
<div class="access-badge">ACCESS GRANTED <svg t="1765849356055" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="4660" width="20" height="20"><path d="M384 384h256v256H384z" p-id="4661"></path><path d="M853.333333 256c0-47.061333-38.272-85.333333-85.333333-85.333333h-85.333333V85.333333h-85.333334v85.333334h-170.666666V85.333333H341.333333v85.333334H256c-47.061333 0-85.333333 38.272-85.333333 85.333333v85.333333H85.333333v85.333334h85.333334v170.666666H85.333333v85.333334h85.333334v85.333333c0 47.061333 38.272 85.333333 85.333333 85.333333h85.333333v85.333334h85.333334v-85.333334h170.666666v85.333334h85.333334v-85.333334h85.333333c47.061333 0 85.333333-38.272 85.333333-85.333333v-85.333333h85.333334v-85.333334h-85.333334v-170.666666h85.333334V341.333333h-85.333334V256zM256 768V256h512l0.085333 512H256z" p-id="4662"></path></svg></div>
<div class="barcode"></div>
<div class="id-number" id="preview-id">ID: BIT-JOJO-001</div>
</div>
</div>
</div>
<div class="controls">
<div class="control-group">
<label>姓名 (NAME)</label>
<input type="text" id="input-name" value="Steven" oninput="updateCard()">
</div>
<div class="control-group">
<label>职位 (POSITION)</label>
<input type="text" id="input-position" value="DATA CLEANER" oninput="updateCard()">
</div>
<div class="control-group">
<label>组织 (ORGANIZATION)</label>
<input type="text" id="input-comp" value="THE NAVIGATOR PROJECT" oninput="updateCard()">
</div>
<div class="control-group">
<label>ID 编号</label>
<input type="text" id="input-id" value="ID: BIT-JOJO-001" oninput="updateCard()">
</div>
<div class="control-group">
<label>格言</label>
<input type="text" id="input-level" value="SECURITY CLEARANCE: LEVEL 5" oninput="updateCard()">
</div>
<div class="control-group">
<label>签名 (SIGNATURE)</label>
<input type="text" id="input-signature" value="Steven Evens" oninput="updateCard()">
</div>
<div class="control-group">
<label>二维码内容 (QR CONTENT)</label>
<input type="text" id="input-qr-content" value="Hello World" oninput="updateQRCode()">
</div>
<!-- 字号调整选项 -->
<div class="control-group">
<label>姓名字号: <span id="font-size-name-value">28</span>px</label>
<input type="range" id="font-size-name" min="10" max="40" value="28" oninput="updateFontSize()">
</div>
<div class="control-group">
<label>职位字号: <span id="font-size-position-value">18</span>px</label>
<input type="range" id="font-size-position" min="10" max="40" value="28" oninput="updateFontSize()">
</div>
<div class="control-group">
<label>部门字号: <span id="font-size-dept-value">22</span>px</label>
<input type="range" id="font-size-dept" min="16" max="28" value="22" oninput="updateFontSize()">
</div>
<div class="control-group">
<label>签名字号: <span id="font-size-signature-value">40</span>px</label>
<input type="range" id="font-size-signature" min="20" max="50" value="40" oninput="updateFontSize()">
</div>
<div class="control-group">
<label>签名加粗</label>
<label style="display: flex; align-items: center; gap: 10px;">
<input type="checkbox" id="signature-bold" onchange="updateSignatureBold()">
<span style="color: #aaa;">启用签名加粗</span>
</label>
</div>
<div class="control-group">
<label>签名字体</label>
<select id="font-family-signature" onchange="updateFontFamily()" style="width: 100%; padding: 8px; background: #222; border: 1px solid #555; color: #fff; font-family: inherit; font-size: 16px; box-sizing: border-box;">
<option value="Friends Z">Friends Z</option>
<option value="Birthlong">Birthlong</option>
<option value="BreezyBolton">BreezyBolton</option>
<option value="Patung">Patung</option>
<option value="Vegabond">Vegabond</option>
</select>
</div>
<div class="control-group">
<label>头像选择</label>
<div class="preset-list">
<img src="Avatar-1.jpg" class="preset-item" onclick="setAvatar(this.src)">
<img src="Avatar-2.jpg" class="preset-item" onclick="setAvatar(this.src)">
<img src="Avatar-3.jpg" class="preset-item" onclick="setAvatar(this.src)">
<img src="Avatar-4.jpg" class="preset-item" onclick="setAvatar(this.src)">
<div class="preset-item" style="display: flex; align-items: center; justify-content: center; background: #555; color: #fff; font-size: 20px; cursor: pointer;" onclick="setRandomAvatar()">🎲</div>
</div>
<label for="upload-avatar" class="upload-btn">📂 上传自定义头像</label>
<input type="file" id="upload-avatar" accept="image/*" onchange="handleImageUpload(this, 'preview-avatar')">
</div>
<div class="control-group">
<label>丑头像随机种子 (点击头像图片也可随机)</label>
<input type="text" id="random-seed" placeholder="输入种子或点击骰子生成" value="" oninput="applySeed()">
<div style="display: flex; gap: 5px; margin-top: 5px;">
<button class="upload-btn" style="flex: 1; margin: 0;" onclick="setRandomAvatar()">🎲 随机生成</button>
<button class="upload-btn" style="flex: 1; margin: 0;" onclick="copySeed()">📋 复制种子</button>
</div>
</div>
<div class="control-group">
<label>Logo 选择</label>
<div class="preset-list">
<img src="https://img.icons8.com/ios-filled/100/000000/king-of-hearts.png" class="preset-item" style="background:#fff" onclick="setLogo(this.src)">
<img src="https://img.icons8.com/ios-filled/100/000000/moizhusnain-corporation.png" class="preset-item" style="background:#fff" onclick="setLogo(this.src)">
<img src="https://img.icons8.com/ios-filled/100/000000/united-nations.png" class="preset-item" style="background:#fff" onclick="setLogo(this.src)">
<img src="https://img.icons8.com/ios-filled/100/000000/sandwich.png" class="preset-item" style="background:#fff" onclick="setLogo(this.src)">
<img src="https://img.icons8.com/ios-filled/100/000000/corinthians.png" class="preset-item" style="background:#fff" onclick="setLogo(this.src)">
</div>
<label for="upload-logo" class="upload-btn">📂 上传自定义Logo</label>
<input type="file" id="upload-logo" accept="image/*" onchange="handleImageUpload(this, 'preview-logo')">
</div>
<div class="control-group" style="text-align: center; color: #aaa; font-size: 14px; padding: 10px; background: #222; border-radius: 5px; border: 1px solid #555;">
💡 请直接使用系统截图工具保存工卡图片,X3可以用手机自带2:3比例重新框选(目前X3仅通过拷贝SD卡来设置),X4则用3:5比例框选。
</div>
</div>
<script>
// 生成条形码函数
function generateBarcode(idText) {
// 简单的哈希函数,将ID文本转换为数字
let hash = 0;
for (let i = 0; i < idText.length; i++) {
const char = idText.charCodeAt(i);
hash = ((hash << 5) - hash) + char;
hash = hash & hash; // Convert to 32bit integer
}
// 使用哈希创建随机的条形码图案
const segments = 10; // 条形码段数
let gradientSteps = [];
let position = 0;
// 生成随机的黑白条纹组合
for (let i = 0; i < segments; i++) {
// 基于哈希的伪随机宽度
const blackWidth = Math.abs((hash * (i + 1)) % 3) + 1; // 1-3px
const whiteWidth = Math.abs((hash * (i + 2)) % 4) + 1; // 1-4px
// 添加黑色条纹
gradientSteps.push(`#000 ${position}px, #000 ${position + blackWidth}px`);
position += blackWidth;
// 添加白色条纹
gradientSteps.push(`transparent ${position}px, transparent ${position + whiteWidth}px`);
position += whiteWidth;
}
// 确保覆盖整个条形码宽度
gradientSteps.push(`#000 ${position}px, #000 ${position + 2}px`);
// 构建渐变字符串
const gradient = `repeating-linear-gradient(to right, ${gradientSteps.join(', ')})`;
// 应用到CSS变量
document.querySelector('.barcode').style.setProperty('--barcode-gradient', gradient);
}
// 1. 文本实时更新
function updateCard() {
document.getElementById('preview-name').innerText = document.getElementById('input-name').value;
document.getElementById('preview-position').innerText = document.getElementById('input-position').value;
document.getElementById('preview-dept').innerText = document.getElementById('input-comp').value;
const idValue = document.getElementById('input-id').value;
document.getElementById('preview-id').innerText = idValue;
document.getElementById('preview-level').innerText = document.getElementById('input-level').value;
document.getElementById('preview-signature').innerText = document.getElementById('input-signature').value;
// 更新条形码
generateBarcode(idValue);
}
// 2. 预设图片切换
function setAvatar(src) {
document.getElementById('preview-avatar').src = src;
}
function setLogo(src) {
document.getElementById('preview-logo').src = src;
}
// 3. 随机头像生成
function setRandomAvatar() {
const randomSeed = Math.random().toString(36).substring(7);
const randomAvatarUrl = `https://api.dicebear.com/7.x/pixel-art/svg?seed=${randomSeed}`;
// 应用到预览头像
document.getElementById('preview-avatar').src = randomAvatarUrl;
// 更新种子输入框
document.getElementById('random-seed').value = randomSeed;
}
// 应用种子生成头像
function applySeed() {
const seed = document.getElementById('random-seed').value.trim();
if (seed) {
const avatarUrl = `https://api.dicebear.com/7.x/pixel-art/svg?seed=${seed}`;
document.getElementById('preview-avatar').src = avatarUrl;
}
}
// 复制种子到剪贴板
function copySeed() {
const seedInput = document.getElementById('random-seed');
if (seedInput.value) {
navigator.clipboard.writeText(seedInput.value).then(() => {
// 简单的成功提示
const originalPlaceholder = seedInput.placeholder;
seedInput.placeholder = '种子已复制到剪贴板!';
setTimeout(() => {
seedInput.placeholder = originalPlaceholder;
}, 2000);
}).catch(() => {
// 降级方案
seedInput.select();
document.execCommand('copy');
const originalPlaceholder = seedInput.placeholder;
seedInput.placeholder = '种子已复制!';
setTimeout(() => {
seedInput.placeholder = originalPlaceholder;
}, 2000);
});
}
}
// 4. 二维码生成和更新
function updateQRCode() {
const qrContent = document.getElementById('input-qr-content').value;
const qrContainer = document.getElementById('preview-qr');
// 清空现有内容
qrContainer.innerHTML = '';
if (qrContent.trim() === '') {
// 如果内容为空,显示占位符
qrContainer.innerHTML = '<div class="qr-code-placeholder">QR</div>';
} else {
// 生成新的二维码
new QRCode(qrContainer, {
text: qrContent,
width: 49,
height: 49,
colorDark: "#000000",
colorLight: "#ffffff",
correctLevel: QRCode.CorrectLevel.L
});
}
}
// 5. 图片上传处理
function handleImageUpload(input, targetId) {
if (input.files && input.files[0]) {
const reader = new FileReader();
reader.onload = function(e) {
document.getElementById(targetId).src = e.target.result;
}
reader.readAsDataURL(input.files[0]);
}
}
// 6. 字号调整函数
function updateFontSize() {
const nameSize = document.getElementById('font-size-name').value;
const positionSize = document.getElementById('font-size-position').value;
const deptSize = document.getElementById('font-size-dept').value;
const signatureSize = document.getElementById('font-size-signature').value;
// 更新显示值
document.getElementById('font-size-name-value').textContent = nameSize;
document.getElementById('font-size-position-value').textContent = positionSize;
document.getElementById('font-size-dept-value').textContent = deptSize;
document.getElementById('font-size-signature-value').textContent = signatureSize;
// 获取对应的元素并更新字号
const nameElements = document.querySelectorAll('.info-value');
const positionElements = nameElements[0]; // 第一个info-value是职位
const nameElement = nameElements[1]; // 第二个info-value是姓名
if (positionElements) positionElements.style.fontSize = positionSize + 'px';
if (nameElement) nameElement.style.fontSize = nameSize + 'px';
// 更新部门字号
document.getElementById('preview-dept').style.fontSize = deptSize + 'px';
// 更新签名字号
document.getElementById('preview-signature').style.fontSize = signatureSize + 'px';
}
// 7. 签名加粗切换函数
function updateSignatureBold() {
const isBold = document.getElementById('signature-bold').checked;
const signatureElement = document.getElementById('preview-signature');
if (isBold) {
signatureElement.style.fontWeight = 'bold';
} else {
signatureElement.style.fontWeight = 'normal';
}
}
// 8. 签名字体切换函数
function updateFontFamily() {
const selectedFont = document.getElementById('font-family-signature').value;
const signatureElement = document.getElementById('preview-signature');
signatureElement.style.fontFamily = selectedFont + ', cursive';
}
// 8. 模式切换功能
function switchMode(mode) {
// 更新按钮状态
document.querySelectorAll('.mode-btn').forEach(btn => {
btn.classList.remove('active');
});
// 确保event对象存在
if (event && event.currentTarget) {
event.currentTarget.classList.add('active');
}
// 获取需要修改的元素
const cardArea = document.getElementById('card-capture-area');
const mainSection = document.querySelector('.main-section');
const signatureContainer = document.querySelector('.signature-container');
const barcode = document.querySelector('.barcode');
// 根据模式设置样式
if (mode === 'X3') {
// X3模式
cardArea.style.height = '490px';
mainSection.style.marginBottom = '8px';
signatureContainer.style.marginBottom = '6px';
barcode.style.height = '15px';
} else if (mode === 'X4') {
// X4模式
cardArea.style.height = '540px';
mainSection.style.marginBottom = '15px';
signatureContainer.style.marginBottom = '10px';
barcode.style.height = '50px';
}
}
// 页面加载时初始化条形码、二维码、字号和字体加粗
window.addEventListener('DOMContentLoaded', () => {
generateBarcode(document.getElementById('input-id').value);
updateQRCode();
updateFontSize(); // 初始化字号
updateSignatureBold(); // 初始化签名加粗状态
updateFontFamily(); // 初始化签名字体
});
</script>
</body>
</html>