tools-min-ns 1.5.2
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 +85 -0
- package/esm/array/ArrayUtil.d.ts +109 -0
- package/esm/array/ArrayUtil.js +242 -0
- package/esm/array/TreeUtil.d.ts +151 -0
- package/esm/array/TreeUtil.js +412 -0
- package/esm/base/BaseUtil.d.ts +91 -0
- package/esm/base/BaseUtil.js +148 -0
- package/esm/browser/BrowserUtil.d.ts +57 -0
- package/esm/browser/BrowserUtil.js +337 -0
- package/esm/browser/fingerprint.d.ts +120 -0
- package/esm/browser/fingerprint.js +1469 -0
- package/esm/check/CheckUtil.d.ts +110 -0
- package/esm/check/CheckUtil.js +465 -0
- package/esm/common.d.ts +43 -0
- package/esm/common.js +44 -0
- package/esm/config.d.ts +7 -0
- package/esm/config.js +7 -0
- package/esm/cookie/CookieUtil.d.ts +56 -0
- package/esm/cookie/CookieUtil.js +12 -0
- package/esm/cookie/cookie.d.ts +2 -0
- package/esm/cookie/cookie.js +104 -0
- package/esm/date/DateUtil.d.ts +261 -0
- package/esm/date/DateUtil.js +763 -0
- package/esm/env/EnvUtil.d.ts +27 -0
- package/esm/env/EnvUtil.js +29 -0
- package/esm/env/env.d.ts +41 -0
- package/esm/env/env.js +106 -0
- package/esm/func/FunctionUtil.d.ts +77 -0
- package/esm/func/FunctionUtil.js +215 -0
- package/esm/index.d.ts +19 -0
- package/esm/index.js +19 -0
- package/esm/number/NumberUtil.d.ts +96 -0
- package/esm/number/NumberUtil.js +256 -0
- package/esm/object/ObjectUtil.d.ts +41 -0
- package/esm/object/ObjectUtil.js +158 -0
- package/esm/pwd/PasswordUtil.d.ts +33 -0
- package/esm/pwd/PasswordUtil.js +68 -0
- package/esm/pwd/crypto.d.ts +6 -0
- package/esm/pwd/crypto.js +1824 -0
- package/esm/request/RequestUtil.d.ts +52 -0
- package/esm/request/RequestUtil.js +53 -0
- package/esm/request/jsonp.d.ts +18 -0
- package/esm/request/jsonp.js +73 -0
- package/esm/request/mgop/env.d.ts +7 -0
- package/esm/request/mgop/env.js +15 -0
- package/esm/request/mgop/index.d.ts +3 -0
- package/esm/request/mgop/index.js +276 -0
- package/esm/request/mgop/responseCode.d.ts +20 -0
- package/esm/request/mgop/responseCode.js +37 -0
- package/esm/request/mgop/type.d.ts +34 -0
- package/esm/request/mgop/type.js +1 -0
- package/esm/request/uniRquest/index.d.ts +2 -0
- package/esm/request/uniRquest/index.js +66 -0
- package/esm/request/uniRquest/miniapp/index.d.ts +2 -0
- package/esm/request/uniRquest/miniapp/index.js +29 -0
- package/esm/request/uniRquest/miniapp-bytedance/index.d.ts +2 -0
- package/esm/request/uniRquest/miniapp-bytedance/index.js +41 -0
- package/esm/request/uniRquest/types.d.ts +65 -0
- package/esm/request/uniRquest/types.js +36 -0
- package/esm/request/uniRquest/utils.d.ts +9 -0
- package/esm/request/uniRquest/utils.js +69 -0
- package/esm/request/uniRquest/web/index.d.ts +2 -0
- package/esm/request/uniRquest/web/index.js +85 -0
- package/esm/request/uniRquest/wechat-miniprogram/index.d.ts +2 -0
- package/esm/request/uniRquest/wechat-miniprogram/index.js +41 -0
- package/esm/request/uniRquest/weex/index.d.ts +14 -0
- package/esm/request/uniRquest/weex/index.js +59 -0
- package/esm/storage/StorageUtil.d.ts +19 -0
- package/esm/storage/StorageUtil.js +75 -0
- package/esm/string/StringUtil.d.ts +392 -0
- package/esm/string/StringUtil.js +556 -0
- package/esm/system/SystemUtil.d.ts +46 -0
- package/esm/system/SystemUtil.js +122 -0
- package/esm/transfer/MapTransferUtil.d.ts +54 -0
- package/esm/transfer/MapTransferUtil.js +160 -0
- package/esm/transfer/TransferUtil.d.ts +98 -0
- package/esm/transfer/TransferUtil.js +323 -0
- package/esm/types.d.ts +25 -0
- package/esm/types.js +1 -0
- package/esm/url/UrlUtil.d.ts +30 -0
- package/esm/url/UrlUtil.js +85 -0
- package/lib/array/ArrayUtil.d.ts +109 -0
- package/lib/array/ArrayUtil.js +252 -0
- package/lib/array/TreeUtil.d.ts +151 -0
- package/lib/array/TreeUtil.js +422 -0
- package/lib/base/BaseUtil.d.ts +91 -0
- package/lib/base/BaseUtil.js +153 -0
- package/lib/browser/BrowserUtil.d.ts +57 -0
- package/lib/browser/BrowserUtil.js +347 -0
- package/lib/browser/fingerprint.d.ts +120 -0
- package/lib/browser/fingerprint.js +1500 -0
- package/lib/check/CheckUtil.d.ts +110 -0
- package/lib/check/CheckUtil.js +475 -0
- package/lib/common.d.ts +43 -0
- package/lib/common.js +50 -0
- package/lib/config.d.ts +7 -0
- package/lib/config.js +12 -0
- package/lib/cookie/CookieUtil.d.ts +56 -0
- package/lib/cookie/CookieUtil.js +22 -0
- package/lib/cookie/cookie.d.ts +2 -0
- package/lib/cookie/cookie.js +109 -0
- package/lib/date/DateUtil.d.ts +261 -0
- package/lib/date/DateUtil.js +773 -0
- package/lib/env/EnvUtil.d.ts +27 -0
- package/lib/env/EnvUtil.js +39 -0
- package/lib/env/env.d.ts +41 -0
- package/lib/env/env.js +112 -0
- package/lib/func/FunctionUtil.d.ts +77 -0
- package/lib/func/FunctionUtil.js +225 -0
- package/lib/index.d.ts +19 -0
- package/lib/index.js +144 -0
- package/lib/number/NumberUtil.d.ts +96 -0
- package/lib/number/NumberUtil.js +266 -0
- package/lib/object/ObjectUtil.d.ts +41 -0
- package/lib/object/ObjectUtil.js +168 -0
- package/lib/pwd/PasswordUtil.d.ts +33 -0
- package/lib/pwd/PasswordUtil.js +78 -0
- package/lib/pwd/crypto.d.ts +6 -0
- package/lib/pwd/crypto.js +1829 -0
- package/lib/request/RequestUtil.d.ts +52 -0
- package/lib/request/RequestUtil.js +94 -0
- package/lib/request/jsonp.d.ts +18 -0
- package/lib/request/jsonp.js +80 -0
- package/lib/request/mgop/env.d.ts +7 -0
- package/lib/request/mgop/env.js +21 -0
- package/lib/request/mgop/index.d.ts +3 -0
- package/lib/request/mgop/index.js +289 -0
- package/lib/request/mgop/responseCode.d.ts +20 -0
- package/lib/request/mgop/responseCode.js +42 -0
- package/lib/request/mgop/type.d.ts +34 -0
- package/lib/request/mgop/type.js +5 -0
- package/lib/request/uniRquest/index.d.ts +2 -0
- package/lib/request/uniRquest/index.js +77 -0
- package/lib/request/uniRquest/miniapp/index.d.ts +2 -0
- package/lib/request/uniRquest/miniapp/index.js +35 -0
- package/lib/request/uniRquest/miniapp-bytedance/index.d.ts +2 -0
- package/lib/request/uniRquest/miniapp-bytedance/index.js +47 -0
- package/lib/request/uniRquest/types.d.ts +65 -0
- package/lib/request/uniRquest/types.js +42 -0
- package/lib/request/uniRquest/utils.d.ts +9 -0
- package/lib/request/uniRquest/utils.js +83 -0
- package/lib/request/uniRquest/web/index.d.ts +2 -0
- package/lib/request/uniRquest/web/index.js +91 -0
- package/lib/request/uniRquest/wechat-miniprogram/index.d.ts +2 -0
- package/lib/request/uniRquest/wechat-miniprogram/index.js +47 -0
- package/lib/request/uniRquest/weex/index.d.ts +14 -0
- package/lib/request/uniRquest/weex/index.js +65 -0
- package/lib/storage/StorageUtil.d.ts +19 -0
- package/lib/storage/StorageUtil.js +85 -0
- package/lib/string/StringUtil.d.ts +392 -0
- package/lib/string/StringUtil.js +566 -0
- package/lib/system/SystemUtil.d.ts +46 -0
- package/lib/system/SystemUtil.js +132 -0
- package/lib/transfer/MapTransferUtil.d.ts +54 -0
- package/lib/transfer/MapTransferUtil.js +165 -0
- package/lib/transfer/TransferUtil.d.ts +98 -0
- package/lib/transfer/TransferUtil.js +333 -0
- package/lib/types.d.ts +25 -0
- package/lib/types.js +5 -0
- package/lib/url/UrlUtil.d.ts +30 -0
- package/lib/url/UrlUtil.js +95 -0
- package/package.json +56 -0
|
@@ -0,0 +1,412 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 树工具
|
|
3
|
+
* @description
|
|
4
|
+
* @author nanshen
|
|
5
|
+
* @creat 2021-09-15 10:31:35
|
|
6
|
+
*/
|
|
7
|
+
var __read = this && this.__read || function (o, n) {
|
|
8
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
9
|
+
if (!m) return o;
|
|
10
|
+
var i = m.call(o),
|
|
11
|
+
r,
|
|
12
|
+
ar = [],
|
|
13
|
+
e;
|
|
14
|
+
try {
|
|
15
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
16
|
+
} catch (error) {
|
|
17
|
+
e = {
|
|
18
|
+
error: error
|
|
19
|
+
};
|
|
20
|
+
} finally {
|
|
21
|
+
try {
|
|
22
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
23
|
+
} finally {
|
|
24
|
+
if (e) throw e.error;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return ar;
|
|
28
|
+
};
|
|
29
|
+
var __spreadArray = this && this.__spreadArray || function (to, from, pack) {
|
|
30
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
31
|
+
if (ar || !(i in from)) {
|
|
32
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
33
|
+
ar[i] = from[i];
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
37
|
+
};
|
|
38
|
+
import BaseUtil from '../base/BaseUtil';
|
|
39
|
+
var isEmpty = BaseUtil.isEmpty;
|
|
40
|
+
var TreeUtil;
|
|
41
|
+
(function (TreeUtil) {
|
|
42
|
+
/**
|
|
43
|
+
* @name 循环树改变原数组
|
|
44
|
+
* @param tree tree数组
|
|
45
|
+
* @param callback 回调(item:当前循环项,parent: 父对象)
|
|
46
|
+
* @param children children字段
|
|
47
|
+
* @param defaultParent 默认上级对象
|
|
48
|
+
*
|
|
49
|
+
*/
|
|
50
|
+
function forEachTree(tree, callback, children, defaultParent) {
|
|
51
|
+
if (children === void 0) {
|
|
52
|
+
children = 'children';
|
|
53
|
+
}
|
|
54
|
+
tree === null || tree === void 0 ? void 0 : tree.forEach(function (item) {
|
|
55
|
+
callback(item, defaultParent);
|
|
56
|
+
forEachTree(item[children], callback, children, item);
|
|
57
|
+
});
|
|
58
|
+
return tree;
|
|
59
|
+
}
|
|
60
|
+
TreeUtil.forEachTree = forEachTree;
|
|
61
|
+
/**
|
|
62
|
+
* @name 查找树
|
|
63
|
+
* @param tree tree数组
|
|
64
|
+
* @param callback 回调(item:当前循环项,parent: 父对象)
|
|
65
|
+
* @param children children字段
|
|
66
|
+
* @param defaultParent 默认上级对象
|
|
67
|
+
*/
|
|
68
|
+
function findTreeData(tree, callback, children, defaultParent) {
|
|
69
|
+
if (children === void 0) {
|
|
70
|
+
children = 'children';
|
|
71
|
+
}
|
|
72
|
+
for (var index = 0; index < ((tree === null || tree === void 0 ? void 0 : tree.length) || 0); index++) {
|
|
73
|
+
var item = tree[index];
|
|
74
|
+
var back = callback(item, defaultParent);
|
|
75
|
+
if (back) return item;
|
|
76
|
+
var isOk = findTreeData(item[children], callback, children, item);
|
|
77
|
+
if (isOk) return isOk;
|
|
78
|
+
}
|
|
79
|
+
return undefined;
|
|
80
|
+
}
|
|
81
|
+
TreeUtil.findTreeData = findTreeData;
|
|
82
|
+
/**
|
|
83
|
+
* @name 筛选树
|
|
84
|
+
* @param tree tree数组
|
|
85
|
+
* @param callback 回调(item:当前循环项,parent: 父对象)
|
|
86
|
+
* @param children children字段
|
|
87
|
+
* @param defaultParent 默认上级对象
|
|
88
|
+
*/
|
|
89
|
+
function filterTreeData(tree, callback, children, defaultParent) {
|
|
90
|
+
if (children === void 0) {
|
|
91
|
+
children = 'children';
|
|
92
|
+
}
|
|
93
|
+
var list = [];
|
|
94
|
+
var fn = function fn(a, c, d) {
|
|
95
|
+
for (var index = 0; index < ((a === null || a === void 0 ? void 0 : a.length) || 0); index++) {
|
|
96
|
+
var item = a[index];
|
|
97
|
+
var back = c(item, d);
|
|
98
|
+
if (back) {
|
|
99
|
+
list.push(item);
|
|
100
|
+
}
|
|
101
|
+
fn(item[children], c, item);
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
fn(tree, callback, defaultParent);
|
|
105
|
+
return list;
|
|
106
|
+
}
|
|
107
|
+
TreeUtil.filterTreeData = filterTreeData;
|
|
108
|
+
/**
|
|
109
|
+
* @name 列表转树
|
|
110
|
+
* @param list 数组
|
|
111
|
+
* @param fieldNames 映射对象
|
|
112
|
+
*/
|
|
113
|
+
function getTreeByList(list, fieldNames) {
|
|
114
|
+
var _a = fieldNames || {},
|
|
115
|
+
_b = _a.label,
|
|
116
|
+
label = _b === void 0 ? 'name' : _b,
|
|
117
|
+
_c = _a.value,
|
|
118
|
+
value = _c === void 0 ? 'id' : _c,
|
|
119
|
+
_d = _a.parent,
|
|
120
|
+
parent = _d === void 0 ? 'pid' : _d,
|
|
121
|
+
_e = _a.children,
|
|
122
|
+
children = _e === void 0 ? 'children' : _e,
|
|
123
|
+
rootPid = _a.rootPid;
|
|
124
|
+
if (!(list === null || list === void 0 ? void 0 : list.length)) return [];
|
|
125
|
+
var inList = JSON.parse(JSON.stringify(list));
|
|
126
|
+
var menuObj = {};
|
|
127
|
+
inList.forEach(function (item) {
|
|
128
|
+
item.key = String(item[value]);
|
|
129
|
+
item.title = item[label];
|
|
130
|
+
item[children] = [];
|
|
131
|
+
item.parent = [];
|
|
132
|
+
menuObj[item[value]] = item;
|
|
133
|
+
});
|
|
134
|
+
inList.forEach(function (item) {
|
|
135
|
+
var _a, _b;
|
|
136
|
+
var childList = (_a = menuObj === null || menuObj === void 0 ? void 0 : menuObj[item === null || item === void 0 ? void 0 : item[parent]]) === null || _a === void 0 ? void 0 : _a[children];
|
|
137
|
+
if (childList) childList.push(item);
|
|
138
|
+
var parentData = menuObj === null || menuObj === void 0 ? void 0 : menuObj[item === null || item === void 0 ? void 0 : item[parent]];
|
|
139
|
+
if (parentData) (_b = item === null || item === void 0 ? void 0 : item.parent) === null || _b === void 0 ? void 0 : _b.push(parentData);
|
|
140
|
+
});
|
|
141
|
+
var rootIds = inList.filter(function (item) {
|
|
142
|
+
var _a;
|
|
143
|
+
return ((_a = item === null || item === void 0 ? void 0 : item.parent) === null || _a === void 0 ? void 0 : _a.length) === 0;
|
|
144
|
+
}).map(function (e) {
|
|
145
|
+
return e[value];
|
|
146
|
+
});
|
|
147
|
+
var l = forEachTree(inList.filter(function (item) {
|
|
148
|
+
var id = item[value];
|
|
149
|
+
if (rootPid === undefined) {
|
|
150
|
+
return rootIds.includes(id);
|
|
151
|
+
}
|
|
152
|
+
return String(id) === String(rootPid);
|
|
153
|
+
}), function (e) {
|
|
154
|
+
var _a;
|
|
155
|
+
delete e.parent;
|
|
156
|
+
if (!((_a = e[children]) === null || _a === void 0 ? void 0 : _a.length)) delete e[children];
|
|
157
|
+
}, children);
|
|
158
|
+
return l;
|
|
159
|
+
}
|
|
160
|
+
TreeUtil.getTreeByList = getTreeByList;
|
|
161
|
+
/**
|
|
162
|
+
* @name 树转列表
|
|
163
|
+
* @param tree 数组
|
|
164
|
+
*/
|
|
165
|
+
function getListByTree(tree, children) {
|
|
166
|
+
var _a;
|
|
167
|
+
if (children === void 0) {
|
|
168
|
+
children = 'children';
|
|
169
|
+
}
|
|
170
|
+
var newList = (_a = {}, _a[children] = tree, _a);
|
|
171
|
+
return treeData2List(newList, children);
|
|
172
|
+
}
|
|
173
|
+
TreeUtil.getListByTree = getListByTree;
|
|
174
|
+
/**
|
|
175
|
+
* @name 获取树中id路径数组
|
|
176
|
+
* @param tree 树
|
|
177
|
+
* @param id 主键
|
|
178
|
+
* @param fieldNames 映射对象
|
|
179
|
+
*/
|
|
180
|
+
function getIdPathByTree(tree, id, fieldNames) {
|
|
181
|
+
var _a = fieldNames !== null && fieldNames !== void 0 ? fieldNames : {},
|
|
182
|
+
_b = _a.value,
|
|
183
|
+
value = _b === void 0 ? 'id' : _b,
|
|
184
|
+
_c = _a.parent,
|
|
185
|
+
parent = _c === void 0 ? 'pid' : _c,
|
|
186
|
+
_d = _a.children,
|
|
187
|
+
children = _d === void 0 ? 'children' : _d,
|
|
188
|
+
_e = _a.rootPid,
|
|
189
|
+
rootPid = _e === void 0 ? undefined : _e;
|
|
190
|
+
if (BaseUtil.isEmpty(id)) return [];
|
|
191
|
+
var idList = [id];
|
|
192
|
+
var list = getListByTree(tree);
|
|
193
|
+
var getList = function getList(importOid) {
|
|
194
|
+
forEachTree(tree, function (info) {
|
|
195
|
+
if (String(info[value]) === String(importOid)) {
|
|
196
|
+
if (parent in info && info[parent] && list.some(function (e) {
|
|
197
|
+
return String(e[value]) === String(info[parent]);
|
|
198
|
+
})) {
|
|
199
|
+
idList.unshift(info === null || info === void 0 ? void 0 : info[parent]);
|
|
200
|
+
getList(info === null || info === void 0 ? void 0 : info[parent]);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}, children);
|
|
204
|
+
};
|
|
205
|
+
getList(id);
|
|
206
|
+
if (!BaseUtil.isEmpty(rootPid)) {
|
|
207
|
+
var idx = idList.findIndex(function (item) {
|
|
208
|
+
return String(item) === String(rootPid);
|
|
209
|
+
});
|
|
210
|
+
return idx === -1 ? idList : idList.slice(idx);
|
|
211
|
+
}
|
|
212
|
+
return idList;
|
|
213
|
+
}
|
|
214
|
+
TreeUtil.getIdPathByTree = getIdPathByTree;
|
|
215
|
+
/**
|
|
216
|
+
* @name 字符串分割转为树结构
|
|
217
|
+
* @param str string
|
|
218
|
+
* @param splitStr /
|
|
219
|
+
* @param fieldNames 映射对象
|
|
220
|
+
* @example
|
|
221
|
+
*
|
|
222
|
+
* `一级选项 1/二级选项 1/三级选项 1
|
|
223
|
+
一级选项 1/二级选项 1/三级选项 2
|
|
224
|
+
一级选项 2/二级选项 1`
|
|
225
|
+
//转换后
|
|
226
|
+
[
|
|
227
|
+
{
|
|
228
|
+
name: '一级选项 1',
|
|
229
|
+
id: '一级选项 1',
|
|
230
|
+
children: [
|
|
231
|
+
{
|
|
232
|
+
name: '二级选项 1',
|
|
233
|
+
id: '二级选项 1',
|
|
234
|
+
pid: '一级选项 1',
|
|
235
|
+
children: [
|
|
236
|
+
{
|
|
237
|
+
name: '三级选项 1',
|
|
238
|
+
id: '三级选项 1',
|
|
239
|
+
pid: '二级选项 1',
|
|
240
|
+
},
|
|
241
|
+
{
|
|
242
|
+
name: '三级选项 2',
|
|
243
|
+
id: '三级选项 2',
|
|
244
|
+
pid: '二级选项 1',
|
|
245
|
+
},
|
|
246
|
+
],
|
|
247
|
+
},
|
|
248
|
+
],
|
|
249
|
+
},
|
|
250
|
+
{
|
|
251
|
+
name: '一级选项 2',
|
|
252
|
+
id: '一级选项 2',
|
|
253
|
+
children: [
|
|
254
|
+
{
|
|
255
|
+
name: '二级选项 1',
|
|
256
|
+
id: '二级选项 1',
|
|
257
|
+
pid: '一级选项 2',
|
|
258
|
+
},
|
|
259
|
+
],
|
|
260
|
+
},
|
|
261
|
+
]
|
|
262
|
+
*/
|
|
263
|
+
function strSplit2tree(str, splitStr, fieldNames) {
|
|
264
|
+
if (splitStr === void 0) {
|
|
265
|
+
splitStr = '/';
|
|
266
|
+
}
|
|
267
|
+
var _a = fieldNames !== null && fieldNames !== void 0 ? fieldNames : {},
|
|
268
|
+
_b = _a.label,
|
|
269
|
+
label = _b === void 0 ? 'name' : _b,
|
|
270
|
+
_c = _a.value,
|
|
271
|
+
value = _c === void 0 ? 'id' : _c,
|
|
272
|
+
_d = _a.parent,
|
|
273
|
+
parent = _d === void 0 ? 'pid' : _d,
|
|
274
|
+
_e = _a.children,
|
|
275
|
+
children = _e === void 0 ? 'children' : _e;
|
|
276
|
+
var menuObj = {};
|
|
277
|
+
var arr = [];
|
|
278
|
+
__spreadArray([], __read(new Set(str.split('\n'))), false).forEach(function (text) {
|
|
279
|
+
var itemArr = text.split(splitStr).map(function (e) {
|
|
280
|
+
return e.trim();
|
|
281
|
+
}).filter(function (e) {
|
|
282
|
+
return e;
|
|
283
|
+
});
|
|
284
|
+
arr.push.apply(arr, __spreadArray([], __read(itemArr.map(function (e, i) {
|
|
285
|
+
var _a;
|
|
286
|
+
return _a = {}, _a[label] = e, _a[value] = e, _a[parent] = itemArr[i - 1], _a._id = String(itemArr.slice(0, i + 1)), _a._pid = String(itemArr.slice(0, i)), _a;
|
|
287
|
+
})), false));
|
|
288
|
+
});
|
|
289
|
+
arr = __spreadArray([], __read(new Set(arr.map(function (e) {
|
|
290
|
+
return JSON.stringify(e);
|
|
291
|
+
}))), false).map(function (e) {
|
|
292
|
+
return JSON.parse(e);
|
|
293
|
+
});
|
|
294
|
+
arr.forEach(function (item) {
|
|
295
|
+
item[children] = [];
|
|
296
|
+
menuObj[item._id] = item;
|
|
297
|
+
});
|
|
298
|
+
arr = arr.filter(function (item) {
|
|
299
|
+
var _a;
|
|
300
|
+
var childList = (_a = menuObj[item === null || item === void 0 ? void 0 : item._pid]) === null || _a === void 0 ? void 0 : _a[children];
|
|
301
|
+
if (childList) childList.push(item);
|
|
302
|
+
return !(parent in item);
|
|
303
|
+
});
|
|
304
|
+
return forEachTree(arr, function (e) {
|
|
305
|
+
var _a;
|
|
306
|
+
delete e._id;
|
|
307
|
+
delete e._pid;
|
|
308
|
+
if (!((_a = e === null || e === void 0 ? void 0 : e[children]) === null || _a === void 0 ? void 0 : _a.length)) delete e[children];
|
|
309
|
+
}, children);
|
|
310
|
+
}
|
|
311
|
+
TreeUtil.strSplit2tree = strSplit2tree;
|
|
312
|
+
/**
|
|
313
|
+
* @name 树结构转为字符串分割
|
|
314
|
+
* @param tree 树
|
|
315
|
+
* @param splitStr /
|
|
316
|
+
* @param fieldNames 映射对象
|
|
317
|
+
* @example
|
|
318
|
+
*
|
|
319
|
+
* [
|
|
320
|
+
{
|
|
321
|
+
name: '一级选项 1',
|
|
322
|
+
id: '一级选项 1',
|
|
323
|
+
children: [
|
|
324
|
+
{
|
|
325
|
+
name: '二级选项 1',
|
|
326
|
+
id: '二级选项 1',
|
|
327
|
+
pid: '一级选项 1',
|
|
328
|
+
children: [
|
|
329
|
+
{
|
|
330
|
+
name: '三级选项 1',
|
|
331
|
+
id: '三级选项 1',
|
|
332
|
+
pid: '二级选项 1',
|
|
333
|
+
},
|
|
334
|
+
{
|
|
335
|
+
name: '三级选项 2',
|
|
336
|
+
id: '三级选项 2',
|
|
337
|
+
pid: '二级选项 1',
|
|
338
|
+
},
|
|
339
|
+
],
|
|
340
|
+
},
|
|
341
|
+
],
|
|
342
|
+
},
|
|
343
|
+
{
|
|
344
|
+
name: '一级选项 2',
|
|
345
|
+
id: '一级选项 2',
|
|
346
|
+
children: [
|
|
347
|
+
{
|
|
348
|
+
name: '二级选项 1',
|
|
349
|
+
id: '二级选项 1',
|
|
350
|
+
pid: '一级选项 2',
|
|
351
|
+
},
|
|
352
|
+
],
|
|
353
|
+
},
|
|
354
|
+
]
|
|
355
|
+
//转换后
|
|
356
|
+
`一级选项 1/二级选项 1/三级选项 1
|
|
357
|
+
一级选项 1/二级选项 1/三级选项 2
|
|
358
|
+
一级选项 2/二级选项 1`
|
|
359
|
+
*/
|
|
360
|
+
function tree2strSplit(tree, splitStr, fieldNames) {
|
|
361
|
+
if (splitStr === void 0) {
|
|
362
|
+
splitStr = '/';
|
|
363
|
+
}
|
|
364
|
+
var _a = fieldNames !== null && fieldNames !== void 0 ? fieldNames : {},
|
|
365
|
+
_b = _a.label,
|
|
366
|
+
label = _b === void 0 ? 'name' : _b,
|
|
367
|
+
_c = _a.parent,
|
|
368
|
+
parent = _c === void 0 ? 'pid' : _c,
|
|
369
|
+
_d = _a.children,
|
|
370
|
+
children = _d === void 0 ? 'children' : _d;
|
|
371
|
+
var strArr = [];
|
|
372
|
+
var treeArr = JSON.parse(JSON.stringify(tree));
|
|
373
|
+
forEachTree(treeArr, function (item, parentData) {
|
|
374
|
+
var _a, _b, _c;
|
|
375
|
+
item[parent] = "".concat((_a = parentData === null || parentData === void 0 ? void 0 : parentData[parent]) !== null && _a !== void 0 ? _a : '', "/").concat((_b = parentData === null || parentData === void 0 ? void 0 : parentData[label]) !== null && _b !== void 0 ? _b : '');
|
|
376
|
+
if (parentData && !((_c = item === null || item === void 0 ? void 0 : item[children]) === null || _c === void 0 ? void 0 : _c.length)) {
|
|
377
|
+
strArr.push("".concat(item[parent], "/").concat(item[label]).split(splitStr).filter(function (e) {
|
|
378
|
+
return e;
|
|
379
|
+
}).join(splitStr));
|
|
380
|
+
}
|
|
381
|
+
}, children);
|
|
382
|
+
return strArr.join('\n');
|
|
383
|
+
}
|
|
384
|
+
TreeUtil.tree2strSplit = tree2strSplit;
|
|
385
|
+
})(TreeUtil || (TreeUtil = {}));
|
|
386
|
+
export default TreeUtil;
|
|
387
|
+
/**
|
|
388
|
+
* @name 这个是需要children包着的树对象
|
|
389
|
+
* @param element 树对象
|
|
390
|
+
* @param children 自定义children
|
|
391
|
+
*/
|
|
392
|
+
function treeData2List(element, children) {
|
|
393
|
+
if (children === void 0) {
|
|
394
|
+
children = 'children';
|
|
395
|
+
}
|
|
396
|
+
var array = [];
|
|
397
|
+
var getList = function getList(item) {
|
|
398
|
+
var _a;
|
|
399
|
+
var newItem = JSON.parse(JSON.stringify(item || '{}')); //序列化
|
|
400
|
+
delete newItem[children];
|
|
401
|
+
if ((_a = item[children]) === null || _a === void 0 ? void 0 : _a.length) {
|
|
402
|
+
if (!isEmpty(newItem)) array.push(newItem);
|
|
403
|
+
item[children].forEach(function (el) {
|
|
404
|
+
return getList(el);
|
|
405
|
+
});
|
|
406
|
+
} else if (!isEmpty(newItem)) {
|
|
407
|
+
array.push(newItem);
|
|
408
|
+
}
|
|
409
|
+
};
|
|
410
|
+
getList(element);
|
|
411
|
+
return array;
|
|
412
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 数据校验
|
|
3
|
+
* @description 基础数据校验
|
|
4
|
+
* @author nanshen
|
|
5
|
+
* @creat 2021-09-15 10:30:05
|
|
6
|
+
*/
|
|
7
|
+
declare namespace BaseUtil {
|
|
8
|
+
/**
|
|
9
|
+
* 判断是否为 undefined
|
|
10
|
+
* @param obj 任意对象
|
|
11
|
+
* @returns 是/否
|
|
12
|
+
*/
|
|
13
|
+
const isUndefined: (obj: any) => obj is undefined;
|
|
14
|
+
/**
|
|
15
|
+
* 判断是否为 null
|
|
16
|
+
* @param obj 任意对象
|
|
17
|
+
* @returns 是/否
|
|
18
|
+
*/
|
|
19
|
+
const isNull: (obj: any) => obj is null;
|
|
20
|
+
/**
|
|
21
|
+
* 判断是否为 Array 类型
|
|
22
|
+
* @param obj 任意对象
|
|
23
|
+
* @returns 是/否
|
|
24
|
+
*/
|
|
25
|
+
const isArray: (obj: any) => obj is any[];
|
|
26
|
+
/**
|
|
27
|
+
* 判断是否为 Function 类型
|
|
28
|
+
* @param obj 任意对象
|
|
29
|
+
* @returns 是/否
|
|
30
|
+
*/
|
|
31
|
+
const isFunction: (obj: any) => obj is Function;
|
|
32
|
+
/**
|
|
33
|
+
* 判断是否为 Boolean 类型
|
|
34
|
+
* @param obj 任意对象
|
|
35
|
+
* @returns 是/否
|
|
36
|
+
*/
|
|
37
|
+
const isBoolean: (obj: any) => obj is boolean;
|
|
38
|
+
/**
|
|
39
|
+
* 判断是否为 String 类型
|
|
40
|
+
* @param obj 任意对象
|
|
41
|
+
* @returns 是/否
|
|
42
|
+
*/
|
|
43
|
+
const isString: (obj: any) => obj is string;
|
|
44
|
+
/**
|
|
45
|
+
* 判断是否为 Number 类型
|
|
46
|
+
* @param obj 任意对象
|
|
47
|
+
* @returns 是/否
|
|
48
|
+
*/
|
|
49
|
+
const isNumber: (obj: any) => obj is number;
|
|
50
|
+
/**
|
|
51
|
+
* 判断是否为 RegExp 类型
|
|
52
|
+
* @param obj 任意对象
|
|
53
|
+
* @returns 是/否
|
|
54
|
+
*/
|
|
55
|
+
const isRegExp: (obj: any) => obj is RegExp;
|
|
56
|
+
/**
|
|
57
|
+
* 判断是否为 Object 类型
|
|
58
|
+
* @param obj 任意对象
|
|
59
|
+
* @returns 是/否
|
|
60
|
+
*/
|
|
61
|
+
const isObject: (obj: any) => obj is object;
|
|
62
|
+
/**
|
|
63
|
+
* 判断是否为 Date 类型
|
|
64
|
+
* @param obj 任意对象
|
|
65
|
+
* @returns 是/否
|
|
66
|
+
*/
|
|
67
|
+
const isDate: (obj: any) => obj is Date;
|
|
68
|
+
/**
|
|
69
|
+
* 判断是否为 Error 类型
|
|
70
|
+
* @param obj 任意对象
|
|
71
|
+
* @returns 是/否
|
|
72
|
+
*/
|
|
73
|
+
const isError: (obj: any) => obj is Error;
|
|
74
|
+
/**
|
|
75
|
+
* 获取对象的类型
|
|
76
|
+
* @param obj 任意对象
|
|
77
|
+
* @returns undefined | null | array | function | boolean | string | number | regexp | object | date | error
|
|
78
|
+
* @example
|
|
79
|
+
* getType(null) => 'null'
|
|
80
|
+
*/
|
|
81
|
+
const getType: (obj: any) => string;
|
|
82
|
+
/**
|
|
83
|
+
* 判断是否为空,包括空对象,空数组,空字符串,null,undefined等
|
|
84
|
+
* @param obj 任意对象
|
|
85
|
+
* @example
|
|
86
|
+
* isEmpty(12) => false
|
|
87
|
+
* isEmpty(null) => true
|
|
88
|
+
*/
|
|
89
|
+
const isEmpty: (obj: any) => obj is "" | null | undefined;
|
|
90
|
+
}
|
|
91
|
+
export default BaseUtil;
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 数据校验
|
|
3
|
+
* @description 基础数据校验
|
|
4
|
+
* @author nanshen
|
|
5
|
+
* @creat 2021-09-15 10:30:05
|
|
6
|
+
*/
|
|
7
|
+
var BaseUtil;
|
|
8
|
+
(function (BaseUtil) {
|
|
9
|
+
/**
|
|
10
|
+
* 创建一个自定义的 typeof 函数
|
|
11
|
+
* @param {String} type 类型
|
|
12
|
+
* @returns {Function} 返回一个可判断特定类型的谓词函数
|
|
13
|
+
*/
|
|
14
|
+
var _createTypeOf = function _createTypeOf(type) {
|
|
15
|
+
return function (obj) {
|
|
16
|
+
return Object.prototype.toString.call(obj) === "[object ".concat(type, "]");
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* 判断是否为 undefined
|
|
21
|
+
* @param obj 任意对象
|
|
22
|
+
* @returns 是/否
|
|
23
|
+
*/
|
|
24
|
+
BaseUtil.isUndefined = _createTypeOf("Undefined");
|
|
25
|
+
/**
|
|
26
|
+
* 判断是否为 null
|
|
27
|
+
* @param obj 任意对象
|
|
28
|
+
* @returns 是/否
|
|
29
|
+
*/
|
|
30
|
+
BaseUtil.isNull = _createTypeOf("Null");
|
|
31
|
+
/**
|
|
32
|
+
* 判断是否为 Array 类型
|
|
33
|
+
* @param obj 任意对象
|
|
34
|
+
* @returns 是/否
|
|
35
|
+
*/
|
|
36
|
+
BaseUtil.isArray = Array.isArray || _createTypeOf("Array");
|
|
37
|
+
/**
|
|
38
|
+
* 判断是否为 Function 类型
|
|
39
|
+
* @param obj 任意对象
|
|
40
|
+
* @returns 是/否
|
|
41
|
+
*/
|
|
42
|
+
BaseUtil.isFunction = _createTypeOf("Function");
|
|
43
|
+
/**
|
|
44
|
+
* 判断是否为 Boolean 类型
|
|
45
|
+
* @param obj 任意对象
|
|
46
|
+
* @returns 是/否
|
|
47
|
+
*/
|
|
48
|
+
BaseUtil.isBoolean = _createTypeOf("Boolean");
|
|
49
|
+
/**
|
|
50
|
+
* 判断是否为 String 类型
|
|
51
|
+
* @param obj 任意对象
|
|
52
|
+
* @returns 是/否
|
|
53
|
+
*/
|
|
54
|
+
BaseUtil.isString = _createTypeOf("String");
|
|
55
|
+
/**
|
|
56
|
+
* 判断是否为 Number 类型
|
|
57
|
+
* @param obj 任意对象
|
|
58
|
+
* @returns 是/否
|
|
59
|
+
*/
|
|
60
|
+
BaseUtil.isNumber = _createTypeOf("Number");
|
|
61
|
+
/**
|
|
62
|
+
* 判断是否为 RegExp 类型
|
|
63
|
+
* @param obj 任意对象
|
|
64
|
+
* @returns 是/否
|
|
65
|
+
*/
|
|
66
|
+
BaseUtil.isRegExp = _createTypeOf("RegExp");
|
|
67
|
+
/**
|
|
68
|
+
* 判断是否为 Object 类型
|
|
69
|
+
* @param obj 任意对象
|
|
70
|
+
* @returns 是/否
|
|
71
|
+
*/
|
|
72
|
+
BaseUtil.isObject = _createTypeOf("Object");
|
|
73
|
+
/**
|
|
74
|
+
* 判断是否为 Date 类型
|
|
75
|
+
* @param obj 任意对象
|
|
76
|
+
* @returns 是/否
|
|
77
|
+
*/
|
|
78
|
+
BaseUtil.isDate = _createTypeOf("Date");
|
|
79
|
+
/**
|
|
80
|
+
* 判断是否为 Error 类型
|
|
81
|
+
* @param obj 任意对象
|
|
82
|
+
* @returns 是/否
|
|
83
|
+
*/
|
|
84
|
+
BaseUtil.isError = _createTypeOf("Error");
|
|
85
|
+
/**
|
|
86
|
+
* 获取对象的类型
|
|
87
|
+
* @param obj 任意对象
|
|
88
|
+
* @returns undefined | null | array | function | boolean | string | number | regexp | object | date | error
|
|
89
|
+
* @example
|
|
90
|
+
* getType(null) => 'null'
|
|
91
|
+
*/
|
|
92
|
+
BaseUtil.getType = function (obj) {
|
|
93
|
+
if (BaseUtil.isUndefined(obj)) {
|
|
94
|
+
return "undefined";
|
|
95
|
+
}
|
|
96
|
+
if (BaseUtil.isNull(obj)) {
|
|
97
|
+
return "null";
|
|
98
|
+
}
|
|
99
|
+
if (BaseUtil.isArray(obj)) {
|
|
100
|
+
return "array";
|
|
101
|
+
}
|
|
102
|
+
if (BaseUtil.isFunction(obj)) {
|
|
103
|
+
return "function";
|
|
104
|
+
}
|
|
105
|
+
if (BaseUtil.isBoolean(obj)) {
|
|
106
|
+
return "boolean";
|
|
107
|
+
}
|
|
108
|
+
if (BaseUtil.isString(obj)) {
|
|
109
|
+
return "string";
|
|
110
|
+
}
|
|
111
|
+
if (BaseUtil.isNumber(obj)) {
|
|
112
|
+
return "number";
|
|
113
|
+
}
|
|
114
|
+
if (BaseUtil.isRegExp(obj)) {
|
|
115
|
+
return "regexp";
|
|
116
|
+
}
|
|
117
|
+
if (BaseUtil.isObject(obj)) {
|
|
118
|
+
return "object";
|
|
119
|
+
}
|
|
120
|
+
if (BaseUtil.isDate(obj)) {
|
|
121
|
+
return "date";
|
|
122
|
+
}
|
|
123
|
+
if (BaseUtil.isError(obj)) {
|
|
124
|
+
return "error";
|
|
125
|
+
}
|
|
126
|
+
return typeof obj;
|
|
127
|
+
};
|
|
128
|
+
/**
|
|
129
|
+
* 判断是否为空,包括空对象,空数组,空字符串,null,undefined等
|
|
130
|
+
* @param obj 任意对象
|
|
131
|
+
* @example
|
|
132
|
+
* isEmpty(12) => false
|
|
133
|
+
* isEmpty(null) => true
|
|
134
|
+
*/
|
|
135
|
+
BaseUtil.isEmpty = function (obj) {
|
|
136
|
+
if (BaseUtil.isString(obj)) {
|
|
137
|
+
obj = obj.trim();
|
|
138
|
+
}
|
|
139
|
+
for (var _ in obj) {
|
|
140
|
+
return false;
|
|
141
|
+
}
|
|
142
|
+
if (BaseUtil.isBoolean(obj) || BaseUtil.isNumber(obj) || BaseUtil.isFunction(obj) || BaseUtil.isDate(obj) || BaseUtil.isError(obj) || BaseUtil.isRegExp(obj)) {
|
|
143
|
+
return false;
|
|
144
|
+
}
|
|
145
|
+
return true;
|
|
146
|
+
};
|
|
147
|
+
})(BaseUtil || (BaseUtil = {}));
|
|
148
|
+
export default BaseUtil;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { WATERMARK_SETTINGS } from '../common';
|
|
2
|
+
/**
|
|
3
|
+
* 浏览器工具
|
|
4
|
+
* @description
|
|
5
|
+
* @author nanshen
|
|
6
|
+
* @creat 2021-09-15 10:30:30
|
|
7
|
+
*/
|
|
8
|
+
export type BrowserType = 'Opera' | 'IE' | 'Edge' | 'Firefox' | 'Safari' | 'Chrome' | 'OverIE10' | '';
|
|
9
|
+
declare namespace BrowserUtil {
|
|
10
|
+
/**
|
|
11
|
+
* 获取浏览器id
|
|
12
|
+
*/
|
|
13
|
+
const getId: () => Promise<any>;
|
|
14
|
+
/**
|
|
15
|
+
* 获取浏览器类型
|
|
16
|
+
* @returns Opera | IE | Edge | Firefox | Safari | Chrome | OverIE10 | ""
|
|
17
|
+
*/
|
|
18
|
+
const browserGetType: () => BrowserType;
|
|
19
|
+
/**
|
|
20
|
+
* 判断是否是移动端浏览器
|
|
21
|
+
* @returns boolean
|
|
22
|
+
*/
|
|
23
|
+
const isMobileBrowser: () => boolean;
|
|
24
|
+
/**
|
|
25
|
+
* 判断是否微信内置浏览器
|
|
26
|
+
* @returns boolean
|
|
27
|
+
*/
|
|
28
|
+
const isWeixinBrowser: () => any;
|
|
29
|
+
/**
|
|
30
|
+
* 判断是否微信小程序WebView
|
|
31
|
+
* @returns boolean
|
|
32
|
+
*/
|
|
33
|
+
const isWeixinMiniWebView: () => boolean;
|
|
34
|
+
/**
|
|
35
|
+
* 判断是否是支付宝浏览器
|
|
36
|
+
* @returns boolean
|
|
37
|
+
*/
|
|
38
|
+
const isAlipayBrowser: () => any;
|
|
39
|
+
/**
|
|
40
|
+
* 判断是否是支付宝小程序webview
|
|
41
|
+
* @returns boolean
|
|
42
|
+
*/
|
|
43
|
+
const isAlipayMiniWebView: () => any;
|
|
44
|
+
/**
|
|
45
|
+
* 判断是否是浙里办
|
|
46
|
+
* @returns boolean
|
|
47
|
+
*/
|
|
48
|
+
const isMgopBrowser: () => any;
|
|
49
|
+
/** 全屏 */
|
|
50
|
+
function fullScreen(root: string | HTMLElement, callback?: (isFull: boolean) => void): void;
|
|
51
|
+
/** 是否全屏 */
|
|
52
|
+
function isFullScreen(): any;
|
|
53
|
+
/** 水印 */
|
|
54
|
+
function waterMark(defaultSettings: typeof WATERMARK_SETTINGS): void;
|
|
55
|
+
function removeMark(): void;
|
|
56
|
+
}
|
|
57
|
+
export default BrowserUtil;
|