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
|
@@ -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 };
|
package/dist/es/request.d.ts
CHANGED
|
@@ -1,24 +1,53 @@
|
|
|
1
1
|
import * as axios from 'axios';
|
|
2
2
|
import { AxiosRequestConfig } from 'axios';
|
|
3
|
+
import { Crypto } from './crypto.js';
|
|
3
4
|
|
|
4
5
|
declare class AxiosRequest {
|
|
5
6
|
private otherOptions;
|
|
7
|
+
private crypto;
|
|
8
|
+
private jumpCallback;
|
|
9
|
+
private isExpired;
|
|
10
|
+
private isOffline;
|
|
11
|
+
private isNotFound;
|
|
12
|
+
private isTimeout;
|
|
13
|
+
private isTimeoutConfirm?;
|
|
14
|
+
private isTimeoutConfirmStr?;
|
|
15
|
+
private messageWarning?;
|
|
16
|
+
private modalConfirm?;
|
|
6
17
|
constructor(otherOptions: IOtherOptions);
|
|
7
18
|
private defaultSetting;
|
|
8
19
|
private interceptorsRequest;
|
|
9
|
-
private
|
|
20
|
+
private interceptorsResponse;
|
|
21
|
+
private responseError;
|
|
22
|
+
private logoutHandle;
|
|
10
23
|
request(options: IOptions): Promise<axios.AxiosResponse<any, any>>;
|
|
11
24
|
}
|
|
12
25
|
interface IOptions extends AxiosRequestConfig {
|
|
13
26
|
isFormData?: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* 是否需要携带请求头默认携带
|
|
29
|
+
*/
|
|
14
30
|
isAuth?: boolean;
|
|
31
|
+
/**
|
|
32
|
+
* 是否对传输数据开启加密模式
|
|
33
|
+
*/
|
|
34
|
+
isCrypto?: boolean | "aes" | "des";
|
|
35
|
+
/**
|
|
36
|
+
* 是否交给实例处理异常
|
|
37
|
+
*/
|
|
38
|
+
isErrorMessage?: boolean;
|
|
15
39
|
}
|
|
16
40
|
interface IOtherOptions {
|
|
17
|
-
jumpCallback?: () => void;
|
|
41
|
+
jumpCallback?: (status: number) => void;
|
|
42
|
+
messageWarning?: (msg: string, duration: number, callback?: () => void) => void;
|
|
43
|
+
modalConfirm?: (msg: string, callback?: () => void) => void;
|
|
18
44
|
TenantId?: string;
|
|
19
45
|
Authorization?: string;
|
|
20
46
|
timeout?: number;
|
|
21
47
|
baseURL?: string;
|
|
48
|
+
crypto?: Crypto;
|
|
49
|
+
isTimeoutConfirm?: boolean;
|
|
50
|
+
isTimeoutConfirmStr?: string;
|
|
22
51
|
}
|
|
23
52
|
|
|
24
53
|
export { AxiosRequest, IOptions, IOtherOptions };
|
package/dist/es/request.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { __rest, __assign } from './_virtual/_tslib.js';
|
|
2
2
|
import axios from 'axios';
|
|
3
|
-
import '
|
|
4
|
-
import { getToken } from './auth.js';
|
|
3
|
+
import { removeToken, getToken } from './auth.js';
|
|
5
4
|
|
|
6
5
|
var defaultOptions = {
|
|
7
6
|
TenantId: "000000",
|
|
@@ -10,10 +9,25 @@ var defaultOptions = {
|
|
|
10
9
|
};
|
|
11
10
|
var AxiosRequest = /** @class */ (function () {
|
|
12
11
|
function AxiosRequest(otherOptions) {
|
|
13
|
-
|
|
12
|
+
// 登录是否过期 这个变量是为了让弹出提示只展示一次
|
|
13
|
+
this.isExpired = false;
|
|
14
|
+
// 被挤下线 定义变量的目的同上
|
|
15
|
+
this.isOffline = false;
|
|
16
|
+
// 404
|
|
17
|
+
this.isNotFound = false;
|
|
18
|
+
// timeout
|
|
19
|
+
this.isTimeout = false;
|
|
20
|
+
var crypto = otherOptions.crypto, jumpCallback = otherOptions.jumpCallback, isTimeoutConfirm = otherOptions.isTimeoutConfirm, isTimeoutConfirmStr = otherOptions.isTimeoutConfirmStr, messageWarning = otherOptions.messageWarning, modalConfirm = otherOptions.modalConfirm, resetOtherOptions = __rest(otherOptions, ["crypto", "jumpCallback", "isTimeoutConfirm", "isTimeoutConfirmStr", "messageWarning", "modalConfirm"]);
|
|
21
|
+
this.otherOptions = __assign(__assign({}, defaultOptions), resetOtherOptions);
|
|
22
|
+
this.crypto = crypto;
|
|
23
|
+
this.isTimeoutConfirm = isTimeoutConfirm;
|
|
24
|
+
this.isTimeoutConfirmStr = isTimeoutConfirmStr;
|
|
25
|
+
this.jumpCallback = jumpCallback;
|
|
26
|
+
this.messageWarning = messageWarning;
|
|
27
|
+
this.modalConfirm = modalConfirm;
|
|
14
28
|
this.defaultSetting();
|
|
15
29
|
this.interceptorsRequest();
|
|
16
|
-
this.
|
|
30
|
+
this.interceptorsResponse();
|
|
17
31
|
}
|
|
18
32
|
// 设置axios方法默认值
|
|
19
33
|
AxiosRequest.prototype.defaultSetting = function () {
|
|
@@ -34,37 +48,108 @@ var AxiosRequest = /** @class */ (function () {
|
|
|
34
48
|
});
|
|
35
49
|
};
|
|
36
50
|
// 拦截响应
|
|
37
|
-
AxiosRequest.prototype.
|
|
51
|
+
AxiosRequest.prototype.interceptorsResponse = function () {
|
|
52
|
+
var _this = this;
|
|
38
53
|
axios.interceptors.response.use(function (response) {
|
|
54
|
+
var _a;
|
|
55
|
+
console.log(response);
|
|
56
|
+
// 对返回数据进行解密后 返回给客户端
|
|
57
|
+
if ((_a = response.config) === null || _a === void 0 ? void 0 : _a.isCrypto) ;
|
|
39
58
|
return response;
|
|
40
59
|
}, function (error) {
|
|
60
|
+
console.log(error);
|
|
61
|
+
// 统一处理响应异常
|
|
62
|
+
_this.responseError(error);
|
|
41
63
|
return Promise.reject(error);
|
|
42
64
|
});
|
|
43
65
|
};
|
|
66
|
+
// 响应错误处理
|
|
67
|
+
AxiosRequest.prototype.responseError = function (error) {
|
|
68
|
+
var _this = this;
|
|
69
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u;
|
|
70
|
+
if (error === void 0) { error = {}; }
|
|
71
|
+
var response = error.response;
|
|
72
|
+
// 处理token失效
|
|
73
|
+
// TODO: 刷新token逻辑
|
|
74
|
+
if ((response === null || response === void 0 ? void 0 : response.status) === 401) {
|
|
75
|
+
removeToken();
|
|
76
|
+
if (!this.isExpired) {
|
|
77
|
+
this.isExpired = true;
|
|
78
|
+
(_a = this.messageWarning) === null || _a === void 0 ? void 0 : _a.call(this, "登录过期", 3.5, function () {
|
|
79
|
+
_this.isExpired = false;
|
|
80
|
+
});
|
|
81
|
+
this.logoutHandle(response.status);
|
|
82
|
+
}
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
// 处理被挤下线逻辑
|
|
86
|
+
if ((response === null || response === void 0 ? void 0 : response.status) === 501) {
|
|
87
|
+
removeToken();
|
|
88
|
+
if (!this.isOffline) {
|
|
89
|
+
this.isOffline = true;
|
|
90
|
+
(_b = this.messageWarning) === null || _b === void 0 ? void 0 : _b.call(this, "你的账号已在其他地方登录!", 3.5, function () {
|
|
91
|
+
_this.isOffline = false;
|
|
92
|
+
});
|
|
93
|
+
this.logoutHandle(response.status);
|
|
94
|
+
}
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
// 处理404逻辑
|
|
98
|
+
if ((response === null || response === void 0 ? void 0 : response.status) === 404) {
|
|
99
|
+
if (!this.isNotFound) {
|
|
100
|
+
this.isNotFound = true;
|
|
101
|
+
(_c = this.messageWarning) === null || _c === void 0 ? void 0 : _c.call(this, "\u63A5\u53E3\uFF1A".concat(response.config.url, " \u672A\u627E\u5230\uFF01"), 3.5, function () {
|
|
102
|
+
_this.isNotFound = false;
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
// 处理接口超时逻辑
|
|
108
|
+
if (this.isTimeoutConfirm &&
|
|
109
|
+
((_f = (_e = (_d = error === null || error === void 0 ? void 0 : error.config) === null || _d === void 0 ? void 0 : _d.method) === null || _e === void 0 ? void 0 : _e.toUpperCase) === null || _f === void 0 ? void 0 : _f.call(_e)) === "POST" &&
|
|
110
|
+
!response &&
|
|
111
|
+
error.code === "ECONNABORTED" &&
|
|
112
|
+
((_h = (_g = error.message) === null || _g === void 0 ? void 0 : _g.indexOf) === null || _h === void 0 ? void 0 : _h.call(_g, "".concat(error.config.timeout, "ms"))) !== -1) {
|
|
113
|
+
if (!this.isTimeout) {
|
|
114
|
+
this.isTimeout = true;
|
|
115
|
+
(_j = this.modalConfirm) === null || _j === void 0 ? void 0 : _j.call(this, "".concat(this.isTimeoutConfirmStr
|
|
116
|
+
? this.isTimeoutConfirmStr
|
|
117
|
+
: "请求超时,请稍后再试,或联系相关人员确认后处理!", "\n \u63A5\u53E3\u5730\u5740: ").concat((_k = error === null || error === void 0 ? void 0 : error.config) === null || _k === void 0 ? void 0 : _k.url, "\n \u8BF7\u6C42\u65B9\u5F0F: ").concat((_l = error === null || error === void 0 ? void 0 : error.config) === null || _l === void 0 ? void 0 : _l.method, "\n \u8BF7\u6C42\u8D85\u65F6\u65F6\u95F4: ").concat(((_m = error === null || error === void 0 ? void 0 : error.config) === null || _m === void 0 ? void 0 : _m.timeout) / 1000, "\u79D2\n "), function () {
|
|
118
|
+
_this.isTimeout = false;
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
// 提示业务错误
|
|
124
|
+
if ((_o = error === null || error === void 0 ? void 0 : error.config) === null || _o === void 0 ? void 0 : _o.isErrorMessage) {
|
|
125
|
+
// 详细信息 再开发模式开启 之后上到别的环境会去掉
|
|
126
|
+
(_p = this.modalConfirm) === null || _p === void 0 ? void 0 : _p.call(this, "".concat(((_r = (_q = error === null || error === void 0 ? void 0 : error.response) === null || _q === void 0 ? void 0 : _q.data) === null || _r === void 0 ? void 0 : _r.msg) || "服务器异常", "\n \u63A5\u53E3\u5730\u5740: ").concat((_s = error === null || error === void 0 ? void 0 : error.config) === null || _s === void 0 ? void 0 : _s.url, "\n \u54CD\u5E94\u72B6\u6001\u7801: ").concat((_t = error === null || error === void 0 ? void 0 : error.response) === null || _t === void 0 ? void 0 : _t.status, "\n \u8BF7\u6C42\u65B9\u5F0F: ").concat((_u = error === null || error === void 0 ? void 0 : error.config) === null || _u === void 0 ? void 0 : _u.method, "\n "));
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
// 跳转逻辑处理
|
|
131
|
+
AxiosRequest.prototype.logoutHandle = function (status) {
|
|
132
|
+
// 自定义跳转
|
|
133
|
+
if (this.jumpCallback) {
|
|
134
|
+
this.jumpCallback(status);
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
window.location.href = "/login";
|
|
138
|
+
}
|
|
139
|
+
};
|
|
44
140
|
// 实例方法
|
|
45
141
|
AxiosRequest.prototype.request = function (options) {
|
|
46
|
-
var _a, _b, _c, _d, _e;
|
|
47
|
-
var
|
|
48
|
-
var isFormData = options.isFormData, _f = options.isAuth, isAuth = _f === void 0 ? true : _f, resetOptions = __rest(options, ["isFormData", "isAuth"]);
|
|
142
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
143
|
+
var isFormData = options.isFormData, _k = options.isAuth, isAuth = _k === void 0 ? true : _k, resetOptions = __rest(options, ["isFormData", "isAuth"]);
|
|
49
144
|
var newOptions = resetOptions;
|
|
50
145
|
// 自定义请求头
|
|
51
146
|
if (!newOptions.headers) {
|
|
52
147
|
newOptions.headers = {};
|
|
53
148
|
}
|
|
54
149
|
if (isAuth) {
|
|
150
|
+
var token = getToken();
|
|
55
151
|
newOptions.headers["Zmdms-Auth"] = "bearer ".concat(token);
|
|
56
152
|
}
|
|
57
|
-
// 处理url
|
|
58
|
-
if ((_a = newOptions.baseURL) === null || _a === void 0 ? void 0 : _a.endsWith("/")) {
|
|
59
|
-
newOptions.url = ((_b = newOptions.url) === null || _b === void 0 ? void 0 : _b.startsWith("/"))
|
|
60
|
-
? (_c = newOptions.url) === null || _c === void 0 ? void 0 : _c.slice(1)
|
|
61
|
-
: newOptions.url;
|
|
62
|
-
}
|
|
63
|
-
else {
|
|
64
|
-
newOptions.url = ((_d = newOptions.url) === null || _d === void 0 ? void 0 : _d.startsWith("/"))
|
|
65
|
-
? newOptions.url
|
|
66
|
-
: "/".concat(newOptions.url);
|
|
67
|
-
}
|
|
68
153
|
// 遍历params,将undefined值 转为null值
|
|
69
154
|
if (newOptions.data) {
|
|
70
155
|
newOptions.data = transformData(newOptions.data);
|
|
@@ -74,7 +159,7 @@ var AxiosRequest = /** @class */ (function () {
|
|
|
74
159
|
}
|
|
75
160
|
// 处理特殊请求
|
|
76
161
|
var specialMethod = ["POST", "PUT", "PATCH"];
|
|
77
|
-
var method = ((
|
|
162
|
+
var method = ((_a = newOptions.method) === null || _a === void 0 ? void 0 : _a.toUpperCase()) || "";
|
|
78
163
|
if (specialMethod.includes(method)) {
|
|
79
164
|
if (isFormData) {
|
|
80
165
|
var formData = new FormData();
|
|
@@ -94,6 +179,24 @@ var AxiosRequest = /** @class */ (function () {
|
|
|
94
179
|
}
|
|
95
180
|
}
|
|
96
181
|
// 数据加密处理 TODO:
|
|
182
|
+
// 将参数进行aes加密
|
|
183
|
+
if (newOptions.isCrypto === true || newOptions.isCrypto === "aes") {
|
|
184
|
+
if (newOptions.data) {
|
|
185
|
+
newOptions.data = (_c = (_b = this.crypto) === null || _b === void 0 ? void 0 : _b.encrypt) === null || _c === void 0 ? void 0 : _c.call(_b, JSON.stringify(newOptions.data));
|
|
186
|
+
}
|
|
187
|
+
if (newOptions.params) {
|
|
188
|
+
newOptions.params = (_e = (_d = this.crypto) === null || _d === void 0 ? void 0 : _d.encrypt) === null || _e === void 0 ? void 0 : _e.call(_d, JSON.stringify(newOptions.params));
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
// 将参数进行des加密
|
|
192
|
+
if (newOptions.isCrypto === "des") {
|
|
193
|
+
if (newOptions.data) {
|
|
194
|
+
newOptions.data = (_g = (_f = this.crypto) === null || _f === void 0 ? void 0 : _f.encrypt_des) === null || _g === void 0 ? void 0 : _g.call(_f, JSON.stringify(newOptions.data));
|
|
195
|
+
}
|
|
196
|
+
if (newOptions.params) {
|
|
197
|
+
newOptions.params = (_j = (_h = this.crypto) === null || _h === void 0 ? void 0 : _h.encrypt_des) === null || _j === void 0 ? void 0 : _j.call(_h, JSON.stringify(newOptions.params));
|
|
198
|
+
}
|
|
199
|
+
}
|
|
97
200
|
return axios(newOptions);
|
|
98
201
|
};
|
|
99
202
|
return AxiosRequest;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
declare const strLenValidate: (type?: "s" | "m" | "l" | "ml") => {
|
|
2
|
+
regex: RegExp;
|
|
3
|
+
message: string;
|
|
4
|
+
};
|
|
5
|
+
declare const phoneValidate: {
|
|
6
|
+
regex: RegExp;
|
|
7
|
+
message: string;
|
|
8
|
+
};
|
|
9
|
+
declare const morePhoneValidate: {
|
|
10
|
+
regex: RegExp;
|
|
11
|
+
message: string;
|
|
12
|
+
};
|
|
13
|
+
declare const idCardValidate: {
|
|
14
|
+
regex: RegExp;
|
|
15
|
+
message: string;
|
|
16
|
+
};
|
|
17
|
+
declare const emailValidate: {
|
|
18
|
+
regex: RegExp;
|
|
19
|
+
message: string;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export { emailValidate, idCardValidate, morePhoneValidate, phoneValidate, strLenValidate };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
var strLenValidate = function (type) {
|
|
2
|
+
if (type === void 0) { type = "s"; }
|
|
3
|
+
if (type === "m") {
|
|
4
|
+
return {
|
|
5
|
+
regex: /^\s*([\s\S]{0,400})\s*$/,
|
|
6
|
+
message: "\u8D85\u8FC7\u6700\u5927\u5B57\u7B26\u957F\u5EA6400!",
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
if (type === "l") {
|
|
10
|
+
return {
|
|
11
|
+
regex: /^\s*([\s\S]{0,600})\s*$/,
|
|
12
|
+
message: "\u8D85\u8FC7\u6700\u5927\u5B57\u7B26\u957F\u5EA6600!",
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
if (type === "ml") {
|
|
16
|
+
return {
|
|
17
|
+
regex: /^\s*([\s\S]{0,5000})\s*$/,
|
|
18
|
+
message: "\u8D85\u8FC7\u6700\u5927\u5B57\u7B26\u957F\u5EA65000!",
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
return {
|
|
22
|
+
regex: /^\s*([\s\S]{0,200})\s*$/,
|
|
23
|
+
message: "\u8D85\u8FC7\u6700\u5927\u5B57\u7B26\u957F\u5EA6200!",
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
var phoneValidate = {
|
|
27
|
+
regex: /^(?:\+?86-?)?(?:(?:0\d{2,3}-?)?[1-9]\d{6,7}|1[3-9]\d{9})$/,
|
|
28
|
+
message: "请输入正确的手机号!",
|
|
29
|
+
};
|
|
30
|
+
var morePhoneValidate = {
|
|
31
|
+
regex: /^(?:(?:\+?86-?)?(?:(?:0\d{2,3}-?)?[1-9]\d{6,7}|1[3-9]\d{9})(?:,\s?)?)+$/,
|
|
32
|
+
message: "请检查输入的电话号码中是否有不符合规则的号码!",
|
|
33
|
+
};
|
|
34
|
+
var idCardValidate = {
|
|
35
|
+
regex: /^[1-9]\d{5}(?:19|20)\d{2}(?:0[1-9]|1[0-2])(?:0[1-9]|[1-2]\d|3[0-1])\d{3}[\dX]$/i,
|
|
36
|
+
message: "请输入正确的身份证号!",
|
|
37
|
+
};
|
|
38
|
+
var emailValidate = {
|
|
39
|
+
regex: /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/,
|
|
40
|
+
message: "请输入正确的邮箱!",
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export { emailValidate, idCardValidate, morePhoneValidate, phoneValidate, strLenValidate };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
export { initMicroApp } from './es/microAppCreator.js';
|
|
2
2
|
export { isQiankun } from './es/qiankunUtils.js';
|
|
3
3
|
export { initGlobalError, initMainApp } from './es/mainApp.js';
|
|
4
|
-
export { getToken, setToken } from './es/auth.js';
|
|
4
|
+
export { getToken, removeToken, setToken } from './es/auth.js';
|
|
5
5
|
export { AxiosRequest, IOptions, IOtherOptions } from './es/request.js';
|
|
6
|
+
export { getBaseUrl } from './es/baseUrl.js';
|
|
7
|
+
export { Crypto, md5 } from './es/crypto.js';
|
|
8
|
+
export { addThousedSeparator, copyToClipboard, delay, emitter, parseQueryParams, unescapeString } from './es/common.js';
|
|
9
|
+
export { divide, exactRound, formatUnit, minus, plus, times } from './es/math.js';
|
|
10
|
+
export { validatePassword } from './es/passwordValidate.js';
|
|
11
|
+
export { emailValidate, idCardValidate, morePhoneValidate, phoneValidate, strLenValidate } from './es/validate.js';
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
export { initMicroApp } from './es/microAppCreator.js';
|
|
2
2
|
export { isQiankun } from './es/qiankunUtils.js';
|
|
3
3
|
export { initGlobalError, initMainApp } from './es/mainApp.js';
|
|
4
|
-
export { getToken, setToken } from './es/auth.js';
|
|
4
|
+
export { getToken, removeToken, setToken } from './es/auth.js';
|
|
5
5
|
export { AxiosRequest } from './es/request.js';
|
|
6
|
+
export { getBaseUrl } from './es/baseUrl.js';
|
|
7
|
+
export { Crypto, md5 } from './es/crypto.js';
|
|
8
|
+
export { addThousedSeparator, copyToClipboard, delay, emitter, parseQueryParams, unescapeString } from './es/common.js';
|
|
9
|
+
export { divide, exactRound, formatUnit, minus, plus, times } from './es/math.js';
|
|
10
|
+
export { validatePassword } from './es/passwordValidate.js';
|
|
11
|
+
export { emailValidate, idCardValidate, morePhoneValidate, phoneValidate, strLenValidate } from './es/validate.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zmdms-utils",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -14,14 +14,19 @@
|
|
|
14
14
|
"license": "ISC",
|
|
15
15
|
"peerDependencies": {
|
|
16
16
|
"axios": "^1.4.0",
|
|
17
|
+
"crypto-js": "^4.1.1",
|
|
17
18
|
"qiankun": "^2.10.8"
|
|
18
19
|
},
|
|
19
|
-
"dependencies": {
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"mitt": "^3.0.0"
|
|
22
|
+
},
|
|
20
23
|
"devDependencies": {
|
|
21
24
|
"@rollup/plugin-commonjs": "^24.0.1",
|
|
22
25
|
"@rollup/plugin-json": "^6.0.0",
|
|
23
26
|
"@rollup/plugin-node-resolve": "^15.0.1",
|
|
27
|
+
"@types/crypto-js": "^4.1.1",
|
|
24
28
|
"axios": "^1.4.0",
|
|
29
|
+
"crypto-js": "^4.1.1",
|
|
25
30
|
"qiankun": "^2.10.8",
|
|
26
31
|
"rimraf": "^4.4.1",
|
|
27
32
|
"rollup": "^3.20.2",
|
package/src/auth.ts
CHANGED
package/src/baseUrl.ts
CHANGED
|
@@ -1 +1,28 @@
|
|
|
1
|
-
|
|
1
|
+
// 根据当前环境变量获取基础的URL
|
|
2
|
+
export function getBaseUrl(processObj: any) {
|
|
3
|
+
const ENV = processObj.REACT_APP_ENV; // 获取当前环境变量
|
|
4
|
+
|
|
5
|
+
// api各个环境地址
|
|
6
|
+
const apiBaseUrlObj: any = {
|
|
7
|
+
dev: processObj.REACT_APP_API_DEV || "http://192.168.0.83:8000",
|
|
8
|
+
test: processObj.REACT_APP_API_TEST || window.location.origin,
|
|
9
|
+
stage: processObj.REACT_APP_API_STAGE || window.location.origin,
|
|
10
|
+
product: processObj.REACT_APP_API_PRODUCT || window.location.origin,
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
// file 服务器
|
|
14
|
+
const fileBaseUrlObj: any = {
|
|
15
|
+
dev: processObj.REACT_APP_FILE_DEV || "http://192.168.0.83:88",
|
|
16
|
+
test: processObj.REACT_APP_FILE_TEST || "http://172.55.5.101:33013",
|
|
17
|
+
stage: processObj.REACT_APP_FILE_STAGE || "https://dzfile-prod.zmd.com.cn",
|
|
18
|
+
product:
|
|
19
|
+
processObj.REACT_APP_FILE_PRODUCT || "https://dzfile.zmd.com.cn:8012",
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const currentKey = ENV.toLowerCase() || "dev";
|
|
23
|
+
|
|
24
|
+
return {
|
|
25
|
+
api: apiBaseUrlObj[currentKey],
|
|
26
|
+
file: fileBaseUrlObj[currentKey],
|
|
27
|
+
};
|
|
28
|
+
}
|