zmdms-utils 0.0.5 → 0.0.7
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/README.md +10 -0
- package/dist/es/auth.d.ts +2 -1
- package/dist/es/auth.js +9 -1
- package/dist/es/baseUrl.d.ts +6 -0
- package/dist/es/baseUrl.js +23 -1
- package/dist/es/common.d.ts +39 -0
- package/dist/es/common.js +143 -0
- package/dist/es/crypto.d.ts +48 -0
- package/dist/es/crypto.js +93 -0
- package/dist/es/math.d.ts +29 -0
- package/dist/es/math.js +87 -0
- package/dist/es/microAppCreator.js +3 -5
- package/dist/es/node_modules/mitt/dist/mitt.js +3 -0
- package/dist/es/passwordValidate.d.ts +9 -0
- package/dist/es/passwordValidate.js +169 -0
- package/dist/es/request.d.ts +31 -2
- package/dist/es/request.js +123 -20
- package/dist/es/validate.d.ts +22 -0
- package/dist/es/validate.js +43 -0
- package/dist/index.d.ts +7 -1
- package/dist/index.js +7 -1
- package/package.json +7 -2
- package/src/auth.ts +8 -0
- package/src/baseUrl.ts +28 -1
- package/src/common.ts +144 -0
- package/src/crypto.ts +109 -0
- package/src/index.ts +20 -1
- package/src/math.ts +90 -0
- package/src/microAppCreator.ts +1 -2
- package/src/passwordValidate.ts +196 -0
- package/src/request.ts +194 -19
- package/src/validate.ts +45 -0
package/src/common.ts
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
// 基础函数
|
|
2
|
+
import mitt from "mitt";
|
|
3
|
+
/**
|
|
4
|
+
* 同步阻断
|
|
5
|
+
* @param time 秒
|
|
6
|
+
*/
|
|
7
|
+
export function delay(time: number) {
|
|
8
|
+
const now = Date.now();
|
|
9
|
+
while (Date.now() - now < time * 1000) {}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* 发布订阅实例
|
|
14
|
+
*/
|
|
15
|
+
export const emitter = mitt();
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* 添加位数分割符
|
|
19
|
+
* @param n 需要分割的字符
|
|
20
|
+
* @param digit 多少位分割
|
|
21
|
+
* @param symbol 添加的符号
|
|
22
|
+
* @returns
|
|
23
|
+
*/
|
|
24
|
+
export function addThousedSeparator(
|
|
25
|
+
n: any,
|
|
26
|
+
digit: number = 3,
|
|
27
|
+
symbol: string = ","
|
|
28
|
+
) {
|
|
29
|
+
if (n != null) {
|
|
30
|
+
let _n = n.toString();
|
|
31
|
+
let pointBeforeNum = "";
|
|
32
|
+
let pointAfterNum = "";
|
|
33
|
+
if (_n.startsWith("-")) {
|
|
34
|
+
pointBeforeNum = "-";
|
|
35
|
+
_n = _n.slice(1);
|
|
36
|
+
}
|
|
37
|
+
const pointIndex = _n.indexOf(".");
|
|
38
|
+
if (pointIndex !== -1) {
|
|
39
|
+
n = _n.slice(0, pointIndex);
|
|
40
|
+
pointAfterNum = _n.slice(pointIndex);
|
|
41
|
+
} else {
|
|
42
|
+
n = _n;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
let res = "";
|
|
46
|
+
const s = n.toString();
|
|
47
|
+
const length = s.length;
|
|
48
|
+
|
|
49
|
+
for (let i = length - 1; i >= 0; i--) {
|
|
50
|
+
const j = length - i;
|
|
51
|
+
if (j % digit === 0) {
|
|
52
|
+
if (i === 0) {
|
|
53
|
+
res = s[i] + res;
|
|
54
|
+
} else {
|
|
55
|
+
res = symbol + s[i] + res;
|
|
56
|
+
}
|
|
57
|
+
} else {
|
|
58
|
+
res = s[i] + res;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return pointBeforeNum + res + pointAfterNum;
|
|
63
|
+
} else {
|
|
64
|
+
return n;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* 获取地址栏参数
|
|
70
|
+
* @returns 地址栏参数对象
|
|
71
|
+
*/
|
|
72
|
+
export function parseQueryParams(url: string): { [key: string]: string } {
|
|
73
|
+
if (!url) {
|
|
74
|
+
return {};
|
|
75
|
+
}
|
|
76
|
+
const queryString = url.split("?")[1];
|
|
77
|
+
const params = new URLSearchParams(queryString);
|
|
78
|
+
const result: { [key: string]: string } = {};
|
|
79
|
+
params.forEach((value, key) => {
|
|
80
|
+
let val: any = decodeURIComponent(value);
|
|
81
|
+
if (val.startsWith("{")) {
|
|
82
|
+
try {
|
|
83
|
+
val = JSON.parse(val);
|
|
84
|
+
} catch (err) {
|
|
85
|
+
console.log("解析失败", err);
|
|
86
|
+
}
|
|
87
|
+
} else if (val === "true" || val === "false") {
|
|
88
|
+
val = val === "true";
|
|
89
|
+
}
|
|
90
|
+
result[key] = val;
|
|
91
|
+
});
|
|
92
|
+
return result;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* 将一些转义字符转换成原先的字符
|
|
97
|
+
* @param input 需要转换的内容
|
|
98
|
+
* @returns 转换过后的结果
|
|
99
|
+
*/
|
|
100
|
+
export function unescapeString(input: string): string {
|
|
101
|
+
if (!input) {
|
|
102
|
+
return "";
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const escapedChars: { [key: string]: string } = {
|
|
106
|
+
"&": "&",
|
|
107
|
+
"<": "<",
|
|
108
|
+
">": ">",
|
|
109
|
+
""": '"',
|
|
110
|
+
"'": "'",
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
return input.replace(/&(amp|lt|gt|quot|#039);/g, (match) => {
|
|
114
|
+
return escapedChars[match] || match;
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* 将内容复制到粘贴板中
|
|
120
|
+
* @param text 需要复制的内容
|
|
121
|
+
*/
|
|
122
|
+
export function copyToClipboard(text: string, callback?: any) {
|
|
123
|
+
try {
|
|
124
|
+
if (navigator?.clipboard && window.isSecureContext) {
|
|
125
|
+
navigator.clipboard?.writeText(text)?.then(() => {
|
|
126
|
+
callback && callback(1);
|
|
127
|
+
});
|
|
128
|
+
} else {
|
|
129
|
+
const textarea = document.createElement("textarea");
|
|
130
|
+
textarea.value = text;
|
|
131
|
+
document.body.appendChild(textarea);
|
|
132
|
+
textarea.select();
|
|
133
|
+
if (document.execCommand) {
|
|
134
|
+
callback && callback(1);
|
|
135
|
+
document.execCommand("copy");
|
|
136
|
+
} else {
|
|
137
|
+
callback && callback(0);
|
|
138
|
+
}
|
|
139
|
+
document.body.removeChild(textarea);
|
|
140
|
+
}
|
|
141
|
+
} catch (err) {
|
|
142
|
+
callback && callback(0);
|
|
143
|
+
}
|
|
144
|
+
}
|
package/src/crypto.ts
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import CryptoJS from "crypto-js";
|
|
2
|
+
|
|
3
|
+
export class Crypto {
|
|
4
|
+
// 使用AesUtil.genAesKey()生成,需和后端配置保持一致
|
|
5
|
+
private aesKey: string;
|
|
6
|
+
|
|
7
|
+
// 使用DesUtil.genDesKey()生成,需和后端配置保持一致
|
|
8
|
+
private desKey: string;
|
|
9
|
+
|
|
10
|
+
constructor(aesKey: string, desKey: string) {
|
|
11
|
+
this.aesKey = aesKey;
|
|
12
|
+
this.desKey = desKey;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* aes 加密方法
|
|
17
|
+
* @param data
|
|
18
|
+
* @returns {*}
|
|
19
|
+
*/
|
|
20
|
+
encrypt(data: string) {
|
|
21
|
+
return this.encryptAES(data, this.aesKey);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* aes 解密方法
|
|
26
|
+
* @param data
|
|
27
|
+
* @returns {*}
|
|
28
|
+
*/
|
|
29
|
+
decrypt(data: string) {
|
|
30
|
+
return this.decryptAES(data, this.aesKey);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* des 加密方法
|
|
35
|
+
* @param data
|
|
36
|
+
* @returns {*}
|
|
37
|
+
*/
|
|
38
|
+
encrypt_des(data: string) {
|
|
39
|
+
return this.encryptDES(data, this.desKey);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* des 解密方法
|
|
44
|
+
* @param data
|
|
45
|
+
* @returns {*}
|
|
46
|
+
*/
|
|
47
|
+
decrypt_des(data: string) {
|
|
48
|
+
return this.decryptDES(data, this.desKey);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* aes 加密方法,同java:AesUtil.encryptToBase64(text, aesKey);
|
|
53
|
+
*/
|
|
54
|
+
private encryptAES(data: string, key: string) {
|
|
55
|
+
const dataBytes = CryptoJS.enc.Utf8.parse(data);
|
|
56
|
+
const keyBytes = CryptoJS.enc.Utf8.parse(key);
|
|
57
|
+
const encrypted = CryptoJS.AES.encrypt(dataBytes, keyBytes, {
|
|
58
|
+
iv: keyBytes,
|
|
59
|
+
mode: CryptoJS.mode.CBC,
|
|
60
|
+
padding: CryptoJS.pad.Pkcs7,
|
|
61
|
+
});
|
|
62
|
+
return CryptoJS.enc.Base64.stringify(encrypted.ciphertext);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* aes 解密方法,同java:AesUtil.decryptFormBase64ToString(encrypt, aesKey);
|
|
67
|
+
*/
|
|
68
|
+
private decryptAES(data: string, key: string) {
|
|
69
|
+
const keyBytes = CryptoJS.enc.Utf8.parse(key);
|
|
70
|
+
const decrypted = CryptoJS.AES.decrypt(data, keyBytes, {
|
|
71
|
+
iv: keyBytes,
|
|
72
|
+
mode: CryptoJS.mode.CBC,
|
|
73
|
+
padding: CryptoJS.pad.Pkcs7,
|
|
74
|
+
});
|
|
75
|
+
return CryptoJS.enc.Utf8.stringify(decrypted);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* des 加密方法,同java:DesUtil.encryptToBase64(text, desKey)
|
|
80
|
+
*/
|
|
81
|
+
private encryptDES(data: string, key: string) {
|
|
82
|
+
const keyHex = CryptoJS.enc.Utf8.parse(key);
|
|
83
|
+
const encrypted = CryptoJS.DES.encrypt(data, keyHex, {
|
|
84
|
+
mode: CryptoJS.mode.ECB,
|
|
85
|
+
padding: CryptoJS.pad.Pkcs7,
|
|
86
|
+
});
|
|
87
|
+
return encrypted.toString();
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* des 解密方法,同java:DesUtil.decryptFormBase64(encryptBase64, desKey);
|
|
92
|
+
*/
|
|
93
|
+
private decryptDES(data: string, key: string) {
|
|
94
|
+
const keyHex = CryptoJS.enc.Utf8.parse(key);
|
|
95
|
+
const decrypted = CryptoJS.DES.decrypt(
|
|
96
|
+
{
|
|
97
|
+
ciphertext: CryptoJS.enc.Base64.parse(data),
|
|
98
|
+
} as any,
|
|
99
|
+
keyHex,
|
|
100
|
+
{
|
|
101
|
+
mode: CryptoJS.mode.ECB,
|
|
102
|
+
padding: CryptoJS.pad.Pkcs7,
|
|
103
|
+
}
|
|
104
|
+
);
|
|
105
|
+
return decrypted.toString(CryptoJS.enc.Utf8);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export const md5 = (str: string) => CryptoJS.MD5(str).toString().toLowerCase();
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
export { initMicroApp } from "./microAppCreator";
|
|
2
2
|
export { isQiankun } from "./qiankunUtils";
|
|
3
3
|
export { initMainApp, initGlobalError } from "./mainApp";
|
|
4
|
-
export { getToken, setToken } from "./auth";
|
|
4
|
+
export { getToken, setToken, removeToken } from "./auth";
|
|
5
5
|
export { AxiosRequest, type IOtherOptions, type IOptions } from "./request";
|
|
6
|
+
export { getBaseUrl } from "./baseUrl";
|
|
7
|
+
export { Crypto, md5 } from "./crypto";
|
|
8
|
+
export {
|
|
9
|
+
delay,
|
|
10
|
+
emitter,
|
|
11
|
+
addThousedSeparator,
|
|
12
|
+
parseQueryParams,
|
|
13
|
+
unescapeString,
|
|
14
|
+
copyToClipboard,
|
|
15
|
+
} from "./common";
|
|
16
|
+
export { plus, minus, times, divide, exactRound, formatUnit } from "./math";
|
|
17
|
+
export { validatePassword } from "./passwordValidate";
|
|
18
|
+
export {
|
|
19
|
+
strLenValidate,
|
|
20
|
+
phoneValidate,
|
|
21
|
+
morePhoneValidate,
|
|
22
|
+
idCardValidate,
|
|
23
|
+
emailValidate,
|
|
24
|
+
} from "./validate";
|
package/src/math.ts
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
type numType = "number" | "string";
|
|
2
|
+
/**
|
|
3
|
+
* 加法
|
|
4
|
+
*/
|
|
5
|
+
export function plus(num1: numType, num2: numType) {
|
|
6
|
+
try {
|
|
7
|
+
const _num1 = Number(num1);
|
|
8
|
+
const _num2 = Number(num2);
|
|
9
|
+
return (isNaN(_num1) ? 0 : _num1) + (isNaN(_num2) ? 0 : _num2);
|
|
10
|
+
} catch (err) {
|
|
11
|
+
console.error("计算加法出错", err);
|
|
12
|
+
return 0;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* 减法
|
|
18
|
+
*/
|
|
19
|
+
export function minus(num1: numType, num2: numType) {
|
|
20
|
+
try {
|
|
21
|
+
const _num1 = Number(num1);
|
|
22
|
+
const _num2 = Number(num2);
|
|
23
|
+
return (isNaN(_num1) ? 0 : _num1) - (isNaN(_num2) ? 0 : _num2);
|
|
24
|
+
} catch (err) {
|
|
25
|
+
console.error("计算减法出错", err);
|
|
26
|
+
return 0;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* 乘法
|
|
32
|
+
*/
|
|
33
|
+
export function times(num1: numType, num2: numType) {
|
|
34
|
+
try {
|
|
35
|
+
const _num1 = Number(num1);
|
|
36
|
+
const _num2 = Number(num2);
|
|
37
|
+
return (isNaN(_num1) ? 0 : _num1) * (isNaN(_num2) ? 0 : _num2);
|
|
38
|
+
} catch (err) {
|
|
39
|
+
console.error("计算乘法出错", err);
|
|
40
|
+
return 0;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* 除法
|
|
46
|
+
*/
|
|
47
|
+
export function divide(num1: numType, num2: numType) {
|
|
48
|
+
try {
|
|
49
|
+
const _num1 = Number(num1);
|
|
50
|
+
const _num2 = Number(num2);
|
|
51
|
+
return (isNaN(_num1) ? 0 : _num1) / (isNaN(_num2) ? 0 : _num2);
|
|
52
|
+
} catch (err) {
|
|
53
|
+
console.error("计算除法出错", err);
|
|
54
|
+
return 0;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* 四舍五入保留小数
|
|
60
|
+
*/
|
|
61
|
+
export function exactRound(num: numType, ratio: number) {
|
|
62
|
+
try {
|
|
63
|
+
return Number(num).toFixed(ratio);
|
|
64
|
+
} catch (err) {
|
|
65
|
+
return num;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* 将字节数加上合适的单位
|
|
71
|
+
* @param numBytes 字节数
|
|
72
|
+
* @returns
|
|
73
|
+
*/
|
|
74
|
+
export function formatUnit(numBytes: number) {
|
|
75
|
+
let _numBytes = Number(numBytes);
|
|
76
|
+
|
|
77
|
+
if (isNaN(_numBytes)) {
|
|
78
|
+
return numBytes;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const units = ["B", "KB", "MB", "GB", "TB"];
|
|
82
|
+
let unitIndex = 0;
|
|
83
|
+
|
|
84
|
+
while (_numBytes >= 1024 && unitIndex < units.length - 1) {
|
|
85
|
+
_numBytes /= 1024;
|
|
86
|
+
unitIndex++;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return _numBytes.toFixed(2) + units[unitIndex];
|
|
90
|
+
}
|
package/src/microAppCreator.ts
CHANGED
|
@@ -63,9 +63,8 @@ export function initMicroApp(render: any, microAppOptions: IMicroAppOptions) {
|
|
|
63
63
|
* 应用每次 切出/卸载 会调用的方法,通常在这里我们会卸载微应用的应用实例
|
|
64
64
|
*/
|
|
65
65
|
async function unmount(props: any) {
|
|
66
|
-
console.log("微应用 unmount");
|
|
66
|
+
console.log("微应用 unmount", props);
|
|
67
67
|
microAppUnMountHandle && microAppUnMountHandle(props);
|
|
68
|
-
microAppRoot?.unmount?.();
|
|
69
68
|
}
|
|
70
69
|
|
|
71
70
|
return {
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
const alphabet1 = [
|
|
2
|
+
"abcdefghijklmnopqrstuvwxyz",
|
|
3
|
+
"ABCDEFGHIJKLMNOPQRSTUVWXYZ",
|
|
4
|
+
"0123456789",
|
|
5
|
+
];
|
|
6
|
+
const alphabet2 = ["qwertyuiop", "asdfghjkl", "zxcvbnm"];
|
|
7
|
+
const alphabet3 = ["qaz", "wsx", "edc", "rfv", "tgb", "yhn", "ujm"];
|
|
8
|
+
|
|
9
|
+
function isConsecutiveChars(
|
|
10
|
+
char1: string,
|
|
11
|
+
char2: string,
|
|
12
|
+
alphabetArr: string[]
|
|
13
|
+
) {
|
|
14
|
+
// const lowerCaseAlphabet = 'abcdefghijklmnopqrstuvwxyz'; // 小写字母
|
|
15
|
+
// const upperCaseAlphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; // 大写字母
|
|
16
|
+
// const numeric = '0123456789'; // 数字
|
|
17
|
+
|
|
18
|
+
// 找到包含两个字符的字符集
|
|
19
|
+
const alphabet = alphabetArr.find(
|
|
20
|
+
(alph: string) => alph.includes(char1) && alph.includes(char2)
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
if (!alphabet) {
|
|
24
|
+
return false; // 如果两个字符不在同一字符集中,那么它们不可能连续
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const index1 = alphabet.indexOf(char1);
|
|
28
|
+
const index2 = alphabet.indexOf(char2);
|
|
29
|
+
|
|
30
|
+
// return Math.abs(index1 - index2) === 1; // 如果两个字符在字符集中的位置相邻,那么它们是连续的
|
|
31
|
+
return index1 - index2;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function validatePassword(password: string, username: string) {
|
|
35
|
+
// 用正则表达式检查密码基本规则
|
|
36
|
+
const regex = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[^\da-zA-Z]).{8,50}$/;
|
|
37
|
+
if (!regex.test(password)) {
|
|
38
|
+
return {
|
|
39
|
+
result: false,
|
|
40
|
+
message:
|
|
41
|
+
"密码中必须包含大小写字母、数字、特殊字符,且长度必须大于8个字符!",
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// 检查密码是否与用户名相同
|
|
46
|
+
if (password === username) {
|
|
47
|
+
return {
|
|
48
|
+
result: false,
|
|
49
|
+
message: "密码与用户名相同!",
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// 检查密码中是否有相同且连续的字符 超过三次
|
|
54
|
+
let count1 = 0;
|
|
55
|
+
for (let i = 0; i < password.length - 1; i++) {
|
|
56
|
+
if (password[i] === password[i + 1]) {
|
|
57
|
+
count1++;
|
|
58
|
+
if (count1 >= 2) {
|
|
59
|
+
return {
|
|
60
|
+
result: false,
|
|
61
|
+
message: "密码中有相同且连续超过三次的字符!",
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
} else {
|
|
65
|
+
count1 = 0;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// 检查密码中是否有连续的字母或数字 连续超过三次
|
|
70
|
+
let count = 0;
|
|
71
|
+
let startChart = 0;
|
|
72
|
+
let currentConsecutiveCount = 0; // 记录上次是递增还是递减
|
|
73
|
+
|
|
74
|
+
// 第一次循环 找出 连续字母 数字
|
|
75
|
+
for (let i = 0; i < password.length - 1; i++) {
|
|
76
|
+
const consecutiveCount = isConsecutiveChars(
|
|
77
|
+
password[i],
|
|
78
|
+
password[i + 1],
|
|
79
|
+
alphabet1
|
|
80
|
+
);
|
|
81
|
+
// 是递增 还是 递减
|
|
82
|
+
if (consecutiveCount === 1 || consecutiveCount === -1) {
|
|
83
|
+
if (currentConsecutiveCount === 0) {
|
|
84
|
+
currentConsecutiveCount = consecutiveCount;
|
|
85
|
+
}
|
|
86
|
+
if (count === 0) {
|
|
87
|
+
startChart = i;
|
|
88
|
+
}
|
|
89
|
+
// 如果记录到上次跟本次的连续规则相同
|
|
90
|
+
if (currentConsecutiveCount === consecutiveCount) {
|
|
91
|
+
count++;
|
|
92
|
+
if (count >= 2) {
|
|
93
|
+
// 密码中不应含有连续的字母或数字
|
|
94
|
+
return {
|
|
95
|
+
result: false,
|
|
96
|
+
message: `从第${startChart + 1}个字符开始,有连续${
|
|
97
|
+
currentConsecutiveCount === 1 ? "递减" : "递增"
|
|
98
|
+
}超过三位的字母或数字!`,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
} else {
|
|
102
|
+
// 需要重置规则
|
|
103
|
+
count = 0;
|
|
104
|
+
startChart = 0;
|
|
105
|
+
}
|
|
106
|
+
currentConsecutiveCount = consecutiveCount;
|
|
107
|
+
} else {
|
|
108
|
+
count = 0;
|
|
109
|
+
startChart = 0;
|
|
110
|
+
currentConsecutiveCount = 0;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
// 第二次循环 找出键盘连续横排字母
|
|
114
|
+
for (let i = 0; i < password.length - 1; i++) {
|
|
115
|
+
const consecutiveCount = isConsecutiveChars(
|
|
116
|
+
password[i],
|
|
117
|
+
password[i + 1],
|
|
118
|
+
alphabet2
|
|
119
|
+
);
|
|
120
|
+
// 是递增 还是 递减
|
|
121
|
+
if (consecutiveCount === 1 || consecutiveCount === -1) {
|
|
122
|
+
if (currentConsecutiveCount === 0) {
|
|
123
|
+
currentConsecutiveCount = consecutiveCount;
|
|
124
|
+
}
|
|
125
|
+
if (count === 0) {
|
|
126
|
+
startChart = i;
|
|
127
|
+
}
|
|
128
|
+
// 如果记录到上次跟本次的连续规则相同
|
|
129
|
+
if (currentConsecutiveCount === consecutiveCount) {
|
|
130
|
+
count++;
|
|
131
|
+
if (count >= 2) {
|
|
132
|
+
// 密码中不应含有连续的字母或数字
|
|
133
|
+
return {
|
|
134
|
+
result: false,
|
|
135
|
+
message: `从第${startChart + 1}个字符开始,有按键盘横向连续${
|
|
136
|
+
currentConsecutiveCount === 1 ? "递减" : "递增"
|
|
137
|
+
}超过三位的字母!`,
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
} else {
|
|
141
|
+
// 需要重置规则
|
|
142
|
+
count = 0;
|
|
143
|
+
startChart = 0;
|
|
144
|
+
}
|
|
145
|
+
currentConsecutiveCount = consecutiveCount;
|
|
146
|
+
} else {
|
|
147
|
+
count = 0;
|
|
148
|
+
startChart = 0;
|
|
149
|
+
currentConsecutiveCount = 0;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
// 第三次循环 找出键盘连续竖排字母
|
|
153
|
+
for (let i = 0; i < password.length - 1; i++) {
|
|
154
|
+
const consecutiveCount = isConsecutiveChars(
|
|
155
|
+
password[i],
|
|
156
|
+
password[i + 1],
|
|
157
|
+
alphabet3
|
|
158
|
+
);
|
|
159
|
+
// 是递增 还是 递减
|
|
160
|
+
if (consecutiveCount === 1 || consecutiveCount === -1) {
|
|
161
|
+
if (currentConsecutiveCount === 0) {
|
|
162
|
+
currentConsecutiveCount = consecutiveCount;
|
|
163
|
+
}
|
|
164
|
+
if (count === 0) {
|
|
165
|
+
startChart = i;
|
|
166
|
+
}
|
|
167
|
+
// 如果记录到上次跟本次的连续规则相同
|
|
168
|
+
if (currentConsecutiveCount === consecutiveCount) {
|
|
169
|
+
count++;
|
|
170
|
+
if (count >= 2) {
|
|
171
|
+
// 密码中不应含有连续的字母或数字
|
|
172
|
+
return {
|
|
173
|
+
result: false,
|
|
174
|
+
message: `从第${startChart + 1}个字符开始,有按键盘竖向连续${
|
|
175
|
+
currentConsecutiveCount === 1 ? "递减" : "递增"
|
|
176
|
+
}超过三位的字母或数字!`,
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
} else {
|
|
180
|
+
// 需要重置规则
|
|
181
|
+
count = 0;
|
|
182
|
+
startChart = 0;
|
|
183
|
+
}
|
|
184
|
+
currentConsecutiveCount = consecutiveCount;
|
|
185
|
+
} else {
|
|
186
|
+
count = 0;
|
|
187
|
+
startChart = 0;
|
|
188
|
+
currentConsecutiveCount = 0;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// 如果通过了所有的检查,则返回true
|
|
193
|
+
return {
|
|
194
|
+
result: true,
|
|
195
|
+
};
|
|
196
|
+
}
|