-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommonUtils.js
More file actions
2198 lines (2004 loc) · 94.6 KB
/
Copy pathcommonUtils.js
File metadata and controls
2198 lines (2004 loc) · 94.6 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
/**
* 智能表单数据模拟助手 - 公共工具函数库
* 提取自utils.js和advancedMockData.js的公共逻辑部分
*/
class CommonUtils {
constructor() {
// 公共常量或配置可以在这里定义
// 中文姓名库(三字姓名占大多数,使用通用姓名)
this.chineseNames = [
// 两字姓名
'张三', '李四', '王五', '赵六', '钱七', '孙八', '周九', '吴十',
'刘明', '陈华', '杨光', '黄强', '林峰', '徐静', '朱婷', '马超',
'高飞', '郑云', '冯军', '于伟', '何芳', '吕燕', '施文', '孔祥',
'张伟', '王芳', '李娜', '刘洋', '陈明', '杨丽', '黄伟', '周强',
'徐敏', '孙静', '马涛', '朱军', '胡强', '林娟', '郭明', '何伟',
'高敏', '梁超', '谢芳', '唐勇', '董丽', '袁伟', '邓静',
// 三字姓名(占大多数,通用姓名)
'张小明', '李大伟', '王美丽', '赵建国', '钱学森', '孙丽华', '周志强', '吴秀兰',
'刘德明', '陈小春', '杨玉华', '黄晓光', '林志远', '徐志国', '朱自明', '马化龙',
'高圆圆', '郑成功', '冯小军', '于谦和', '何明亮', '吕良才', '施文华', '孔祥瑞',
'张艺文', '王家明', '李连成', '刘青云', '陈道远', '杨丽萍', '黄波涛', '周润泽',
'吴京华', '徐峥嵘', '孙红霞', '马伊宁', '朱一凡', '胡歌德', '林更新', '郭德明',
'何冰雪', '高亚东', '梁朝辉', '谢霆宇', '唐嫣然', '董洁玉', '袁泉清', '邓超然',
'张国强', '王志文', '李冰洁', '刘晓云', '陈坤明', '杨紫萱', '黄磊磊', '周迅捷',
'吴彦斌', '徐静怡', '孙俪娜', '马思远', '朱丹丹', '胡军强', '林心如', '郭富强',
'何家明', '高曙光', '梁家栋', '谢娜娜', '唐国强', '董璇璇', '袁弘毅', '邓伦伦',
'张嘉文', '王凯旋', '李小璐', '刘诗雨', '陈乔安', '杨颖颖', '黄轩轩', '周杰文',
'吴亦辰', '徐璐璐', '孙楠楠', '马天宇', '朱迅捷', '胡彦斌', '林俊杰', '郭碧云',
'何穗穗', '高以翔', '梁静茹', '谢依霖', '唐艺昕', '董子健', '袁姗姗', '邓紫琪',
'张一鸣', '王源源', '李易峰', '刘浩然', '陈伟霆', '杨洋洋', '黄子韬', '周冬雨',
'吴磊磊', '徐娇娇', '孙怡怡', '马可可', '朱正廷', '胡一天', '林允儿', '郭京飞',
'何润泽', '高伟光', '梁咏琪', '谢孟伟', '唐禹哲', '董成鹏', '袁成杰', '邓家佳',
'张若昀', '王俊凯', '李荣浩', '刘雯雯', '陈赫赫', '杨超越', '黄景瑜', '周渝民',
'吴尊尊', '徐海乔', '孙耀威', '马伯骞', '朱梓骁', '胡夏夏', '林宥嘉', '郭采洁',
'何晟铭', '高瀚宇', '梁洛施', '谢楠楠', '唐诗咏', '董洁洁', '袁冰妍', '邓萃雯',
'张钧甯', '王鸥鸥', '李沁沁', '刘亦菲', '陈妍希', '杨蓉蓉', '黄圣依', '周笔畅'
];
// 英文姓名库(通用英文姓名)
this.englishNames = [
'John Smith', 'Jane Doe', 'Michael Johnson', 'Sarah Williams',
'David Brown', 'Emily Davis', 'Robert Wilson', 'Lisa Miller',
'James Taylor', 'Mary Anderson', 'William Thomas', 'Jennifer Moore',
'Christopher Lee', 'Amanda White', 'Daniel Harris', 'Jessica Martin',
'Matthew Thompson', 'Olivia Garcia', 'Andrew Martinez', 'Sophia Robinson',
'Kevin Clark', 'Emma Rodriguez', 'Brian Lewis', 'Ashley Walker',
'Steven Hall', 'Megan Young', 'Richard King', 'Lauren Scott',
'Thomas Johnson', 'Susan Davis', 'Mark Wilson', 'Karen Miller',
'Paul Taylor', 'Nancy Anderson', 'George Thomas', 'Betty Moore',
'Edward Lee', 'Dorothy White', 'Charles Harris', 'Helen Martin',
'Joseph Thompson', 'Margaret Garcia', 'Donald Martinez', 'Donna Robinson',
'Ronald Clark', 'Carol Rodriguez', 'Kenneth Lewis', 'Michelle Walker',
'Gary Hall', 'Sandra Young', 'Eric King', 'Kimberly Scott'
];
// 省份城市库(更详细的地址数据)
this.provinces = [
'北京市', '天津市', '河北省', '山西省', '内蒙古自治区', '辽宁省', '吉林省', '黑龙江省',
'上海市', '江苏省', '浙江省', '安徽省', '福建省', '江西省', '山东省', '河南省',
'湖北省', '湖南省', '广东省', '广西壮族自治区', '海南省', '重庆市', '四川省', '贵州省',
'云南省', '西藏自治区', '陕西省', '甘肃省', '青海省', '宁夏回族自治区', '新疆维吾尔自治区'
];
this.cities = [
// 直辖市和主要城市
'北京市', '天津市', '上海市', '重庆市',
'石家庄市', '太原市', '呼和浩特市', '沈阳市', '长春市', '哈尔滨市',
'南京市', '杭州市', '合肥市', '福州市', '南昌市', '济南市', '郑州市',
'武汉市', '长沙市', '广州市', '南宁市', '海口市', '成都市', '贵阳市',
'昆明市', '拉萨市', '西安市', '兰州市', '西宁市', '银川市', '乌鲁木齐市'
];
this.districts = [
// 各区县
'朝阳区', '海淀区', '西城区', '东城区', '丰台区', '石景山区', '通州区', '顺义区',
'浦东新区', '徐汇区', '长宁区', '静安区', '普陀区', '虹口区', '杨浦区', '黄浦区',
'天河区', '越秀区', '荔湾区', '海珠区', '白云区', '黄埔区', '番禺区', '花都区',
'西湖区', '上城区', '下城区', '江干区', '拱墅区', '滨江区', '萧山区', '余杭区',
'鼓楼区', '玄武区', '秦淮区', '建邺区', '栖霞区', '雨花台区', '江宁区', '浦口区'
];
this.streets = [
'人民路', '解放路', '中山路', '建设路', '文化路', '科技路', '和平路', '幸福路',
'光明路', '胜利路', '前进路', '团结路', '友谊路', '民主路', '自由路', '平等路',
'新华路', '中华路', '长江路', '黄河路', '珠江路', '淮海路', '延安路', '北京路',
'南京路', '上海路', '广州路', '深圳路', '杭州路', '成都路', '武汉路', '西安路'
];
this.roadTypes = ['大道', '大街', '路', '街', '巷', '弄', '胡同', '里'];
this.buildingNumbers = ['号', '栋', '幢', '座', '单元'];
// 公司名称库
this.companies = [
'科技有限公司', '信息技术有限公司', '软件开发有限公司', '网络科技有限公司',
'电子科技有限公司', '智能科技有限公司', '数据科技有限公司', '创新科技有限公司',
'多亿科技有限公司', '肯德信息技术有限公司', '黑作软件开发有限公司', '姆超网络科技有限公司',
'麦当电子科技有限公司', '里里智能科技有限公司', '星巴数据科技有限公司', '大洋创新科技有限公司'
];
}
/**
* 智能获取父级元素中的label文本信息(支持多种UI框架)
* 这个方法在utils.js和advancedMockData.js中完全相同
*/
getParentLabelText(element) {
// 常见UI框架的表单项选择器配置
const formItemSelectors = [
// Element UI
{ formItem: '.el-form-item', label: '.el-form-item__label' },
// Ant Design
{ formItem: '.ant-form-item', label: '.ant-form-item-label' },
// Bootstrap
{ formItem: '.form-group', label: 'label' },
// Vuetify
{ formItem: '.v-input', label: '.v-label' },
// Material-UI
{ formItem: '.MuiFormControl-root', label: '.MuiFormLabel-root' },
// PrimeNG
{ formItem: '.p-field', label: 'label' },
// Chakra UI
{ formItem: '.chakra-form-control', label: '.chakra-form__label' },
// Tailwind CSS 常见模式
{ formItem: '[class*="form-group"]', label: 'label' }
];
// 首先尝试UI框架特定的选择器
for (const { formItem, label } of formItemSelectors) {
const formItemElement = element.closest(formItem);
if (formItemElement) {
const labelElement = formItemElement.querySelector(label);
if (labelElement?.textContent?.trim()) {
return labelElement.textContent.trim();
}
}
}
// 如果UI框架选择器失败,尝试通用查找策略
const genericStrategies = [
// 1. 查找最近的label元素
() => {
const label = element.closest('label');
return label?.textContent?.trim();
},
// 2. 查找前一个兄弟元素中的label
() => {
let sibling = element.previousElementSibling;
while (sibling) {
if (sibling.tagName === 'LABEL') {
return sibling.textContent?.trim();
}
if (sibling.querySelector('label')) {
return sibling.querySelector('label')?.textContent?.trim();
}
sibling = sibling.previousElementSibling;
}
return null;
},
// 3. 查找父元素中的label
() => {
const parentLabel = element.parentElement?.querySelector('label');
return parentLabel?.textContent?.trim();
},
// 4. 向上遍历祖先元素查找包含"label"字样的元素
() => {
let ancestor = element.parentElement;
while (ancestor && ancestor !== document.body) {
const labels = ancestor.querySelectorAll('[class*="label"], [id*="label"], [for]');
for (const label of labels) {
if (label.textContent?.trim()) {
return label.textContent.trim();
}
}
ancestor = ancestor.parentElement;
}
return null;
},
// 5. 查找包含"标题"、"名称"等文本的相邻元素
() => {
const siblings = [
element.previousElementSibling,
element.nextElementSibling,
element.parentElement?.firstElementChild,
element.parentElement?.lastElementChild
];
for (const sibling of siblings) {
if (sibling?.textContent?.trim() &&
/标题|名称|标题|label|title|caption|heading/i.test(sibling.textContent)) {
return sibling.textContent.trim();
}
}
return null;
}
];
// 按顺序尝试通用策略
for (const strategy of genericStrategies) {
const result = strategy();
if (result) {
return result;
}
}
return '';
}
/**
* 通用的表单填充辅助方法
* 支持多种表单元素类型,包括输入框、下拉框、复选框、单选按钮等
*/
fillFormElementHelper(element, value) {
try {
// 确保值为字符串类型,避免数字类型在某些框架中无法正确处理
const stringValue = String(value);
if (element.tagName === 'SELECT') {
// 处理下拉框
for (let i = 0; i < element.options.length; i++) {
if (element.options[i].text.includes(stringValue) || element.options[i].value.includes(stringValue)) {
element.selectedIndex = i;
break;
}
}
element.dispatchEvent(new Event('change', { bubbles: true, composed: true }));
} else if (element.tagName === 'INPUT' && (element.type === 'checkbox' || element.type === 'radio')) {
// 处理复选框和单选按钮
const shouldCheck = value === true || value === 'true' || value === '1';
element.checked = shouldCheck;
element.dispatchEvent(new Event('change', { bubbles: true, composed: true }));
element.dispatchEvent(new Event('click', { bubbles: true, composed: true }));
} else {
// 处理普通输入框和文本域
element.value = stringValue;
['input', 'change', 'blur'].forEach(eventType => {
element.dispatchEvent(new Event(eventType, { bubbles: true, composed: true }));
});
}
} catch (error) {
console.error('表单填充失败:', error);
}
}
/**
* 通用的字段类型识别方法
* 提取自detectPlaceholderFormat和detectInputType的公共逻辑
* @param {string} text - 要识别的文本
* @param {boolean} isEnglishField - 是否为英文字段
* @returns {string|null} - 识别出的字段类型,未识别返回null
*/
detectFieldTypeByText(text, isEnglishField = false) {
if (!text || text.trim() === '') return null;
const textLower = text.toLowerCase();
// ================= 1. 强特征个人隐私与账号类 =================
if (/身份证|id.*card|identity|证件号|身份证号|公民身份|护照|驾照|驾驶证|passport|driver.*license/.test(textLower)) {
return 'id_card';
}
if (/银行卡.*号|卡号|bank.*card|credit.*card|信用卡|借记卡|账户.*号|account.*no|iban|银行账户|账户/.test(textLower)) {
return 'bank_card';
}
if (/微信号|微信id|wechat|wxid|wechat.*id|微信.*账号/.test(textLower)) {
return 'wechat';
}
if (/qq|qq号|qq号码|腾讯qq|tencent.*qq|q号/.test(textLower)) {
return 'qq';
}
if (/手机|电话|phone|mobile|tel|电话号码|手机号|手机号码|联系电话|收货人.*电话|紧急.*联系.*电话|座机|固定电话|telephone|cellphone|contact.*no/.test(textLower)) {
return 'phone';
}
if (/邮箱|email|mail|电子邮箱|电子邮件|e-mail|mailbox/.test(textLower)) {
return 'email';
}
if (/密码|password|pwd|pass|secret|确认.*密码|支付密码|登录密码|pin.*code/.test(textLower)) {
return 'password';
}
if (/验证码|captcha|code|verify|verification|security.*code|短信验证码|动态验证码|otp|token/.test(textLower)) {
return 'captcha';
}
// ================= 2. 独立抽离:具有强特征/约定俗成的业务标识(从 large_number 中解放) =================
if (/uuid|guid/.test(textLower)) {
return 'uuid'; // 独立类型:36位唯一标识符
}
if (/商品.*条码|条形码|barcode/.test(textLower)) {
return 'barcode'; // 独立类型:通常是13位 EAN 条码
}
if (/sku.*id|spu.*id|sku编码|spu编码|商品.*编码/.test(textLower)) {
return 'sku_spu'; // 独立类型:电商货品唯一代码
}
if (/发票.*号|发票号码|invoice.*no/.test(textLower)) {
return 'invoice_no'; // 独立类型:发票号(国内通常为8位或20位数字)
}
if (/车牌|车牌号|plate.*number|车牌号码|机动车号/.test(textLower)) {
return 'license_plate';
}
if (/ip地址|ip.*address|ip网段|ipv4|ipv6|主机ip/.test(textLower)) {
return 'ip_address';
}
if (/物料.*编码|物料.*号|物料.*代码|货位.*编码|库位.*编码|条码.*标签|material.*no|material.*code|sku.*code/.test(textLower)) {
return 'material_code'; // 独立类型:物料/货位专属编码(如:MAT-10023 或 LOC-A1-02)
}
if (/物料.*名称|物料.*品名|商品.*品名|物料.*规格|规格.*型号|specifications|material.*name/.test(textLower)) {
return 'material_name_spec'; // 独立类型:物料名称与规格(如:不锈钢螺丝 M6*16)
}
if (/计量.*单位|主.*单位|库存.*单位|发料.*单位|unit.*of.*measure|uom/.test(textLower)) {
return 'material_uom'; // 独立类型:ERP 计量单位(如:pcs, 件, 吨, 箱)
}
if (/仓库.*名称|库房.*名称|存储.*仓库|收货.*仓库|出库.*仓库|wh.*name|warehouse/.test(textLower)) {
return 'warehouse_name'; // 独立类型:仓库名称(如:综合成品仓、一号原材料库)
}
if (/库存.*状态|质检.*状态|物料.*状态|批次.*状态|inventory.*status/.test(textLower)) {
return 'inventory_status'; // 独立类型:仓储专用状态(如:合格、待检、不合格、冻结)
}
if (/货位|库位|排架|仓位|储位|storage.*location|bin.*location/.test(textLower)) {
return 'storage_location'; // 独立类型:具体货位(如:A区03排4层02号)
}
if (/供应商.*名称|生产.*厂商|制造.*商|vendor.*name|supplier/.test(textLower)) {
return 'supplier_company'; // 独立类型:工业级供应商/厂商名称
}
if (/车架号|vin.*码|vin|车身.*号|底盘号|chassis.*no/.test(textLower)) {
return 'car_vin'; // 独立类型:17位国际标准车架号(VIN)
}
if (/发动机.*号|发动机.*编码|engine.*no|motor.*no/.test(textLower)) {
return 'engine_no'; // 独立类型:汽车发动机号
}
if (/车型|车辆.*型号|汽车.*型号|维保.*车型|car.*model|vehicle.*type/.test(textLower)) {
return 'car_model'; //独立类型:特定汽车车型(如:2024款 奔驰C200L)
}
if (/汽车.*厂商|汽车.*品牌|主机厂|车企|汽车.*制造|car.*brand|oem/.test(textLower)) {
return 'car_brand'; // 独立类型:汽车品牌/厂商名称(如:比亚迪、保时捷、广汽本田)
}
if (/配件.*编码|配件.*号|汽配.*编码|零件.*号|part.*no|part.*code/.test(textLower)) {
return 'car_part_code'; // 独立类型:标准汽配零件号(如:4F0-616-039)
}
if (/配件.*名称|汽配.*名称|零件.*名称|更换.*配件|part.*name/.test(textLower)) {
return 'car_part_name'; // 独立类型:汽配零件名称与规格(如:前制动刹车片、机油滤清器)
}
if (/行驶.*里程|维保.*里程|公里数|当前.*里程|mileage|odometer/.test(textLower)) {
return 'car_mileage'; // 独立类型:车辆行驶里程数(如:65200 km)
}
if (/维保.*项目|维修.*项目|保养.*项目|故障.*描述|故障.*现象|repair.*item|diagnostic/.test(textLower)) {
return 'car_repair_item'; // 独立类型:车辆故障或维保工单项目(如:更换变速箱油、火花塞积碳清洗)
}
if (/车.*颜色|汽车.*颜色|车身.*颜色|车色|car.*color|vehicle.*color/.test(textLower)) {
return 'car_color';
}
// ================= 3. 确定性枚举与状态属性类 =================
if (/性别|性別|男女|gender|sex|male|female/.test(textLower)) {
return 'gender';
}
if (/求职状态|求職狀態|在职状态|在職狀態|工作状态|工作狀態|job_status|employment_status|求职.*意向|离职.*状态|在校.*状态/.test(textLower)) {
return 'job_status';
}
if (/状态|狀態|情况|情況|status|state|phase|stage|status_type|设备.*状态|订单.*状态|支付.*状态|状态.*开关|审核.*结果|审批.*进度/.test(textLower)) {
return 'status_type';
}
if (/支付.*方式|付款方式|买单|買單|pay|payment|method|pay_method|结算.*渠道|收款.*方式|网银|微信支付|支付宝/.test(textLower)) {
return 'payment_method';
}
if (/是否.*及格|是否.*同意.*条款|是否.*开通|是否.*必填|is_|是否.*启用|是否.*有效|是否.*包邮|是否.*首次|boolean|checked|switch/.test(textLower)) {
return 'yes_no_type';
}
if (/与本人.*关系|家属关系|亲属关系|relationship|紧急.*联系人.*关系|亲属|家属/.test(textLower)) {
return 'relationship_type';
}
if (/优先级|優先級|紧迫|紧要|程度|priority|urgency|重要性|缓急|级别/.test(textLower)) {
return 'priority';
}
if (/风险|風險|危险|危險|risk|hazard|danger|risk_level|安全等级|漏洞.*级别|风控/.test(textLower)) {
return 'risk_level';
}
if (/血型|blood|type|abo/.test(textLower)) {
return 'blood_type';
}
if (/星座|星象|constellation|horoscope/.test(textLower)) {
return 'constellation';
}
// ================= 4. 社交 / 人口普查属性类 =================
if (/民族|族别|族別|nation/.test(textLower)) {
return 'nation';
}
if (/籍贯|籍贯|老家|出生地|户籍|戶籍|native|place|常住地|祖籍|户口.*所在地/.test(textLower)) {
return 'native';
}
if (/政治面貌|党派|黨派|political|party|党员|共青团员|群众/.test(textLower)) {
return 'political';
}
if (/婚姻.*状态|婚姻.*狀態|婚姻|婚况|婚況|marital|status|marriage|已婚|未婚|离婚|丧偶/.test(textLower)) {
return 'marital';
}
// ================= 5. 教育与职场类 =================
if (/学历|學歷|学位|學位|文化程度|education|degree|最高学历|本科|硕士|博士|大专|高中/.test(textLower)) {
return 'education';
}
if (/毕业.*学校|毕业.*學校|毕业院校|畢業院校|学校|學校|大学|大學|school|university|college|学院|中小学|机构/.test(textLower)) {
return 'school';
}
if (/毕业.*专业|毕业.*專業|专业|專業|学科|學科|major|profession|discipline|研究方向/.test(textLower)) {
return 'major';
}
if (/职业|occupation|job|职位|position|行业|industry|职务|job_title|角色|role|职称|部门|工种|名衔/.test(textLower)) {
return 'job';
}
if (/特长|特長|技能|专长|專長|specialty|skill|ability|核心能力|掌握技术|证书/.test(textLower)) {
return 'specialty';
}
if (/兴趣.*爱好|兴趣.*愛好|兴趣|興趣|爱好|愛好|嗜好|hobby|interest|休闲休闲|偏好/.test(textLower)) {
return 'hobby';
}
// ================= 6. 地理与实体类 =================
if (/公司|企业|上班地点|商户|工商|Company|企业名称|单位|组织|机构|店铺|商铺|vendor|merchant|firm/.test(textLower)) {
return isEnglishField ? 'english_company' : 'chinese_company';
}
if (/地址|address|addr|location|住址|收货地址|配送地址|省市区|详细.*地址|国家|省份|城市|县区|街道|门牌号|区域|zone|region/.test(textLower)) {
return 'address';
}
if (/邮政.*编码|邮政编码|zip.*code|邮编|postal.*code/.test(textLower)) {
return 'zip_code';
}
if (/网址|url|website|link|链接|主页|homepage|视频.*链接|网址.*链接|域名|domain/.test(textLower)) {
return 'url';
}
if (/生肖|属相|zodiac/.test(textLower)) {
return 'zodiac_animal'; // 独立类型:可用于生成 "龙"、"虎" 等十二生肖
}
if (/季度|周期|quarter|period/.test(textLower)) {
return 'quarter_period'; // 独立类型:可按您的要求生成类似 "2026Q1" 的特定格式
}
if (/国籍|nationality/.test(textLower)) {
return 'nationality'; // 独立类型:可用于生成国家名称,如 "中国"、"美国"
}
if (/种族|ethnicity/.test(textLower)) {
return 'ethnicity'; // 独立类型:可用于生成特定族群,如 "亚裔"、"高加索人"
}
if (/运动|健身|体育|项目|爱好.*运动|sport|sports|fitness|workout|exercise/.test(textLower)) {
return 'sports_type'; // 新增类型:可用于生成 "羽毛球"、"跑步"、"游泳" 等运动项目
}
if (/衣服.*尺码|衣服.*尺寸|上衣.*尺码|外套.*尺码|裤子.*尺码|服装.*尺寸|clothing.*size|apparel.*size/.test(textLower)) {
return isEnglishField ? 'english_clothing_size' : 'chinese_clothing_size'; // 独立类型:生成国际标准尺码(如 S, M, L, XL)
}
if (/鞋码|鞋子.*尺码|鞋号|shoe.*size|footwear.*size/.test(textLower)) {
return isEnglishField ? 'english_shoe_size' : 'chinese_shoe_size'; // 独立类型:生成鞋码(如 38, 42 或 US 8.5)
}
// ================= 电商场景高频扩充:约定俗成的强特征字段 =================
if (/快递公司|物流.*渠道|承运商|carrier|logistic.*company/.test(textLower)) {
return 'logistic_company'; // 独立类型:生成 "顺丰速运", "中通快递" 等
}
if (/售后.*类型|退换.*类型|退款.*类型|after.*sales.*type/.test(textLower)) {
return 'after_sales_type'; // 独立类型:生成 "仅退款", "退货退款", "换货"
}
if (/优惠券.*类型|券.*种类|coupon.*type/.test(textLower)) {
return 'coupon_type'; // 独立类型:生成 "满减券", "折扣券", "立减券"
}
if (/店铺.*类型|商户.*类型|shop.*type|store.*type/.test(textLower)) {
return 'shop_type'; // 独立类型:生成 "旗舰店", "专营店", "自营"
}
// ================= 7. 时间日期与经济金融类 =================
if (/时间|date|time|生日|birthday|出生|创建|更新|发起|开始|结束|发货|签收|保修|有效|截止|时段|打卡|日程|年份|月份|日期|datetime|timestamp/.test(textLower)) {
return 'date';
}
if (/金额|价格|price|amount|money|cost|fee|总金额|单价|优惠券.*金额|实付.*金额|退款.*金额|运费|预计.*预算|税率|开销|计费|充值|提现|尾款|定金|折后价|税后|薪资|工钱|salary/.test(textLower)) {
return 'price';
}
// ================= 8. 数字与量化度量类 =================
if (/年龄|age|岁数/.test(textLower)) {
return 'age';
}
if (/身高|height|tall|身长/.test(textLower)) {
return 'tall';
}
if (/体重|weight|磅数|公斤数/.test(textLower)) {
return 'weight';
}
if (/文件大小|字节|视频大小|图片大小|存储.*容量|存储容量|运行.*内存|ram|rom|磁盘空间|size|bytes/.test(textLower)) {
return 'large_number';
}
if (/编号|编号.*号|serial.*number|id.*number|订单.*编号|支付.*交易号|物流.*单号|设备.*序列号|imei|学号|工号|准考证.*号|纳税人.*识别号|合同.*号|快递单号|运单号|sn码/.test(textLower)) {
return 'large_number'; // 各种自定义的长编号流水号
}
if (/数量|个数|quantity|count|number|级别|level|grade|年级|班级|考试.*座位号|考试.*时长|折扣.*比例|满意.*度.*评分|排序.*序号|屏幕.*尺寸|计数|频次|点击量|浏览量|pv|uv|天数|件数|打折|得分|score/.test(textLower)) {
return 'small_number';
}
if (/代码|code|编码|coding|计划.*代码|批次|batch|客房.*代码|提取码|激活码|券码|兑换码|coupon.*code/.test(textLower)) {
return 'code_number';
}
// ================= 9. 独立抽离:软硬件系统环境类(从 description 中解放) =================
if (/操作.*系统|固件.*版本|os.*version|linux|windows|android|ios/.test(textLower)) {
return 'os_type'; // 独立类型:生成诸如 "iOS 17.4" 或 "Ubuntu 22.04"
}
if (/产品.*品牌|产品.*型号|产品.*颜色|手机.*品牌|品牌.*型号|brand|model/.test(textLower)) {
return 'device_brand'; // 独立类型:生成诸如 "Apple iPhone 15" 或 "Sony WH-1000XM4"
}
// ================= 10. 名字与文本泛化类(较低优先级) =================
if (/姓名|名称|name|title|用户.*姓名|收货人.*姓名|教师.*姓名|紧急.*联系人|联系人|昵称|别名|姓名.*拼音|收款人|付款人|.*人|明星|歌手|演员|humer|star|singer|actor|alias|nickname/.test(textLower)) {
return isEnglishField ? 'english_name' : 'chinese_name';
}
if (/角色|权限|權限|类型|類型|role|permission|type|role_type|群组|组织架构/.test(textLower)) {
return 'role_type';
}
// ================= 11. 兜底描述备注类(最低优先级) =================
if (/描述|description|desc|remark|note|备注|说明|介绍|个人.*简介|type|category|lots|网络.*制式|发票.*类型|退款.*原因|证件.*类型|行业.*类型|核心.*诉求.*意向|意见反馈|文本|详情|正文|摘要|评论|留言|content|summary|comment/.test(textLower)) {
return isEnglishField ? 'english_description' : 'chinese_description';
}
return null;
}
/**
* 通用的placeholder格式检测方法
* 提取自detectPlaceholderFormat的格式识别逻辑
* @param {string} placeholder - placeholder文本
* @returns {string|null} - 格式类型标识,未识别到格式返回null
*/
detectPlaceholderFormatCommon(placeholder) {
if (!placeholder || placeholder.trim() === '') return null;
const placeholderText = placeholder.trim();
// 1. 月份格式识别:YYYYMM (如202504 → 2025年04月)
if (/^\d{6}$/.test(placeholderText) &&
parseInt(placeholderText.substring(4, 6)) >= 1 &&
parseInt(placeholderText.substring(4, 6)) <= 12) {
return 'month_format';
}
// 2. 日期格式识别:YYYY-MM-DD、YYYY/MM/DD、YYYY.MM.DD
if (/^\d{4}[-./]\d{1,2}[-./]\d{1,2}$/.test(placeholderText)) {
return 'date_format';
}
// 3. 金额格式识别:¥1,234.56、1,234.56元、1,234.56
if (/^[¥¥]?\d{1,3}(,\d{3})*(\.\d{1,2})?[元]?$/.test(placeholderText) ||
/^\d{1,3}(,\d{3})*(\.\d{1,2})?[元]?$/.test(placeholderText)) {
return 'price_format';
}
// 4. 时间格式识别:HH:mm、HH:mm:ss
if (/^\d{1,2}:\d{2}(:\d{2})?$/.test(placeholderText)) {
return 'time_format';
}
// 5. 年份格式识别:YYYY年
if (/^\d{4}年$/.test(placeholderText)) {
return 'year_format';
}
// 6. 手机号格式识别:11位数字
if (/^\d{11}$/.test(placeholderText)) {
return 'phone_format';
}
// 7. 邮箱格式识别:包含@符号
if (/^[^@]+@[^@]+\.[^@]+$/.test(placeholderText)) {
return 'email_format';
}
// 8. 身份证格式识别:15位或18位数字
if (/^\d{15}$|^\d{17}[\dxX]$/.test(placeholderText)) {
return 'id_card_format';
}
return null;
}
/**
* 通用的随机数生成器
*/
getRandom() {
return Math.random();
}
/**
* 通用的随机整数生成器
*/
getRandomInt(min, max) {
return Math.floor(this.getRandom() * (max - min + 1)) + min;
}
/**
* 从数组中随机获取元素
*/
getRandomFromArray(array) {
if (!array || array.length === 0) return null;
return array[this.getRandomInt(0, array.length - 1)];
}
/**
* 生成随机字符串
*/
generateRandomString(length, includeNumbers = true, includeSymbols = false, includeLowercase = true, includeUppercase = true) {
const numbers = '0123456789';
const symbols = '!@#$%^&*()_+-=[]{}|;:,.<>?';
const lowercase = 'abcdefghijklmnopqrstuvwxyz';
const uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
let charset = '';
if (includeNumbers) charset += numbers;
if (includeSymbols) charset += symbols;
if (includeLowercase) charset += lowercase;
if (includeUppercase) charset += uppercase;
if (charset.length === 0) charset = lowercase + uppercase;
let result = '';
for (let i = 0; i < length; i++) {
result += charset[this.getRandomInt(0, charset.length - 1)];
}
return result;
}
/**
* 格式化日期为字符串
*/
formatDate(date, format = 'yyyy-MM-dd') {
const year = date.getFullYear();
const month = String(date.getMonth() + 1).padStart(2, '0');
const day = String(date.getDate()).padStart(2, '0');
return format
.replace('yyyy', year)
.replace('MM', month)
.replace('dd', day);
}
/**
* 生成模拟数据(带选项) 公共
*/
generateMockDataWithOptions(type, options = {}) {
switch (type) {
case 'checkbox':
// 复选框返回true表示勾选
return true;
case 'radio':
// 单选按钮返回true表示选中
return true;
case 'select':
return this.generateSelect();
case 'chinese_name':
return this.generateChineseName();
case 'english_name':
return this.generateEnglishName();
case 'small_price':
return this.generateSmallPrice();
case 'large_price':
return this.generateLargePrice();
case 'small_number':
return this.generateSmallNumber();
case 'large_number':
return this.generateLargeNumber();
case 'price':
return this.generatePrice();
case 'phone':
return this.generatePhone();
case 'captcha':
return this.generateCaptcha(options.length);
case 'email':
return this.generateEmail();
case 'qq':
return this.generateQQ();
case 'id_card':
return this.generateIDCard();
case 'address':
return this.generateAddress();
case 'password':
return this.generatePassword();
case 'date':
return this.generateDate();
case 'chinese_description':
return this.generateChineseDescription();
case 'english_description':
return this.generateEnglishDescription();
case 'chinese_company':
return this.generateCompanyName(false);
case 'english_company':
return this.generateCompanyName(true);
case 'chinese_position':
return this.generatePosition(false);
case 'english_position':
return this.generatePosition(true);
case 'url':
return this.generateURL();
case 'random_chinese_text':
return this.generateRandomChineseText();
case 'random_english_text':
return this.generateRandomEnglishText();
// 新增:placeholder格式类型
case 'month_format':
return this.generateMonthFormat();
case 'date_format':
return this.generateDateFormat();
case 'price_format':
return this.generatePriceFormat();
case 'time_format':
return this.generateTimeFormat();
case 'year_format':
return this.generateYearFormat();
case 'phone_format':
return this.generatePhone();
case 'email_format':
return this.generateEmail();
case 'id_card_format':
return this.generateIDCard();
// 新增:高级模式兼容类型
case 'username':
return this.generateUsername();
case 'zip_code':
return this.generateZipCode();
case 'age':
return this.generateAge();
case 'gender':
return this.generateGender();
case 'tall':
return this.generateTall();
case 'weight':
return this.generateWeight();
// 新增:省市街道区类型
case 'province':
return this.generateProvince();
case 'city':
return this.generateCity();
case 'district':
return this.generateDistrict();
case 'street':
return this.generateStreet();
// 新增:日期类型
case 'past_date':
return this.generatePastDate();
case 'future_date':
return this.generateFutureDate();
case 'wechat':
return this.generateWechat();
case 'license_plate':
return this.generateLicensePlate();
case 'ip_address':
return this.generateIpAddress();
case 'uuid':
return this.generateUuid();
case 'barcode':
return this.generateBarcode();
case 'sku_spu':
return this.generateSkuSpu();
case 'invoice_no':
return this.generateInvoiceNo();
case 'os_type':
return this.generateOsType();
case 'device_brand':
return this.generateDeviceBrand();
case 'zodiac_animal':
return this.generateZodiacAnimal();
case 'quarter_period':
return this.generateQuarterPeriod();
case 'nationality':
return this.generateNationality();
case 'ethnicity':
return this.generateEthnicity();
case 'sports_type':
return this.generateSportsType();
case 'chinese_clothing_size':
return this.generateClothingSize(false);
case 'chinese_shoe_size':
return this.generateShoeSize(false);
case 'english_clothing_size':
return this.generateClothingSize(true);
case 'english_shoe_size':
return this.generateShoeSize(true);
case 'logistic_company':
return this.generateLogisticCompany();
case 'after_sales_type':
return this.generateAfterSalesType();
case 'coupon_type':
return this.generateCouponType();
case 'shop_type':
return this.generateShopType();
case 'material_code':
return this.generateMaterialCode();
case 'material_name_spec':
return this.generateMaterialNameSpec();
case 'material_uom':
return this.generateMaterialUom();
case 'warehouse_name':
return this.generateWarehouseName();
case 'inventory_status':
return this.generateInventoryStatus();
case 'storage_location':
return this.generateStorageLocation();
case 'supplier_company':
return this.generateSupplierCompany();
case 'car_vin':
return this.generateCarVin();
case 'engine_no':
return this.generateEngineNo();
case 'car_model':
return this.generateCarModel();
case 'car_brand':
return this.generateCarBrand();
case 'car_part_code':
return this.generateCarPartCode();
case 'car_part_name':
return this.generateCarPartName();
case 'car_mileage':
return this.generateCarMileage();
case 'car_repair_item':
return this.generateCarRepairItem();
case 'car_color':
return this.generateCarColor();
// 新增:存储容量、职位、编码、银行卡类型
case 'byte_number':
return this.generateByteNumber();
case 'job':
return this.generateJob();
case 'job_status': {
const a = ['在职-暂无跳槽意向', '在职-急寻新机会', '离职-随时到岗', '在校应届生', '自由职业者', '创业中', '退休', '待业/正在寻找新方向'];
return a[Math.floor(Math.random() * a.length)];
}
case 'code_number':
return this.generateCodeNumber();
case 'bank_card':
return this.generateBankCard();
// 新增:状态类型、支付方式、是否类型、关系类型
case 'status_type':{
const a = ['未完成', '进行中', '已完成', '已取消', '未知'];
return a[Math.floor(Math.random() * a.length)];
}
case 'nation': { // 56个民族精选
const a = ['汉族', '蒙古族', '回族', '藏族', '维吾尔族', '苗族', '彝族', '壮族', '布依族', '朝鲜族', '满族', '侗族', '瑶族', '白族', '土家族', '哈尼族', '哈萨克族', '傣族', '黎族', '高山族', '畲族', '高山族', '拉祜族', '水族'];
return a[Math.floor(Math.random() * a.length)];
}
case 'native': { // 籍贯
const a = ['北京市', '上海市', '天津市', '重庆市', '广东省广州市', '广东省深圳市', '浙江省杭州市', '江苏省南京市', '江苏省苏州市', '山东省青岛市', '四川省成都市', '湖北省武汉市', '陕西省西安市', '福建省厦门市', '湖南省长沙市', '河南省郑州市', '辽宁省大连市', '安徽省合肥市'];
return a[Math.floor(Math.random() * a.length)];
}
case 'political': { // 政治面貌
const a = ['中共党员', '中共预备党员', '共青团员', '群众', '无党派民主人士', '其他'];
return a[Math.floor(Math.random() * a.length)];
}
case 'marital': { // 婚姻状况
const a = ['未婚', '已婚', '离异', '丧偶', '再婚', '分居', '恋爱中', '不便透露'];
return a[Math.floor(Math.random() * a.length)];
}
case 'blood_type': { // 血型
const a = ['A型', 'B型', 'AB型', 'O型', 'AB型'];
return a[Math.floor(Math.random() * a.length)];
}
case 'school': { // 知名高校扩充
const a = ['清华大学', '北京大学', '复旦大学', '上海交通大学', '浙江大学', '南京大学', '中国科学技术大学', '华中科技大学', '武汉大学', '西安交通大学', '中山大学', '四川大学', '哈尔滨工业大学', '同济大学', '北京航空航天大学', '南开大学', '厦门大学', '山东大学', '吉林大学', '东南大学'];
return a[Math.floor(Math.random() * a.length)];
}
case 'major': { // 热门专业扩充
const a = ['计算机科学与技术', '软件工程', '人工智能', '数据科学与大数据技术', '工商管理', '金融学', '经济学', '机械工程', '自动化', '汉语言文学', '英语', '法学', '临床医学', '土木工程', '电子信息工程', '通信工程', '环境科学', '新闻学', '数字媒体技术', '统计学'];
return a[Math.floor(Math.random() * a.length)];
}
case 'hobby': { // 兴趣爱好扩充
const a = ['篮球', '足球', '羽毛球', '网球', '游泳', '健身', '跑步', '摄影', '旅游', '徒步', '看电影', '听音乐', '吉他', '钢琴', '玩游戏', '看书', '写作', '烹饪', '烘焙', '手工DIY', '画画', '跳舞', '剧本杀', '钓鱼', '露营', '乐高'];
return a[Math.floor(Math.random() * a.length)];
}
case 'specialty': { // 特长技能扩充
const a = ['全栈开发', '视频剪辑与特效', '熟练UI设计', '擅长公众演讲', '英语同声传译', '日语N1', '钢琴十级', '高级数据分析', '精通高并发架构', '擅长文案策划', '危机公关处理', '熟练掌握三维建模', '速读与快速记忆', '精通跨境电商运营', '擅长团队组织协调'];
return a[Math.floor(Math.random() * a.length)];
}
case 'education': {
const a = ['博士后', '博士', '硕士', '本科(双一流)', '本科(一本)', '本科(二本)', '大专', '高职/非全日制', '高中', '中专/职高', '初中及以下'];
return a[Math.floor(Math.random() * a.length)];
}
case 'role_type': {
const a = ['超级管理员', '系统管理员', '运营总监', '普通运营', '财务总监', '出纳/财务人员', '技术负责人', '开发工程师', '测试工程师', '产品经理', '客服主管', '普通客服', '普通用户', 'VIP会员', '访客'];
return a[Math.floor(Math.random() * a.length)];
}
case 'priority': {
const a = ['P0-紧急致命', 'P1-高优先级', 'P2-正常处理', 'P3-低优先级', 'P4-优化建议', '最高级', '次高级', '普通', '较低'];
return a[Math.floor(Math.random() * a.length)];
}
case 'risk_level': {
const a = ['极高风险', '高风险', '中风险', '低风险', '零风险', '安全安全', '核心监控中', '合规豁免'];
return a[Math.floor(Math.random() * a.length)];
}
case 'constellation': {
const a = ['白羊座', '金牛座', '双子座', '巨蟹座', '狮子座', '处女座', '天秤座', '天蝎座', '射手座', '摩羯座', '水瓶座', '双鱼座'];
return a[Math.floor(Math.random() * a.length)];
}
case 'payment_method':
{
const a = ['银行卡', '支付宝', '微信', '现金', '信用卡', '其他'];
return a[Math.floor(Math.random() * a.length)];
}
case 'yes_no_type':
return Math.random() > 0.5 ? '是' : '否';
case 'relationship_type':
{
const a = ['父亲', '母亲', '配偶', '子女', '兄弟姐妹', '朋友', '同事', '其他'];
return a[Math.floor(Math.random() * a.length)];
}
default:
return this.generateRandomChineseText();
}
}
/**
* 获取元素类型
*/
getElementType(element){
// 特殊处理:如果是复选框或单选按钮,直接返回对应类型
if (!element || typeof element.hasAttribute !== 'function') return 'unknown';
// 1. 特殊处理:如果是复选框或单选按钮,直接返回对应类型
if (element.type === 'checkbox' || element.tagName === 'CHECKBOX') {
return 'checkbox';
}
if (element.type === 'radio' || element.tagName === 'RADIO') {
return 'radio';
}
// 2. 判断原生 HTML 下拉框
if (element.tagName === 'SELECT') {
return 'select';
}
// 3. 判断所有主流框架魔改的下拉框
if (element.tagName === 'INPUT') {
const className = element.className || '';
const placeholderText = element.placeholder || '';
// 兼容 Element、AntD、Arco Design 等多选框内部的活动 input
const isInputItselfSelect = className.includes('select__input') ||
className.includes('selection-search') ||
className.includes('select-search');
// 精准匹配常见框架外壳:.el-select, .ant-select, .arco-select, .form-select, .v-select
const isFrameworkSelectContainer = element.closest(
'.el-select, .ant-select, .arco-select, .form-select, .v-select, [class*="-select"]'
) !== null;
// 🌟 特征 C:行为特征降级兜底
// 只要是只读输入框,且提示词包含“选择”、“请选”或英文“select”
const hasSelectBehavior = element.readOnly &&
(placeholderText.includes('选') || placeholderText.toLowerCase().includes('select'));
// 三者满足其一,它就是 100% 的下拉框类型
if (isInputItselfSelect || isFrameworkSelectContainer || hasSelectBehavior) {
return 'select';
}
}
// 第一步:根据输入类型属性检测(最高优先级)
const inputType = element.type ? element.type.toLowerCase() : '';
switch (inputType) {
case 'email': return 'email';
case 'tel': case 'phone': return 'phone';
case 'password': return 'password';
case 'date': case 'datetime': case 'datetime-local': return 'date';
case 'number': case 'range': return 'price';
case 'url': return 'url';
}
return '';
}
getControlRoot(element) {
if (!element) return null;
return element.closest(
[
// Element
'.el-select',
'.el-input',
'.el-cascader',
// Ant
'.ant-select',
'.ant-input',
'.ant-picker',
// Arco
'.arco-select',
'.arco-input',
// Naive UI
'.n-select',
'.n-input',
// fallback
'[class*="select"]',
'[class*="input"]',
'[class*="picker"]'
].join(',')
);