tools-min-ns 1.6.0 → 1.8.0
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 +19 -0
- package/esm/array/TreeUtil.d.ts +7 -0
- package/esm/array/TreeUtil.js +20 -4
- package/esm/browser/BrowserUtil.d.ts +1 -0
- package/esm/browser/BrowserUtil.js +34 -1
- package/esm/date/DateUtil.d.ts +7 -0
- package/esm/date/DateUtil.js +26 -0
- package/esm/file/FileUtil.d.ts +10 -0
- package/esm/file/FileUtil.js +182 -0
- package/esm/object/ObjectUtil.d.ts +5 -0
- package/esm/object/ObjectUtil.js +15 -7
- package/esm/request/RequestUtil.d.ts +14 -0
- package/esm/request/RequestUtil.js +184 -0
- package/esm/string/StringUtil.d.ts +6 -0
- package/esm/string/StringUtil.js +14 -0
- package/esm/transfer/TransferUtil.d.ts +2 -2
- package/esm/transfer/TransferUtil.js +57 -57
- package/lib/array/TreeUtil.d.ts +7 -0
- package/lib/array/TreeUtil.js +20 -4
- package/lib/browser/BrowserUtil.d.ts +1 -0
- package/lib/browser/BrowserUtil.js +34 -1
- package/lib/date/DateUtil.d.ts +7 -0
- package/lib/date/DateUtil.js +26 -0
- package/lib/file/FileUtil.d.ts +10 -0
- package/lib/file/FileUtil.js +192 -0
- package/lib/object/ObjectUtil.d.ts +5 -0
- package/lib/object/ObjectUtil.js +14 -6
- package/lib/request/RequestUtil.d.ts +14 -0
- package/lib/request/RequestUtil.js +184 -0
- package/lib/string/StringUtil.d.ts +6 -0
- package/lib/string/StringUtil.js +14 -0
- package/lib/transfer/TransferUtil.d.ts +2 -2
- package/lib/transfer/TransferUtil.js +56 -56
- package/package.json +4 -2
package/README.md
CHANGED
|
@@ -5,6 +5,25 @@ cnpm i tools-min-ns --save
|
|
|
5
5
|
```
|
|
6
6
|
|
|
7
7
|
# updates
|
|
8
|
+
## v1.8.0
|
|
9
|
+
|
|
10
|
+
> TreeUtil 新增getItemPathByTree
|
|
11
|
+
|
|
12
|
+
## v1.7.2
|
|
13
|
+
|
|
14
|
+
> TreeUtil 修复getIdPathByTree
|
|
15
|
+
|
|
16
|
+
## v1.7.1
|
|
17
|
+
|
|
18
|
+
> DateUtil 新增getDatesOfMonth
|
|
19
|
+
|
|
20
|
+
## v1.7.0
|
|
21
|
+
|
|
22
|
+
> 新增FileUtil
|
|
23
|
+
> ObjectUtil 新增getHash
|
|
24
|
+
> StringUtil 新增getHash
|
|
25
|
+
> BrowserUtil 新增getIdSync
|
|
26
|
+
|
|
8
27
|
## v1.6.0
|
|
9
28
|
|
|
10
29
|
> CheckUtil
|
package/esm/array/TreeUtil.d.ts
CHANGED
|
@@ -49,6 +49,13 @@ declare namespace TreeUtil {
|
|
|
49
49
|
* @param fieldNames 映射对象
|
|
50
50
|
*/
|
|
51
51
|
function getIdPathByTree<T>(tree: T[], id: ValueType, fieldNames?: FieldNames): ValueType[];
|
|
52
|
+
/**
|
|
53
|
+
* @name 获取树中路径对象数组
|
|
54
|
+
* @param tree 树
|
|
55
|
+
* @param id 主键
|
|
56
|
+
* @param fieldNames 映射对象
|
|
57
|
+
*/
|
|
58
|
+
function getItemPathByTree<T>(tree: T[], id: ValueType, fieldNames?: FieldNames): T[];
|
|
52
59
|
/**
|
|
53
60
|
* @name 字符串分割转为树结构
|
|
54
61
|
* @param str string
|
package/esm/array/TreeUtil.js
CHANGED
|
@@ -178,6 +178,20 @@ var TreeUtil;
|
|
|
178
178
|
* @param fieldNames 映射对象
|
|
179
179
|
*/
|
|
180
180
|
function getIdPathByTree(tree, id, fieldNames) {
|
|
181
|
+
var _a = (fieldNames !== null && fieldNames !== void 0 ? fieldNames : {}).value,
|
|
182
|
+
value = _a === void 0 ? 'id' : _a;
|
|
183
|
+
return getItemPathByTree(tree, id, fieldNames).map(function (item) {
|
|
184
|
+
return item[value];
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
TreeUtil.getIdPathByTree = getIdPathByTree;
|
|
188
|
+
/**
|
|
189
|
+
* @name 获取树中路径对象数组
|
|
190
|
+
* @param tree 树
|
|
191
|
+
* @param id 主键
|
|
192
|
+
* @param fieldNames 映射对象
|
|
193
|
+
*/
|
|
194
|
+
function getItemPathByTree(tree, id, fieldNames) {
|
|
181
195
|
var _a = fieldNames !== null && fieldNames !== void 0 ? fieldNames : {},
|
|
182
196
|
_b = _a.value,
|
|
183
197
|
value = _b === void 0 ? 'id' : _b,
|
|
@@ -188,15 +202,17 @@ var TreeUtil;
|
|
|
188
202
|
_e = _a.rootPid,
|
|
189
203
|
rootPid = _e === void 0 ? undefined : _e;
|
|
190
204
|
if (BaseUtil.isEmpty(id)) return [];
|
|
191
|
-
var idList =
|
|
192
|
-
|
|
205
|
+
var idList = filterTreeData(tree, function (t) {
|
|
206
|
+
return t[value] === id;
|
|
207
|
+
});
|
|
208
|
+
var list = getListByTree(tree, children);
|
|
193
209
|
var getList = function getList(importOid) {
|
|
194
210
|
forEachTree(tree, function (info) {
|
|
195
211
|
if (String(info[value]) === String(importOid)) {
|
|
196
212
|
if (parent in info && info[parent] && list.some(function (e) {
|
|
197
213
|
return String(e[value]) === String(info[parent]);
|
|
198
214
|
})) {
|
|
199
|
-
idList.unshift(info
|
|
215
|
+
idList.unshift(info);
|
|
200
216
|
getList(info === null || info === void 0 ? void 0 : info[parent]);
|
|
201
217
|
}
|
|
202
218
|
}
|
|
@@ -211,7 +227,7 @@ var TreeUtil;
|
|
|
211
227
|
}
|
|
212
228
|
return idList;
|
|
213
229
|
}
|
|
214
|
-
TreeUtil.
|
|
230
|
+
TreeUtil.getItemPathByTree = getItemPathByTree;
|
|
215
231
|
/**
|
|
216
232
|
* @name 字符串分割转为树结构
|
|
217
233
|
* @param str string
|
|
@@ -142,6 +142,27 @@ var BrowserUtil;
|
|
|
142
142
|
});
|
|
143
143
|
});
|
|
144
144
|
};
|
|
145
|
+
function getIdSync() {
|
|
146
|
+
var fingerprint;
|
|
147
|
+
var canvas = document.createElement('canvas');
|
|
148
|
+
var ctx = canvas.getContext('2d');
|
|
149
|
+
var txt = window.location.host;
|
|
150
|
+
ctx.textBaseline = 'top';
|
|
151
|
+
ctx.font = "14px 'Arial'";
|
|
152
|
+
ctx.textBaseline = 'tencent';
|
|
153
|
+
ctx.fillStyle = '#f60';
|
|
154
|
+
ctx.fillRect(125, 1, 62, 20);
|
|
155
|
+
ctx.fillStyle = '#069';
|
|
156
|
+
ctx.fillText(txt, 2, 15);
|
|
157
|
+
ctx.fillStyle = 'rgba(102, 204, 0, 0.7)';
|
|
158
|
+
ctx.fillText(txt, 4, 17);
|
|
159
|
+
var b64 = canvas.toDataURL().replace('data:image/png;base64,', '');
|
|
160
|
+
var bin = atob(b64);
|
|
161
|
+
var crc = bin2hex(bin.slice(-16, -12));
|
|
162
|
+
fingerprint = crc;
|
|
163
|
+
return fingerprint;
|
|
164
|
+
}
|
|
165
|
+
BrowserUtil.getIdSync = getIdSync;
|
|
145
166
|
/**
|
|
146
167
|
* 获取浏览器类型
|
|
147
168
|
* @returns Opera | IE | Edge | Firefox | Safari | Chrome | OverIE10 | ""
|
|
@@ -334,4 +355,16 @@ var BrowserUtil;
|
|
|
334
355
|
}
|
|
335
356
|
BrowserUtil.removeMark = removeMark;
|
|
336
357
|
})(BrowserUtil || (BrowserUtil = {}));
|
|
337
|
-
export default BrowserUtil;
|
|
358
|
+
export default BrowserUtil;
|
|
359
|
+
function bin2hex(s) {
|
|
360
|
+
var i,
|
|
361
|
+
l,
|
|
362
|
+
n,
|
|
363
|
+
o = '';
|
|
364
|
+
s += '';
|
|
365
|
+
for (i = 0, l = s.length; i < l; i++) {
|
|
366
|
+
n = s.charCodeAt(i).toString(16);
|
|
367
|
+
o += n.length < 2 ? '0' + n : n;
|
|
368
|
+
}
|
|
369
|
+
return o;
|
|
370
|
+
}
|
package/esm/date/DateUtil.d.ts
CHANGED
|
@@ -257,5 +257,12 @@ declare namespace DateUtil {
|
|
|
257
257
|
* @returns
|
|
258
258
|
*/
|
|
259
259
|
const timeFix: (t?: string) => string | undefined;
|
|
260
|
+
/**
|
|
261
|
+
* 格式为“年-月”,然后输出该月所有日期的数组
|
|
262
|
+
* @param yearMonth 2024-01
|
|
263
|
+
* @param format 'yyyy-MM-dd'
|
|
264
|
+
* @returns ['2024-01-01',...]
|
|
265
|
+
*/
|
|
266
|
+
function getDatesOfMonth(yearMonth: string, format?: string): string[];
|
|
260
267
|
}
|
|
261
268
|
export default DateUtil;
|
package/esm/date/DateUtil.js
CHANGED
|
@@ -731,6 +731,32 @@ var DateUtil;
|
|
|
731
731
|
var _a;
|
|
732
732
|
return (_a = t === null || t === void 0 ? void 0 : t.split('.')) === null || _a === void 0 ? void 0 : _a[0];
|
|
733
733
|
};
|
|
734
|
+
/**
|
|
735
|
+
* 格式为“年-月”,然后输出该月所有日期的数组
|
|
736
|
+
* @param yearMonth 2024-01
|
|
737
|
+
* @param format 'yyyy-MM-dd'
|
|
738
|
+
* @returns ['2024-01-01',...]
|
|
739
|
+
*/
|
|
740
|
+
function getDatesOfMonth(yearMonth, format) {
|
|
741
|
+
if (format === void 0) {
|
|
742
|
+
format = 'yyyy-MM-dd';
|
|
743
|
+
}
|
|
744
|
+
var _a = __read(yearMonth.split('-').map(Number), 2),
|
|
745
|
+
year = _a[0],
|
|
746
|
+
month = _a[1]; // 分割字符串并转换为数字
|
|
747
|
+
var dates = []; // 初始化存储日期的数组
|
|
748
|
+
// 获取该月的第一天
|
|
749
|
+
var date = new Date(year, month - 1, 1);
|
|
750
|
+
// 循环直到月份改变
|
|
751
|
+
while (date.getMonth() === month - 1) {
|
|
752
|
+
// 将日期格式化为字符串并添加到数组中
|
|
753
|
+
dates.push(DateUtil.formatDate(date, format));
|
|
754
|
+
// 日期加一天
|
|
755
|
+
date.setDate(date.getDate() + 2);
|
|
756
|
+
}
|
|
757
|
+
return dates;
|
|
758
|
+
}
|
|
759
|
+
DateUtil.getDatesOfMonth = getDatesOfMonth;
|
|
734
760
|
})(DateUtil || (DateUtil = {}));
|
|
735
761
|
export default DateUtil;
|
|
736
762
|
var dateFormatRules = [{
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
var __awaiter = this && this.__awaiter || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) {
|
|
3
|
+
return value instanceof P ? value : new P(function (resolve) {
|
|
4
|
+
resolve(value);
|
|
5
|
+
});
|
|
6
|
+
}
|
|
7
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
8
|
+
function fulfilled(value) {
|
|
9
|
+
try {
|
|
10
|
+
step(generator.next(value));
|
|
11
|
+
} catch (e) {
|
|
12
|
+
reject(e);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function rejected(value) {
|
|
16
|
+
try {
|
|
17
|
+
step(generator["throw"](value));
|
|
18
|
+
} catch (e) {
|
|
19
|
+
reject(e);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
function step(result) {
|
|
23
|
+
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
24
|
+
}
|
|
25
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
var __generator = this && this.__generator || function (thisArg, body) {
|
|
29
|
+
var _ = {
|
|
30
|
+
label: 0,
|
|
31
|
+
sent: function sent() {
|
|
32
|
+
if (t[0] & 1) throw t[1];
|
|
33
|
+
return t[1];
|
|
34
|
+
},
|
|
35
|
+
trys: [],
|
|
36
|
+
ops: []
|
|
37
|
+
},
|
|
38
|
+
f,
|
|
39
|
+
y,
|
|
40
|
+
t,
|
|
41
|
+
g;
|
|
42
|
+
return g = {
|
|
43
|
+
next: verb(0),
|
|
44
|
+
"throw": verb(1),
|
|
45
|
+
"return": verb(2)
|
|
46
|
+
}, typeof Symbol === "function" && (g[Symbol.iterator] = function () {
|
|
47
|
+
return this;
|
|
48
|
+
}), g;
|
|
49
|
+
function verb(n) {
|
|
50
|
+
return function (v) {
|
|
51
|
+
return step([n, v]);
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
function step(op) {
|
|
55
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
56
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
57
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
58
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
59
|
+
switch (op[0]) {
|
|
60
|
+
case 0:
|
|
61
|
+
case 1:
|
|
62
|
+
t = op;
|
|
63
|
+
break;
|
|
64
|
+
case 4:
|
|
65
|
+
_.label++;
|
|
66
|
+
return {
|
|
67
|
+
value: op[1],
|
|
68
|
+
done: false
|
|
69
|
+
};
|
|
70
|
+
case 5:
|
|
71
|
+
_.label++;
|
|
72
|
+
y = op[1];
|
|
73
|
+
op = [0];
|
|
74
|
+
continue;
|
|
75
|
+
case 7:
|
|
76
|
+
op = _.ops.pop();
|
|
77
|
+
_.trys.pop();
|
|
78
|
+
continue;
|
|
79
|
+
default:
|
|
80
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
81
|
+
_ = 0;
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
85
|
+
_.label = op[1];
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
88
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
89
|
+
_.label = t[1];
|
|
90
|
+
t = op;
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
93
|
+
if (t && _.label < t[2]) {
|
|
94
|
+
_.label = t[2];
|
|
95
|
+
_.ops.push(op);
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
if (t[2]) _.ops.pop();
|
|
99
|
+
_.trys.pop();
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
op = body.call(thisArg, _);
|
|
103
|
+
} catch (e) {
|
|
104
|
+
op = [6, e];
|
|
105
|
+
y = 0;
|
|
106
|
+
} finally {
|
|
107
|
+
f = t = 0;
|
|
108
|
+
}
|
|
109
|
+
if (op[0] & 5) throw op[1];
|
|
110
|
+
return {
|
|
111
|
+
value: op[0] ? op[1] : void 0,
|
|
112
|
+
done: true
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
var __values = this && this.__values || function (o) {
|
|
117
|
+
var s = typeof Symbol === "function" && Symbol.iterator,
|
|
118
|
+
m = s && o[s],
|
|
119
|
+
i = 0;
|
|
120
|
+
if (m) return m.call(o);
|
|
121
|
+
if (o && typeof o.length === "number") return {
|
|
122
|
+
next: function next() {
|
|
123
|
+
if (o && i >= o.length) o = void 0;
|
|
124
|
+
return {
|
|
125
|
+
value: o && o[i++],
|
|
126
|
+
done: !o
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
131
|
+
};
|
|
132
|
+
import JSZip from 'jszip';
|
|
133
|
+
var FileUtil;
|
|
134
|
+
(function (FileUtil) {
|
|
135
|
+
/**
|
|
136
|
+
* 多个文件压缩成zip
|
|
137
|
+
* @param fileList
|
|
138
|
+
* @param onProgress
|
|
139
|
+
* @returns
|
|
140
|
+
*/
|
|
141
|
+
function getZipByFiles(fileList, onProgress) {
|
|
142
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
143
|
+
var zip, fileList_1, fileList_1_1, file_1, blob, file;
|
|
144
|
+
var e_1, _a;
|
|
145
|
+
return __generator(this, function (_b) {
|
|
146
|
+
switch (_b.label) {
|
|
147
|
+
case 0:
|
|
148
|
+
zip = new JSZip();
|
|
149
|
+
try {
|
|
150
|
+
for (fileList_1 = __values(fileList), fileList_1_1 = fileList_1.next(); !fileList_1_1.done; fileList_1_1 = fileList_1.next()) {
|
|
151
|
+
file_1 = fileList_1_1.value;
|
|
152
|
+
zip.file(file_1.name, file_1);
|
|
153
|
+
}
|
|
154
|
+
} catch (e_1_1) {
|
|
155
|
+
e_1 = {
|
|
156
|
+
error: e_1_1
|
|
157
|
+
};
|
|
158
|
+
} finally {
|
|
159
|
+
try {
|
|
160
|
+
if (fileList_1_1 && !fileList_1_1.done && (_a = fileList_1.return)) _a.call(fileList_1);
|
|
161
|
+
} finally {
|
|
162
|
+
if (e_1) throw e_1.error;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
return [4 /*yield*/, zip.generateAsync({
|
|
166
|
+
type: 'blob'
|
|
167
|
+
}, function (item) {
|
|
168
|
+
onProgress === null || onProgress === void 0 ? void 0 : onProgress(item.currentFile, item.percent);
|
|
169
|
+
})];
|
|
170
|
+
case 1:
|
|
171
|
+
blob = _b.sent();
|
|
172
|
+
file = new File([blob], "\u201C".concat(fileList[0].name, "\u201D\u7B49").concat(fileList.length, "\u4E2A\u6587\u4EF6.zip"), {
|
|
173
|
+
type: blob.type
|
|
174
|
+
});
|
|
175
|
+
return [2 /*return*/, file];
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
FileUtil.getZipByFiles = getZipByFiles;
|
|
181
|
+
})(FileUtil || (FileUtil = {}));
|
|
182
|
+
export default FileUtil;
|
package/esm/object/ObjectUtil.js
CHANGED
|
@@ -26,9 +26,8 @@ var __read = this && this.__read || function (o, n) {
|
|
|
26
26
|
* @author nanshen
|
|
27
27
|
* @creat 2021-09-15 14:23:23
|
|
28
28
|
*/
|
|
29
|
-
import
|
|
30
|
-
|
|
31
|
-
isArray = BaseUtil.isArray;
|
|
29
|
+
import StringUtil from '../string/StringUtil';
|
|
30
|
+
import BaseUtil from '../base/BaseUtil';
|
|
32
31
|
var ObjectUtil;
|
|
33
32
|
(function (ObjectUtil) {
|
|
34
33
|
/**
|
|
@@ -40,12 +39,12 @@ var ObjectUtil;
|
|
|
40
39
|
*/
|
|
41
40
|
function deepClone(source) {
|
|
42
41
|
var target;
|
|
43
|
-
if (isObject(source)) {
|
|
42
|
+
if (BaseUtil.isObject(source)) {
|
|
44
43
|
target = {};
|
|
45
44
|
for (var key in source) {
|
|
46
45
|
target[key] = deepClone(source[key]);
|
|
47
46
|
}
|
|
48
|
-
} else if (isArray(source)) {
|
|
47
|
+
} else if (BaseUtil.isArray(source)) {
|
|
49
48
|
target = [];
|
|
50
49
|
for (var i = 0, len = source.length; i < len; i++) {
|
|
51
50
|
target.push(deepClone(source[i]));
|
|
@@ -66,7 +65,7 @@ var ObjectUtil;
|
|
|
66
65
|
// 判断 object 是否是数组或者对象,否则直接返回默认值 defaultValue
|
|
67
66
|
if (!BaseUtil.isObject(object)) return defaultValue;
|
|
68
67
|
// 沿着路径寻找到对应的值,未找到则返回默认值 defaultValue
|
|
69
|
-
return path.split(
|
|
68
|
+
return path.split('.').reduce(function (o, k) {
|
|
70
69
|
return (o || {})[k];
|
|
71
70
|
}, object) || defaultValue;
|
|
72
71
|
}
|
|
@@ -81,7 +80,7 @@ var ObjectUtil;
|
|
|
81
80
|
function setObjValue(object, path, value, isChangeOriginObj) {
|
|
82
81
|
if (!BaseUtil.isObject(object)) return object;
|
|
83
82
|
var newObj = isChangeOriginObj ? object : deepClone(object);
|
|
84
|
-
path.split(
|
|
83
|
+
path.split('.').reduce(function (o, k, i, _) {
|
|
85
84
|
if (i === _.length - 1) {
|
|
86
85
|
// 若遍历结束直接赋值
|
|
87
86
|
o[k] = value;
|
|
@@ -154,5 +153,14 @@ var ObjectUtil;
|
|
|
154
153
|
return newData;
|
|
155
154
|
}
|
|
156
155
|
ObjectUtil.mergeParams = mergeParams;
|
|
156
|
+
/**
|
|
157
|
+
* 获取对象的唯一hash
|
|
158
|
+
* @param obj
|
|
159
|
+
*/
|
|
160
|
+
function getHash(obj) {
|
|
161
|
+
var str = JSON.stringify(obj);
|
|
162
|
+
return StringUtil.getHash(str);
|
|
163
|
+
}
|
|
164
|
+
ObjectUtil.getHash = getHash;
|
|
157
165
|
})(ObjectUtil || (ObjectUtil = {}));
|
|
158
166
|
export default ObjectUtil;
|
|
@@ -48,5 +48,19 @@ declare namespace RequestUtil {
|
|
|
48
48
|
}).then(response => {}).catch(error => {});
|
|
49
49
|
*/
|
|
50
50
|
const jsonpRquest: typeof jsonpRquestFn;
|
|
51
|
+
/**
|
|
52
|
+
* 异步请求并发处理
|
|
53
|
+
* @param requests 请求列表
|
|
54
|
+
* @param options limit同时处理几个请求默认6个,onUploadProgress进度条
|
|
55
|
+
* @returns
|
|
56
|
+
*/
|
|
57
|
+
function handleRequests<T = any>(requests: (() => Promise<any>)[], options?: {
|
|
58
|
+
limit?: number;
|
|
59
|
+
onUploadProgress?: (opt: {
|
|
60
|
+
total: number;
|
|
61
|
+
loaded: number;
|
|
62
|
+
progress: number;
|
|
63
|
+
}) => void;
|
|
64
|
+
}): Promise<T[]>;
|
|
51
65
|
}
|
|
52
66
|
export default RequestUtil;
|
|
@@ -1,3 +1,118 @@
|
|
|
1
|
+
var __awaiter = this && this.__awaiter || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) {
|
|
3
|
+
return value instanceof P ? value : new P(function (resolve) {
|
|
4
|
+
resolve(value);
|
|
5
|
+
});
|
|
6
|
+
}
|
|
7
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
8
|
+
function fulfilled(value) {
|
|
9
|
+
try {
|
|
10
|
+
step(generator.next(value));
|
|
11
|
+
} catch (e) {
|
|
12
|
+
reject(e);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function rejected(value) {
|
|
16
|
+
try {
|
|
17
|
+
step(generator["throw"](value));
|
|
18
|
+
} catch (e) {
|
|
19
|
+
reject(e);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
function step(result) {
|
|
23
|
+
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
24
|
+
}
|
|
25
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
var __generator = this && this.__generator || function (thisArg, body) {
|
|
29
|
+
var _ = {
|
|
30
|
+
label: 0,
|
|
31
|
+
sent: function sent() {
|
|
32
|
+
if (t[0] & 1) throw t[1];
|
|
33
|
+
return t[1];
|
|
34
|
+
},
|
|
35
|
+
trys: [],
|
|
36
|
+
ops: []
|
|
37
|
+
},
|
|
38
|
+
f,
|
|
39
|
+
y,
|
|
40
|
+
t,
|
|
41
|
+
g;
|
|
42
|
+
return g = {
|
|
43
|
+
next: verb(0),
|
|
44
|
+
"throw": verb(1),
|
|
45
|
+
"return": verb(2)
|
|
46
|
+
}, typeof Symbol === "function" && (g[Symbol.iterator] = function () {
|
|
47
|
+
return this;
|
|
48
|
+
}), g;
|
|
49
|
+
function verb(n) {
|
|
50
|
+
return function (v) {
|
|
51
|
+
return step([n, v]);
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
function step(op) {
|
|
55
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
56
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
57
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
58
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
59
|
+
switch (op[0]) {
|
|
60
|
+
case 0:
|
|
61
|
+
case 1:
|
|
62
|
+
t = op;
|
|
63
|
+
break;
|
|
64
|
+
case 4:
|
|
65
|
+
_.label++;
|
|
66
|
+
return {
|
|
67
|
+
value: op[1],
|
|
68
|
+
done: false
|
|
69
|
+
};
|
|
70
|
+
case 5:
|
|
71
|
+
_.label++;
|
|
72
|
+
y = op[1];
|
|
73
|
+
op = [0];
|
|
74
|
+
continue;
|
|
75
|
+
case 7:
|
|
76
|
+
op = _.ops.pop();
|
|
77
|
+
_.trys.pop();
|
|
78
|
+
continue;
|
|
79
|
+
default:
|
|
80
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
81
|
+
_ = 0;
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
85
|
+
_.label = op[1];
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
88
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
89
|
+
_.label = t[1];
|
|
90
|
+
t = op;
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
93
|
+
if (t && _.label < t[2]) {
|
|
94
|
+
_.label = t[2];
|
|
95
|
+
_.ops.push(op);
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
if (t[2]) _.ops.pop();
|
|
99
|
+
_.trys.pop();
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
op = body.call(thisArg, _);
|
|
103
|
+
} catch (e) {
|
|
104
|
+
op = [6, e];
|
|
105
|
+
y = 0;
|
|
106
|
+
} finally {
|
|
107
|
+
f = t = 0;
|
|
108
|
+
}
|
|
109
|
+
if (op[0] & 5) throw op[1];
|
|
110
|
+
return {
|
|
111
|
+
value: op[0] ? op[1] : void 0,
|
|
112
|
+
done: true
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
};
|
|
1
116
|
/**
|
|
2
117
|
* 请求工具
|
|
3
118
|
* @description
|
|
@@ -49,5 +164,74 @@ var RequestUtil;
|
|
|
49
164
|
}).then(response => {}).catch(error => {});
|
|
50
165
|
*/
|
|
51
166
|
RequestUtil.jsonpRquest = jsonpRquestFn;
|
|
167
|
+
/**
|
|
168
|
+
* 异步请求并发处理
|
|
169
|
+
* @param requests 请求列表
|
|
170
|
+
* @param options limit同时处理几个请求默认6个,onUploadProgress进度条
|
|
171
|
+
* @returns
|
|
172
|
+
*/
|
|
173
|
+
function handleRequests(requests, options) {
|
|
174
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
175
|
+
// 存储所有请求的结果
|
|
176
|
+
// 定义一个递归函数,用于处理请求并控制并发数量
|
|
177
|
+
function processRequest() {
|
|
178
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
179
|
+
var res, result;
|
|
180
|
+
return __generator(this, function (_a) {
|
|
181
|
+
switch (_a.label) {
|
|
182
|
+
case 0:
|
|
183
|
+
if (!(requests.length > 0)) return [3 /*break*/, 3];
|
|
184
|
+
res = requests.shift();
|
|
185
|
+
if (!res) return [2 /*return*/];
|
|
186
|
+
return [4 /*yield*/, res()];
|
|
187
|
+
case 1:
|
|
188
|
+
result = _a.sent();
|
|
189
|
+
// 执行请求并等待其完成
|
|
190
|
+
results.push(result);
|
|
191
|
+
// 将结果存储
|
|
192
|
+
// 递归调用,确保有新的请求补充进去
|
|
193
|
+
return [4 /*yield*/, processRequest()];
|
|
194
|
+
case 2:
|
|
195
|
+
// 将结果存储
|
|
196
|
+
// 递归调用,确保有新的请求补充进去
|
|
197
|
+
_a.sent();
|
|
198
|
+
loaded += 1;
|
|
199
|
+
onUploadProgress === null || onUploadProgress === void 0 ? void 0 : onUploadProgress({
|
|
200
|
+
total: resLength,
|
|
201
|
+
loaded: loaded,
|
|
202
|
+
progress: loaded / resLength
|
|
203
|
+
});
|
|
204
|
+
_a.label = 3;
|
|
205
|
+
case 3:
|
|
206
|
+
return [2 /*return*/];
|
|
207
|
+
}
|
|
208
|
+
});
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
var _a, _b, limit, onUploadProgress, resLength, results, loaded, concurrent;
|
|
212
|
+
return __generator(this, function (_c) {
|
|
213
|
+
switch (_c.label) {
|
|
214
|
+
case 0:
|
|
215
|
+
_a = options !== null && options !== void 0 ? options : {}, _b = _a.limit, limit = _b === void 0 ? 6 : _b, onUploadProgress = _a.onUploadProgress;
|
|
216
|
+
resLength = requests.length;
|
|
217
|
+
results = [];
|
|
218
|
+
loaded = 0;
|
|
219
|
+
concurrent = Array.from({
|
|
220
|
+
length: Math.min(limit, resLength)
|
|
221
|
+
}, function () {
|
|
222
|
+
return processRequest();
|
|
223
|
+
});
|
|
224
|
+
// 等待所有并发的请求完成
|
|
225
|
+
return [4 /*yield*/, Promise.all(concurrent)];
|
|
226
|
+
case 1:
|
|
227
|
+
// 等待所有并发的请求完成
|
|
228
|
+
_c.sent();
|
|
229
|
+
return [2 /*return*/, results];
|
|
230
|
+
// 返回所有请求的结果
|
|
231
|
+
}
|
|
232
|
+
});
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
RequestUtil.handleRequests = handleRequests;
|
|
52
236
|
})(RequestUtil || (RequestUtil = {}));
|
|
53
237
|
export default RequestUtil;
|
|
@@ -388,5 +388,11 @@ declare namespace StringUtil {
|
|
|
388
388
|
* @param index 默认随机
|
|
389
389
|
*/
|
|
390
390
|
const getColor: (index?: number) => string;
|
|
391
|
+
/**
|
|
392
|
+
* fnv1a算法获取字符串hash
|
|
393
|
+
* @param str
|
|
394
|
+
* @returns
|
|
395
|
+
*/
|
|
396
|
+
function getHash(str: string): number;
|
|
391
397
|
}
|
|
392
398
|
export default StringUtil;
|