Utils.js
4.97 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
'use strict';
import ReactNative from 'react-native';
/**
*正则替换卡号,保留后4位,并且四位插入一个空格
**/
function replaceBankCardNo(cardNo){
let newCardNo = cardNo ? cardNo.replace(/(\d+)(\d{4})$/, (a, b, c)=> {
return b.replace(/\d/g, '*') + c;
}) : "";
//newCardNo = newCardNo.replace(/(\w{4})(?=\w)/g, '$1 ');
return newCardNo;
}
/**
*将卡号四位插入一个空格
**/
function formatBankCardNo(cardNo){
let newCardNo = cardNo ? cardNo.replace(/\s/g, '') : "";
newCardNo = newCardNo.replace(/[^\d]/g, '').replace(/(\d{4})(?=\d)/g, '$1 ');
return newCardNo;
}
/**
*替换空格为空
**/
function replaceSpace(cardNo){
let newCardNo = cardNo ? cardNo.replace(/\s/g, '') : "";
return newCardNo;
}
/**
*保留银行卡最后4位
**/
function splitLast4Number(cardNo){
let newCardNo = cardNo ? cardNo.substring(cardNo.length - 4, cardNo.length) : "";
return newCardNo;
}
/**
*获取银行卡大图
**/
function getBankBigImage(bank){
let bankImg;
switch(bank){
case "ABC":
bankImg = require('../image/bank/b-ABC.png');
break;
case "BOC":
bankImg = require('../image/bank/b-BOC.png');
break;
case "CCB":
bankImg = require('../image/bank/b-CCB.png');
break;
case "CEB":
bankImg = require('../image/bank/b-CEB.png');
break;
case "CGB":
bankImg = require('../image/bank/b-CGB.png');
break;
case "CIB":
bankImg = require('../image/bank/b-CIB.png');
break;
case "CITIC":
bankImg = require('../image/bank/b-CITIC.png');
break;
case "CMBC":
bankImg = require('../image/bank/b-CMBC.png');
break;
case "ICBC":
bankImg = require('../image/bank/b-ICBC.png');
break;
case "PAYH":
bankImg = require('../image/bank/b-PAYH.png');
break;
case "PSBC":
bankImg = require('../image/bank/b-PSBC.png');
break;
default:
bankImg = require('../image/bank/bank-EMPTY.png');
break;
}
return bankImg;
}
/**
*获取银行卡大图
**/
function getBankSmallImage(bank){
let bankImg;
switch(bank){
case "ABC":
bankImg = require('../image/bank/ABC.png');
break;
case "BOC":
bankImg = require('../image/bank/BOC.png');
break;
case "CCB":
bankImg = require('../image/bank/CCB.png');
break;
case "CEB":
bankImg = require('../image/bank/CEB.png');
break;
case "CGB":
bankImg = require('../image/bank/CGB.png');
break;
case "CIB":
bankImg = require('../image/bank/CIB.png');
break;
case "CITIC":
bankImg = require('../image/bank/CITIC.png');
break;
case "CMBC":
bankImg = require('../image/bank/CMBC.png');
break;
case "ICBC":
bankImg = require('../image/bank/ICBC.png');
break;
case "PAYH":
bankImg = require('../image/bank/PAYH.png');
break;
case "PSBC":
bankImg = require('../image/bank/PSBC.png');
break;
default:
bankImg = require('../image/bank/bank-EMPTY.png');
break;
}
return bankImg;
}
/**
*获取银行卡背景图
**/
function getBankBackgroundImage(bank){
let bankImg;
switch(bank){
case "ABC":
bankImg = require('../image/bank/bank-ABC.png');
break;
case "BOC":
bankImg = require('../image/bank/bank-BOC.png');
break;
case "CCB":
bankImg = require('../image/bank/bank-CCB.png');
break;
case "CEB":
bankImg = require('../image/bank/bank-CEB.png');
break;
case "CGB":
bankImg = require('../image/bank/bank-CGB.png');
break;
case "CIB":
bankImg = require('../image/bank/bank-CIB.png');
break;
case "CITIC":
bankImg = require('../image/bank/bank-CITIC.png');
break;
case "CMBC":
bankImg = require('../image/bank/bank-CMBC.png');
break;
case "ICBC":
bankImg = require('../image/bank/bank-ICBC.png');
break;
case "PAYH":
bankImg = require('../image/bank/bank-PAYH.png');
break;
case "PSBC":
bankImg = require('../image/bank/bank-PSBC.png');
break;
default:
bankImg = require('../image/bank/bank-EMPTY.png');
break;
}
return bankImg;
}
module.exports = {
getBankBigImage,
getBankSmallImage,
getBankBackgroundImage,
replaceBankCardNo,
formatBankCardNo,
replaceSpace,
splitLast4Number,
};