qmwts 1.1.78 → 1.1.80
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/utils/array-utils.d.ts +1 -1
- package/dist/utils/array-utils.js +22 -10
- package/dist/utils/axios-instance.js +12 -3
- package/dist/utils/downloader.js +31 -20
- package/package.json +1 -1
|
@@ -30,7 +30,7 @@ declare const _default: {
|
|
|
30
30
|
* @param override 遇到重复元素是否覆盖
|
|
31
31
|
*/
|
|
32
32
|
uniqueByKey<T, K = unknown>(array: T[] | undefined, value: (item: T) => K, override?: boolean): T[];
|
|
33
|
-
sort<T>(array: T[], order: "asc" | "desc", ...values: ((item: T) =>
|
|
33
|
+
sort<T>(array: T[], order: "asc" | "desc", ...values: ((item: T) => any)[]): void;
|
|
34
34
|
mergeByKey<T extends object>(keyExtractor: (item: T) => string | number | symbol, ...arrays: T[][]): T[];
|
|
35
35
|
};
|
|
36
36
|
export default _default;
|
|
@@ -10,6 +10,7 @@ exports.default = {
|
|
|
10
10
|
* @param childrenKey 下级字段
|
|
11
11
|
*/
|
|
12
12
|
treeify(array = [], idKey = 'id', parentKey = 'parentId', childrenKey = 'children') {
|
|
13
|
+
var _a;
|
|
13
14
|
const map = new Map(); // 先根据每项的parentId将该项放入Map
|
|
14
15
|
const ids = []; // 记录所有的id,parentId不在这个集合内则说明是最上级
|
|
15
16
|
const length = array.length;
|
|
@@ -18,7 +19,7 @@ exports.default = {
|
|
|
18
19
|
if (e == null)
|
|
19
20
|
continue;
|
|
20
21
|
const id = e[idKey], pid = e[parentKey];
|
|
21
|
-
const children = map.get(pid)
|
|
22
|
+
const children = (_a = map.get(pid)) !== null && _a !== void 0 ? _a : [];
|
|
22
23
|
children.push(e);
|
|
23
24
|
map.set(pid, children);
|
|
24
25
|
ids.push(id);
|
|
@@ -91,7 +92,7 @@ exports.default = {
|
|
|
91
92
|
* @param override 遇到重复元素是否覆盖
|
|
92
93
|
*/
|
|
93
94
|
uniqueByKey(array = [], value, override = false) {
|
|
94
|
-
array = array
|
|
95
|
+
array = array !== null && array !== void 0 ? array : [];
|
|
95
96
|
const map = new Map();
|
|
96
97
|
for (let i = 0; i < array.length; i++) {
|
|
97
98
|
const e = array[i];
|
|
@@ -111,30 +112,41 @@ exports.default = {
|
|
|
111
112
|
for (const fn of values) {
|
|
112
113
|
const valueA = fn(a);
|
|
113
114
|
const valueB = fn(b);
|
|
115
|
+
if (typeof valueA === 'string' && typeof valueB === 'string')
|
|
116
|
+
return valueA.localeCompare(valueB) * multiplier;
|
|
114
117
|
if (valueA - valueB !== 0)
|
|
115
118
|
return (valueA - valueB) * multiplier;
|
|
116
119
|
}
|
|
117
120
|
return 0;
|
|
118
121
|
});
|
|
119
122
|
},
|
|
120
|
-
mergeByKey(keyExtractor,
|
|
123
|
+
mergeByKey(keyExtractor, // 限定key类型,避免非可哈希值
|
|
124
|
+
...arrays) {
|
|
121
125
|
// 1. 空值防御:过滤空数组,避免无效遍历
|
|
122
126
|
const validArrays = arrays.filter(arr => Array.isArray(arr) && arr.length > 0);
|
|
123
127
|
if (validArrays.length === 0)
|
|
124
128
|
return [];
|
|
125
129
|
const mergeMap = new Map();
|
|
126
|
-
|
|
127
|
-
|
|
130
|
+
// 2. 扁平化数组并遍历(仅处理有效数组,提升性能)
|
|
131
|
+
const arr = validArrays.flat();
|
|
132
|
+
for (let i = 0; i < arr.length; i++) {
|
|
133
|
+
const item = arr[i];
|
|
134
|
+
// 3. 空项防御:跳过undefined/null项
|
|
135
|
+
if (!item)
|
|
128
136
|
continue;
|
|
129
|
-
const key = keyExtractor(
|
|
130
|
-
const
|
|
131
|
-
if (
|
|
132
|
-
|
|
137
|
+
const key = keyExtractor(item);
|
|
138
|
+
const existingItem = mergeMap.get(key);
|
|
139
|
+
if (existingItem) {
|
|
140
|
+
// 4. 深度合并:保留先插入的值(existingItem在前,item在后不覆盖)
|
|
141
|
+
// 使用lodash的merge,保证深度合并;空对象作为目标,避免修改原对象
|
|
142
|
+
mergeMap.set(key, (0, lodash_es_1.merge)({}, existingItem, item)); // 元素在后的覆盖前面的
|
|
133
143
|
}
|
|
134
144
|
else {
|
|
135
|
-
|
|
145
|
+
// 5. 首次插入:浅拷贝原对象,避免外部修改影响map内数据
|
|
146
|
+
mergeMap.set(key, Object.assign({}, item));
|
|
136
147
|
}
|
|
137
148
|
}
|
|
149
|
+
// 6. 转换为数组返回
|
|
138
150
|
return Array.from(mergeMap.values());
|
|
139
151
|
}
|
|
140
152
|
};
|
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
2
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
12
|
const axios_1 = require("axios");
|
|
4
13
|
const param_builder_1 = require("./param-builder");
|
|
@@ -16,7 +25,7 @@ instance.interceptors.request.use(request => {
|
|
|
16
25
|
}, error => {
|
|
17
26
|
return Promise.reject(error);
|
|
18
27
|
});
|
|
19
|
-
instance.interceptors.response.use(
|
|
28
|
+
instance.interceptors.response.use((response) => __awaiter(void 0, void 0, void 0, function* () {
|
|
20
29
|
if (response.config.responseType === 'blob') {
|
|
21
30
|
const { data } = response;
|
|
22
31
|
if (data.type === 'application/x-download') { // 不是json说明下载成功
|
|
@@ -31,11 +40,11 @@ instance.interceptors.response.use(async (response) => {
|
|
|
31
40
|
return Promise.resolve(response);
|
|
32
41
|
}
|
|
33
42
|
else if (data.type === 'application/json') { // 是json说明有报错
|
|
34
|
-
response.data =
|
|
43
|
+
response.data = yield new Response(data).json();
|
|
35
44
|
}
|
|
36
45
|
}
|
|
37
46
|
return response;
|
|
38
|
-
}, error => {
|
|
47
|
+
}), error => {
|
|
39
48
|
return Promise.reject(error);
|
|
40
49
|
});
|
|
41
50
|
exports.default = instance;
|
package/dist/utils/downloader.js
CHANGED
|
@@ -1,28 +1,39 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
2
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
12
|
const JSZip = require("jszip");
|
|
4
13
|
const file_utils_1 = require("./file-utils");
|
|
5
14
|
exports.default = {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
15
|
+
zip(urls) {
|
|
16
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
17
|
+
const { fetch, URL } = window;
|
|
18
|
+
if (!fetch) {
|
|
19
|
+
alert('您的浏览器不支持fetch');
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
urls = [urls].flat(Infinity);
|
|
23
|
+
const zip = new JSZip();
|
|
24
|
+
let index = 1;
|
|
25
|
+
for (const url of urls) {
|
|
26
|
+
const response = yield fetch(url);
|
|
27
|
+
const blob = yield response.blob();
|
|
28
|
+
zip.file([index++, file_utils_1.default.fileType(url)].filter(e => !!e).join('.'), blob);
|
|
29
|
+
}
|
|
30
|
+
zip.generateAsync({ type: 'blob' }).then(blob => {
|
|
31
|
+
const a = document.createElement('a');
|
|
32
|
+
a.href = URL.createObjectURL(blob);
|
|
33
|
+
a.click();
|
|
34
|
+
URL.revokeObjectURL(a.href);
|
|
35
|
+
a.remove();
|
|
36
|
+
});
|
|
26
37
|
});
|
|
27
38
|
}
|
|
28
39
|
};
|