@kmkf-fe-packages/kmkf-utils 1.20.2-beta.0 → 1.20.2-beta.3
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.
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: (sourceOptions: any[]) => any;
|
|
1
|
+
declare const _default: (sourceOptions: any[], isFilterHide?: boolean) => any;
|
|
2
2
|
export default _default;
|
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import get from "lodash/get";
|
|
2
2
|
var findNodeById = function findNodeById(tree) {
|
|
3
3
|
var actived = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "";
|
|
4
|
+
var isFilterHide = arguments.length > 2 ? arguments[2] : undefined;
|
|
4
5
|
for (var i = 0; i < tree.length; i++) {
|
|
5
6
|
if (tree[i].actived == actived) {
|
|
6
|
-
return tree[i];
|
|
7
|
+
return isFilterHide ? tree[i].hide ? null : tree[i] : tree[i];
|
|
7
8
|
}
|
|
8
9
|
if (tree[i].children) {
|
|
9
|
-
var
|
|
10
|
+
var newTree = isFilterHide ? tree[i].children.filter(function (t) {
|
|
11
|
+
return !t.hide;
|
|
12
|
+
}) : tree[i].children;
|
|
13
|
+
var result = findNodeById(newTree, actived, isFilterHide);
|
|
10
14
|
if (result) {
|
|
11
15
|
return result;
|
|
12
16
|
}
|
|
@@ -14,16 +18,25 @@ var findNodeById = function findNodeById(tree) {
|
|
|
14
18
|
}
|
|
15
19
|
};
|
|
16
20
|
export default (function (sourceOptions) {
|
|
21
|
+
var isFilterHide = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
17
22
|
var tree = [];
|
|
18
23
|
var newOptions = JSON.parse(JSON.stringify(sourceOptions));
|
|
19
24
|
newOptions.map(function (item) {
|
|
20
25
|
if (tree.length === 0) {
|
|
21
|
-
|
|
26
|
+
var list = get(item, "list.1", []);
|
|
27
|
+
if (isFilterHide) {
|
|
28
|
+
list = list.filter(function (t) {
|
|
29
|
+
return !t.hide;
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
return tree = tree.concat(list);
|
|
22
33
|
}
|
|
23
34
|
Object.keys(item.list).map(function (l) {
|
|
24
35
|
// 在树中找到l对应的节点,将当前数组放到children里面
|
|
25
|
-
var result = findNodeById(tree, l);
|
|
26
|
-
result && (result.children = item.list[l])
|
|
36
|
+
var result = findNodeById(tree, l, isFilterHide);
|
|
37
|
+
result && (result.children = isFilterHide ? item.list[l].filter(function (t) {
|
|
38
|
+
return !t.hide;
|
|
39
|
+
}) : item.list[l]);
|
|
27
40
|
});
|
|
28
41
|
});
|
|
29
42
|
return tree;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kmkf-fe-packages/kmkf-utils",
|
|
3
|
-
"version": "1.20.2-beta.
|
|
3
|
+
"version": "1.20.2-beta.3",
|
|
4
4
|
"module": "dist/esm/index.js",
|
|
5
5
|
"typings": "dist/esm/index.d.ts",
|
|
6
6
|
"files": [
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"publishConfig": {
|
|
42
42
|
"access": "public"
|
|
43
43
|
},
|
|
44
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "2d0488e9a1a8d010aa6877a5dcc803e9171e5709",
|
|
45
45
|
"gitHooks": {
|
|
46
46
|
"pre-commit": "lint-staged"
|
|
47
47
|
}
|