@lambo-design/shared 1.0.0-beta.4 → 1.0.0-beta.5

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.
Files changed (2) hide show
  1. package/package.json +2 -2
  2. package/utils/menu/index.js +113 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lambo-design/shared",
3
- "version": "1.0.0-beta.4",
3
+ "version": "1.0.0-beta.5",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {},
@@ -13,7 +13,7 @@
13
13
  "axios": "^0.24.0",
14
14
  "axios-cache-plugin": "^0.1.0",
15
15
  "qs": "^6.11.0",
16
- "xlsx": "https://cdn.sheetjs.com/xlsx-0.19.1/xlsx-0.19.1.tgz",
16
+ "xlsx": "http://10.110.34.38/package/cdn/xlsx-0.19.1.tgz",
17
17
  "classnames": "^2.3.1",
18
18
  "xlsx-style": "^0.8.13"
19
19
  }
@@ -0,0 +1,113 @@
1
+ /**
2
+ * 动态生成菜单
3
+ * @param permissionList
4
+ * @returns []
5
+ */
6
+ export const generatorMenuList = (permissionList,appId) => {
7
+ let menuData = [],
8
+ pageNode = {
9
+ path: "/page",
10
+ name: "page",
11
+ meta: {
12
+ hideInMenu: true,
13
+ notCache: true
14
+ },
15
+ component: "Main",
16
+ children: []
17
+ };
18
+ listToMenuTree(permissionList, menuData, pageNode, "0", [], true,appId);
19
+
20
+ /*if (pageNode.children.length > 0) {
21
+ menuData.push(pageNode);
22
+ }*/
23
+ return menuData;
24
+ };
25
+
26
+
27
+
28
+ /**
29
+ * 数组转树形结构
30
+ */
31
+ const listToMenuTree = (list, menuTree, pageNode, parentId, crumbs, root, appId) => {
32
+ if (list == null) {
33
+ return;
34
+ }
35
+ list.forEach(item => {
36
+ if (item.appId == appId) {
37
+ // 判断是否为父级菜单
38
+ if (item.pid === parentId) {
39
+ if (item.type === 1 || item.type === 2) {
40
+ let node = {
41
+ meta: {
42
+ appId: item.appId,
43
+ title: item.label,
44
+ icon: item.icon,
45
+ crumbs: [...crumbs],
46
+ activeName: item.name
47
+ },
48
+ type: item.type,
49
+ pid: item.pid,
50
+ component: item.name,
51
+ name: item.name,
52
+ uri: item.uri,
53
+ children: []
54
+ };
55
+ node.meta.crumbs.push({
56
+ icon: item.icon,
57
+ name: item.name,
58
+ title: item.label,
59
+ type: item.type
60
+ });
61
+
62
+ if (item.type === 1) {
63
+ if (root) {
64
+ node.component = "Main";
65
+ } else {
66
+ node.component = "parentView";
67
+ }
68
+ }
69
+ // 迭代 list, 找到当前菜单相符合的所有子菜单
70
+ listToMenuTree(
71
+ list,
72
+ node.children,
73
+ pageNode,
74
+ item.permissionId,
75
+ node.meta.crumbs,
76
+ false,
77
+ appId
78
+ );
79
+ // 删掉不存在 children 值的属性
80
+ if (node.children.length <= 0) {
81
+ delete node.children;
82
+ }
83
+ // 加入到树中
84
+ menuTree.push(node);
85
+ }
86
+ if (item.type === 4) {
87
+ let child = {
88
+ meta: {
89
+ title: item.label,
90
+ hideInMenu: true,
91
+ notCache: true,
92
+ crumbs: [...crumbs],
93
+ type: item.type
94
+ },
95
+ type: item.type,
96
+ pid: item.pid,
97
+ component: item.name,
98
+ name: item.name,
99
+ uri: item.uri
100
+ };
101
+ child.meta.crumbs.push({
102
+ icon: item.icon,
103
+ name: item.name,
104
+ title: item.label,
105
+ type: item.type
106
+ });
107
+ pageNode.children.push(child);
108
+ }
109
+ }
110
+ }
111
+ });
112
+ };
113
+ export default generatorMenuList;