@lambo-design/shared 1.0.0-beta.237 → 1.0.0-beta.239

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 (182) hide show
  1. package/config/config.js +51 -51
  2. package/config/env.js +4 -4
  3. package/config/index.js +7 -7
  4. package/config/themes/atrovirens/atrovirens.css +575 -575
  5. package/config/themes/atrovirens/atrovirens.less +667 -667
  6. package/config/themes/atrovirens/var.less +674 -674
  7. package/config/themes/blue/blue.css +575 -575
  8. package/config/themes/blue/blue.less +669 -669
  9. package/config/themes/blue/var.less +677 -677
  10. package/config/themes/blue-white/blue-white.css +575 -575
  11. package/config/themes/blue-white/blue-white.less +669 -669
  12. package/config/themes/blue-white/var.less +676 -676
  13. package/config/themes/blue-white-tight/blue-white-tight.css +576 -576
  14. package/config/themes/blue-white-tight/blue-white-tight.less +672 -672
  15. package/config/themes/blue-white-tight/var.less +677 -677
  16. package/config/themes/danqing/danqing.css +576 -575
  17. package/config/themes/danqing/danqing.css.map +1 -1
  18. package/config/themes/danqing/danqing.less +668 -668
  19. package/config/themes/danqing/danqing.wxss +572 -572
  20. package/config/themes/danqing/var.less +679 -679
  21. package/config/themes/deep/deep.css +575 -575
  22. package/config/themes/deep/deep.less +669 -669
  23. package/config/themes/deep/var.less +677 -677
  24. package/config/themes/default/default.css +575 -575
  25. package/config/themes/default/default.less +671 -671
  26. package/config/themes/default/var.less +677 -677
  27. package/config/themes/eap/eap.css +575 -575
  28. package/config/themes/eap/eap.less +671 -671
  29. package/config/themes/eap/var.less +677 -677
  30. package/config/themes/gold/gold.css +575 -575
  31. package/config/themes/gold/gold.less +671 -671
  32. package/config/themes/gold/var.less +677 -677
  33. package/config/themes/index.js +28 -28
  34. package/config/themes/lime/lime.css +575 -575
  35. package/config/themes/lime/lime.less +671 -671
  36. package/config/themes/lime/var.less +678 -678
  37. package/config/themes/orange/orange.css +575 -575
  38. package/config/themes/orange/orange.less +671 -671
  39. package/config/themes/orange/var.less +678 -678
  40. package/config/themes/red/red.css +575 -575
  41. package/config/themes/red/red.less +671 -671
  42. package/config/themes/red/var.less +677 -677
  43. package/config/themes/theme-atrovirens.js +558 -558
  44. package/config/themes/theme-blue.js +558 -558
  45. package/config/themes/theme-bw.js +558 -558
  46. package/config/themes/theme-bwt.js +559 -559
  47. package/config/themes/theme-danqing.js +558 -558
  48. package/config/themes/theme-deep.js +558 -558
  49. package/config/themes/theme-default.js +558 -558
  50. package/config/themes/theme-eap.js +558 -558
  51. package/config/themes/theme-gold.js +558 -558
  52. package/config/themes/theme-lime.js +558 -558
  53. package/config/themes/theme-orange.js +559 -559
  54. package/config/themes/theme-red.js +558 -558
  55. package/config/themes/theme-white.js +557 -557
  56. package/config/themes/white/var.less +675 -675
  57. package/config/themes/white/white.css +575 -575
  58. package/config/themes/white/white.less +668 -668
  59. package/directives/index.js +23 -23
  60. package/directives/module/draggable.js +56 -56
  61. package/directives/module/permission.js +49 -49
  62. package/directives/module/print.js +1 -1
  63. package/directives/module/vue-print-nb/README.md +63 -63
  64. package/directives/module/vue-print-nb/print.js +94 -94
  65. package/directives/module/vue-print-nb/printarea.js +532 -532
  66. package/index.js +10 -10
  67. package/nstyles/common.less +197 -197
  68. package/nstyles/components/404.less +46 -46
  69. package/nstyles/components/button.less +34 -34
  70. package/nstyles/components/date-picker.less +37 -37
  71. package/nstyles/components/drawer.less +20 -20
  72. package/nstyles/components/dropdown.less +18 -18
  73. package/nstyles/components/excel-flow.less +72 -72
  74. package/nstyles/components/form.less +313 -303
  75. package/nstyles/components/index.less +23 -23
  76. package/nstyles/components/layout/collect.less +10 -10
  77. package/nstyles/components/layout/detail-view.less +107 -107
  78. package/nstyles/components/layout/full-screen.less +7 -7
  79. package/nstyles/components/layout/index.less +7 -7
  80. package/nstyles/components/layout/other-menu.less +142 -142
  81. package/nstyles/components/layout/page-view.less +101 -101
  82. package/nstyles/components/layout/sider-trigger.less +41 -41
  83. package/nstyles/components/layout/tags-nav.less +113 -113
  84. package/nstyles/components/modal.less +85 -85
  85. package/nstyles/components/n-button.less +131 -131
  86. package/nstyles/components/n-image-preview.less +131 -131
  87. package/nstyles/components/n-model/index.less +19 -19
  88. package/nstyles/components/n-model/report-index.less +43 -43
  89. package/nstyles/components/n-panel.less +40 -40
  90. package/nstyles/components/n-picker.less +37 -37
  91. package/nstyles/components/n-sign.less +17 -17
  92. package/nstyles/components/n-tooltip.less +10 -10
  93. package/nstyles/components/panel.less +31 -31
  94. package/nstyles/components/select.less +3 -3
  95. package/nstyles/components/sign.less +27 -27
  96. package/nstyles/components/table.less +315 -315
  97. package/nstyles/components/tree.less +158 -158
  98. package/nstyles/components/upload.less +164 -164
  99. package/nstyles/index.less +5 -5
  100. package/nstyles/reset.less +65 -65
  101. package/nstyles/third/ag.less +174 -174
  102. package/nstyles/third/index.less +11 -11
  103. package/nstyles/third/view-design.less +366 -366
  104. package/nstyles/variables/base.less +143 -143
  105. package/nstyles/variables/index.less +4 -4
  106. package/nstyles/variables/theme/default/button.less +7 -7
  107. package/nstyles/variables/theme/default/common.less +57 -57
  108. package/nstyles/variables/theme/default/index.less +7 -7
  109. package/nstyles/variables/theme/default/layout.less +40 -40
  110. package/nstyles/variables/theme/default/table.less +37 -37
  111. package/nstyles/variables/theme/default/tag.less +3 -3
  112. package/nstyles/variables/theme/default/upload.less +3 -3
  113. package/nstyles/variables/theme/index.less +13 -13
  114. package/nstyles/variables/theme/small/button.less +7 -7
  115. package/nstyles/variables/theme/small/common.less +39 -39
  116. package/nstyles/variables/theme/small/index.less +5 -5
  117. package/nstyles/variables/theme/small/layout.less +21 -21
  118. package/nstyles/variables/theme/small/table.less +17 -17
  119. package/nstyles/variables/theme/small/tag.less +3 -3
  120. package/package.json +1 -1
  121. package/plugin/index.js +12 -12
  122. package/plugin/module/date-format.js +30 -30
  123. package/plugin/module/loading.js +26 -26
  124. package/plugin/module/warn-handler.js +11 -11
  125. package/styles/variables.less +21 -21
  126. package/utils/ajax/cacheconf.js +19 -19
  127. package/utils/ajax/content-type.js +30 -30
  128. package/utils/ajax/index.js +12 -12
  129. package/utils/ajax/interceptors.js +97 -97
  130. package/utils/assist.js +147 -147
  131. package/utils/base64.js +126 -126
  132. package/utils/blob.js +47 -47
  133. package/utils/bus.js +3 -3
  134. package/utils/crypto/index.js +48 -48
  135. package/utils/crypto/md5.js +152 -152
  136. package/utils/crypto/sm3.js +235 -235
  137. package/utils/date.js +381 -381
  138. package/utils/dict/built-in-dict.js +20 -20
  139. package/utils/dict/index.js +167 -167
  140. package/utils/dom.js +38 -38
  141. package/utils/event.js +72 -72
  142. package/utils/excel.js +655 -655
  143. package/utils/file.js +19 -19
  144. package/utils/form/validate.js +29 -29
  145. package/utils/half-year.js +68 -68
  146. package/utils/index.js +41 -41
  147. package/utils/json.js +29 -29
  148. package/utils/lodop.js +165 -165
  149. package/utils/menu/before-close.js +17 -17
  150. package/utils/menu/index.js +395 -395
  151. package/utils/mime_type.js +67 -67
  152. package/utils/modelerUtil.js +227 -227
  153. package/utils/n/api.js +22 -22
  154. package/utils/n/date.js +57 -57
  155. package/utils/n/index.js +9 -9
  156. package/utils/n/is-type.js +176 -176
  157. package/utils/n/number.js +144 -144
  158. package/utils/n/permission-cache.js +11 -11
  159. package/utils/n/reuqest/axiosN.js +17 -17
  160. package/utils/n/reuqest/content-type.js +19 -19
  161. package/utils/n/reuqest/interceptors.js +95 -95
  162. package/utils/n/reuqest/url-params.js +12 -12
  163. package/utils/n/storage.js +51 -51
  164. package/utils/n/token.js +51 -51
  165. package/utils/n/user-cache.js +11 -11
  166. package/utils/n/user.js +34 -34
  167. package/utils/n/uuid.js +16 -16
  168. package/utils/n-generator-routers.js +208 -208
  169. package/utils/n-router.js +205 -205
  170. package/utils/n-theme.js +30 -30
  171. package/utils/number.js +180 -180
  172. package/utils/oss.js +57 -57
  173. package/utils/platform.js +1334 -1334
  174. package/utils/quarter.js +58 -58
  175. package/utils/storage.js +198 -198
  176. package/utils/theme.js +138 -138
  177. package/utils/transform.js +179 -0
  178. package/utils/type.js +102 -102
  179. package/utils/util.js +795 -795
  180. package/utils/validator.js +181 -181
  181. package/utils/vxetable/index.js +25 -25
  182. package/utils/zoomScroll.js +9 -9
@@ -1,395 +1,395 @@
1
- import config from "../../config/config"
2
- import {deepCopy} from "../assist";
3
- import {getUrlParams} from "../platform"
4
- /**
5
- * 判断是否存在路由
6
- * @param $router
7
- * @param name
8
- * @returns {*|boolean}
9
- */
10
- export const hasRoute = ($router, name) => {
11
- let routes = $router.getRoutes();
12
- let res = routes.filter(item => item.name === name)
13
- return res && res.length > 0
14
- }
15
- /**
16
- * 判断是否存在路由并且页面存在
17
- * @param $router
18
- * @param path
19
- * @returns {*|boolean}
20
- */
21
- export const hasRoutePath = ($router, path) => {
22
- if ($router && path) {
23
- let routes = $router.getRoutes();
24
- if (path.trim().startsWith("dida/")) {
25
- path = path.trim().replace("dida/","");
26
- if (!path.startsWith("/")) {
27
- path = "/" + path;
28
- }
29
- } else if (path.trim().startsWith("dareport/")) {
30
- path = path.trim().replace("dareport/","");
31
- if (!path.startsWith("/")) {
32
- path = "/" + path;
33
- }
34
- } else if (path.trim().startsWith("/" + config.routerBase + "/")) {
35
- path = "/" + path.replace("/" + config.routerBase + "/","")
36
- }
37
- let res = routes.filter(item => item.path === path)
38
- return res && res.length > 0
39
- }
40
- return false
41
- }
42
- /**
43
- * 动态生成菜单
44
- * @param permissionList
45
- * @returns []
46
- */
47
- export const generatorMenuList = (permissionList,appId,generateType = 'router') => {
48
- let menuRouter = generatorMenuRouter(permissionList,appId,generateType);
49
- return menuRouter && menuRouter.menuData ? menuRouter.menuData : [];
50
- };
51
- /**
52
- * 动态生成菜单
53
- * @param generatorMenuRouter
54
- * @returns []
55
- */
56
- export const generatorMenuRouter = (permissionList,appId,generateType = 'router') => {
57
- let menuData = [],
58
- pageNode = {
59
- path: "/page",
60
- name: "page",
61
- meta: {
62
- hideInMenu: true,
63
- notCache: true
64
- },
65
- component: "Main",
66
- children: []
67
- };
68
- listToMenuTree(permissionList, menuData, pageNode, "0", [], true,appId,generateType);
69
- return {menuData,pageNode};
70
- };
71
-
72
-
73
- /**
74
- * 数组转树形结构
75
- */
76
- const listToMenuTree = (list, menuTree, pageNode, parentId, crumbs, root, appId,generateType = 'router') => {
77
- if (list == null) {
78
- return;
79
- }
80
- list.forEach(item => {
81
- let appIdCondition = !appId || item.appId == appId || appId.indexOf(item.appId) > -1;//过滤是否要求的应用
82
- let hideInMenuCondition = !(item.hasOwnProperty("hideInMenu") && item.hideInMenu);//过滤是否隐藏的菜单
83
- if ((generateType && generateType == 'router' && appIdCondition) ||
84
- (generateType == 'menu' && appIdCondition && hideInMenuCondition)) {
85
- // 判断是否为父级菜单
86
- if (item.pid === parentId) {
87
- if (item.type === 1 || item.type === 2) {
88
- let node = {
89
- meta: {
90
- data: deepCopy(item),
91
- appId: item.appId,
92
- title: item.label,
93
- icon: item.icon,
94
- crumbs: [...crumbs],
95
- activeName: item.name,
96
- notCache: item.notCache ? true : false,
97
- hideInMenu: item.hideInMenu ? true : false
98
- },
99
- permissionId: item.permissionId,
100
- type: item.type,
101
- pid: item.pid,
102
- component: item.name,
103
- name: item.name,
104
- uri: item.uri,
105
- children: []
106
- };
107
- node.meta.crumbs.push({
108
- icon: item.icon,
109
- name: item.name,
110
- title: item.label,
111
- type: item.type
112
- });
113
-
114
- if (item.type === 1) {
115
- if (root) {
116
- node.component = "Main";
117
- } else {
118
- node.component = "parentView";
119
- }
120
- }
121
- // 迭代 list, 找到当前菜单相符合的所有子菜单
122
- listToMenuTree(
123
- list,
124
- node.children,
125
- pageNode,
126
- item.permissionId,
127
- node.meta.crumbs,
128
- false,
129
- appId,
130
- generateType
131
- );
132
- // 删掉不存在 children 值的属性
133
- if (node.children.length <= 0) {
134
- delete node.children;
135
- }
136
- // 加入到树中
137
- menuTree.push(node);
138
- }
139
- if (item.type === 4) {
140
- let child = {
141
- meta: {
142
- data: deepCopy(item),
143
- appId: item.appId,
144
- title: item.label,
145
- hideInMenu: true,
146
- notCache: true,
147
- crumbs: [...crumbs],
148
- type: item.type
149
- },
150
- permissionId: item.permissionId,
151
- type: item.type,
152
- pid: item.pid,
153
- component: item.name,
154
- name: item.name,
155
- uri: item.uri
156
- };
157
- child.meta.crumbs.push({
158
- icon: item.icon,
159
- name: item.name,
160
- title: item.label,
161
- type: item.type
162
- });
163
- pageNode.children.push(child);
164
- }
165
- }
166
- }
167
- });
168
- };
169
-
170
- /**
171
- * 动态生成路由
172
- * @param generatorMenuRouter
173
- * @returns []
174
- */
175
- export const generatorDynamicRouter = (permissionList,constantRouterComponents,appIds = null,generateType = 'router') => {
176
- let allMenu = generatorMenuRouter(permissionList, appIds,generateType);
177
- let menuData = allMenu.menuData;
178
- let pageNode = allMenu.pageNode;
179
- if (menuData && pageNode && pageNode.children.length > 0) {
180
- menuData.push(pageNode);
181
- }
182
- //给路由添加面包屑属性,解决示例页面左侧菜单点击不选中的问题
183
- //routesAddCrumbs(exampleMenuData,[]);
184
- //menuData = menuData.concat(exampleMenuData)
185
- let dynamicRouter = generator(menuData,constantRouterComponents);
186
-
187
- return dynamicRouter;
188
- }
189
- /**
190
- * 路由添加面包屑属性
191
- */
192
- export const routesAddCrumbs = (routes ,crumbs) => {
193
- routes.forEach(item => {
194
- if (item.meta.hasOwnProperty('crumbs')){
195
- item.meta.crumbs.push({
196
- icon: item.meta.icon,
197
- name: item.name,
198
- title: item.meta.title,
199
- type: item.type
200
- });
201
- }else{
202
- item.meta['crumbs'] = [...crumbs];
203
- item.meta.crumbs.push({
204
- icon: item.meta.icon,
205
- name: item.name,
206
- title: item.meta.title,
207
- type: item.type
208
- });
209
- }
210
- if (item.hasOwnProperty("children")){
211
- routesAddCrumbs(item.children,item.meta.crumbs)
212
- }
213
- });
214
- }
215
-
216
- /*
217
- 生成 vue-router 层级路由表
218
- */
219
- const generator = (menuData,constantRouterComponents) => {
220
- for (let item of menuData) {
221
- if (item.component && typeof item.component == "string") {
222
- const target = constantRouterComponents[item.component];
223
- if (target) {
224
- if (target.component) {
225
- if (typeof target.component == "string") {
226
- // 解决路由name与组件name不一致导致的keeplive不生效的问题
227
- try {
228
- //let componentPath = '@/view/' + target.component;
229
- item.component = resolve =>
230
- require(['@/view/'+ target.component], data => {
231
- data.default.name = item.name;
232
- resolve(data);
233
- });
234
- }catch (e) {
235
- delete item.component
236
- }
237
- } else {
238
- item.component = target.component;
239
- }
240
- }
241
- if (target.url) {
242
- let path = target.url;
243
- let query = {};
244
- if (path.indexOf("?") > -1) {
245
- query = getUrlParams(path.substr(path.indexOf("?")));
246
- item.query = query;
247
- path = path.substr(0,path.indexOf("?"));
248
- }
249
- item.path = path;
250
- }
251
- if (item.uri) {
252
- item.meta.uriParam = item.uri;
253
- }
254
- if (target.notCache) {
255
- item.meta.notCache = target.notCache;
256
- }
257
- if (target.hideInMenu) {
258
- item.meta.hideInMenu = target.hideInMenu;
259
- }
260
- }
261
- if (item.uri) {
262
- if (item.uri.startsWith("/")) {
263
- item.uri = item.uri.substr(1);
264
- }
265
- let uri = item.uri;
266
- if (uri.startsWith(config.routerBase + "/")) {
267
- uri = uri.replace(config.routerBase + "/","")
268
- }
269
- if (uri.startsWith("dida/")) {
270
- item.meta.notCache = true;
271
- let path = uri;
272
- let query = {};
273
- if (path.indexOf("?") > -1) {
274
- query = getUrlParams(path.substr(path.indexOf("?")));
275
- item.query = query;
276
- path = path.substr(0,path.indexOf("?"));
277
- }
278
- try{
279
- //let path = '@/view/dida/dida-page';
280
- item.component = resolve => {
281
- require(['@/view/dida/dida-page'], data => {
282
- data.default.name = item.name;
283
- resolve(data);
284
- });
285
- };
286
- }catch (e){
287
- delete item.component
288
- }
289
- item.path = "/" + path;
290
- } else if(uri.startsWith("dareport/")){
291
- item.meta.notCache = true;
292
- let path = uri;
293
- let query = {};
294
- if (path.indexOf("?") > -1) {
295
- query = getUrlParams(path.substr(path.indexOf("?")));
296
- item.query = query;
297
- path = path.substr(0,path.indexOf("?"));
298
- }
299
- try{
300
- item.component = resolve => {
301
- require(['@/view/dida/dida-page'], data => {
302
- data.default.name = item.name;
303
- resolve(data);
304
- });
305
- };
306
- }catch (e){
307
- delete item.component
308
- }
309
- item.path = "/" + path;
310
- } else {
311
- try{
312
- let path = item.uri;
313
- if (item.uri.startsWith(config.routerBase + "/")) {
314
- path = path.replace(config.routerBase + "/","")
315
- }
316
- let query = {};
317
- if (path.indexOf("?") > -1) {
318
- query = getUrlParams(path.substr(path.indexOf("?")));
319
- path = path.substr(0,path.indexOf("?"));
320
- }
321
- if (target && target.component) {
322
-
323
- } else {
324
- let component = require('@/view/' + path);
325
- if (component) {
326
- item.component = resolve => {
327
- require(['@/view/' + path], data => {
328
- data.default.name = item.name;
329
- resolve(data);
330
- });
331
- };
332
- } else {
333
- //console.warn(`${item.name}(${item.uri})页面不存在`)
334
- delete item.component;
335
- }
336
- }
337
- if (target && target.url) {
338
-
339
- } else {
340
- item.path = "/" + path;
341
- item.query = query;
342
- }
343
- }catch (e){
344
- //console.warn(`${item.name}(${item.uri})页面不存在`)
345
- delete item.component;
346
- }
347
- }
348
- }
349
- if (item.path == null) {
350
- item.path = "";
351
- }
352
- if (item.component && typeof item.component == "string") {
353
- delete item.component;
354
- }
355
- if (item.children && item.children.length > 0) {
356
- generator(item.children,constantRouterComponents);
357
- }
358
- }
359
- }
360
- return menuData;
361
- };
362
-
363
- /**
364
- * 根据权限组织tab数据
365
- * @param originMenuList
366
- * @param name
367
- * @param appId
368
- * @returns {{}}
369
- */
370
- export const generateTabDataFromPermission = (originMenuList,name,appId) => {
371
- let menuItem = {};
372
- if (name && originMenuList) {
373
- let originalMenu = originMenuList.find(item => item.name == name && item.type && item.type == '2' && (appId && item.appId == appId || !appId));
374
- if (originalMenu && originalMenu.name) {
375
- menuItem = {
376
- meta: {
377
- data: originalMenu,
378
- appId: originalMenu.appId,
379
- title: originalMenu.label,
380
- icon: originalMenu.icon,
381
- crumbs: [],
382
- activeName: originalMenu.name
383
- },
384
- permissionId: originalMenu.permissionId,
385
- pid: originalMenu.pid,
386
- type: originalMenu.type,
387
- name: originalMenu.name,
388
- uri: originalMenu.uri
389
- }
390
- }
391
- }
392
- return menuItem;
393
- }
394
-
395
- export default generatorMenuList;
1
+ import config from "../../config/config"
2
+ import {deepCopy} from "../assist";
3
+ import {getUrlParams} from "../platform"
4
+ /**
5
+ * 判断是否存在路由
6
+ * @param $router
7
+ * @param name
8
+ * @returns {*|boolean}
9
+ */
10
+ export const hasRoute = ($router, name) => {
11
+ let routes = $router.getRoutes();
12
+ let res = routes.filter(item => item.name === name)
13
+ return res && res.length > 0
14
+ }
15
+ /**
16
+ * 判断是否存在路由并且页面存在
17
+ * @param $router
18
+ * @param path
19
+ * @returns {*|boolean}
20
+ */
21
+ export const hasRoutePath = ($router, path) => {
22
+ if ($router && path) {
23
+ let routes = $router.getRoutes();
24
+ if (path.trim().startsWith("dida/")) {
25
+ path = path.trim().replace("dida/","");
26
+ if (!path.startsWith("/")) {
27
+ path = "/" + path;
28
+ }
29
+ } else if (path.trim().startsWith("dareport/")) {
30
+ path = path.trim().replace("dareport/","");
31
+ if (!path.startsWith("/")) {
32
+ path = "/" + path;
33
+ }
34
+ } else if (path.trim().startsWith("/" + config.routerBase + "/")) {
35
+ path = "/" + path.replace("/" + config.routerBase + "/","")
36
+ }
37
+ let res = routes.filter(item => item.path === path)
38
+ return res && res.length > 0
39
+ }
40
+ return false
41
+ }
42
+ /**
43
+ * 动态生成菜单
44
+ * @param permissionList
45
+ * @returns []
46
+ */
47
+ export const generatorMenuList = (permissionList,appId,generateType = 'router') => {
48
+ let menuRouter = generatorMenuRouter(permissionList,appId,generateType);
49
+ return menuRouter && menuRouter.menuData ? menuRouter.menuData : [];
50
+ };
51
+ /**
52
+ * 动态生成菜单
53
+ * @param generatorMenuRouter
54
+ * @returns []
55
+ */
56
+ export const generatorMenuRouter = (permissionList,appId,generateType = 'router') => {
57
+ let menuData = [],
58
+ pageNode = {
59
+ path: "/page",
60
+ name: "page",
61
+ meta: {
62
+ hideInMenu: true,
63
+ notCache: true
64
+ },
65
+ component: "Main",
66
+ children: []
67
+ };
68
+ listToMenuTree(permissionList, menuData, pageNode, "0", [], true,appId,generateType);
69
+ return {menuData,pageNode};
70
+ };
71
+
72
+
73
+ /**
74
+ * 数组转树形结构
75
+ */
76
+ const listToMenuTree = (list, menuTree, pageNode, parentId, crumbs, root, appId,generateType = 'router') => {
77
+ if (list == null) {
78
+ return;
79
+ }
80
+ list.forEach(item => {
81
+ let appIdCondition = !appId || item.appId == appId || appId.indexOf(item.appId) > -1;//过滤是否要求的应用
82
+ let hideInMenuCondition = !(item.hasOwnProperty("hideInMenu") && item.hideInMenu);//过滤是否隐藏的菜单
83
+ if ((generateType && generateType == 'router' && appIdCondition) ||
84
+ (generateType == 'menu' && appIdCondition && hideInMenuCondition)) {
85
+ // 判断是否为父级菜单
86
+ if (item.pid === parentId) {
87
+ if (item.type === 1 || item.type === 2) {
88
+ let node = {
89
+ meta: {
90
+ data: deepCopy(item),
91
+ appId: item.appId,
92
+ title: item.label,
93
+ icon: item.icon,
94
+ crumbs: [...crumbs],
95
+ activeName: item.name,
96
+ notCache: item.notCache ? true : false,
97
+ hideInMenu: item.hideInMenu ? true : false
98
+ },
99
+ permissionId: item.permissionId,
100
+ type: item.type,
101
+ pid: item.pid,
102
+ component: item.name,
103
+ name: item.name,
104
+ uri: item.uri,
105
+ children: []
106
+ };
107
+ node.meta.crumbs.push({
108
+ icon: item.icon,
109
+ name: item.name,
110
+ title: item.label,
111
+ type: item.type
112
+ });
113
+
114
+ if (item.type === 1) {
115
+ if (root) {
116
+ node.component = "Main";
117
+ } else {
118
+ node.component = "parentView";
119
+ }
120
+ }
121
+ // 迭代 list, 找到当前菜单相符合的所有子菜单
122
+ listToMenuTree(
123
+ list,
124
+ node.children,
125
+ pageNode,
126
+ item.permissionId,
127
+ node.meta.crumbs,
128
+ false,
129
+ appId,
130
+ generateType
131
+ );
132
+ // 删掉不存在 children 值的属性
133
+ if (node.children.length <= 0) {
134
+ delete node.children;
135
+ }
136
+ // 加入到树中
137
+ menuTree.push(node);
138
+ }
139
+ if (item.type === 4) {
140
+ let child = {
141
+ meta: {
142
+ data: deepCopy(item),
143
+ appId: item.appId,
144
+ title: item.label,
145
+ hideInMenu: true,
146
+ notCache: true,
147
+ crumbs: [...crumbs],
148
+ type: item.type
149
+ },
150
+ permissionId: item.permissionId,
151
+ type: item.type,
152
+ pid: item.pid,
153
+ component: item.name,
154
+ name: item.name,
155
+ uri: item.uri
156
+ };
157
+ child.meta.crumbs.push({
158
+ icon: item.icon,
159
+ name: item.name,
160
+ title: item.label,
161
+ type: item.type
162
+ });
163
+ pageNode.children.push(child);
164
+ }
165
+ }
166
+ }
167
+ });
168
+ };
169
+
170
+ /**
171
+ * 动态生成路由
172
+ * @param generatorMenuRouter
173
+ * @returns []
174
+ */
175
+ export const generatorDynamicRouter = (permissionList,constantRouterComponents,appIds = null,generateType = 'router') => {
176
+ let allMenu = generatorMenuRouter(permissionList, appIds,generateType);
177
+ let menuData = allMenu.menuData;
178
+ let pageNode = allMenu.pageNode;
179
+ if (menuData && pageNode && pageNode.children.length > 0) {
180
+ menuData.push(pageNode);
181
+ }
182
+ //给路由添加面包屑属性,解决示例页面左侧菜单点击不选中的问题
183
+ //routesAddCrumbs(exampleMenuData,[]);
184
+ //menuData = menuData.concat(exampleMenuData)
185
+ let dynamicRouter = generator(menuData,constantRouterComponents);
186
+
187
+ return dynamicRouter;
188
+ }
189
+ /**
190
+ * 路由添加面包屑属性
191
+ */
192
+ export const routesAddCrumbs = (routes ,crumbs) => {
193
+ routes.forEach(item => {
194
+ if (item.meta.hasOwnProperty('crumbs')){
195
+ item.meta.crumbs.push({
196
+ icon: item.meta.icon,
197
+ name: item.name,
198
+ title: item.meta.title,
199
+ type: item.type
200
+ });
201
+ }else{
202
+ item.meta['crumbs'] = [...crumbs];
203
+ item.meta.crumbs.push({
204
+ icon: item.meta.icon,
205
+ name: item.name,
206
+ title: item.meta.title,
207
+ type: item.type
208
+ });
209
+ }
210
+ if (item.hasOwnProperty("children")){
211
+ routesAddCrumbs(item.children,item.meta.crumbs)
212
+ }
213
+ });
214
+ }
215
+
216
+ /*
217
+ 生成 vue-router 层级路由表
218
+ */
219
+ const generator = (menuData,constantRouterComponents) => {
220
+ for (let item of menuData) {
221
+ if (item.component && typeof item.component == "string") {
222
+ const target = constantRouterComponents[item.component];
223
+ if (target) {
224
+ if (target.component) {
225
+ if (typeof target.component == "string") {
226
+ // 解决路由name与组件name不一致导致的keeplive不生效的问题
227
+ try {
228
+ //let componentPath = '@/view/' + target.component;
229
+ item.component = resolve =>
230
+ require(['@/view/'+ target.component], data => {
231
+ data.default.name = item.name;
232
+ resolve(data);
233
+ });
234
+ }catch (e) {
235
+ delete item.component
236
+ }
237
+ } else {
238
+ item.component = target.component;
239
+ }
240
+ }
241
+ if (target.url) {
242
+ let path = target.url;
243
+ let query = {};
244
+ if (path.indexOf("?") > -1) {
245
+ query = getUrlParams(path.substr(path.indexOf("?")));
246
+ item.query = query;
247
+ path = path.substr(0,path.indexOf("?"));
248
+ }
249
+ item.path = path;
250
+ }
251
+ if (item.uri) {
252
+ item.meta.uriParam = item.uri;
253
+ }
254
+ if (target.notCache) {
255
+ item.meta.notCache = target.notCache;
256
+ }
257
+ if (target.hideInMenu) {
258
+ item.meta.hideInMenu = target.hideInMenu;
259
+ }
260
+ }
261
+ if (item.uri) {
262
+ if (item.uri.startsWith("/")) {
263
+ item.uri = item.uri.substr(1);
264
+ }
265
+ let uri = item.uri;
266
+ if (uri.startsWith(config.routerBase + "/")) {
267
+ uri = uri.replace(config.routerBase + "/","")
268
+ }
269
+ if (uri.startsWith("dida/")) {
270
+ item.meta.notCache = true;
271
+ let path = uri;
272
+ let query = {};
273
+ if (path.indexOf("?") > -1) {
274
+ query = getUrlParams(path.substr(path.indexOf("?")));
275
+ item.query = query;
276
+ path = path.substr(0,path.indexOf("?"));
277
+ }
278
+ try{
279
+ //let path = '@/view/dida/dida-page';
280
+ item.component = resolve => {
281
+ require(['@/view/dida/dida-page'], data => {
282
+ data.default.name = item.name;
283
+ resolve(data);
284
+ });
285
+ };
286
+ }catch (e){
287
+ delete item.component
288
+ }
289
+ item.path = "/" + path;
290
+ } else if(uri.startsWith("dareport/")){
291
+ item.meta.notCache = true;
292
+ let path = uri;
293
+ let query = {};
294
+ if (path.indexOf("?") > -1) {
295
+ query = getUrlParams(path.substr(path.indexOf("?")));
296
+ item.query = query;
297
+ path = path.substr(0,path.indexOf("?"));
298
+ }
299
+ try{
300
+ item.component = resolve => {
301
+ require(['@/view/dida/dida-page'], data => {
302
+ data.default.name = item.name;
303
+ resolve(data);
304
+ });
305
+ };
306
+ }catch (e){
307
+ delete item.component
308
+ }
309
+ item.path = "/" + path;
310
+ } else {
311
+ try{
312
+ let path = item.uri;
313
+ if (item.uri.startsWith(config.routerBase + "/")) {
314
+ path = path.replace(config.routerBase + "/","")
315
+ }
316
+ let query = {};
317
+ if (path.indexOf("?") > -1) {
318
+ query = getUrlParams(path.substr(path.indexOf("?")));
319
+ path = path.substr(0,path.indexOf("?"));
320
+ }
321
+ if (target && target.component) {
322
+
323
+ } else {
324
+ let component = require('@/view/' + path);
325
+ if (component) {
326
+ item.component = resolve => {
327
+ require(['@/view/' + path], data => {
328
+ data.default.name = item.name;
329
+ resolve(data);
330
+ });
331
+ };
332
+ } else {
333
+ //console.warn(`${item.name}(${item.uri})页面不存在`)
334
+ delete item.component;
335
+ }
336
+ }
337
+ if (target && target.url) {
338
+
339
+ } else {
340
+ item.path = "/" + path;
341
+ item.query = query;
342
+ }
343
+ }catch (e){
344
+ //console.warn(`${item.name}(${item.uri})页面不存在`)
345
+ delete item.component;
346
+ }
347
+ }
348
+ }
349
+ if (item.path == null) {
350
+ item.path = "";
351
+ }
352
+ if (item.component && typeof item.component == "string") {
353
+ delete item.component;
354
+ }
355
+ if (item.children && item.children.length > 0) {
356
+ generator(item.children,constantRouterComponents);
357
+ }
358
+ }
359
+ }
360
+ return menuData;
361
+ };
362
+
363
+ /**
364
+ * 根据权限组织tab数据
365
+ * @param originMenuList
366
+ * @param name
367
+ * @param appId
368
+ * @returns {{}}
369
+ */
370
+ export const generateTabDataFromPermission = (originMenuList,name,appId) => {
371
+ let menuItem = {};
372
+ if (name && originMenuList) {
373
+ let originalMenu = originMenuList.find(item => item.name == name && item.type && item.type == '2' && (appId && item.appId == appId || !appId));
374
+ if (originalMenu && originalMenu.name) {
375
+ menuItem = {
376
+ meta: {
377
+ data: originalMenu,
378
+ appId: originalMenu.appId,
379
+ title: originalMenu.label,
380
+ icon: originalMenu.icon,
381
+ crumbs: [],
382
+ activeName: originalMenu.name
383
+ },
384
+ permissionId: originalMenu.permissionId,
385
+ pid: originalMenu.pid,
386
+ type: originalMenu.type,
387
+ name: originalMenu.name,
388
+ uri: originalMenu.uri
389
+ }
390
+ }
391
+ }
392
+ return menuItem;
393
+ }
394
+
395
+ export default generatorMenuList;