zmdms-utils 0.0.75 → 0.0.76
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/_virtual/_commonjsHelpers.js +3 -0
- package/dist/es/_virtual/_tslib.js +87 -0
- package/dist/es/_virtual/decimal.js +7 -0
- package/dist/es/_virtual/parseTimeTest.js +3 -0
- package/dist/es/_virtual/test.js +3 -0
- package/dist/es/auth.d.ts +9 -0
- package/dist/es/auth.js +49 -0
- package/dist/es/baseUrl.d.ts +23 -0
- package/dist/es/baseUrl.js +50 -0
- package/dist/es/canvas.d.ts +6 -0
- package/dist/es/canvas.js +14 -0
- package/dist/es/common.d.ts +81 -0
- package/dist/es/common.js +304 -0
- package/dist/es/constants.d.ts +20 -0
- package/dist/es/constants.js +33 -0
- package/dist/es/crypto.d.ts +51 -0
- package/dist/es/crypto.js +97 -0
- package/dist/es/file.d.ts +127 -0
- package/dist/es/file.js +373 -0
- package/dist/es/htmlToPdf.d.ts +44 -0
- package/dist/es/htmlToPdf.js +84 -0
- package/dist/es/locales/i18n.d.ts +15 -0
- package/dist/es/locales/t-in-non-react.d.ts +17 -0
- package/dist/es/locales/t-options.d.ts +7 -0
- package/dist/es/locales/use-translation.d.ts +42 -0
- package/dist/es/mainApp.d.ts +36 -0
- package/dist/es/mainApp.js +44 -0
- package/dist/es/math.d.ts +29 -0
- package/dist/es/math.js +147 -0
- package/dist/es/microAppCreator.d.ts +46 -0
- package/dist/es/microAppCreator.js +89 -0
- package/dist/es/node_modules/decimal.js/decimal.js +4896 -0
- package/dist/es/node_modules/decimal.js/decimal2.js +4930 -0
- package/dist/es/node_modules/html-parse-stringify/dist/html-parse-stringify.module.js +5 -0
- package/dist/es/node_modules/i18next/dist/esm/i18next.js +2242 -0
- package/dist/es/node_modules/js-base64/base64.js +273 -0
- package/dist/es/node_modules/jwt-decode/build/jwt-decode.esm.js +3 -0
- package/dist/es/node_modules/mitt/dist/mitt.js +3 -0
- package/dist/es/node_modules/pinyin-pro/dist/index.js +12627 -0
- package/dist/es/node_modules/react-i18next/dist/es/Trans.js +47 -0
- package/dist/es/node_modules/react-i18next/dist/es/TransWithoutContext.js +312 -0
- package/dist/es/node_modules/react-i18next/dist/es/context.js +18 -0
- package/dist/es/node_modules/react-i18next/dist/es/defaults.js +21 -0
- package/dist/es/node_modules/react-i18next/dist/es/i18nInstance.js +7 -0
- package/dist/es/node_modules/react-i18next/dist/es/initReactI18next.js +12 -0
- package/dist/es/node_modules/react-i18next/dist/es/unescape.js +27 -0
- package/dist/es/node_modules/react-i18next/dist/es/useTranslation.js +112 -0
- package/dist/es/node_modules/react-i18next/dist/es/utils.js +63 -0
- package/dist/es/node_modules/void-elements/index.js +23 -0
- package/dist/es/parseTime.d.ts +29 -0
- package/dist/es/parseTime.js +189 -0
- package/dist/es/parseTimeTest.js +2 -0
- package/dist/es/passwordValidate.d.ts +9 -0
- package/dist/es/passwordValidate.js +169 -0
- package/dist/es/pdf.d.ts +49 -0
- package/dist/es/pdf.js +176 -0
- package/dist/es/pinyin.js +1 -0
- package/dist/es/print.d.ts +23 -0
- package/dist/es/print.js +43 -0
- package/dist/es/qiankunUtils.d.ts +13 -0
- package/dist/es/qiankunUtils.js +32 -0
- package/dist/es/request.d.ts +87 -0
- package/dist/es/request.js +308 -0
- package/dist/es/src/locales/i18n.js +16 -0
- package/dist/es/src/locales/t-in-non-react.js +54 -0
- package/dist/es/src/locales/t-options.js +20 -0
- package/dist/es/src/locales/use-translation.js +60 -0
- package/dist/es/src/parseTimeTest.js +288 -0
- package/dist/es/src/test.js +245 -0
- package/dist/es/test.js +2 -0
- package/dist/es/validate.d.ts +26 -0
- package/dist/es/validate.js +47 -0
- package/dist/es/water.d.ts +53 -0
- package/dist/es/water.js +88 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.js +26 -0
- package/package.json +1 -1
- package/src/math.ts +1 -1
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import dayjs from 'dayjs';
|
|
2
|
+
|
|
3
|
+
var defaultFormat = "YYYY-MM-DD";
|
|
4
|
+
/**
|
|
5
|
+
* 解析时间
|
|
6
|
+
* 可能转换的结果
|
|
7
|
+
* 日期对象转字符串
|
|
8
|
+
* Dayjs => "20xx-xx-xx"
|
|
9
|
+
* { key: Dayjs } => { key: "20xx-xx-xx" }
|
|
10
|
+
* { mergeKey: [Dayjs, Dayjs] } => { key1: "20xx-xx-xx", key2: "20xx-xx-xx" }
|
|
11
|
+
* 字符串转日期对象
|
|
12
|
+
* "20xx-xx-xx" => Dayjs
|
|
13
|
+
* { key: "20xx-xx-xx" } => { key: Dayjs }
|
|
14
|
+
* { key1: "20xx-xx-xx", key1: "20xx-xx-xx" } => { mergeKey: [Dayjs, Dayjs] }
|
|
15
|
+
*/
|
|
16
|
+
function parseTime(config) {
|
|
17
|
+
var params = config.params, _a = config.format, format = _a === void 0 ? defaultFormat : _a, _b = config.type, type = _b === void 0 ? "string" : _b, _c = config.fromKeys, fromKeys = _c === void 0 ? [] : _c, _d = config.toKeys, toKeys = _d === void 0 ? [] : _d, endType = config.endType;
|
|
18
|
+
// 获取最终结果
|
|
19
|
+
var getParseResult = parseByResult({ format: format, type: type });
|
|
20
|
+
// 如果传入的是一个字符串(就是单字段)
|
|
21
|
+
if (typeof params === "string" || typeof params === "number") {
|
|
22
|
+
// 1. 结果类型是一个日期对象
|
|
23
|
+
// 2. 如果结果类型是字符串,那么字符串转字符串可能的一个场景是:将一个日期格式的数据转成另外一种格式的日期
|
|
24
|
+
return getParseResult({
|
|
25
|
+
value: params,
|
|
26
|
+
endType: typeof endType === "string" ? endType : undefined,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
// 浅拷贝一下
|
|
31
|
+
var newParams_1 = Object.assign({}, params);
|
|
32
|
+
fromKeys.forEach(function (fromKey, index) {
|
|
33
|
+
var _a, _b;
|
|
34
|
+
var toKey = toKeys[index];
|
|
35
|
+
var endTypeItem = Array.isArray(endType) ? endType[index] : endType;
|
|
36
|
+
// 1. 从一个键 转成 一个键
|
|
37
|
+
if (typeof fromKey === "string" && typeof toKey === "string") {
|
|
38
|
+
newParams_1[toKey] = getParseResult({
|
|
39
|
+
value: newParams_1[fromKey],
|
|
40
|
+
index: index,
|
|
41
|
+
endType: endTypeItem,
|
|
42
|
+
});
|
|
43
|
+
if (fromKey !== toKey) {
|
|
44
|
+
// 删除原有key
|
|
45
|
+
Reflect.deleteProperty(newParams_1, fromKey);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
// 2. 从一个键 转成 两个键
|
|
49
|
+
if (typeof fromKey === "string" && typeof toKey === "object") {
|
|
50
|
+
var toKey1 = toKey[0], toKey2 = toKey[1];
|
|
51
|
+
// 初始定义转义类型 是否拼接一天的开始 一天的结束
|
|
52
|
+
var startEndType = "startOf";
|
|
53
|
+
var endEndType = "endOf";
|
|
54
|
+
if (Array.isArray(endTypeItem)) {
|
|
55
|
+
startEndType = endTypeItem[0];
|
|
56
|
+
endEndType = endTypeItem[1];
|
|
57
|
+
}
|
|
58
|
+
newParams_1[toKey1] = getParseResult({
|
|
59
|
+
value: (_a = newParams_1[fromKey]) === null || _a === void 0 ? void 0 : _a[0],
|
|
60
|
+
index: index,
|
|
61
|
+
endType: startEndType,
|
|
62
|
+
});
|
|
63
|
+
newParams_1[toKey2] = getParseResult({
|
|
64
|
+
value: (_b = newParams_1[fromKey]) === null || _b === void 0 ? void 0 : _b[1],
|
|
65
|
+
index: index,
|
|
66
|
+
endType: endEndType,
|
|
67
|
+
});
|
|
68
|
+
if (fromKey !== toKey1 && fromKey !== toKey2) {
|
|
69
|
+
Reflect.deleteProperty(newParams_1, fromKey);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
// 3. 从两个键 转成 一个键
|
|
73
|
+
if (typeof fromKey === "object" && typeof toKey === "string") {
|
|
74
|
+
var fromKey1 = fromKey[0], fromtKey2 = fromKey[1];
|
|
75
|
+
// 初始定义转义类型 是否拼接一天的开始 一天的结束
|
|
76
|
+
var startEndType = "startOf";
|
|
77
|
+
var endEndType = "endOf";
|
|
78
|
+
if (Array.isArray(endTypeItem)) {
|
|
79
|
+
startEndType = endTypeItem[0];
|
|
80
|
+
endEndType = endTypeItem[1];
|
|
81
|
+
}
|
|
82
|
+
newParams_1[toKey] = [
|
|
83
|
+
getParseResult({
|
|
84
|
+
value: newParams_1[fromKey1],
|
|
85
|
+
index: index,
|
|
86
|
+
endType: startEndType,
|
|
87
|
+
}),
|
|
88
|
+
getParseResult({
|
|
89
|
+
value: newParams_1[fromtKey2],
|
|
90
|
+
index: index,
|
|
91
|
+
endType: endEndType,
|
|
92
|
+
}),
|
|
93
|
+
];
|
|
94
|
+
if (fromKey1 !== toKey) {
|
|
95
|
+
Reflect.deleteProperty(newParams_1, fromKey1);
|
|
96
|
+
}
|
|
97
|
+
if (fromtKey2 !== toKey) {
|
|
98
|
+
Reflect.deleteProperty(newParams_1, fromtKey2);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
// 4. 从两个键 转成 两个键
|
|
102
|
+
if (typeof fromKey === "object" && typeof toKey === "object") {
|
|
103
|
+
var fromKey1 = fromKey[0], fromtKey2 = fromKey[1];
|
|
104
|
+
var toKey1 = toKey[0], toKey2 = toKey[1];
|
|
105
|
+
// 初始定义转义类型 是否拼接一天的开始 一天的结束
|
|
106
|
+
var startEndType = undefined;
|
|
107
|
+
var endEndType = undefined;
|
|
108
|
+
if (Array.isArray(endTypeItem)) {
|
|
109
|
+
startEndType = endTypeItem[0];
|
|
110
|
+
endEndType = endTypeItem[1];
|
|
111
|
+
}
|
|
112
|
+
newParams_1[toKey1] = getParseResult({
|
|
113
|
+
value: newParams_1[fromKey1],
|
|
114
|
+
index: index,
|
|
115
|
+
endType: startEndType,
|
|
116
|
+
});
|
|
117
|
+
newParams_1[toKey2] = getParseResult({
|
|
118
|
+
value: newParams_1[fromtKey2],
|
|
119
|
+
index: index,
|
|
120
|
+
endType: endEndType,
|
|
121
|
+
});
|
|
122
|
+
if (fromKey1 !== toKey1) {
|
|
123
|
+
// 删除原有key
|
|
124
|
+
Reflect.deleteProperty(newParams_1, fromKey1);
|
|
125
|
+
}
|
|
126
|
+
if (fromtKey2 !== toKey2) {
|
|
127
|
+
// 删除原有key
|
|
128
|
+
Reflect.deleteProperty(newParams_1, fromtKey2);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
return newParams_1;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
function parseByResult(option) {
|
|
136
|
+
var _a = option.format, format = _a === void 0 ? defaultFormat : _a, _b = option.type, type = _b === void 0 ? "string" : _b;
|
|
137
|
+
return function (option) {
|
|
138
|
+
var value = option.value, _a = option.index, index = _a === void 0 ? 0 : _a, endType = option.endType; option.formatType;
|
|
139
|
+
if (!value) {
|
|
140
|
+
return undefined;
|
|
141
|
+
}
|
|
142
|
+
var parseType = typeof type === "string" ? type : type[index];
|
|
143
|
+
var parseFormat = typeof format === "string" ? format : format[index];
|
|
144
|
+
var parseEndType = Array.isArray(endType) ? endType[0] : endType;
|
|
145
|
+
if (parseType === "string") {
|
|
146
|
+
var dayjsValue = dayjs.isDayjs(value) ? value : dayjs(value);
|
|
147
|
+
if (parseEndType === "startOf") {
|
|
148
|
+
return dayjsValue.startOf("day").format(
|
|
149
|
+
// parseFormat.length === 10 ? `${parseFormat} HH:mm:ss` : parseFormat
|
|
150
|
+
parseFormat);
|
|
151
|
+
}
|
|
152
|
+
if (parseEndType === "endOf") {
|
|
153
|
+
return dayjsValue.endOf("day").format(
|
|
154
|
+
// parseFormat.length === 10 ? `${parseFormat} HH:mm:ss` : parseFormat
|
|
155
|
+
parseFormat);
|
|
156
|
+
}
|
|
157
|
+
return dayjsValue.format(parseFormat);
|
|
158
|
+
}
|
|
159
|
+
else {
|
|
160
|
+
if (parseEndType === "startOf") {
|
|
161
|
+
return dayjs(value).startOf("day");
|
|
162
|
+
}
|
|
163
|
+
if (parseEndType === "endOf") {
|
|
164
|
+
return dayjs(value).endOf("day");
|
|
165
|
+
}
|
|
166
|
+
return dayjs(value);
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* 计算年龄
|
|
172
|
+
*/
|
|
173
|
+
function calculateAge(birthday) {
|
|
174
|
+
if (!birthday) {
|
|
175
|
+
console.error("请传入一个生日信息");
|
|
176
|
+
return -1;
|
|
177
|
+
}
|
|
178
|
+
var birthDate = dayjs(birthday);
|
|
179
|
+
var today = dayjs();
|
|
180
|
+
var age = today.year() - birthDate.year();
|
|
181
|
+
var monthDifference = today.month() - birthDate.month();
|
|
182
|
+
if (monthDifference < 0 ||
|
|
183
|
+
(monthDifference === 0 && today.date() < birthDate.date())) {
|
|
184
|
+
age -= 1;
|
|
185
|
+
}
|
|
186
|
+
return age;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
export { calculateAge, parseTime };
|
|
@@ -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/pdf.d.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { RGBAData } from 'jspdf';
|
|
2
|
+
import { IWaterResult } from './water.js';
|
|
3
|
+
|
|
4
|
+
declare function imgToPdf(config: IImgToPdfConfig): Promise<unknown>;
|
|
5
|
+
type IImage = string | HTMLImageElement | HTMLCanvasElement | Uint8Array | RGBAData;
|
|
6
|
+
interface IIMageConfig {
|
|
7
|
+
image: IImage;
|
|
8
|
+
width: number;
|
|
9
|
+
height: number;
|
|
10
|
+
}
|
|
11
|
+
interface IImgToPdfConfig {
|
|
12
|
+
/** 图片 base64字符串 */
|
|
13
|
+
images: IIMageConfig | any[];
|
|
14
|
+
/** 生成的pdf左边距 */
|
|
15
|
+
leftPadding?: number;
|
|
16
|
+
pdfConfig?: IPdfConfig;
|
|
17
|
+
pdfDownloadConfig?: IPdfDownloadConfig;
|
|
18
|
+
/**
|
|
19
|
+
* 水印相关信息
|
|
20
|
+
*/
|
|
21
|
+
waterConfig?: IWaterResult;
|
|
22
|
+
}
|
|
23
|
+
interface IPdfConfig {
|
|
24
|
+
/** 导出pdf单位 */
|
|
25
|
+
unit?: "pt" | "mm";
|
|
26
|
+
/**
|
|
27
|
+
* 横向 还是 纵向
|
|
28
|
+
* l: 横向 p:纵向
|
|
29
|
+
*/
|
|
30
|
+
orientation?: "p" | "l";
|
|
31
|
+
/**
|
|
32
|
+
* pdf格式 a4 ..
|
|
33
|
+
*/
|
|
34
|
+
format?: string | [width: number, height: number];
|
|
35
|
+
/**
|
|
36
|
+
* 生成的pdf是否压缩
|
|
37
|
+
*/
|
|
38
|
+
compress?: boolean;
|
|
39
|
+
}
|
|
40
|
+
interface IPdfDownloadConfig {
|
|
41
|
+
/**
|
|
42
|
+
* 生成pdf的名称
|
|
43
|
+
*/
|
|
44
|
+
pdfName?: string;
|
|
45
|
+
/** 是否直接下载pdf */
|
|
46
|
+
isDownload?: boolean;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export { IImgToPdfConfig, IPdfConfig, IPdfDownloadConfig, imgToPdf };
|
package/dist/es/pdf.js
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { __awaiter, __generator } from './_virtual/_tslib.js';
|
|
2
|
+
import { jsPDF } from 'jspdf';
|
|
3
|
+
import dayjs from 'dayjs';
|
|
4
|
+
|
|
5
|
+
function imgToPdf(config) {
|
|
6
|
+
var images = config.images, leftPadding = config.leftPadding, pdfConfig = config.pdfConfig, pdfDownloadConfig = config.pdfDownloadConfig, waterConfig = config.waterConfig;
|
|
7
|
+
var _a = pdfDownloadConfig || {}, isDownload = _a.isDownload, pdfName = _a.pdfName;
|
|
8
|
+
if (Array.isArray(images)) {
|
|
9
|
+
// 合并成一个pdf导出
|
|
10
|
+
// 解析pdf参数
|
|
11
|
+
var resultPdfConfig = parsePdfConfig(pdfConfig);
|
|
12
|
+
var _b = resultPdfConfig.format, pdfWidth_1 = _b[0], pdfHeight_1 = _b[1];
|
|
13
|
+
// 创建一个新的jsPDF实例
|
|
14
|
+
var pdf_1 = new jsPDF(resultPdfConfig);
|
|
15
|
+
return (function () {
|
|
16
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
17
|
+
var i, _i, images_1, canvasPromise, canvas, canvasWidth, canvasHeight;
|
|
18
|
+
return __generator(this, function (_a) {
|
|
19
|
+
switch (_a.label) {
|
|
20
|
+
case 0:
|
|
21
|
+
i = 0;
|
|
22
|
+
_i = 0, images_1 = images;
|
|
23
|
+
_a.label = 1;
|
|
24
|
+
case 1:
|
|
25
|
+
if (!(_i < images_1.length)) return [3 /*break*/, 4];
|
|
26
|
+
canvasPromise = images_1[_i];
|
|
27
|
+
i++;
|
|
28
|
+
return [4 /*yield*/, canvasPromise];
|
|
29
|
+
case 2:
|
|
30
|
+
canvas = _a.sent();
|
|
31
|
+
canvasWidth = canvas.width;
|
|
32
|
+
canvasHeight = canvas.height;
|
|
33
|
+
insertImgToPdf(pdf_1, pdfWidth_1, pdfHeight_1, {
|
|
34
|
+
imageConfig: {
|
|
35
|
+
image: canvas,
|
|
36
|
+
width: canvasWidth,
|
|
37
|
+
height: canvasHeight,
|
|
38
|
+
},
|
|
39
|
+
leftPadding: leftPadding,
|
|
40
|
+
waterConfig: waterConfig,
|
|
41
|
+
});
|
|
42
|
+
// 继续分页
|
|
43
|
+
if (i < images.length) {
|
|
44
|
+
pdf_1.addPage();
|
|
45
|
+
}
|
|
46
|
+
_a.label = 3;
|
|
47
|
+
case 3:
|
|
48
|
+
_i++;
|
|
49
|
+
return [3 /*break*/, 1];
|
|
50
|
+
case 4:
|
|
51
|
+
if (isDownload) {
|
|
52
|
+
pdf_1.save("".concat(pdfName || dayjs().format("YYYY-MM-DD"), ".pdf"));
|
|
53
|
+
}
|
|
54
|
+
return [2 /*return*/, Promise.resolve(pdf_1)];
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
})();
|
|
59
|
+
}
|
|
60
|
+
var image = images.image, width = images.width, height = images.height;
|
|
61
|
+
return new Promise(function (resolve, reject) {
|
|
62
|
+
try {
|
|
63
|
+
// 解析pdf参数
|
|
64
|
+
var resultPdfConfig = parsePdfConfig(pdfConfig);
|
|
65
|
+
var _a = resultPdfConfig.format, pdfWidth = _a[0], pdfHeight = _a[1];
|
|
66
|
+
// 创建一个新的jsPDF实例
|
|
67
|
+
var pdf = new jsPDF(resultPdfConfig);
|
|
68
|
+
insertImgToPdf(pdf, pdfWidth, pdfHeight, {
|
|
69
|
+
imageConfig: {
|
|
70
|
+
image: image,
|
|
71
|
+
width: width,
|
|
72
|
+
height: height,
|
|
73
|
+
},
|
|
74
|
+
leftPadding: leftPadding,
|
|
75
|
+
waterConfig: waterConfig,
|
|
76
|
+
});
|
|
77
|
+
if (isDownload) {
|
|
78
|
+
pdf.save("".concat(pdfName, ".pdf"));
|
|
79
|
+
}
|
|
80
|
+
resolve(pdf);
|
|
81
|
+
}
|
|
82
|
+
catch (err) {
|
|
83
|
+
reject(err);
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
// 解析format 为数值
|
|
88
|
+
function parsePdfFormat(format) {
|
|
89
|
+
if (format === "a4") {
|
|
90
|
+
return [595.28, 841.89];
|
|
91
|
+
}
|
|
92
|
+
if (Array.isArray(format)) {
|
|
93
|
+
return format;
|
|
94
|
+
}
|
|
95
|
+
// 默认返回a4的数值
|
|
96
|
+
return [595.28, 841.89];
|
|
97
|
+
}
|
|
98
|
+
// 解析pdf实例化参数
|
|
99
|
+
function parsePdfConfig(pdfConfig) {
|
|
100
|
+
var _a;
|
|
101
|
+
var _b = pdfConfig || {}, _c = _b.compress, compress = _c === void 0 ? true : _c, _d = _b.orientation, orientation = _d === void 0 ? "p" : _d, _e = _b.format, format = _e === void 0 ? "a4" : _e, _f = _b.unit, unit = _f === void 0 ? "pt" : _f;
|
|
102
|
+
// 单位转换
|
|
103
|
+
var _g = parsePdfFormat(format), pdfWidth = _g[0], pdfHeight = _g[1];
|
|
104
|
+
// 如果是横向的话,需要转换下宽高的位置
|
|
105
|
+
if (orientation === "l") {
|
|
106
|
+
_a = [pdfHeight, pdfWidth], pdfWidth = _a[0], pdfHeight = _a[1];
|
|
107
|
+
}
|
|
108
|
+
return {
|
|
109
|
+
// 方向 l:横向 p:纵向
|
|
110
|
+
orientation: orientation,
|
|
111
|
+
// 单位
|
|
112
|
+
unit: unit,
|
|
113
|
+
format: [pdfWidth, pdfHeight],
|
|
114
|
+
compress: compress,
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
// 将图片插入pdf中
|
|
118
|
+
function insertImgToPdf(pdf, pdfWidth, pdfHeight, config) {
|
|
119
|
+
var imageConfig = config.imageConfig, _a = config.leftPadding, leftPadding = _a === void 0 ? 15 : _a, waterConfig = config.waterConfig;
|
|
120
|
+
var image = imageConfig.image, width = imageConfig.width, height = imageConfig.height;
|
|
121
|
+
// 缩放图片 以适应PDF页面宽度
|
|
122
|
+
var canvasWidth = width; // 图片原始宽度
|
|
123
|
+
var canvasHeight = height; // 图片原始高度
|
|
124
|
+
// 一页pdf能显示的canvas高度
|
|
125
|
+
var pageHeight = (canvasWidth / pdfWidth) * pdfHeight;
|
|
126
|
+
// 将绘制图片的宽度 设置 成pdf的宽度 (减去偏移)
|
|
127
|
+
var imgWidth = pdfWidth - leftPadding * 2;
|
|
128
|
+
// 等比例换算绘制图片高度
|
|
129
|
+
var imgHeight = (imgWidth / canvasWidth) * canvasHeight;
|
|
130
|
+
// 需要打印的图片总高度,初始状态和图片高度相等
|
|
131
|
+
var totalHeight = canvasHeight;
|
|
132
|
+
if (totalHeight < pageHeight) {
|
|
133
|
+
pdf.addImage(image, "JPEG", leftPadding, 0, imgWidth, imgHeight);
|
|
134
|
+
// 添加水印
|
|
135
|
+
if (waterConfig) {
|
|
136
|
+
addImageWater(pdf, waterConfig.image, {
|
|
137
|
+
width: waterConfig.width,
|
|
138
|
+
height: waterConfig.height,
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
var position = 0;
|
|
144
|
+
while (totalHeight > 0) {
|
|
145
|
+
pdf.addImage(image, "JPEG", leftPadding, position, imgWidth, imgHeight);
|
|
146
|
+
// 添加水印
|
|
147
|
+
if (waterConfig) {
|
|
148
|
+
addImageWater(pdf, waterConfig.image, {
|
|
149
|
+
width: waterConfig.width,
|
|
150
|
+
height: waterConfig.height,
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
totalHeight -= pageHeight;
|
|
154
|
+
//避免添加空白页
|
|
155
|
+
position -= pdfHeight;
|
|
156
|
+
if (totalHeight > 0) {
|
|
157
|
+
pdf.addPage();
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* 给PDF添加图片水印
|
|
164
|
+
*/
|
|
165
|
+
function addImageWater(pdf, imgData, options) {
|
|
166
|
+
var width = (options === null || options === void 0 ? void 0 : options.width) || 200;
|
|
167
|
+
var height = (options === null || options === void 0 ? void 0 : options.height) || 80;
|
|
168
|
+
var x = (options === null || options === void 0 ? void 0 : options.x) || 40;
|
|
169
|
+
var y = (options === null || options === void 0 ? void 0 : options.y) || 140;
|
|
170
|
+
for (var i = 0; i < 4; i++) {
|
|
171
|
+
pdf.addImage(imgData, "PNG", x, y * i, width, height, "1-".concat(i));
|
|
172
|
+
pdf.addImage(imgData, "PNG", x + x + width, y * i, width, height, "2-".concat(i));
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export { addImageWater, imgToPdf, insertImgToPdf, parsePdfConfig, parsePdfFormat };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { convert, html, match, pinyin } from './node_modules/pinyin-pro/dist/index.js';
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import printJS from 'print-js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 打印页面 直接调用window.print方法打印
|
|
5
|
+
*/
|
|
6
|
+
declare function windowPrint(config?: IWindowPrint): void;
|
|
7
|
+
interface IWindowPrint {
|
|
8
|
+
hiddenClassNames?: string[];
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* 打印页面dom 通过库来打印
|
|
12
|
+
*/
|
|
13
|
+
declare function htmlPrint(config: printJS.Configuration): void;
|
|
14
|
+
/**
|
|
15
|
+
* 打印图片
|
|
16
|
+
*/
|
|
17
|
+
declare function imgPrint(config: printJS.Configuration): void;
|
|
18
|
+
/**
|
|
19
|
+
* 打印pdf
|
|
20
|
+
*/
|
|
21
|
+
declare function pdfPrint(config: printJS.Configuration): void;
|
|
22
|
+
|
|
23
|
+
export { IWindowPrint, htmlPrint, imgPrint, pdfPrint, windowPrint };
|
package/dist/es/print.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { __spreadArray, __assign } from './_virtual/_tslib.js';
|
|
2
|
+
import printJS from 'print-js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* 打印页面 直接调用window.print方法打印
|
|
6
|
+
*/
|
|
7
|
+
function windowPrint(config) {
|
|
8
|
+
if (config === null || config === void 0 ? void 0 : config.hiddenClassNames) {
|
|
9
|
+
var hiddenClassNames = config.hiddenClassNames;
|
|
10
|
+
var printStyleDom = document.getElementById("print--window__00100");
|
|
11
|
+
if (printStyleDom) {
|
|
12
|
+
printStyleDom.remove();
|
|
13
|
+
}
|
|
14
|
+
var styleDom = document.createElement("style");
|
|
15
|
+
styleDom.setAttribute("type", "text/css");
|
|
16
|
+
styleDom.setAttribute("id", "print--window__00100");
|
|
17
|
+
styleDom.innerHTML = "@media print{ ".concat(__spreadArray(__spreadArray([], (hiddenClassNames || []), true), [
|
|
18
|
+
".non-printable",
|
|
19
|
+
], false).join(","), " { display: none; } }");
|
|
20
|
+
document.head.appendChild(styleDom);
|
|
21
|
+
}
|
|
22
|
+
window.print();
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* 打印页面dom 通过库来打印
|
|
26
|
+
*/
|
|
27
|
+
function htmlPrint(config) {
|
|
28
|
+
printJS(__assign({ type: "html" }, config));
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* 打印图片
|
|
32
|
+
*/
|
|
33
|
+
function imgPrint(config) {
|
|
34
|
+
printJS(__assign({ type: "image" }, config));
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* 打印pdf
|
|
38
|
+
*/
|
|
39
|
+
function pdfPrint(config) {
|
|
40
|
+
printJS(__assign({ type: "pdf" }, config));
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export { htmlPrint, imgPrint, pdfPrint, windowPrint };
|