ztxkutils 2.10.45 → 2.10.47
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/fileOperation.js +3 -3
- package/dist/request-ef290b9a.js +2838 -0
- package/dist/stompClient.d.ts +3 -0
- package/dist/stompClient.js +41 -11
- package/dist/validate-6e735536.js +79 -0
- package/package.json +2 -2
- package/dist/validate-2081dd82.js +0 -161
- package/dist/validate-20c4d4f6.js +0 -161
- package/dist/validate-e3483c15.js +0 -196
package/dist/stompClient.d.ts
CHANGED
@@ -24,10 +24,13 @@ declare class StompClient {
|
|
24
24
|
successCallbacks: any;
|
25
25
|
errorCallbacks: any;
|
26
26
|
reconnectionNum: number;
|
27
|
+
reconnectiontime: number;
|
28
|
+
maxReconnectiontime: number;
|
27
29
|
userClose: boolean;
|
28
30
|
isInit: boolean;
|
29
31
|
constructor(connectWsConfig: IConnectWsConfig);
|
30
32
|
init(): void;
|
33
|
+
getReconnectionTime(): number;
|
31
34
|
subscribeSuccessCall(subscribeId: string, callback: () => void): void;
|
32
35
|
subscribeErrorCall(subscribeId: string, callback: () => void): void;
|
33
36
|
subscribe(subscribeId: string, pipe: string, callback?: (response: any) => void, headers?: any): void;
|
package/dist/stompClient.js
CHANGED
@@ -13,6 +13,8 @@ var StompClient = /** @class */ (function () {
|
|
13
13
|
this.successCallbacks = {}; // 连接成功执行的回调存储对象
|
14
14
|
this.errorCallbacks = {}; // 连接失败执行的回调存储对象
|
15
15
|
this.reconnectionNum = 0; // 重连次数
|
16
|
+
this.reconnectiontime = 5000; // 重连时间
|
17
|
+
this.maxReconnectiontime = 60000; // 最大重连时间 60s
|
16
18
|
this.userClose = false; // 是否用户主动关闭
|
17
19
|
this.isInit = false;
|
18
20
|
this.connectWsConfig = connectWsConfig;
|
@@ -28,6 +30,18 @@ var StompClient = /** @class */ (function () {
|
|
28
30
|
// 获取 STOMP 子协议的客户端对象
|
29
31
|
this.client = Stomp.over(socket);
|
30
32
|
this.isClient = false;
|
33
|
+
if (!this.subscriptions) {
|
34
|
+
this.subscriptions = {};
|
35
|
+
}
|
36
|
+
if (!this.subscriptionsFn) {
|
37
|
+
this.subscriptionsFn = {};
|
38
|
+
}
|
39
|
+
if (!this.successCallbacks) {
|
40
|
+
this.successCallbacks = {};
|
41
|
+
}
|
42
|
+
if (!this.errorCallbacks) {
|
43
|
+
this.errorCallbacks = {};
|
44
|
+
}
|
31
45
|
// 如果存在 证明已经初始化过,直接删除
|
32
46
|
if (this.clearIsClient) {
|
33
47
|
clearTimeout(this.clearIsClient);
|
@@ -54,7 +68,7 @@ var StompClient = /** @class */ (function () {
|
|
54
68
|
console.log('---连接未建立的关闭出错---', err);
|
55
69
|
}
|
56
70
|
_this.reconnectionNum++;
|
57
|
-
var timeInterval =
|
71
|
+
var timeInterval = _this.getReconnectionTime();
|
58
72
|
console.log("---\u7B2C" + _this.reconnectionNum + "\u6B21\u91CD\u8FDE\uFF01time=" + Date.now() + "system=" + _this.connectWsConfig.systemType + "---");
|
59
73
|
if (_this.clearIsClientNo) {
|
60
74
|
clearTimeout(_this.clearIsClientNo);
|
@@ -62,17 +76,20 @@ var StompClient = /** @class */ (function () {
|
|
62
76
|
}
|
63
77
|
_this.clearIsClientNo = setTimeout(function () {
|
64
78
|
_this.init();
|
65
|
-
}, timeInterval >
|
79
|
+
}, timeInterval > _this.maxReconnectiontime
|
80
|
+
? _this.maxReconnectiontime
|
81
|
+
: timeInterval);
|
66
82
|
}
|
67
83
|
}, 10000);
|
68
84
|
// 拦截输出的一大堆垃圾信息
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
}
|
85
|
+
this.client.debug = null;
|
86
|
+
// if (this.connectWsConfig.debug) {
|
87
|
+
// this.client.debug = (str: string) => {
|
88
|
+
// if (this.connectWsConfig.debug) {
|
89
|
+
// console.log(str);
|
90
|
+
// }
|
91
|
+
// };
|
92
|
+
// }
|
76
93
|
// 心跳检测 stompjs 底层使用window.setInterval() 定期发送心跳检测
|
77
94
|
this.client.heartbeat.outgoing =
|
78
95
|
(_b = (_a = this.connectWsConfig.heartbeat) === null || _a === void 0 ? void 0 : _a.outgoing) !== null && _b !== void 0 ? _b : 2000; // 客户端将每2000ms发送一次心跳
|
@@ -200,13 +217,22 @@ var StompClient = /** @class */ (function () {
|
|
200
217
|
// const timeInterval =
|
201
218
|
// Math.ceil(this.reconnectionNum / 5) *
|
202
219
|
// (this.connectWsConfig.reconnectionTime ?? 3000);
|
203
|
-
var timeInterval =
|
220
|
+
var timeInterval = _this.getReconnectionTime();
|
204
221
|
console.log("---\u7B2C" + _this.reconnectionNum + "\u6B21\u91CD\u8FDE\uFF01time=" + Date.now() + "system=" + _this.connectWsConfig.systemType);
|
205
222
|
_this.clearIsClientYes = setTimeout(function () {
|
206
223
|
_this.init();
|
207
|
-
}, timeInterval
|
224
|
+
}, timeInterval > _this.maxReconnectiontime
|
225
|
+
? _this.maxReconnectiontime
|
226
|
+
: timeInterval);
|
208
227
|
});
|
209
228
|
};
|
229
|
+
// 重连时间计算
|
230
|
+
StompClient.prototype.getReconnectionTime = function () {
|
231
|
+
var _a;
|
232
|
+
var timeInterval = Math.ceil(this.reconnectionNum / 5) *
|
233
|
+
((_a = this.connectWsConfig.reconnectionTime) !== null && _a !== void 0 ? _a : this.reconnectiontime);
|
234
|
+
return timeInterval;
|
235
|
+
};
|
210
236
|
// 订阅连接成功回调
|
211
237
|
StompClient.prototype.subscribeSuccessCall = function (subscribeId, callback) {
|
212
238
|
this.successCallbacks[subscribeId] = {
|
@@ -266,6 +292,10 @@ var StompClient = /** @class */ (function () {
|
|
266
292
|
var _this = this;
|
267
293
|
this.isInit = false;
|
268
294
|
this.userClose = true;
|
295
|
+
this.subscriptions = null;
|
296
|
+
this.subscriptionsFn = null;
|
297
|
+
this.successCallbacks = null;
|
298
|
+
this.errorCallbacks = null;
|
269
299
|
return new Promise(function (resolve, reject) {
|
270
300
|
try {
|
271
301
|
_this.client.disconnect(function () {
|
@@ -0,0 +1,79 @@
|
|
1
|
+
/**
|
2
|
+
* @description 常用正则表达式
|
3
|
+
*/
|
4
|
+
var validate = {
|
5
|
+
/**
|
6
|
+
* @description 长度验证,最小长度字符,0-200个字符
|
7
|
+
*/
|
8
|
+
smallLenValidate: /^(?:\s*)[\s\S]{0,200}(?:\s*)$/,
|
9
|
+
/**
|
10
|
+
* @description 长度验证,中等长度字符,0-400个字符
|
11
|
+
*/
|
12
|
+
middleLenValidate: /^(?:\s*)[\s\S]{0,400}(?:\s*)$/,
|
13
|
+
/**
|
14
|
+
* @description 长度验证,最大长度字符,0-600个字符
|
15
|
+
*/
|
16
|
+
largeLenValidate: /^(?:\s*)[\s\S]{0,600}(?:\s*)$/,
|
17
|
+
/**
|
18
|
+
* @description 长度验证,最大长度字符,0-5000个字符
|
19
|
+
*/
|
20
|
+
maxlargeLenValidate: /^(?:\s*)[\s\S]{0,5000}(?:\s*)$/,
|
21
|
+
/**
|
22
|
+
* @description 电话号码验证
|
23
|
+
*/
|
24
|
+
// phoneValidate: /^1(3\d|4\d|5\d|6\d|7\d|8\d|9\d)\d{8}$/,
|
25
|
+
// 数字 横线 长度 0 - 15位/^([0-9])|(\-)*$/
|
26
|
+
phoneValidate: /^[0-9\-]{0,15}$/,
|
27
|
+
/**
|
28
|
+
* @description 短信验证码 接受11位手机号
|
29
|
+
*/
|
30
|
+
shortPhoneValidate: /^1[0-9]{10}$/,
|
31
|
+
/**
|
32
|
+
* @description 身份证验证
|
33
|
+
* 18位 最后一位可以是X x
|
34
|
+
*/
|
35
|
+
idCardValidate: /^[1-9]\d{5}(18|19|20|(3\d))\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/,
|
36
|
+
/**
|
37
|
+
* @description 邮箱验证
|
38
|
+
*/
|
39
|
+
emailValidate: /^([\s\S])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,8})$/,
|
40
|
+
/**
|
41
|
+
* @description 密码验证
|
42
|
+
*/
|
43
|
+
passwordValidate: /^(?![0-9]+$)(?![a-z]+$)(?![A-Z]+$)(?!([^(0-9a-zA-Z)])+$)^.{8,16}$/,
|
44
|
+
/**
|
45
|
+
* @description 空格验证
|
46
|
+
*/
|
47
|
+
spaceValidate: /^[^\s]*$/g,
|
48
|
+
};
|
49
|
+
var commonMessage = {
|
50
|
+
smallLenMessage: function (type) {
|
51
|
+
if (type === void 0) { type = ''; }
|
52
|
+
return type + "\u8D85\u8FC7\u6700\u5927\u5B57\u7B26\u957F\u5EA6200";
|
53
|
+
},
|
54
|
+
middleLenMessage: function (type) {
|
55
|
+
if (type === void 0) { type = ''; }
|
56
|
+
return type + "\u8D85\u8FC7\u6700\u5927\u5B57\u7B26\u957F\u5EA6400";
|
57
|
+
},
|
58
|
+
largeLenMessage: function (type) {
|
59
|
+
if (type === void 0) { type = ''; }
|
60
|
+
return type + "\u8D85\u8FC7\u6700\u5927\u5B57\u7B26\u957F\u5EA6600";
|
61
|
+
},
|
62
|
+
maxlargeLenValidate: function (type) {
|
63
|
+
if (type === void 0) { type = ''; }
|
64
|
+
return type + "\u8D85\u8FC7\u6700\u5927\u5B57\u7B26\u957F\u5EA65000";
|
65
|
+
},
|
66
|
+
phoneMessage: '请输入正确的手机号',
|
67
|
+
idCardMessage: '请输入正确的身份证',
|
68
|
+
emailMessage: '请输入正确的邮箱',
|
69
|
+
passwordMessage: '密码由8-16位的字母+数字,字母+特殊字符,数字+特殊字符组成',
|
70
|
+
spaceMessage: '请勿输入空格',
|
71
|
+
};
|
72
|
+
|
73
|
+
var validate$1 = /*#__PURE__*/Object.freeze({
|
74
|
+
__proto__: null,
|
75
|
+
validate: validate,
|
76
|
+
commonMessage: commonMessage
|
77
|
+
});
|
78
|
+
|
79
|
+
export { validate as a, commonMessage as c, validate$1 as v };
|
package/package.json
CHANGED
@@ -1,161 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* @description 常用正则表达式
|
3
|
-
*/
|
4
|
-
var validate = {
|
5
|
-
/**
|
6
|
-
* @description 长度验证,最小长度字符,0-200个字符
|
7
|
-
*/
|
8
|
-
smallLenValidate: /^(?:\s*)[\s\S]{0,200}(?:\s*)$/,
|
9
|
-
/**
|
10
|
-
* @description 长度验证,中等长度字符,0-400个字符
|
11
|
-
*/
|
12
|
-
middleLenValidate: /^(?:\s*)[\s\S]{0,400}(?:\s*)$/,
|
13
|
-
/**
|
14
|
-
* @description 长度验证,最大长度字符,0-600个字符
|
15
|
-
*/
|
16
|
-
largeLenValidate: /^(?:\s*)[\s\S]{0,600}(?:\s*)$/,
|
17
|
-
/**
|
18
|
-
* @description 长度验证,最大长度字符,0-5000个字符
|
19
|
-
*/
|
20
|
-
maxlargeLenValidate: /^(?:\s*)[\s\S]{0,5000}(?:\s*)$/,
|
21
|
-
/**
|
22
|
-
* @description 电话号码验证
|
23
|
-
*/
|
24
|
-
// phoneValidate: /^1(3\d|4\d|5\d|6\d|7\d|8\d|9\d)\d{8}$/,
|
25
|
-
// 数字 横线 长度 0 - 15位/^([0-9])|(\-)*$/
|
26
|
-
phoneValidate: /^[0-9\-]{0,15}$/,
|
27
|
-
/**
|
28
|
-
* @description 短信验证码 接受11位手机号
|
29
|
-
*/
|
30
|
-
shortPhoneValidate: /^1[0-9]{10}$/,
|
31
|
-
/**
|
32
|
-
* @description 身份证验证
|
33
|
-
* 18位 最后一位可以是X x
|
34
|
-
*/
|
35
|
-
idCardValidate: /^[1-9]\d{5}(18|19|20|(3\d))\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/,
|
36
|
-
/**
|
37
|
-
* @description 邮箱验证
|
38
|
-
*/
|
39
|
-
emailValidate: /^([\s\S])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,8})$/,
|
40
|
-
/**
|
41
|
-
* @description 密码验证
|
42
|
-
*/
|
43
|
-
// passwordValidate: /^(?![0-9]+$)(?![a-z]+$)(?![A-Z]+$)(?!([^(0-9a-zA-Z)])+$)^.{8,16}$/,
|
44
|
-
passwordValidate: /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[^\da-zA-Z]).{8,}$/,
|
45
|
-
/**
|
46
|
-
* @description 空格验证
|
47
|
-
*/
|
48
|
-
spaceValidate: /^[^\s]*$/g,
|
49
|
-
};
|
50
|
-
var commonMessage = {
|
51
|
-
smallLenMessage: function (type) {
|
52
|
-
if (type === void 0) { type = ''; }
|
53
|
-
return type + "\u8D85\u8FC7\u6700\u5927\u5B57\u7B26\u957F\u5EA6200";
|
54
|
-
},
|
55
|
-
middleLenMessage: function (type) {
|
56
|
-
if (type === void 0) { type = ''; }
|
57
|
-
return type + "\u8D85\u8FC7\u6700\u5927\u5B57\u7B26\u957F\u5EA6400";
|
58
|
-
},
|
59
|
-
largeLenMessage: function (type) {
|
60
|
-
if (type === void 0) { type = ''; }
|
61
|
-
return type + "\u8D85\u8FC7\u6700\u5927\u5B57\u7B26\u957F\u5EA6600";
|
62
|
-
},
|
63
|
-
maxlargeLenValidate: function (type) {
|
64
|
-
if (type === void 0) { type = ''; }
|
65
|
-
return type + "\u8D85\u8FC7\u6700\u5927\u5B57\u7B26\u957F\u5EA65000";
|
66
|
-
},
|
67
|
-
phoneMessage: '请输入正确的手机号',
|
68
|
-
idCardMessage: '请输入正确的身份证',
|
69
|
-
emailMessage: '请输入正确的邮箱',
|
70
|
-
// passwordMessage: '密码由8-16位的字母+数字,字母+特殊字符,数字+特殊字符组成',
|
71
|
-
passwordMessage: '密码必须包含大小写字母、数字、特殊字符且最小长度为8,且不能出现连续数字或字符,不能出现相同字符,且禁止使用用户账号作为密码',
|
72
|
-
spaceMessage: '请勿输入空格',
|
73
|
-
};
|
74
|
-
function isConsecutiveChars(char1, char2) {
|
75
|
-
var lowerCaseAlphabet = 'abcdefghijklmnopqrstuvwxyz'; // 小写字母
|
76
|
-
var upperCaseAlphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; // 大写字母
|
77
|
-
var numeric = '0123456789'; // 数字
|
78
|
-
// 找到包含两个字符的字符集
|
79
|
-
var alphabet = [lowerCaseAlphabet, upperCaseAlphabet, numeric].find(function (alph) { return alph.includes(char1) && alph.includes(char2); });
|
80
|
-
if (!alphabet) {
|
81
|
-
return false; // 如果两个字符不在同一字符集中,那么它们不可能连续
|
82
|
-
}
|
83
|
-
var index1 = alphabet.indexOf(char1);
|
84
|
-
var index2 = alphabet.indexOf(char2);
|
85
|
-
return Math.abs(index1 - index2) === 1; // 如果两个字符在字符集中的位置相邻,那么它们是连续的
|
86
|
-
}
|
87
|
-
function validatePassword(password, username) {
|
88
|
-
// 用正则表达式检查密码基本规则
|
89
|
-
var regex = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[^\da-zA-Z]).{8,}$/;
|
90
|
-
if (!regex.test(password)) {
|
91
|
-
return {
|
92
|
-
result: false,
|
93
|
-
message: '密码中必须包含大小写字母、数字、特殊字符,且长度必须大于8个字符!',
|
94
|
-
};
|
95
|
-
}
|
96
|
-
// 检查密码中是否有连续的字母或数字 连续超过三次
|
97
|
-
var count = 0;
|
98
|
-
var startChart = 0;
|
99
|
-
for (var i = 0; i < password.length - 1; i++) {
|
100
|
-
if (isConsecutiveChars(password[i], password[i + 1])) {
|
101
|
-
if (count === 0) {
|
102
|
-
startChart = i;
|
103
|
-
}
|
104
|
-
count++;
|
105
|
-
if (count >= 2) {
|
106
|
-
// 密码中不应含有连续的字母或数字
|
107
|
-
return {
|
108
|
-
result: false,
|
109
|
-
message: "\u4ECE\u7B2C" + (startChart + 1) + "\u4E2A\u5B57\u7B26\u5F00\u59CB\uFF0C\u6709\u8FDE\u7EED\u8D85\u8FC7\u4E09\u4F4D\u7684\u5B57\u6BCD\u6216\u6570\u5B57!",
|
110
|
-
};
|
111
|
-
}
|
112
|
-
}
|
113
|
-
else {
|
114
|
-
count = 0;
|
115
|
-
startChart = 0;
|
116
|
-
}
|
117
|
-
}
|
118
|
-
// 检查密码中是否有相同且连续的字符 超过三次
|
119
|
-
var count1 = 0;
|
120
|
-
for (var i = 0; i < password.length - 1; i++) {
|
121
|
-
if (password[i] === password[i + 1]) {
|
122
|
-
count1++;
|
123
|
-
if (count1 >= 2) {
|
124
|
-
return {
|
125
|
-
result: false,
|
126
|
-
message: '密码中有相同且连续超过三次的字符!',
|
127
|
-
};
|
128
|
-
}
|
129
|
-
}
|
130
|
-
else {
|
131
|
-
count1 = 0;
|
132
|
-
}
|
133
|
-
}
|
134
|
-
// const uniqueChars = new Set(password.split(''));
|
135
|
-
// if (uniqueChars.size !== password.length) {
|
136
|
-
// return {
|
137
|
-
// result: false,
|
138
|
-
// message: '密码中有相同的字符!',
|
139
|
-
// };
|
140
|
-
// }
|
141
|
-
// 检查密码是否与用户名相同
|
142
|
-
if (password === username) {
|
143
|
-
return {
|
144
|
-
result: false,
|
145
|
-
message: '密码与用户名相同!',
|
146
|
-
};
|
147
|
-
}
|
148
|
-
// 如果通过了所有的检查,则返回true
|
149
|
-
return {
|
150
|
-
result: true,
|
151
|
-
};
|
152
|
-
}
|
153
|
-
|
154
|
-
var validate$1 = /*#__PURE__*/Object.freeze({
|
155
|
-
__proto__: null,
|
156
|
-
validatePassword: validatePassword,
|
157
|
-
validate: validate,
|
158
|
-
commonMessage: commonMessage
|
159
|
-
});
|
160
|
-
|
161
|
-
export { validatePassword as a, validate as b, commonMessage as c, validate$1 as v };
|
@@ -1,161 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* @description 常用正则表达式
|
3
|
-
*/
|
4
|
-
var validate = {
|
5
|
-
/**
|
6
|
-
* @description 长度验证,最小长度字符,0-200个字符
|
7
|
-
*/
|
8
|
-
smallLenValidate: /^(?:\s*)[\s\S]{0,200}(?:\s*)$/,
|
9
|
-
/**
|
10
|
-
* @description 长度验证,中等长度字符,0-400个字符
|
11
|
-
*/
|
12
|
-
middleLenValidate: /^(?:\s*)[\s\S]{0,400}(?:\s*)$/,
|
13
|
-
/**
|
14
|
-
* @description 长度验证,最大长度字符,0-600个字符
|
15
|
-
*/
|
16
|
-
largeLenValidate: /^(?:\s*)[\s\S]{0,600}(?:\s*)$/,
|
17
|
-
/**
|
18
|
-
* @description 长度验证,最大长度字符,0-5000个字符
|
19
|
-
*/
|
20
|
-
maxlargeLenValidate: /^(?:\s*)[\s\S]{0,5000}(?:\s*)$/,
|
21
|
-
/**
|
22
|
-
* @description 电话号码验证
|
23
|
-
*/
|
24
|
-
// phoneValidate: /^1(3\d|4\d|5\d|6\d|7\d|8\d|9\d)\d{8}$/,
|
25
|
-
// 数字 横线 长度 0 - 15位/^([0-9])|(\-)*$/
|
26
|
-
phoneValidate: /^[0-9\-]{0,15}$/,
|
27
|
-
/**
|
28
|
-
* @description 短信验证码 接受11位手机号
|
29
|
-
*/
|
30
|
-
shortPhoneValidate: /^1[0-9]{10}$/,
|
31
|
-
/**
|
32
|
-
* @description 身份证验证
|
33
|
-
* 18位 最后一位可以是X x
|
34
|
-
*/
|
35
|
-
idCardValidate: /^[1-9]\d{5}(18|19|20|(3\d))\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/,
|
36
|
-
/**
|
37
|
-
* @description 邮箱验证
|
38
|
-
*/
|
39
|
-
emailValidate: /^([\s\S])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,8})$/,
|
40
|
-
/**
|
41
|
-
* @description 密码验证
|
42
|
-
*/
|
43
|
-
// passwordValidate: /^(?![0-9]+$)(?![a-z]+$)(?![A-Z]+$)(?!([^(0-9a-zA-Z)])+$)^.{8,16}$/,
|
44
|
-
passwordValidate: /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[^\da-zA-Z]).{8,}$/,
|
45
|
-
/**
|
46
|
-
* @description 空格验证
|
47
|
-
*/
|
48
|
-
spaceValidate: /^[^\s]*$/g,
|
49
|
-
};
|
50
|
-
var commonMessage = {
|
51
|
-
smallLenMessage: function (type) {
|
52
|
-
if (type === void 0) { type = ''; }
|
53
|
-
return type + "\u8D85\u8FC7\u6700\u5927\u5B57\u7B26\u957F\u5EA6200";
|
54
|
-
},
|
55
|
-
middleLenMessage: function (type) {
|
56
|
-
if (type === void 0) { type = ''; }
|
57
|
-
return type + "\u8D85\u8FC7\u6700\u5927\u5B57\u7B26\u957F\u5EA6400";
|
58
|
-
},
|
59
|
-
largeLenMessage: function (type) {
|
60
|
-
if (type === void 0) { type = ''; }
|
61
|
-
return type + "\u8D85\u8FC7\u6700\u5927\u5B57\u7B26\u957F\u5EA6600";
|
62
|
-
},
|
63
|
-
maxlargeLenValidate: function (type) {
|
64
|
-
if (type === void 0) { type = ''; }
|
65
|
-
return type + "\u8D85\u8FC7\u6700\u5927\u5B57\u7B26\u957F\u5EA65000";
|
66
|
-
},
|
67
|
-
phoneMessage: '请输入正确的手机号',
|
68
|
-
idCardMessage: '请输入正确的身份证',
|
69
|
-
emailMessage: '请输入正确的邮箱',
|
70
|
-
// passwordMessage: '密码由8-16位的字母+数字,字母+特殊字符,数字+特殊字符组成',
|
71
|
-
passwordMessage: '密码必须包含大小写字母、数字、特殊字符且最小长度为8,且不能出现连续数字或字符,不能出现相同字符,且禁止使用用户账号作为密码',
|
72
|
-
spaceMessage: '请勿输入空格',
|
73
|
-
};
|
74
|
-
function isConsecutiveChars(char1, char2) {
|
75
|
-
var lowerCaseAlphabet = 'abcdefghijklmnopqrstuvwxyz'; // 小写字母
|
76
|
-
var upperCaseAlphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; // 大写字母
|
77
|
-
var numeric = '0123456789'; // 数字
|
78
|
-
// 找到包含两个字符的字符集
|
79
|
-
var alphabet = [lowerCaseAlphabet, upperCaseAlphabet, numeric].find(function (alph) { return alph.includes(char1) && alph.includes(char2); });
|
80
|
-
if (!alphabet) {
|
81
|
-
return false; // 如果两个字符不在同一字符集中,那么它们不可能连续
|
82
|
-
}
|
83
|
-
var index1 = alphabet.indexOf(char1);
|
84
|
-
var index2 = alphabet.indexOf(char2);
|
85
|
-
return Math.abs(index1 - index2) === 1; // 如果两个字符在字符集中的位置相邻,那么它们是连续的
|
86
|
-
}
|
87
|
-
function validatePassword(password, username) {
|
88
|
-
// 用正则表达式检查密码基本规则
|
89
|
-
var regex = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[^\da-zA-Z]).{8,}$/;
|
90
|
-
if (!regex.test(password)) {
|
91
|
-
return {
|
92
|
-
result: false,
|
93
|
-
message: '密码中必须包含大小写字母、数字、特殊字符,且长度必须大于8个字符!',
|
94
|
-
};
|
95
|
-
}
|
96
|
-
// 检查密码中是否有连续的字母或数字 连续超过三次
|
97
|
-
var count = 0;
|
98
|
-
var startChart = 0;
|
99
|
-
for (var i = 0; i < password.length - 1; i++) {
|
100
|
-
if (isConsecutiveChars(password[i], password[i + 1])) {
|
101
|
-
if (count === 0) {
|
102
|
-
startChart = i;
|
103
|
-
}
|
104
|
-
count++;
|
105
|
-
if (count >= 2) {
|
106
|
-
// 密码中不应含有连续的字母或数字
|
107
|
-
return {
|
108
|
-
result: false,
|
109
|
-
message: "\u4ECE\u7B2C" + (startChart + 1) + "\u4E2A\u5B57\u7B26\u5F00\u59CB\uFF0C\u6709\u8FDE\u7EED\u8D85\u8FC7\u4E09\u4F4D\u7684\u5B57\u6BCD\u6216\u6570\u5B57!",
|
110
|
-
};
|
111
|
-
}
|
112
|
-
}
|
113
|
-
else {
|
114
|
-
count = 0;
|
115
|
-
startChart = 0;
|
116
|
-
}
|
117
|
-
}
|
118
|
-
// 检查密码中是否有相同且连续的字符 超过三次
|
119
|
-
var count1 = 0;
|
120
|
-
for (var i = 0; i < password.length - 1; i++) {
|
121
|
-
if (password[i] === password[i + 1]) {
|
122
|
-
count1++;
|
123
|
-
if (count1 >= 2) {
|
124
|
-
return {
|
125
|
-
result: false,
|
126
|
-
message: '密码中有相同的字符!',
|
127
|
-
};
|
128
|
-
}
|
129
|
-
}
|
130
|
-
else {
|
131
|
-
count1 = 0;
|
132
|
-
}
|
133
|
-
}
|
134
|
-
var uniqueChars = new Set(password.split(''));
|
135
|
-
if (uniqueChars.size !== password.length) {
|
136
|
-
return {
|
137
|
-
result: false,
|
138
|
-
message: '密码中有相同的字符!',
|
139
|
-
};
|
140
|
-
}
|
141
|
-
// 检查密码是否与用户名相同
|
142
|
-
if (password === username) {
|
143
|
-
return {
|
144
|
-
result: false,
|
145
|
-
message: '密码与用户名相同!',
|
146
|
-
};
|
147
|
-
}
|
148
|
-
// 如果通过了所有的检查,则返回true
|
149
|
-
return {
|
150
|
-
result: true,
|
151
|
-
};
|
152
|
-
}
|
153
|
-
|
154
|
-
var validate$1 = /*#__PURE__*/Object.freeze({
|
155
|
-
__proto__: null,
|
156
|
-
validatePassword: validatePassword,
|
157
|
-
validate: validate,
|
158
|
-
commonMessage: commonMessage
|
159
|
-
});
|
160
|
-
|
161
|
-
export { validatePassword as a, validate as b, commonMessage as c, validate$1 as v };
|