func.js
5.17 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
// 不命中统一返回
const NOT_MATCH_OBJ = {
beautyNum: "",
index: -1,
len: 0
}
// 验证AABB
export function checkBeautyNumberAAA(phone) {
var reg = new RegExp('(.)\\1{2}', "g");
if (phone.match(reg) != null) {
var result = phone.match(reg)[0].toString();
return {
beautyNum: result,
index: phone.indexOf(result),
len: result.length,
type: "AAA+",
}
}
return NOT_MATCH_OBJ
}
// 验证AABB
export function checkBeautyNumberAABB(phone) {
var reg = new RegExp("(\\d)\\1((?!\\1)\\d)\\2", "g");
if (phone.match(reg) != null) {
var result = phone.match(reg)[0].toString();
return {
beautyNum: result,
index: phone.indexOf(result),
len: result.length,
type: "AABB+",
}
}
return NOT_MATCH_OBJ
}
// 验证ABAB
export function checkBeautyNumberABAB(phone) {
var reg = new RegExp("(\\d)((?!\\1)\\d)\\1\\2", "g");
if (phone.match(reg) != null) {
var result = phone.match(reg)[0].toString();
return {
beautyNum: result,
index: phone.indexOf(result),
len: result.length,
type: "ABAB+"
}
}
return NOT_MATCH_OBJ
}
// 验证AABB
export function checkBeautyNumberABBA(phone) {
var reg = new RegExp("(\\d)((?!\\1)\\d)\\2[\\d]", "g");
if (phone.match(reg) != null) {
var result = phone.match(reg)[0].toString();
if (result.substring(0, 1) == result.substring(3, 4)) {
return {
beautyNum: result,
index: phone.indexOf(result),
len: result.length,
type: "ABBA"
}
}
}
return NOT_MATCH_OBJ
}
// 验证ABCAB
export function checkBeautyNumberABCAB(phone) {
var reg = new RegExp("(?:0(?=1)|1(?=2)|2(?=3)|3(?=4)|4(?=5)|5(?=6)|6(?=7)|7(?=8)|8(?=9)){2}\\d{3}", "g");
if (phone.match(reg) != null) {
var result = phone.match(reg)[0].toString();
if (result.substring(0, 2) == result.substring(3, 5)) {
return {
beautyNum: result,
index: phone.indexOf(result),
len: result.length,
type: "ABCAB"
}
}
}
return NOT_MATCH_OBJ
}
// 验证ABCD
export function checkBeautyNumberABCD(phone) {
var reg = new RegExp("(?:0123|1234|2345|3456|4567|5678|6789|7890|0987|9876|8765|7654|6543|5432|4321|3210)\\d", "g");
if (phone.match(reg) != null) {
var result = phone.match(reg)[0].toString()
result = result.substring(0, 4);
return {
beautyNum: result,
index: phone.indexOf(result),
len: result.length,
type: "ABCD"
}
}
return NOT_MATCH_OBJ
}
// // 最后一位是6/8/9
export function checkBeautyNumberLast(phone) {
const reg = new RegExp("\\d+[689]$");
if (phone.match(reg) != null) {
return {
beautyNum: phone.slice(-1),
index: phone.length - 1,
len: 1,
type: "LAST689"
}
}
return NOT_MATCH_OBJ
}
// 获取吉祥口号
export function getFeatureName(mobile) {
let featureName = {
0: "寓意圆满",
1: "大吉大利",
2: "成双成对",
3: "三生万物",
4: "四季来财",
5: "五福临门",
6: "六六大顺",
7: "升职加薪",
8: "发财旺运",
9: "富贵长久"
}
let num = mobile.slice(-1);
let result = featureName[num + ''];
return result;
}
export function sortByLength(array) {
array.sort((a, b) => a.beautyList.length > 0 ? -1 : 1);
}
// 支付宝省市区结构
export function addressToTree(address) {
let districtssheng = address.province_list;
let districtsShi = address.city_list;
let districtsQu = address.county_list;
let newArrSheng = [];
for (var i in districtssheng) {
// 第一层循环遍历出省份
let districtsShengObj = {}
districtsShengObj.id = i
districtsShengObj.name = districtssheng[i]
let newArrShi = []
for (var s in districtsShi) {
//第二层循环出市
if (i.substring(0, 2) === s.substring(0, 2)) {
// 以城市编码的前两位作为匹配项
let shiobj = {};
shiobj.id = s
shiobj.name = districtsShi[s]
let newArrQU = []
for (var q in districtsQu) {
//第三层循环遍历出区
if (s.substring(0, 4) == q.substring(0, 4)) {
//市与区以编码的前四位作为匹配
let quobj = {};
quobj.id = q
quobj.name = districtsQu[q]
newArrQU.push(quobj);
shiobj.subList = newArrQU;
}
}
newArrShi.push(shiobj);
districtsShengObj.subList = newArrShi;
//添加到所需的对象里
}
}
newArrSheng.push(districtsShengObj) // 最后添加到数组里
}
return newArrSheng;
}