qmwts 1.1.78 → 1.1.79

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.
@@ -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];
@@ -117,24 +118,33 @@ exports.default = {
117
118
  return 0;
118
119
  });
119
120
  },
120
- mergeByKey(keyExtractor, ...arrays) {
121
+ mergeByKey(keyExtractor, // 限定key类型,避免非可哈希值
122
+ ...arrays) {
121
123
  // 1. 空值防御:过滤空数组,避免无效遍历
122
124
  const validArrays = arrays.filter(arr => Array.isArray(arr) && arr.length > 0);
123
125
  if (validArrays.length === 0)
124
126
  return [];
125
127
  const mergeMap = new Map();
126
- for (let e of validArrays.flat()) {
127
- if (!e)
128
+ // 2. 扁平化数组并遍历(仅处理有效数组,提升性能)
129
+ const arr = validArrays.flat();
130
+ for (let i = 0; i < arr.length; i++) {
131
+ const item = arr[i];
132
+ // 3. 空项防御:跳过undefined/null项
133
+ if (!item)
128
134
  continue;
129
- const key = keyExtractor(e);
130
- const v = mergeMap.get(key);
131
- if (v) {
132
- mergeMap.set(key, (0, lodash_es_1.merge)({}, e, v)); // v放在后面,即保留先插入的值
135
+ const key = keyExtractor(item);
136
+ const existingItem = mergeMap.get(key);
137
+ if (existingItem) {
138
+ // 4. 深度合并:保留先插入的值(existingItem在前,item在后不覆盖)
139
+ // 使用lodash的merge,保证深度合并;空对象作为目标,避免修改原对象
140
+ mergeMap.set(key, (0, lodash_es_1.merge)({}, existingItem, item)); // 元素在后的覆盖前面的
133
141
  }
134
142
  else {
135
- mergeMap.set(key, { ...e });
143
+ // 5. 首次插入:浅拷贝原对象,避免外部修改影响map内数据
144
+ mergeMap.set(key, Object.assign({}, item));
136
145
  }
137
146
  }
147
+ // 6. 转换为数组返回
138
148
  return Array.from(mergeMap.values());
139
149
  }
140
150
  };
@@ -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(async (response) => {
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 = await new Response(data).json();
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;
@@ -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
- async zip(urls) {
7
- const { fetch, URL } = window;
8
- if (!fetch) {
9
- alert('您的浏览器不支持fetch');
10
- return;
11
- }
12
- urls = [urls].flat(Infinity);
13
- const zip = new JSZip();
14
- let index = 1;
15
- for (const url of urls) {
16
- const response = await fetch(url);
17
- const blob = await response.blob();
18
- zip.file([index++, file_utils_1.default.fileType(url)].filter(e => !!e).join('.'), blob);
19
- }
20
- zip.generateAsync({ type: 'blob' }).then(blob => {
21
- const a = document.createElement('a');
22
- a.href = URL.createObjectURL(blob);
23
- a.click();
24
- URL.revokeObjectURL(a.href);
25
- a.remove();
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
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "qmwts",
3
- "version": "1.1.78",
3
+ "version": "1.1.79",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",