forked from xxss0903/drawstamputils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DrawStampUtilsDemo.vue
1914 lines (1752 loc) · 56.3 KB
/
DrawStampUtilsDemo.vue
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
<template>
<!-- 添加法律提示弹窗 -->
<div v-if="showLegalDialog" class="legal-dialog-overlay">
<div class="legal-dialog">
<h3>⚠️ 法律提示</h3>
<div class="legal-content">
<p><strong>请确认您已知悉并同意以下内容:</strong></p>
<ol>
<li>本工具仅供学习和技术研究使用</li>
<li>使用本工具生成的任何图片请勿用于任何非法用途</li>
<li>因违法使用本工具造成的任何法律责任和损失,需自行承担</li>
<li>如果使用本工具请遵守相关法律法规</li>
</ol>
</div>
<div class="dialog-buttons">
<button @click="cancelSave" class="cancel-button">取消</button>
<button @click="confirmSave" class="confirm-button">我已知悉并同意</button>
</div>
</div>
</div>
<div class="container">
<!-- 修改法律免责说明 -->
<div class="legal-disclaimer">
<div class="disclaimer-content">
<div class="warning-icon">⚠️</div>
<div class="warning-text">
<h3>安全警告</h3>
<p><strong>本项目仅供学习和参考!严禁用于任何非法用途!</strong></p>
<p>
1. 本项目开源代码仅用于技术学习和交流。<br>
2. 使用本项目生成的任何图片请勿用于任何非法用途。<br>
3. 因违法使用本项目造成的任何法律责任和损失,需自行承担,与本项目无关。<br>
4. 如果使用本项目请遵守相关法律法规。
</p>
</div>
</div>
</div>
<div class="editor-controls" ref="editorControls">
<!-- 顶部固定按钮 -->
<div
class="button-group"
style="position: sticky; top: 0; z-index: 1000; background-color: white; padding: 10px"
>
<button @click="saveStampAsPNG">保存印章</button>
<button @click="saveAsTemplate">保存模板</button>
<input
type="file"
ref="templateFileInput"
style="display: none"
accept=".json"
@change="loadTemplate"
/>
<button @click="triggerTemplateLoad">加载模板</button>
</div>
<!-- 印章基本设置 -->
<div class="control-group">
<div class="group-header" @click="toggleGroup('basic')">
<h3>印章基本设置</h3>
<span class="expand-icon" :class="{ 'expanded': expandedGroups.basic }">▼</span>
</div>
<div class="group-content" v-show="expandedGroups.basic">
<label class="checkbox-label">
<input type="checkbox" v-model="isCircleDetect" />
提取圆形印章
</label>
<label
>印章宽度 (mm):
<input type="number" v-model.number="drawStampWidth" min="1" max="50" step="1"
/></label>
<label
>印章高度 (mm):
<input type="number" v-model.number="drawStampHeight" min="1" max="50" step="1"
/></label>
<label
>圆形边框宽度 (mm): <input type="number" step="0.1" v-model.number="circleBorderWidth"
/></label>
<label>圆形边框颜色: <input type="color" v-model="circleBorderColor" /></label>
</div>
</div>
<!-- 公司名称设置 -->
<div class="control-group">
<div class="group-header" @click="toggleGroup('company')">
<h3>公司名称列表设置</h3>
<span class="expand-icon" :class="{ 'expanded': expandedGroups.company }">▼</span>
</div>
<div class="group-content" v-show="expandedGroups.company">
<div v-for="(company, index) in companyList" :key="index" class="company-item">
<div class="company-header">
<span>第 {{ index + 1 }} 行</span>
<button class="small-button delete-button" @click="removeCompany(index)">删除</button>
</div>
<label>
公司名称:
<input type="text" v-model="company.companyName" />
</label>
<label>
字体:
<div class="font-input-group">
<select
v-model="company.fontFamily"
class="font-select"
@change="updateFontPreview"
>
<option
v-for="font in systemFonts"
:key="font"
:value="font"
:style="{ fontFamily: font }"
>
{{ font }}
</option>
</select>
<input
type="text"
v-model="company.fontFamily"
class="font-input"
@input="updateFontPreview"
placeholder="输入字体名称"
/>
</div>
</label>
<label>
字体大小 (mm):
<input type="number" v-model.number="company.fontHeight" min="1" max="10" step="0.1" />
</label>
<label>
字体粗细:
<select v-model="company.fontWeight">
<option value="normal">正常</option>
<option value="bold">粗体</option>
<option value="100">100</option>
<option value="200">200</option>
<option value="300">300</option>
<option value="400">400</option>
<option value="500">500</option>
<option value="600">600</option>
<option value="700">700</option>
<option value="800">800</option>
<option value="900">900</option>
</select>
</label>
<label>
压缩比例:
<input
type="range"
v-model.number="company.compression"
min="0.5"
max="1.5"
step="0.05"
/>
<span>{{ company.compression.toFixed(2) }}</span>
</label>
<label>
分布因子:
<input
type="range"
v-model.number="company.textDistributionFactor"
min="1"
max="50"
step="0.5"
/>
<span>{{ company.textDistributionFactor.toFixed(1) }}</span>
</label>
<label>
边距 (mm):
<input type="number" v-model.number="company.borderOffset" min="-10" max="10" step="0.05" />
</label>
<label class="checkbox-label">
<input type="checkbox" v-model="company.adjustEllipseText" /> 调整椭圆文字
</label>
<label v-if="company.adjustEllipseText">
椭圆文字调整:
<input
type="range"
v-model.number="company.adjustEllipseTextFactor"
min="0"
max="2"
step="0.01"
/>
<span>{{ company.adjustEllipseTextFactor.toFixed(2) }}</span>
</label>
</div>
<button class="add-button" @click="addNewCompany">添加新行</button>
</div>
</div>
<!-- 印章类型设置 -->
<div class="control-group">
<div class="group-header" @click="toggleGroup('stampType')">
<h3>印章类型列表设置</h3>
<span class="expand-icon" :class="{ 'expanded': expandedGroups.stampType }">▼</span>
</div>
<div class="group-content" v-show="expandedGroups.stampType">
<div v-for="(type, index) in stampTypeList" :key="index" class="stamp-type-item">
<div class="stamp-type-header">
<span>第 {{ index + 1 }} 行</span>
<button class="small-button delete-button" @click="removeStampType(index)">删除</button>
</div>
<label>
文字内容:
<input type="text" v-model="type.stampType" />
</label>
<label>
字体大小 (mm):
<input type="number" v-model.number="type.fontHeight" min="1" max="10" step="0.1" />
</label>
<label>
字体:
<div class="font-input-group">
<input
type="text"
v-model="type.fontFamily"
list="stampTypeFontList"
class="font-input"
/>
<datalist id="stampTypeFontList">
<option v-for="font in systemFonts"
:key="font"
:value="font">
{{ font }}
</option>
</datalist>
</div>
</label>
<label>
字体粗细:
<select v-model="type.fontWeight">
<option value="normal">正常</option>
<option value="bold">粗体</option>
<option value="100">100</option>
<option value="200">200</option>
<option value="300">300</option>
<option value="400">400</option>
<option value="500">500</option>
<option value="600">600</option>
<option value="700">700</option>
<option value="800">800</option>
<option value="900">900</option>
</select>
</label>
<label>
压缩比例:
<input
type="range"
v-model.number="type.compression"
min="0.1"
max="1.5"
step="0.05"
/>
<span>{{ type.compression.toFixed(2) }}</span>
</label>
<label>
字符间距 (mm):
<input
type="range"
v-model.number="type.letterSpacing"
min="-1"
max="10"
step="0.05"
/>
<span>{{ type.letterSpacing.toFixed(2) }}</span>
</label>
<label>
垂直位置 (mm):
<input
type="number"
v-model.number="type.positionY"
min="-20"
max="20"
step="0.5"
/>
</label>
</div>
<button class="add-button" @click="addNewStampType">添加新行</button>
</div>
</div>
<!-- 印章编码设置 -->
<div class="control-group">
<div class="group-header" @click="toggleGroup('code')">
<h3>印章编码设置</h3>
<span class="expand-icon" :class="{ 'expanded': expandedGroups.code }">▼</span>
</div>
<div class="group-content" v-show="expandedGroups.code">
<label>印章编码: <input v-model="stampCode" /></label>
<label>
字体:
<div class="font-input-group">
<select
v-model="codeFontFamily"
class="font-select"
@change="updateFontPreview"
>
<option
v-for="font in systemFonts"
:key="font"
:value="font"
:style="{ fontFamily: font }"
>
{{ font }}
</option>
</select>
<input
type="text"
v-model="codeFontFamily"
class="font-input"
@input="updateFontPreview"
placeholder="输入字体名称"
/>
</div>
</label>
<label
>字体大小 (mm): <input type="number" v-model.number="codeFontSizeMM" step="0.1"
/></label>
<label>
字体粗细:
<select v-model="codeFontWeight">
<option value="normal">正常</option>
<option value="bold">粗体</option>
<option value="100">100</option>
<option value="200">200</option>
<option value="300">300</option>
<option value="400">400</option>
<option value="500">500</option>
<option value="600">600</option>
<option value="700">700</option>
<option value="800">800</option>
<option value="900">900</option>
</select>
</label>
<label>
<span>压缩比例:{{ codeCompression.toFixed(2) }}</span>
<input type="range" v-model.number="codeCompression" min="0.0" max="3" step="0.01" />
</label>
<label>
<span>分布因子: {{ codeDistributionFactor.toFixed(1) }}</span>
<input
type="range"
v-model.number="codeDistributionFactor"
min="0"
max="100"
step="0.5"
/>
</label>
<label>
边距 (mm):
<input type="number" v-model.number="codeMarginMM" min="-10" max="20" step="0.05" />
</label>
</div>
</div>
<!-- 税号设置 -->
<div class="control-group">
<div class="group-header" @click="toggleGroup('taxNumber')">
<h3>税号设置</h3>
<span class="expand-icon" :class="{ 'expanded': expandedGroups.taxNumber }">▼</span>
</div>
<div class="group-content" v-show="expandedGroups.taxNumber">
<label>税号: <input v-model="taxNumberValue" /></label>
<label>
字体:
<div class="font-input-group">
<select
v-model="taxNumberFontFamily"
class="font-select"
@change="updateFontPreview"
>
<option
v-for="font in systemFonts"
:key="font"
:value="font"
:style="{ fontFamily: font }"
>
{{ font }}
</option>
</select>
<input
type="text"
v-model="taxNumberFontFamily"
class="font-input"
@input="updateFontPreview"
placeholder="输入字体名称"
/>
</div>
</label>
<label>
字体粗细:
<select v-model="taxNumberFontWeight">
<option value="normal">正常</option>
<option value="bold">粗体</option>
<option value="100">100</option>
<option value="200">200</option>
<option value="300">300</option>
<option value="400">400</option>
<option value="500">500</option>
<option value="600">600</option>
<option value="700">700</option>
<option value="800">800</option>
<option value="900">900</option>
</select>
</label>
<label>
<span>压缩比例:{{ taxNumberCompression.toFixed(2) }}</span>
<input type="range" v-model.number="taxNumberCompression" min="0.0" max="3" step="0.01" />
</label>
<label>
<span>字符间距 (mm):{{ taxNumberLetterSpacing.toFixed(2) }}</span>
<input
type="range"
v-model.number="taxNumberLetterSpacing"
min="-1"
max="20"
step="0.05"
/>
</label>
<label>
<span>垂直位置调整 (mm):{{ taxNumberPositionY.toFixed(1) }}</span>
<input type="range" v-model.number="taxNumberPositionY" min="-10" max="10" step="0.1" />
</label>
</div>
</div>
<!-- 五角星设置 -->
<div class="control-group">
<div class="group-header" @click="toggleGroup('star')">
<h3>五角星/图片设置</h3>
<span class="expand-icon" :class="{ 'expanded': expandedGroups.star }">▼</span>
</div>
<div class="group-content" v-show="expandedGroups.star">
<label class="checkbox-label">
<input type="checkbox" v-model="shouldDrawStar" />
绘制五角星/图片
</label>
<label class="checkbox-label">
<input type="checkbox" v-model="useStarImage" />
使用图片
</label>
<div v-if="shouldDrawStar">
<div v-if="useStarImage">
<label>
选择图片:
<input type="file" @change="handleStarImageUpload" accept="image/*" />
</label>
<label>
图片宽度 (mm):
<input type="number" v-model.number="starImageWidth" min="1" max="20" step="0.5" />
</label>
<label>
图片高度 (mm):
<input type="number" v-model.number="starImageHeight" min="1" max="20" step="0.5" />
</label>
<label class="checkbox-label">
<input type="checkbox" v-model="keepAspectRatio" />
保持宽高比
</label>
</div>
<label v-else>
五角星直径 (mm):
<input type="number" v-model.number="starDiameter" step="0.1" />
</label>
<label>
垂直位置 (mm):
<input type="number" v-model.number="starPositionY" min="-10" max="10" step="0.1" />
</label>
</div>
</div>
</div>
<!-- 防伪纹路设置 -->
<div class="control-group">
<div class="group-header" @click="toggleGroup('security')">
<h3>防伪纹路设置</h3>
<span class="expand-icon" :class="{ 'expanded': expandedGroups.security }">▼</span>
</div>
<div class="group-content" v-show="expandedGroups.security">
<label>
启用防伪纹路:
<input type="checkbox" v-model="securityPatternEnabled" />
</label>
<button @click="drawStamp(true, false)">刷新纹路</button>
<label
>纹路数量:
<input type="range" v-model.number="securityPatternCount" min="1" max="20" step="1"
/></label>
<label
>纹路长度 (mm):
<input type="range" v-model.number="securityPatternLength" min="0.1" max="20" step="0.1"
/></label>
<label
>纹路宽度 (mm):
<input
type="range"
v-model.number="securityPatternWidth"
min="0.05"
max="0.5"
step="0.05"
/></label>
</div>
</div>
<!-- 毛边效果设置 -->
<div class="control-group">
<div class="group-header" @click="toggleGroup('roughEdge')">
<h3>毛边效果设置</h3>
<span class="expand-icon" :class="{ 'expanded': expandedGroups.roughEdge }">▼</span>
</div>
<div class="group-content" v-show="expandedGroups.roughEdge">
<label class="checkbox-label">
<input type="checkbox" v-model="shouldDrawRoughEdge" />
启用毛边效果
</label>
<label v-if="shouldDrawRoughEdge">
毛边宽度 (mm):
<input type="range" v-model.number="roughEdgeWidth" min="0.05" max="0.5" step="0.05" />
<span>{{ roughEdgeWidth.toFixed(2) }}</span>
</label>
<label v-if="shouldDrawRoughEdge">
毛边高度 (mm):
<input type="range" v-model.number="roughEdgeHeight" min="0.1" max="5" step="0.1" />
<span>{{ roughEdgeHeight.toFixed(1) }}</span>
</label>
<label v-if="shouldDrawRoughEdge">
毛边概率:
<input type="range" v-model.number="roughEdgeProbability" min="0" max="1" step="0.01" />
<span>{{ roughEdgeProbability.toFixed(2) }}</span>
</label>
<label v-if="shouldDrawRoughEdge">
毛边偏移 (mm):
<input type="range" v-model.number="roughEdgeShift" min="-10" max="10" step="0.01" />
<span>{{ roughEdgeShift.toFixed(2) }}</span>
</label>
<label v-if="shouldDrawRoughEdge">
毛边点数:
<input type="range" v-model.number="roughEdgePoints" min="100" max="1000" step="10" />
<span>{{ roughEdgePoints }}</span>
</label>
<button @click="drawStamp(false, true)">刷新毛边</button>
</div>
</div>
<!-- 做旧效果设置 -->
<div class="control-group">
<div class="group-header" @click="toggleGroup('aging')">
<h3>做旧效果</h3>
<span class="expand-icon" :class="{ 'expanded': expandedGroups.aging }">▼</span>
</div>
<div class="group-content" v-show="expandedGroups.aging">
<label class="checkbox-label">
<input type="checkbox" v-model="applyAging" />
启用做旧效果
</label>
<label class="checkbox-label">
<input type="checkbox" v-model="manualAging" />
手动做旧
</label>
<label v-if="applyAging">
做旧强度:
<input type="range" v-model.number="agingIntensity" min="0" max="100" step="1" />
</label>
<button @click="drawStamp(false, true)">刷新做旧</button>
</div>
</div>
<!-- 内圈圆形设置 -->
<div class="control-group">
<div class="group-header" @click="toggleGroup('innerCircle')">
<h3>内圈圆形设置</h3>
<span class="expand-icon" :class="{ 'expanded': expandedGroups.innerCircle }">▼</span>
</div>
<div class="group-content" v-show="expandedGroups.innerCircle">
<button @click="addNewInnerCircle">添加新行</button>
<div v-for="(innerCircle, index) in innerCircleList" :key="index" class="inner-circle-item">
<div class="inner-circle-header">
<span>第 {{ index + 1 }} 行</span>
<button class="small-button delete-button" @click="removeInnerCircle(index)">删除</button>
</div>
<label>
内圈圆线宽 (mm):
<input type="number" v-model.number="innerCircle.innerCircleLineWidth" min="0.05" max="0.5" step="0.05" />
</label>
<label>
内圈圆半径X (mm):
<input type="number" v-model.number="innerCircle.innerCircleLineRadiusX" min="1" max="50" step="0.1" />
</label>
<label>
内圈圆半径Y (mm):
<input type="number" v-model.number="innerCircle.innerCircleLineRadiusY" min="1" max="50" step="0.1" />
</label>
</div>
</div>
</div>
</div>
<!-- Canvas 容器 -->
<div class="canvas-container">
<div style="display: flex; flex-direction: row; margin-top: 12px; gap: 12px">
<!-- 做旧效果设置 -->
<div class="control-group">
<h3>做旧效果</h3>
<label class="checkbox-label">
<input type="checkbox" v-model="applyAging" />
启用做旧效果
</label>
<label class="checkbox-label">
<input type="checkbox" v-model="manualAging" />
手动做旧
</label>
<label v-if="applyAging">
做旧强度:
<input type="range" v-model.number="agingIntensity" min="0" max="100" step="1" />
</label>
<button @click="drawStamp(false, true)">刷新做旧</button>
</div>
<!-- 修改提取印章功能部分 -->
<div class="control-group">
<h3>提取印章</h3>
<button @click="openExtractStampTool">提取印章工具</button>
</div>
</div>
<canvas ref="stampCanvas" width="600" height="600"></canvas>
</div>
</div>
</template>
<script setup lang="ts">
import { ref, onMounted, watch } from 'vue'
import {
DrawStampUtils,
IRoughEdge,
type ICode,
type ICompany,
type IDrawStar,
type IInnerCircle,
type ISecurityPattern,
type IStampType,
type ITaxNumber
} from './DrawStampUtils'
import { getSystemFonts } from './utils/fontUtils'
const editorControls = ref<HTMLDivElement | null>(null)
const stampCanvas = ref<HTMLCanvasElement | null>(null)
const MM_PER_PIXEL = 10 // 毫米换算像素
const isCircleDetect = ref(true)
// 添加响应式数据
const companyName = ref('绘制印章有限责任公司')
// 印章编码
const stampCode = ref('1234567890123')
// 税号
const taxNumberValue = ref('000000000000000000')
// 公司名称字体大小(毫米)
const companyFontFamily = ref('Songti SC')
const companyFontSizeMM = ref(4.2)
const codeFontFamily = ref('SimSun')
// 编码字体大小(毫米)
const codeFontSizeMM = ref(1.2)
// 编码字体宽度(毫米)
const codeFontWidthMM = ref(1.2)
// 圆形印章半径(毫米)
const circleRadius = ref(20)
// 圆形边框宽度(毫米)
const circleBorderWidth = ref(1)
// 圆形边框颜色
const circleBorderColor = ref('#ff0000')
// 五角星直径(毫米)
const starDiameter = ref(14)
// 做旧效果
const applyAging = ref(false)
// 手动做旧
const manualAging = ref(false)
// 添加新的响应式数据
const agingIntensity = ref(50)
// 文字分布因子,控制公司名称文字在椭圆上的分布范围
const textDistributionFactor = ref(3)
// 调整椭圆文字
const adjustEllipseText = ref(false)
// 调整椭圆文字因子
const adjustEllipseTextFactor = ref(0.5)
// 文字边距,控制公司名称文字距离椭圆边缘的距离(单位:毫米)
const textMarginMM = ref(1) // 默认值为1mm
// 编码边距,控制印章编码距离椭圆边缘的距离(单位��毫米)
const codeMarginMM = ref(1) // 默认值为1mm
// 编码分布因子,控制印章编码在椭圆下方的分布范围
const codeDistributionFactor = ref(20) // 默认值可以根据需要调整
// 印章印章类型
const bottomText = ref('合同专用章')
// 印章类型大小,默认 4mm
const bottomTextFontFamily = ref('SimSun')
const bottomTextFontSizeMM = ref(4.6)
const bottomTextFontWidthMM = ref(3)
// 印章类型字符间距,默认 0
const bottomTextLetterSpacing = ref(0)
// 五角星垂直位置调整,认 0
const starPositionY = ref(0)
// 印章类型垂直位置调整,默认 0
const bottomTextPositionY = ref(-5)
const companyNameCompression = ref(1)
const companyNameFontWeight = ref(400)
const bottomTextFontWeight = ref(400)
const codeFontWeight = ref(400)
const taxNumberFontFamily = ref('Songti SC')
const taxNumberFontWeight = ref(400)
const bottomTextCompression = ref(1)
const codeCompression = ref(1)
// 防伪纹路
const securityPatternEnabled = ref(true)
const securityPatternDensity = ref(0.5)
const securityPatternWidth = ref(0.2) // 纹路宽度,单位为毫米
const securityPatternColor = ref('#FF0000')
const securityPatternCount = ref(5) // 防伪纹路数量
const securityPatternLength = ref(2) // 纹路长度,单���为毫米
const showFullRuler = ref(false)
const shouldDrawStar = ref(false) // 默认绘制五角星
const taxNumberCompression = ref(1) // 税号文字宽度缩放比例
const taxNumberLetterSpacing = ref(0.3) // 税号文字间距(单位:毫米)
const taxNumberPositionY = ref(0) // 税号垂直位置调,默认为0
const drawInnerCircle = ref(true) // 是否绘制内圈圆
const innerCircleLineWidth = ref(0.5) // 内圈圆线宽,单位为毫米
const innerCircleWidth = ref(15) // 内圈圆宽度,单位为毫米
const innerCircleHeight = ref(12) // 内圈圆高度,单位为毫米
const drawOutThinCircle = ref(true) // 是否绘制内圈圆
const outThinCircleLineWidth = ref(0.5) // 内圈圆线宽,单位为毫米
const outThinCircleWidth = ref(25) // 内圈圆宽度,单位为毫米
const outThinCircleHeight = ref(22) // 内圈圆高度,单位为毫米
const stampImageRef = ref<HTMLImageElement | null>(null)
const shouldDrawRoughEdge = ref(false) // 是否绘制毛边
const roughEdgeWidth = ref(0.2) // 毛边宽度,单位为毫米
const roughEdgeHeight = ref(5) // 毛边高度,单位为毫米
const roughEdgeProbability = ref(0.5) // 毛边概率
const roughEdgeShift = ref(8) // 毛边偏移
const roughEdgePoints = ref(360) // 毛边点数
const showLegalDialog = ref(false) // 是否显示法律提示弹窗
// 添加印章类型列表的响式数据
const stampTypeList = ref<IStampType[]>([
{
stampType: '发票专用章',
fontHeight: 4.6,
fontFamily: 'SimSun',
compression: 0.75,
letterSpacing: 0,
positionY: -3,
fontWeight: 'normal',
lineSpacing: 2,
fontWidth: 3
}
])
// 添加公司列表的响应式数据
const companyList = ref<ICompany[]>([
{
companyName: '绘制印章有限责任公司',
compression: 1,
borderOffset: 1,
textDistributionFactor: 3,
fontFamily: 'SimSun',
fontHeight: 4.2,
fontWeight: 'normal',
shape: 'ellipse',
adjustEllipseText: false,
adjustEllipseTextFactor: 0.5
}
])
// 添加新的响应式变量
const useStarImage = ref(false)
const starImageWidth = ref(10) // 图片宽度,单位mm
const starImageHeight = ref(10) // 图片高度,单位mm
const keepAspectRatio = ref(true) // 是否保持宽高比
// 添加内圈列表的响应式数据
const innerCircleList = ref<IInnerCircle[]>([
{
drawInnerCircle: true,
innerCircleLineWidth: 0.5,
innerCircleLineRadiusX: 36,
innerCircleLineRadiusY: 27
},
{
drawInnerCircle: true,
innerCircleLineWidth: 0.5,
innerCircleLineRadiusX: 16,
innerCircleLineRadiusY: 12
}
])
const templateFileInput = ref<HTMLInputElement | null>(null)
// 保存模板
const saveAsTemplate = () => {
const drawConfigs = drawStampUtils.getDrawConfigs()
const jsonStr = JSON.stringify(drawConfigs, null, 2)
// 创建 Blob
const blob = new Blob([jsonStr], { type: 'application/json' })
const url = URL.createObjectURL(blob)
// 创建下载链接
const link = document.createElement('a')
link.href = url
link.download = '印章模板.json'
document.body.appendChild(link)
link.click()
// 清理
document.body.removeChild(link)
URL.revokeObjectURL(url)
}
// 触发文件选择
const triggerTemplateLoad = () => {
templateFileInput.value?.click()
}
// 载模板
const loadTemplate = (event: Event) => {
const target = event.target as HTMLInputElement
if (target.files && target.files[0]) {
const file = target.files[0]
const reader = new FileReader()
reader.onload = (e) => {
try {
if (e.target?.result) {
const jsonStr = e.target.result as string
const configs = JSON.parse(jsonStr)
// 设置新的配置
drawStampUtils.setDrawConfigs(configs)
// 恢复界面显示
restoreDrawConfigs()
// 刷新印章显示
drawStamp()
}
} catch (error) {
console.error('加载模板失败:', error)
alert('加载模板失败,请确保文件格式正确')
}
}
reader.readAsText(file)
}
// 清除文件选择,确保同一文件可以重复选择
target.value = ''
}
// 修改图片上传处理函数
const handleStarImageUpload = (event: Event) => {
const target = event.target as HTMLInputElement;
if (target.files && target.files[0]) {
const file = target.files[0];
const reader = new FileReader();
reader.onload = (e) => {
if (e.target?.result) {
const imageUrl = e.target.result as string;
// 使用新方法更新图片
drawStampUtils.updateStarImage(imageUrl);
drawStamp();
}
};
reader.readAsDataURL(file);
}
}
// 添加新的印章类型行
const addNewStampType = () => {
let newPositionY = -3
if(stampTypeList.value.length > 0){
const lastStampType = stampTypeList.value[stampTypeList.value.length - 1]
newPositionY = lastStampType.positionY + lastStampType.fontHeight
}
stampTypeList.value.push({
stampType: '新印章类型',
fontHeight: 4.0,
fontFamily: 'SimSun',
compression: 0.75,
letterSpacing: 0,
positionY: newPositionY,
fontWeight: 'normal',
lineSpacing: 2,
fontWidth: 3
})
}
// 删除指定的印章型行
const removeStampType = (index: number) => {
stampTypeList.value.splice(index, 1)
}
// 添加新的公司行
const addNewCompany = () => {
let newBorderOffset = 1
if(companyList.value.length > 0) {
const lastCompany = companyList.value[companyList.value.length - 1]
newBorderOffset = lastCompany.borderOffset + lastCompany.fontHeight
}
companyList.value.push({
companyName: '新公司名称',
compression: 1,
borderOffset: newBorderOffset,
textDistributionFactor: 3,
fontFamily: 'SimSun',
fontHeight: 4.2,
fontWeight: 'normal',
shape: 'ellipse',
adjustEllipseText: false,
adjustEllipseTextFactor: 0.5
})
}
// 删除指定的公司行
const removeCompany = (index: number) => {
companyList.value.splice(index, 1)
}
const saveStampAsPNG = () => {
showLegalDialog.value = true
}
const drawStampWidth = ref(40)
const drawStampHeight = ref(30)
// 添加新的响应式变量
const bottomTextLineSpacing = ref(1.2) // 默认行间距为1.2mm
// 绘制工具
let drawStampUtils: DrawStampUtils
// 初始化绘制印章参数
const initDrawStampUtils = () => {
drawStampUtils = new DrawStampUtils(stampCanvas.value, MM_PER_PIXEL)
}
const drawStamp = (refreshSecurityPattern: boolean = false, refreshOld: boolean = false) => {
// 使用drawstamputils进行绘制
drawStampUtils.refreshStamp(refreshSecurityPattern, refreshOld)
}
// 添加新内圈
const addNewInnerCircle = () => {
innerCircleList.value.push({
drawInnerCircle: true,
innerCircleLineWidth: 0.5,
innerCircleLineRadiusX: 16,
innerCircleLineRadiusY: 12
})
}
// 删除内圈
const removeInnerCircle = (index: number) => {
innerCircleList.value.splice(index, 1)
}
// 更新绘制配置
const updateDrawConfigs = () => {
const drawConfigs = drawStampUtils.getDrawConfigs()
// 做旧效果
const agingEffect = drawConfigs.agingEffect
agingEffect.applyAging = applyAging.value
agingEffect.agingIntensity = agingIntensity.value
drawConfigs.openManualAging = manualAging.value
// 防伪纹路
const securityPattern: ISecurityPattern = drawConfigs.securityPattern
securityPattern.openSecurityPattern = securityPatternEnabled.value
securityPattern.securityPatternCount = securityPatternCount.value
securityPattern.securityPatternWidth = securityPatternWidth.value
securityPattern.securityPatternLength = securityPatternLength.value
// 公司名称
const company: ICompany = drawConfigs.company
company.companyName = companyName.value
company.textDistributionFactor = textDistributionFactor.value
company.borderOffset = textMarginMM.value
company.fontHeight = companyFontSizeMM.value
company.fontFamily = companyFontFamily.value
company.compression = companyNameCompression.value
company.fontWeight = companyNameFontWeight.value
company.adjustEllipseText = adjustEllipseText.value
company.adjustEllipseTextFactor = adjustEllipseTextFactor.value
// 税号
const taxNumber: ITaxNumber = drawConfigs.taxNumber
taxNumber.code = taxNumberValue.value
taxNumber.compression = taxNumberCompression.value
taxNumber.positionY = taxNumberPositionY.value
taxNumber.letterSpacing = taxNumberLetterSpacing.value
taxNumber.fontFamily = taxNumberFontFamily.value
taxNumber.fontWeight = taxNumberFontWeight.value
// 印章类型
const stampType: IStampType = drawConfigs.stampType
stampType.stampType = bottomText.value
stampType.fontFamily = bottomTextFontFamily.value
stampType.fontHeight = bottomTextFontSizeMM.value