@@ -2,23 +2,6 @@ import Util from '@/lin/util/util'
2
2
3
3
let stageMap = { }
4
4
5
- const deepTravel = ( obj , fuc ) => {
6
- if ( Array . isArray ( obj ) ) {
7
- obj . forEach ( item => {
8
- deepTravel ( item , fuc )
9
- } )
10
- return
11
- }
12
- if ( obj && obj . children ) {
13
- fuc ( obj )
14
- deepTravel ( obj . children , fuc )
15
- return
16
- }
17
- if ( obj . name ) {
18
- fuc ( obj )
19
- }
20
- }
21
-
22
5
export const loggedIn = state => state . loggedIn
23
6
24
7
export const user = state => state . user
@@ -27,43 +10,6 @@ export const alreadyReadMessages = state => state.alreadyReadMessages
27
10
28
11
export const unreadMessages = state => state . unreadMessages
29
12
30
- /**
31
- * 在侧边栏展示时,如果当前路由 children 属性为空,则删除该路由
32
- * @param {* } arr 路由配置项数据
33
- */
34
- function IterationDelateMenuChildren ( arr ) {
35
- if ( arr . length ) {
36
- // eslint-disable-next-line no-unused-vars
37
- for ( const i in arr ) {
38
- if ( arr [ i ] . children && ! arr [ i ] . children . length ) {
39
- delete arr [ i ]
40
- } else if ( arr [ i ] . children && arr [ i ] . children . length ) {
41
- IterationDelateMenuChildren ( arr [ i ] . children )
42
- }
43
- }
44
- }
45
- return arr
46
- }
47
-
48
- /**
49
- * Shaking 掉无权限路由
50
- * @param {array } stageConfig 路由配置项数据
51
- * @param {array } permissions 当前登录管理员所拥有的权限集合
52
- * @param {object } currentUser 当前登录管理员
53
- */
54
- function permissionShaking ( stageConfig , permissions , currentUser ) {
55
- const shookConfig = stageConfig . filter ( route => {
56
- if ( Util . hasPermission ( permissions , route , currentUser ) ) {
57
- if ( route . children && route . children . length ) {
58
- route . children = permissionShaking ( route . children , permissions , currentUser )
59
- }
60
- return true
61
- }
62
- return false
63
- } )
64
- return IterationDelateMenuChildren ( shookConfig )
65
- }
66
-
67
13
/**
68
14
* 获取有权限的舞台配置
69
15
* @param {* } state
@@ -216,3 +162,62 @@ export const getStageInfo = state => {
216
162
return stageInfo
217
163
}
218
164
}
165
+
166
+ /**
167
+ * 递归
168
+ * @param {* } obj
169
+ * @param {* } fuc
170
+ */
171
+ function deepTravel ( obj , fuc ) {
172
+ if ( Array . isArray ( obj ) ) {
173
+ obj . forEach ( item => {
174
+ deepTravel ( item , fuc )
175
+ } )
176
+ return
177
+ }
178
+ if ( obj && obj . children ) {
179
+ fuc ( obj )
180
+ deepTravel ( obj . children , fuc )
181
+ return
182
+ }
183
+ if ( obj . name ) {
184
+ fuc ( obj )
185
+ }
186
+ }
187
+
188
+ /**
189
+ * 在侧边栏展示时,如果当前路由 children 属性为空,则删除该路由
190
+ * @param {* } arr 路由配置项数据
191
+ */
192
+ function IterationDelateMenuChildren ( arr ) {
193
+ if ( arr . length ) {
194
+ // eslint-disable-next-line no-unused-vars
195
+ for ( const i in arr ) {
196
+ if ( arr [ i ] . children && ! arr [ i ] . children . length ) {
197
+ delete arr [ i ]
198
+ } else if ( arr [ i ] . children && arr [ i ] . children . length ) {
199
+ IterationDelateMenuChildren ( arr [ i ] . children )
200
+ }
201
+ }
202
+ }
203
+ return arr
204
+ }
205
+
206
+ /**
207
+ * Shaking 掉无权限路由
208
+ * @param {array } stageConfig 路由配置项数据
209
+ * @param {array } permissions 当前登录管理员所拥有的权限集合
210
+ * @param {object } currentUser 当前登录管理员
211
+ */
212
+ function permissionShaking ( stageConfig , permissions , currentUser ) {
213
+ const shookConfig = stageConfig . filter ( route => {
214
+ if ( Util . hasPermission ( permissions , route , currentUser ) ) {
215
+ if ( route . children && route . children . length ) {
216
+ route . children = permissionShaking ( route . children , permissions , currentUser )
217
+ }
218
+ return true
219
+ }
220
+ return false
221
+ } )
222
+ return IterationDelateMenuChildren ( shookConfig )
223
+ }
0 commit comments