zmdms-utils 0.0.4 → 0.0.6
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/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 +125 -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/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 +22 -2
- package/dist/es/request.js +123 -28
- 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 +129 -0
- package/src/crypto.ts +109 -0
- package/src/index.ts +20 -1
- package/src/math.ts +90 -0
- package/src/passwordValidate.ts +196 -0
- package/src/request.ts +177 -27
- package/src/validate.ts +45 -0
package/dist/es/auth.d.ts
CHANGED
package/dist/es/auth.js
CHANGED
|
@@ -18,5 +18,13 @@ function setToken(token) {
|
|
|
18
18
|
console.error("设置token失败", err);
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
|
+
function removeToken() {
|
|
22
|
+
try {
|
|
23
|
+
window.localStorage.removeItem("system-token");
|
|
24
|
+
}
|
|
25
|
+
catch (err) {
|
|
26
|
+
console.error("设置token失败", err);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
21
29
|
|
|
22
|
-
export { getToken, setToken };
|
|
30
|
+
export { getToken, removeToken, setToken };
|
package/dist/es/baseUrl.js
CHANGED
|
@@ -1,3 +1,25 @@
|
|
|
1
|
-
|
|
1
|
+
// 根据当前环境变量获取基础的URL
|
|
2
|
+
function getBaseUrl(processObj) {
|
|
3
|
+
var ENV = processObj.REACT_APP_ENV; // 获取当前环境变量
|
|
4
|
+
// api各个环境地址
|
|
5
|
+
var apiBaseUrlObj = {
|
|
6
|
+
dev: processObj.REACT_APP_API_DEV || "http://192.168.0.83:8000",
|
|
7
|
+
test: processObj.REACT_APP_API_TEST || window.location.origin,
|
|
8
|
+
stage: processObj.REACT_APP_API_STAGE || window.location.origin,
|
|
9
|
+
product: processObj.REACT_APP_API_PRODUCT || window.location.origin,
|
|
10
|
+
};
|
|
11
|
+
// file 服务器
|
|
12
|
+
var fileBaseUrlObj = {
|
|
13
|
+
dev: processObj.REACT_APP_FILE_DEV || "http://192.168.0.83:88",
|
|
14
|
+
test: processObj.REACT_APP_FILE_TEST || "http://172.55.5.101:33013",
|
|
15
|
+
stage: processObj.REACT_APP_FILE_STAGE || "https://dzfile-prod.zmd.com.cn",
|
|
16
|
+
product: processObj.REACT_APP_FILE_PRODUCT || "https://dzfile.zmd.com.cn:8012",
|
|
17
|
+
};
|
|
18
|
+
var currentKey = ENV.toLowerCase() || "dev";
|
|
19
|
+
return {
|
|
20
|
+
api: apiBaseUrlObj[currentKey],
|
|
21
|
+
file: fileBaseUrlObj[currentKey],
|
|
22
|
+
};
|
|
23
|
+
}
|
|
2
24
|
|
|
3
25
|
export { getBaseUrl };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import * as mitt from 'mitt';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 同步阻断
|
|
5
|
+
* @param time 秒
|
|
6
|
+
*/
|
|
7
|
+
declare function delay(time: number): void;
|
|
8
|
+
/**
|
|
9
|
+
* 发布订阅实例
|
|
10
|
+
*/
|
|
11
|
+
declare const emitter: mitt.Emitter<Record<mitt.EventType, unknown>>;
|
|
12
|
+
/**
|
|
13
|
+
* 添加位数分割符
|
|
14
|
+
* @param n 需要分割的字符
|
|
15
|
+
* @param digit 多少位分割
|
|
16
|
+
* @param symbol 添加的符号
|
|
17
|
+
* @returns
|
|
18
|
+
*/
|
|
19
|
+
declare function addThousedSeparator(n: any, digit?: number, symbol?: string): any;
|
|
20
|
+
/**
|
|
21
|
+
* 获取地址栏参数
|
|
22
|
+
* @returns 地址栏参数对象
|
|
23
|
+
*/
|
|
24
|
+
declare function parseQueryParams(url: string): {
|
|
25
|
+
[key: string]: string;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* 将一些转义字符转换成原先的字符
|
|
29
|
+
* @param input 需要转换的内容
|
|
30
|
+
* @returns 转换过后的结果
|
|
31
|
+
*/
|
|
32
|
+
declare function unescapeString(input: string): string;
|
|
33
|
+
/**
|
|
34
|
+
* 将内容复制到粘贴板中
|
|
35
|
+
* @param text 需要复制的内容
|
|
36
|
+
*/
|
|
37
|
+
declare function copyToClipboard(text: string): void;
|
|
38
|
+
|
|
39
|
+
export { addThousedSeparator, copyToClipboard, delay, emitter, parseQueryParams, unescapeString };
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import mitt from './node_modules/mitt/dist/mitt.js';
|
|
2
|
+
|
|
3
|
+
// 基础函数
|
|
4
|
+
/**
|
|
5
|
+
* 同步阻断
|
|
6
|
+
* @param time 秒
|
|
7
|
+
*/
|
|
8
|
+
function delay(time) {
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* 发布订阅实例
|
|
12
|
+
*/
|
|
13
|
+
var emitter = mitt();
|
|
14
|
+
/**
|
|
15
|
+
* 添加位数分割符
|
|
16
|
+
* @param n 需要分割的字符
|
|
17
|
+
* @param digit 多少位分割
|
|
18
|
+
* @param symbol 添加的符号
|
|
19
|
+
* @returns
|
|
20
|
+
*/
|
|
21
|
+
function addThousedSeparator(n, digit, symbol) {
|
|
22
|
+
if (digit === void 0) { digit = 3; }
|
|
23
|
+
if (symbol === void 0) { symbol = ","; }
|
|
24
|
+
if (n != null) {
|
|
25
|
+
var _n = n.toString();
|
|
26
|
+
var pointBeforeNum = "";
|
|
27
|
+
var pointAfterNum = "";
|
|
28
|
+
if (_n.startsWith("-")) {
|
|
29
|
+
pointBeforeNum = "-";
|
|
30
|
+
_n = _n.slice(1);
|
|
31
|
+
}
|
|
32
|
+
var pointIndex = _n.indexOf(".");
|
|
33
|
+
if (pointIndex !== -1) {
|
|
34
|
+
n = _n.slice(0, pointIndex);
|
|
35
|
+
pointAfterNum = _n.slice(pointIndex);
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
n = _n;
|
|
39
|
+
}
|
|
40
|
+
var res = "";
|
|
41
|
+
var s = n.toString();
|
|
42
|
+
var length_1 = s.length;
|
|
43
|
+
for (var i = length_1 - 1; i >= 0; i--) {
|
|
44
|
+
var j = length_1 - i;
|
|
45
|
+
if (j % digit === 0) {
|
|
46
|
+
if (i === 0) {
|
|
47
|
+
res = s[i] + res;
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
res = symbol + s[i] + res;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
res = s[i] + res;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return pointBeforeNum + res + pointAfterNum;
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
return n;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* 获取地址栏参数
|
|
65
|
+
* @returns 地址栏参数对象
|
|
66
|
+
*/
|
|
67
|
+
function parseQueryParams(url) {
|
|
68
|
+
if (!url) {
|
|
69
|
+
return {};
|
|
70
|
+
}
|
|
71
|
+
var queryString = url.split("?")[1];
|
|
72
|
+
var params = new URLSearchParams(queryString);
|
|
73
|
+
var result = {};
|
|
74
|
+
params.forEach(function (value, key) {
|
|
75
|
+
var val = decodeURIComponent(value);
|
|
76
|
+
if (val.startsWith("{")) {
|
|
77
|
+
try {
|
|
78
|
+
val = JSON.parse(val);
|
|
79
|
+
}
|
|
80
|
+
catch (err) {
|
|
81
|
+
console.log("解析失败", err);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
else if (val === "true" || val === "false") {
|
|
85
|
+
val = val === "true";
|
|
86
|
+
}
|
|
87
|
+
result[key] = val;
|
|
88
|
+
});
|
|
89
|
+
return result;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* 将一些转义字符转换成原先的字符
|
|
93
|
+
* @param input 需要转换的内容
|
|
94
|
+
* @returns 转换过后的结果
|
|
95
|
+
*/
|
|
96
|
+
function unescapeString(input) {
|
|
97
|
+
if (!input) {
|
|
98
|
+
return "";
|
|
99
|
+
}
|
|
100
|
+
var escapedChars = {
|
|
101
|
+
"&": "&",
|
|
102
|
+
"<": "<",
|
|
103
|
+
">": ">",
|
|
104
|
+
""": '"',
|
|
105
|
+
"'": "'",
|
|
106
|
+
};
|
|
107
|
+
return input.replace(/&(amp|lt|gt|quot|#039);/g, function (match) {
|
|
108
|
+
return escapedChars[match] || match;
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* 将内容复制到粘贴板中
|
|
113
|
+
* @param text 需要复制的内容
|
|
114
|
+
*/
|
|
115
|
+
function copyToClipboard(text) {
|
|
116
|
+
var _a;
|
|
117
|
+
var textarea = document.createElement("textarea");
|
|
118
|
+
textarea.value = text;
|
|
119
|
+
document.body.appendChild(textarea);
|
|
120
|
+
textarea.select();
|
|
121
|
+
(_a = document === null || document === void 0 ? void 0 : document.execCommand) === null || _a === void 0 ? void 0 : _a.call(document, "copy");
|
|
122
|
+
document.body.removeChild(textarea);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export { addThousedSeparator, copyToClipboard, delay, emitter, parseQueryParams, unescapeString };
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
declare class Crypto {
|
|
2
|
+
private aesKey;
|
|
3
|
+
private desKey;
|
|
4
|
+
constructor(aesKey: string, desKey: string);
|
|
5
|
+
/**
|
|
6
|
+
* aes 加密方法
|
|
7
|
+
* @param data
|
|
8
|
+
* @returns {*}
|
|
9
|
+
*/
|
|
10
|
+
encrypt(data: string): string;
|
|
11
|
+
/**
|
|
12
|
+
* aes 解密方法
|
|
13
|
+
* @param data
|
|
14
|
+
* @returns {*}
|
|
15
|
+
*/
|
|
16
|
+
decrypt(data: string): string;
|
|
17
|
+
/**
|
|
18
|
+
* des 加密方法
|
|
19
|
+
* @param data
|
|
20
|
+
* @returns {*}
|
|
21
|
+
*/
|
|
22
|
+
encrypt_des(data: string): string;
|
|
23
|
+
/**
|
|
24
|
+
* des 解密方法
|
|
25
|
+
* @param data
|
|
26
|
+
* @returns {*}
|
|
27
|
+
*/
|
|
28
|
+
decrypt_des(data: string): string;
|
|
29
|
+
/**
|
|
30
|
+
* aes 加密方法,同java:AesUtil.encryptToBase64(text, aesKey);
|
|
31
|
+
*/
|
|
32
|
+
private encryptAES;
|
|
33
|
+
/**
|
|
34
|
+
* aes 解密方法,同java:AesUtil.decryptFormBase64ToString(encrypt, aesKey);
|
|
35
|
+
*/
|
|
36
|
+
private decryptAES;
|
|
37
|
+
/**
|
|
38
|
+
* des 加密方法,同java:DesUtil.encryptToBase64(text, desKey)
|
|
39
|
+
*/
|
|
40
|
+
private encryptDES;
|
|
41
|
+
/**
|
|
42
|
+
* des 解密方法,同java:DesUtil.decryptFormBase64(encryptBase64, desKey);
|
|
43
|
+
*/
|
|
44
|
+
private decryptDES;
|
|
45
|
+
}
|
|
46
|
+
declare const md5: (str: string) => string;
|
|
47
|
+
|
|
48
|
+
export { Crypto, md5 };
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import CryptoJS from 'crypto-js';
|
|
2
|
+
|
|
3
|
+
var Crypto = /** @class */ (function () {
|
|
4
|
+
function Crypto(aesKey, desKey) {
|
|
5
|
+
this.aesKey = aesKey;
|
|
6
|
+
this.desKey = desKey;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* aes 加密方法
|
|
10
|
+
* @param data
|
|
11
|
+
* @returns {*}
|
|
12
|
+
*/
|
|
13
|
+
Crypto.prototype.encrypt = function (data) {
|
|
14
|
+
return this.encryptAES(data, this.aesKey);
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* aes 解密方法
|
|
18
|
+
* @param data
|
|
19
|
+
* @returns {*}
|
|
20
|
+
*/
|
|
21
|
+
Crypto.prototype.decrypt = function (data) {
|
|
22
|
+
return this.decryptAES(data, this.aesKey);
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* des 加密方法
|
|
26
|
+
* @param data
|
|
27
|
+
* @returns {*}
|
|
28
|
+
*/
|
|
29
|
+
Crypto.prototype.encrypt_des = function (data) {
|
|
30
|
+
return this.encryptDES(data, this.desKey);
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* des 解密方法
|
|
34
|
+
* @param data
|
|
35
|
+
* @returns {*}
|
|
36
|
+
*/
|
|
37
|
+
Crypto.prototype.decrypt_des = function (data) {
|
|
38
|
+
return this.decryptDES(data, this.desKey);
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* aes 加密方法,同java:AesUtil.encryptToBase64(text, aesKey);
|
|
42
|
+
*/
|
|
43
|
+
Crypto.prototype.encryptAES = function (data, key) {
|
|
44
|
+
var dataBytes = CryptoJS.enc.Utf8.parse(data);
|
|
45
|
+
var keyBytes = CryptoJS.enc.Utf8.parse(key);
|
|
46
|
+
var encrypted = CryptoJS.AES.encrypt(dataBytes, keyBytes, {
|
|
47
|
+
iv: keyBytes,
|
|
48
|
+
mode: CryptoJS.mode.CBC,
|
|
49
|
+
padding: CryptoJS.pad.Pkcs7,
|
|
50
|
+
});
|
|
51
|
+
return CryptoJS.enc.Base64.stringify(encrypted.ciphertext);
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* aes 解密方法,同java:AesUtil.decryptFormBase64ToString(encrypt, aesKey);
|
|
55
|
+
*/
|
|
56
|
+
Crypto.prototype.decryptAES = function (data, key) {
|
|
57
|
+
var keyBytes = CryptoJS.enc.Utf8.parse(key);
|
|
58
|
+
var decrypted = CryptoJS.AES.decrypt(data, keyBytes, {
|
|
59
|
+
iv: keyBytes,
|
|
60
|
+
mode: CryptoJS.mode.CBC,
|
|
61
|
+
padding: CryptoJS.pad.Pkcs7,
|
|
62
|
+
});
|
|
63
|
+
return CryptoJS.enc.Utf8.stringify(decrypted);
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* des 加密方法,同java:DesUtil.encryptToBase64(text, desKey)
|
|
67
|
+
*/
|
|
68
|
+
Crypto.prototype.encryptDES = function (data, key) {
|
|
69
|
+
var keyHex = CryptoJS.enc.Utf8.parse(key);
|
|
70
|
+
var encrypted = CryptoJS.DES.encrypt(data, keyHex, {
|
|
71
|
+
mode: CryptoJS.mode.ECB,
|
|
72
|
+
padding: CryptoJS.pad.Pkcs7,
|
|
73
|
+
});
|
|
74
|
+
return encrypted.toString();
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* des 解密方法,同java:DesUtil.decryptFormBase64(encryptBase64, desKey);
|
|
78
|
+
*/
|
|
79
|
+
Crypto.prototype.decryptDES = function (data, key) {
|
|
80
|
+
var keyHex = CryptoJS.enc.Utf8.parse(key);
|
|
81
|
+
var decrypted = CryptoJS.DES.decrypt({
|
|
82
|
+
ciphertext: CryptoJS.enc.Base64.parse(data),
|
|
83
|
+
}, keyHex, {
|
|
84
|
+
mode: CryptoJS.mode.ECB,
|
|
85
|
+
padding: CryptoJS.pad.Pkcs7,
|
|
86
|
+
});
|
|
87
|
+
return decrypted.toString(CryptoJS.enc.Utf8);
|
|
88
|
+
};
|
|
89
|
+
return Crypto;
|
|
90
|
+
}());
|
|
91
|
+
var md5 = function (str) { return CryptoJS.MD5(str).toString().toLowerCase(); };
|
|
92
|
+
|
|
93
|
+
export { Crypto, md5 };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
type numType = "number" | "string";
|
|
2
|
+
/**
|
|
3
|
+
* 加法
|
|
4
|
+
*/
|
|
5
|
+
declare function plus(num1: numType, num2: numType): number;
|
|
6
|
+
/**
|
|
7
|
+
* 减法
|
|
8
|
+
*/
|
|
9
|
+
declare function minus(num1: numType, num2: numType): number;
|
|
10
|
+
/**
|
|
11
|
+
* 乘法
|
|
12
|
+
*/
|
|
13
|
+
declare function times(num1: numType, num2: numType): number;
|
|
14
|
+
/**
|
|
15
|
+
* 除法
|
|
16
|
+
*/
|
|
17
|
+
declare function divide(num1: numType, num2: numType): number;
|
|
18
|
+
/**
|
|
19
|
+
* 四舍五入保留小数
|
|
20
|
+
*/
|
|
21
|
+
declare function exactRound(num: numType, ratio: number): string;
|
|
22
|
+
/**
|
|
23
|
+
* 将字节数加上合适的单位
|
|
24
|
+
* @param numBytes 字节数
|
|
25
|
+
* @returns
|
|
26
|
+
*/
|
|
27
|
+
declare function formatUnit(numBytes: number): string | number;
|
|
28
|
+
|
|
29
|
+
export { divide, exactRound, formatUnit, minus, plus, times };
|
package/dist/es/math.js
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 加法
|
|
3
|
+
*/
|
|
4
|
+
function plus(num1, num2) {
|
|
5
|
+
try {
|
|
6
|
+
var _num1 = Number(num1);
|
|
7
|
+
var _num2 = Number(num2);
|
|
8
|
+
return (isNaN(_num1) ? 0 : _num1) + (isNaN(_num2) ? 0 : _num2);
|
|
9
|
+
}
|
|
10
|
+
catch (err) {
|
|
11
|
+
console.error("计算加法出错", err);
|
|
12
|
+
return 0;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* 减法
|
|
17
|
+
*/
|
|
18
|
+
function minus(num1, num2) {
|
|
19
|
+
try {
|
|
20
|
+
var _num1 = Number(num1);
|
|
21
|
+
var _num2 = Number(num2);
|
|
22
|
+
return (isNaN(_num1) ? 0 : _num1) - (isNaN(_num2) ? 0 : _num2);
|
|
23
|
+
}
|
|
24
|
+
catch (err) {
|
|
25
|
+
console.error("计算减法出错", err);
|
|
26
|
+
return 0;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* 乘法
|
|
31
|
+
*/
|
|
32
|
+
function times(num1, num2) {
|
|
33
|
+
try {
|
|
34
|
+
var _num1 = Number(num1);
|
|
35
|
+
var _num2 = Number(num2);
|
|
36
|
+
return (isNaN(_num1) ? 0 : _num1) * (isNaN(_num2) ? 0 : _num2);
|
|
37
|
+
}
|
|
38
|
+
catch (err) {
|
|
39
|
+
console.error("计算乘法出错", err);
|
|
40
|
+
return 0;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* 除法
|
|
45
|
+
*/
|
|
46
|
+
function divide(num1, num2) {
|
|
47
|
+
try {
|
|
48
|
+
var _num1 = Number(num1);
|
|
49
|
+
var _num2 = Number(num2);
|
|
50
|
+
return (isNaN(_num1) ? 0 : _num1) / (isNaN(_num2) ? 0 : _num2);
|
|
51
|
+
}
|
|
52
|
+
catch (err) {
|
|
53
|
+
console.error("计算除法出错", err);
|
|
54
|
+
return 0;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* 四舍五入保留小数
|
|
59
|
+
*/
|
|
60
|
+
function exactRound(num, ratio) {
|
|
61
|
+
try {
|
|
62
|
+
return Number(num).toFixed(ratio);
|
|
63
|
+
}
|
|
64
|
+
catch (err) {
|
|
65
|
+
return num;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* 将字节数加上合适的单位
|
|
70
|
+
* @param numBytes 字节数
|
|
71
|
+
* @returns
|
|
72
|
+
*/
|
|
73
|
+
function formatUnit(numBytes) {
|
|
74
|
+
var _numBytes = Number(numBytes);
|
|
75
|
+
if (isNaN(_numBytes)) {
|
|
76
|
+
return numBytes;
|
|
77
|
+
}
|
|
78
|
+
var units = ["B", "KB", "MB", "GB", "TB"];
|
|
79
|
+
var unitIndex = 0;
|
|
80
|
+
while (_numBytes >= 1024 && unitIndex < units.length - 1) {
|
|
81
|
+
_numBytes /= 1024;
|
|
82
|
+
unitIndex++;
|
|
83
|
+
}
|
|
84
|
+
return _numBytes.toFixed(2) + units[unitIndex];
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export { divide, exactRound, formatUnit, minus, plus, times };
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
function mitt(n){return {all:n=n||new Map,on:function(t,e){var i=n.get(t);i?i.push(e):n.set(t,[e]);},off:function(t,e){var i=n.get(t);i&&(e?i.splice(i.indexOf(e)>>>0,1):n.set(t,[]));},emit:function(t,e){var i=n.get(t);i&&i.slice().map(function(n){n(e);}),(i=n.get("*"))&&i.slice().map(function(n){n(t,e);});}}}
|
|
2
|
+
|
|
3
|
+
export { mitt as default };
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
var alphabet1 = [
|
|
2
|
+
"abcdefghijklmnopqrstuvwxyz",
|
|
3
|
+
"ABCDEFGHIJKLMNOPQRSTUVWXYZ",
|
|
4
|
+
"0123456789",
|
|
5
|
+
];
|
|
6
|
+
var alphabet2 = ["qwertyuiop", "asdfghjkl", "zxcvbnm"];
|
|
7
|
+
var alphabet3 = ["qaz", "wsx", "edc", "rfv", "tgb", "yhn", "ujm"];
|
|
8
|
+
function isConsecutiveChars(char1, char2, alphabetArr) {
|
|
9
|
+
// const lowerCaseAlphabet = 'abcdefghijklmnopqrstuvwxyz'; // 小写字母
|
|
10
|
+
// const upperCaseAlphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; // 大写字母
|
|
11
|
+
// const numeric = '0123456789'; // 数字
|
|
12
|
+
// 找到包含两个字符的字符集
|
|
13
|
+
var alphabet = alphabetArr.find(function (alph) { return alph.includes(char1) && alph.includes(char2); });
|
|
14
|
+
if (!alphabet) {
|
|
15
|
+
return false; // 如果两个字符不在同一字符集中,那么它们不可能连续
|
|
16
|
+
}
|
|
17
|
+
var index1 = alphabet.indexOf(char1);
|
|
18
|
+
var index2 = alphabet.indexOf(char2);
|
|
19
|
+
// return Math.abs(index1 - index2) === 1; // 如果两个字符在字符集中的位置相邻,那么它们是连续的
|
|
20
|
+
return index1 - index2;
|
|
21
|
+
}
|
|
22
|
+
function validatePassword(password, username) {
|
|
23
|
+
// 用正则表达式检查密码基本规则
|
|
24
|
+
var regex = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[^\da-zA-Z]).{8,50}$/;
|
|
25
|
+
if (!regex.test(password)) {
|
|
26
|
+
return {
|
|
27
|
+
result: false,
|
|
28
|
+
message: "密码中必须包含大小写字母、数字、特殊字符,且长度必须大于8个字符!",
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
// 检查密码是否与用户名相同
|
|
32
|
+
if (password === username) {
|
|
33
|
+
return {
|
|
34
|
+
result: false,
|
|
35
|
+
message: "密码与用户名相同!",
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
// 检查密码中是否有相同且连续的字符 超过三次
|
|
39
|
+
var count1 = 0;
|
|
40
|
+
for (var i = 0; i < password.length - 1; i++) {
|
|
41
|
+
if (password[i] === password[i + 1]) {
|
|
42
|
+
count1++;
|
|
43
|
+
if (count1 >= 2) {
|
|
44
|
+
return {
|
|
45
|
+
result: false,
|
|
46
|
+
message: "密码中有相同且连续超过三次的字符!",
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
count1 = 0;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
// 检查密码中是否有连续的字母或数字 连续超过三次
|
|
55
|
+
var count = 0;
|
|
56
|
+
var startChart = 0;
|
|
57
|
+
var currentConsecutiveCount = 0; // 记录上次是递增还是递减
|
|
58
|
+
// 第一次循环 找出 连续字母 数字
|
|
59
|
+
for (var i = 0; i < password.length - 1; i++) {
|
|
60
|
+
var consecutiveCount = isConsecutiveChars(password[i], password[i + 1], alphabet1);
|
|
61
|
+
// 是递增 还是 递减
|
|
62
|
+
if (consecutiveCount === 1 || consecutiveCount === -1) {
|
|
63
|
+
if (currentConsecutiveCount === 0) {
|
|
64
|
+
currentConsecutiveCount = consecutiveCount;
|
|
65
|
+
}
|
|
66
|
+
if (count === 0) {
|
|
67
|
+
startChart = i;
|
|
68
|
+
}
|
|
69
|
+
// 如果记录到上次跟本次的连续规则相同
|
|
70
|
+
if (currentConsecutiveCount === consecutiveCount) {
|
|
71
|
+
count++;
|
|
72
|
+
if (count >= 2) {
|
|
73
|
+
// 密码中不应含有连续的字母或数字
|
|
74
|
+
return {
|
|
75
|
+
result: false,
|
|
76
|
+
message: "\u4ECE\u7B2C".concat(startChart + 1, "\u4E2A\u5B57\u7B26\u5F00\u59CB\uFF0C\u6709\u8FDE\u7EED").concat(currentConsecutiveCount === 1 ? "递减" : "递增", "\u8D85\u8FC7\u4E09\u4F4D\u7684\u5B57\u6BCD\u6216\u6570\u5B57!"),
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
// 需要重置规则
|
|
82
|
+
count = 0;
|
|
83
|
+
startChart = 0;
|
|
84
|
+
}
|
|
85
|
+
currentConsecutiveCount = consecutiveCount;
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
count = 0;
|
|
89
|
+
startChart = 0;
|
|
90
|
+
currentConsecutiveCount = 0;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
// 第二次循环 找出键盘连续横排字母
|
|
94
|
+
for (var i = 0; i < password.length - 1; i++) {
|
|
95
|
+
var consecutiveCount = isConsecutiveChars(password[i], password[i + 1], alphabet2);
|
|
96
|
+
// 是递增 还是 递减
|
|
97
|
+
if (consecutiveCount === 1 || consecutiveCount === -1) {
|
|
98
|
+
if (currentConsecutiveCount === 0) {
|
|
99
|
+
currentConsecutiveCount = consecutiveCount;
|
|
100
|
+
}
|
|
101
|
+
if (count === 0) {
|
|
102
|
+
startChart = i;
|
|
103
|
+
}
|
|
104
|
+
// 如果记录到上次跟本次的连续规则相同
|
|
105
|
+
if (currentConsecutiveCount === consecutiveCount) {
|
|
106
|
+
count++;
|
|
107
|
+
if (count >= 2) {
|
|
108
|
+
// 密码中不应含有连续的字母或数字
|
|
109
|
+
return {
|
|
110
|
+
result: false,
|
|
111
|
+
message: "\u4ECE\u7B2C".concat(startChart + 1, "\u4E2A\u5B57\u7B26\u5F00\u59CB\uFF0C\u6709\u6309\u952E\u76D8\u6A2A\u5411\u8FDE\u7EED").concat(currentConsecutiveCount === 1 ? "递减" : "递增", "\u8D85\u8FC7\u4E09\u4F4D\u7684\u5B57\u6BCD!"),
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
// 需要重置规则
|
|
117
|
+
count = 0;
|
|
118
|
+
startChart = 0;
|
|
119
|
+
}
|
|
120
|
+
currentConsecutiveCount = consecutiveCount;
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
count = 0;
|
|
124
|
+
startChart = 0;
|
|
125
|
+
currentConsecutiveCount = 0;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
// 第三次循环 找出键盘连续竖排字母
|
|
129
|
+
for (var i = 0; i < password.length - 1; i++) {
|
|
130
|
+
var consecutiveCount = isConsecutiveChars(password[i], password[i + 1], alphabet3);
|
|
131
|
+
// 是递增 还是 递减
|
|
132
|
+
if (consecutiveCount === 1 || consecutiveCount === -1) {
|
|
133
|
+
if (currentConsecutiveCount === 0) {
|
|
134
|
+
currentConsecutiveCount = consecutiveCount;
|
|
135
|
+
}
|
|
136
|
+
if (count === 0) {
|
|
137
|
+
startChart = i;
|
|
138
|
+
}
|
|
139
|
+
// 如果记录到上次跟本次的连续规则相同
|
|
140
|
+
if (currentConsecutiveCount === consecutiveCount) {
|
|
141
|
+
count++;
|
|
142
|
+
if (count >= 2) {
|
|
143
|
+
// 密码中不应含有连续的字母或数字
|
|
144
|
+
return {
|
|
145
|
+
result: false,
|
|
146
|
+
message: "\u4ECE\u7B2C".concat(startChart + 1, "\u4E2A\u5B57\u7B26\u5F00\u59CB\uFF0C\u6709\u6309\u952E\u76D8\u7AD6\u5411\u8FDE\u7EED").concat(currentConsecutiveCount === 1 ? "递减" : "递增", "\u8D85\u8FC7\u4E09\u4F4D\u7684\u5B57\u6BCD\u6216\u6570\u5B57!"),
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
// 需要重置规则
|
|
152
|
+
count = 0;
|
|
153
|
+
startChart = 0;
|
|
154
|
+
}
|
|
155
|
+
currentConsecutiveCount = consecutiveCount;
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
count = 0;
|
|
159
|
+
startChart = 0;
|
|
160
|
+
currentConsecutiveCount = 0;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
// 如果通过了所有的检查,则返回true
|
|
164
|
+
return {
|
|
165
|
+
result: true,
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
export { validatePassword };
|