vue2-client 1.2.4 → 1.2.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.
@@ -1,366 +1,366 @@
1
- import routerMap from '@vue2-client/router/async/router.map'
2
- import { mergeI18nFromRoutes } from '@vue2-client/utils/i18n'
3
- import Router from 'vue-router'
4
- import deepMerge from 'deepmerge'
5
- import basicOptions from '@vue2-client/router/async/config.async'
6
-
7
- // 应用配置
8
- const appOptions = {
9
- router: undefined,
10
- i18n: undefined,
11
- store: undefined
12
- }
13
-
14
- /**
15
- * 设置应用配置
16
- * @param options
17
- */
18
- function setAppOptions (options) {
19
- const { router, store, i18n } = options
20
- appOptions.router = router
21
- appOptions.store = store
22
- appOptions.i18n = i18n
23
- }
24
-
25
- // 应用路由资源
26
- const appRouterMap = {
27
- routerMap: routerMap
28
- }
29
-
30
- /**
31
- * 设置应用路由资源
32
- * @param options
33
- */
34
- function setAppRouterMap (router) {
35
- appRouterMap.routerMap = Object.assign(appRouterMap.routerMap, router)
36
- }
37
-
38
- /**
39
- * 根据 路由配置 和 路由组件注册 解析路由
40
- * @param routesConfig 路由配置
41
- * @param routerMap 本地路由组件注册配置
42
- */
43
- function parseRoutes (routesConfig, routerMap) {
44
- const routes = []
45
- routesConfig.forEach(item => {
46
- // 获取注册在 routerMap 中的 router,初始化 routeCfg
47
- let router; let routeCfg = {}
48
- if (typeof item === 'string') {
49
- router = routerMap[item]
50
- routeCfg = { path: (router && router.path) || item, router: item }
51
- } else if (typeof item === 'object') {
52
- // 当没有设置路由对象名或者设置的是blank路由对象时, 给空界面, path为名称
53
- if (!item.router || item.router == 'blank') {
54
- router = routerMap['blank']
55
- item.path = item.name
56
- } else {
57
- router = routerMap[item.router]
58
- }
59
- // 查看是否是单页面
60
- if (item.meta && item.meta.singlePage) {
61
- router = routerMap['singlePage']
62
- item.path = item.name
63
- }
64
- // 当没在动态路由对象中找到时, 给404页面
65
- if (!router) {
66
- router = routerMap['exp404']
67
- item.path = item.name
68
- }
69
- routeCfg = item
70
- }
71
- if (!router) {
72
- console.warn(`can't find register for router ${routeCfg.router}, please register it in advance.`)
73
- router = typeof item === 'string' ? { path: item, name: item } : item
74
- }
75
- // 从 router 和 routeCfg 解析路由
76
- const meta = {
77
- authority: router.authority,
78
- icon: router.icon,
79
- page: router.page,
80
- link: router.link,
81
- params: router.params,
82
- query: router.query,
83
- ...router.meta
84
- }
85
- const cfgMeta = {
86
- authority: routeCfg.authority,
87
- icon: routeCfg.icon,
88
- page: routeCfg.page,
89
- link: routeCfg.link,
90
- params: routeCfg.params,
91
- query: routeCfg.query,
92
- ...routeCfg.meta
93
- }
94
- Object.keys(cfgMeta).forEach(key => {
95
- if (cfgMeta[key] === undefined || cfgMeta[key] === null || cfgMeta[key] === '') {
96
- delete cfgMeta[key]
97
- }
98
- })
99
- Object.assign(meta, cfgMeta)
100
- const route = {
101
- path: routeCfg.path || router.path || routeCfg.router,
102
- name: routeCfg.name || router.name,
103
- component: router.component || router,
104
- redirect: routeCfg.redirect || router.redirect,
105
- meta: { ...meta, authority: meta.authority || '*' }
106
- }
107
- if (routeCfg.invisible || router.invisible) {
108
- route.meta.invisible = true
109
- }
110
- if (routeCfg.children && routeCfg.children.length > 0) {
111
- route.children = parseRoutes(routeCfg.children, routerMap)
112
- }
113
- routes.push(route)
114
- })
115
- return routes
116
- }
117
-
118
- /**
119
- * 加载路由
120
- * @param routesConfig {[{router: string, children: [{router: string, children: string[]}, {router: string, children: string[]}, {router: string, authority: string, name: string, icon: string}, {path: string, router: string, name: string, icon: string, link: string}, {path: string, router: string, name: string, icon: string, link: string}]}]} 路由配置
121
- */
122
- function loadRoutes (routesConfig) {
123
- // 兼容 0.6.1 以下版本
124
- /** ************* 兼容 version < v0.6.1 *****************/
125
- if (arguments.length > 0) {
126
- const arg0 = arguments[0]
127
- if (arg0.router || arg0.i18n || arg0.store) {
128
- routesConfig = arguments[1]
129
- console.error('the usage of signature loadRoutes({router, store, i18n}, routesConfig) is out of date, please use the new signature: loadRoutes(routesConfig).')
130
- console.error('方法签名 loadRoutes({router, store, i18n}, routesConfig) 的用法已过时, 请使用新的方法签名 loadRoutes(routesConfig)。')
131
- }
132
- }
133
- /** ************* 兼容 version < v0.6.1 *****************/
134
-
135
- // 应用配置
136
- const { router, store, i18n } = appOptions
137
-
138
- // 如果 routesConfig 有值,则更新到本地,否则从本地获取
139
- if (routesConfig) {
140
- store.commit('account/setRoutesConfig', routesConfig)
141
- } else {
142
- routesConfig = store.getters['account/routesConfig']
143
- }
144
- // 如果开启了异步路由,则加载异步路由配置
145
- const asyncRoutes = store.state.setting.asyncRoutes
146
- if (asyncRoutes) {
147
- if (routesConfig && routesConfig.length > 0) {
148
- const routes = parseRoutes(routesConfig, appRouterMap.routerMap)
149
- const finalRoutes = mergeRoutes(basicOptions.routes, routes)
150
- formatRoutes(finalRoutes)
151
- router.options = { ...router.options, routes: finalRoutes }
152
- router.matcher = new Router({ ...router.options, routes: [] }).matcher
153
- router.addRoutes(finalRoutes)
154
- }
155
- }
156
- // 提取路由国际化数据
157
- mergeI18nFromRoutes(i18n, router.options.routes)
158
- // 初始化Admin后台菜单数据
159
- const rootRoute = router.options.routes.find(item => item.path === '/')
160
- const menuRoutes = rootRoute && rootRoute.children
161
- if (menuRoutes) {
162
- store.commit('setting/setMenuData', menuRoutes)
163
- }
164
- }
165
-
166
- /**
167
- * 合并路由
168
- * @param target {Route[]}
169
- * @param source {Route[]}
170
- * @returns {Route[]}
171
- */
172
- function mergeRoutes (target, source) {
173
- const routesMap = {}
174
- // eslint-disable-next-line no-return-assign
175
- target.forEach(item => routesMap[item.path] = item)
176
- // eslint-disable-next-line no-return-assign
177
- source.forEach(item => routesMap[item.path] = item)
178
- return Object.values(routesMap)
179
- }
180
-
181
- /**
182
- * 深度合并路由
183
- * @param target {Route[]}
184
- * @param source {Route[]}
185
- * @returns {Route[]}
186
- */
187
- function deepMergeRoutes (target, source) {
188
- // 映射路由数组
189
- const mapRoutes = routes => {
190
- const routesMap = {}
191
- routes.forEach(item => {
192
- routesMap[item.path] = {
193
- ...item,
194
- children: item.children ? mapRoutes(item.children) : undefined
195
- }
196
- })
197
- return routesMap
198
- }
199
- const tarMap = mapRoutes(target)
200
- const srcMap = mapRoutes(source)
201
-
202
- // 合并路由
203
- const merge = deepMerge(tarMap, srcMap)
204
-
205
- // 转换为 routes 数组
206
- const parseRoutesMap = routesMap => {
207
- return Object.values(routesMap).map(item => {
208
- if (item.children) {
209
- item.children = parseRoutesMap(item.children)
210
- } else {
211
- delete item.children
212
- }
213
- return item
214
- })
215
- }
216
- return parseRoutesMap(merge)
217
- }
218
-
219
- /**
220
- * 格式化路由
221
- * @param routes 路由配置
222
- */
223
- function formatRoutes (routes) {
224
- routes.forEach(route => {
225
- const { path } = route
226
- if (!path.startsWith('/') && path !== '*') {
227
- route.path = '/' + path
228
- }
229
- })
230
- formatAuthority(routes)
231
- }
232
-
233
- /**
234
- * 格式化路由的权限配置
235
- * @param routes 路由
236
- * @param pAuthorities 父级路由权限配置集合
237
- */
238
- function formatAuthority (routes, pAuthorities = []) {
239
- routes.forEach(route => {
240
- const meta = route.meta
241
- const defaultAuthority = pAuthorities[pAuthorities.length - 1] || { permission: '*' }
242
- if (meta) {
243
- let authority = {}
244
- if (!meta.authority) {
245
- authority = defaultAuthority
246
- } else if (typeof meta.authority === 'string') {
247
- authority.permission = meta.authority
248
- } else if (typeof meta.authority === 'object') {
249
- authority = meta.authority
250
- const { role } = authority
251
- if (typeof role === 'string') {
252
- authority.role = [role]
253
- }
254
- if (!authority.permission && !authority.role) {
255
- authority = defaultAuthority
256
- }
257
- }
258
- meta.authority = authority
259
- } else {
260
- const authority = defaultAuthority
261
- route.meta = { authority }
262
- }
263
- route.meta.pAuthorities = pAuthorities
264
- if (route.children) {
265
- formatAuthority(route.children, [...pAuthorities, route.meta.authority])
266
- }
267
- })
268
- }
269
-
270
- /**
271
- * 从路由 path 解析 i18n key
272
- * @param path
273
- * @returns {*}
274
- */
275
- function getI18nKey (path) {
276
- const keys = path.split('/').filter(item => !item.startsWith(':') && item != '')
277
- keys.push('name')
278
- return keys.join('.')
279
- }
280
-
281
- /**
282
- * 加载导航守卫
283
- * @param guards
284
- * @param options
285
- */
286
- function loadGuards (guards, options) {
287
- const { beforeEach, afterEach } = guards
288
- const { router } = options
289
- beforeEach.forEach(guard => {
290
- if (guard && typeof guard === 'function') {
291
- router.beforeEach((to, from, next) => guard(to, from, next, options))
292
- }
293
- })
294
- afterEach.forEach(guard => {
295
- if (guard && typeof guard === 'function') {
296
- router.afterEach((to, from) => guard(to, from, options))
297
- }
298
- })
299
- }
300
-
301
- /**
302
- * 资源服务路由转新路由
303
- * @param func
304
- */
305
- function funcToRouter (func) {
306
- const router = [{
307
- router: 'root',
308
- children: positionRouter(parsefunc(func))
309
- }]
310
- // 任何情况首位加入资源管理
311
- const resourceManageMain = {
312
- router: 'resourceManageMain',
313
- position: 0,
314
- icon: 'api',
315
- name: '资源管理'
316
- }
317
- router[0].children.unshift(resourceManageMain)
318
- return router
319
- }
320
-
321
- function parsefunc (func) {
322
- const router = []
323
- for (const row of func) {
324
- const route = {
325
- router: row.link,
326
- meta: {
327
- singlePage: row.navigate
328
- },
329
- position: row.position - 1,
330
- icon: row.icon,
331
- name: row.name
332
- }
333
- if (row.children && row.children.length > 0) {
334
- route.children = parsefunc(row.children)
335
- }
336
- router.push(route)
337
- }
338
- return router
339
- }
340
-
341
- /**
342
- * 资源服务路由排序
343
- */
344
- function positionRouter (r) {
345
- let router = []
346
- for (const row of r) {
347
- router[row.position] = row
348
- }
349
- router = arrRemoveEmpty(router)
350
- return router
351
- }
352
-
353
- /**
354
- * 数组去空值
355
- */
356
- function arrRemoveEmpty (arr) {
357
- for (var i = 0; i < arr.length; i++) {
358
- if (arr[i] == '' || typeof (arr[i]) == 'undefined') {
359
- arr.splice(i, 1)
360
- i--
361
- }
362
- }
363
- return arr
364
- }
365
-
366
- export { parseRoutes, loadRoutes, formatAuthority, getI18nKey, loadGuards, deepMergeRoutes, formatRoutes, setAppOptions, funcToRouter, setAppRouterMap }
1
+ import routerMap from '@vue2-client/router/async/router.map'
2
+ import { mergeI18nFromRoutes } from '@vue2-client/utils/i18n'
3
+ import Router from 'vue-router'
4
+ import deepMerge from 'deepmerge'
5
+ import basicOptions from '@vue2-client/router/async/config.async'
6
+
7
+ // 应用配置
8
+ const appOptions = {
9
+ router: undefined,
10
+ i18n: undefined,
11
+ store: undefined
12
+ }
13
+
14
+ /**
15
+ * 设置应用配置
16
+ * @param options
17
+ */
18
+ function setAppOptions (options) {
19
+ const { router, store, i18n } = options
20
+ appOptions.router = router
21
+ appOptions.store = store
22
+ appOptions.i18n = i18n
23
+ }
24
+
25
+ // 应用路由资源
26
+ const appRouterMap = {
27
+ routerMap: routerMap
28
+ }
29
+
30
+ /**
31
+ * 设置应用路由资源
32
+ * @param options
33
+ */
34
+ function setAppRouterMap (router) {
35
+ appRouterMap.routerMap = Object.assign(appRouterMap.routerMap, router)
36
+ }
37
+
38
+ /**
39
+ * 根据 路由配置 和 路由组件注册 解析路由
40
+ * @param routesConfig 路由配置
41
+ * @param routerMap 本地路由组件注册配置
42
+ */
43
+ function parseRoutes (routesConfig, routerMap) {
44
+ const routes = []
45
+ routesConfig.forEach(item => {
46
+ // 获取注册在 routerMap 中的 router,初始化 routeCfg
47
+ let router; let routeCfg = {}
48
+ if (typeof item === 'string') {
49
+ router = routerMap[item]
50
+ routeCfg = { path: (router && router.path) || item, router: item }
51
+ } else if (typeof item === 'object') {
52
+ // 当没有设置路由对象名或者设置的是blank路由对象时, 给空界面, path为名称
53
+ if (!item.router || item.router == 'blank') {
54
+ router = routerMap['blank']
55
+ item.path = item.name
56
+ } else {
57
+ router = routerMap[item.router]
58
+ }
59
+ // 查看是否是单页面
60
+ if (item.meta && item.meta.singlePage) {
61
+ router = routerMap['singlePage']
62
+ item.path = item.name
63
+ }
64
+ // 当没在动态路由对象中找到时, 给404页面
65
+ if (!router) {
66
+ router = routerMap['exp404']
67
+ item.path = item.name
68
+ }
69
+ routeCfg = item
70
+ }
71
+ if (!router) {
72
+ console.warn(`can't find register for router ${routeCfg.router}, please register it in advance.`)
73
+ router = typeof item === 'string' ? { path: item, name: item } : item
74
+ }
75
+ // 从 router 和 routeCfg 解析路由
76
+ const meta = {
77
+ authority: router.authority,
78
+ icon: router.icon,
79
+ page: router.page,
80
+ link: router.link,
81
+ params: router.params,
82
+ query: router.query,
83
+ ...router.meta
84
+ }
85
+ const cfgMeta = {
86
+ authority: routeCfg.authority,
87
+ icon: routeCfg.icon,
88
+ page: routeCfg.page,
89
+ link: routeCfg.link,
90
+ params: routeCfg.params,
91
+ query: routeCfg.query,
92
+ ...routeCfg.meta
93
+ }
94
+ Object.keys(cfgMeta).forEach(key => {
95
+ if (cfgMeta[key] === undefined || cfgMeta[key] === null || cfgMeta[key] === '') {
96
+ delete cfgMeta[key]
97
+ }
98
+ })
99
+ Object.assign(meta, cfgMeta)
100
+ const route = {
101
+ path: routeCfg.path || router.path || routeCfg.router,
102
+ name: routeCfg.name || router.name,
103
+ component: router.component || router,
104
+ redirect: routeCfg.redirect || router.redirect,
105
+ meta: { ...meta, authority: meta.authority || '*' }
106
+ }
107
+ if (routeCfg.invisible || router.invisible) {
108
+ route.meta.invisible = true
109
+ }
110
+ if (routeCfg.children && routeCfg.children.length > 0) {
111
+ route.children = parseRoutes(routeCfg.children, routerMap)
112
+ }
113
+ routes.push(route)
114
+ })
115
+ return routes
116
+ }
117
+
118
+ /**
119
+ * 加载路由
120
+ * @param routesConfig {[{router: string, children: [{router: string, children: string[]}, {router: string, children: string[]}, {router: string, authority: string, name: string, icon: string}, {path: string, router: string, name: string, icon: string, link: string}, {path: string, router: string, name: string, icon: string, link: string}]}]} 路由配置
121
+ */
122
+ function loadRoutes (routesConfig) {
123
+ // 兼容 0.6.1 以下版本
124
+ /** ************* 兼容 version < v0.6.1 *****************/
125
+ if (arguments.length > 0) {
126
+ const arg0 = arguments[0]
127
+ if (arg0.router || arg0.i18n || arg0.store) {
128
+ routesConfig = arguments[1]
129
+ console.error('the usage of signature loadRoutes({router, store, i18n}, routesConfig) is out of date, please use the new signature: loadRoutes(routesConfig).')
130
+ console.error('方法签名 loadRoutes({router, store, i18n}, routesConfig) 的用法已过时, 请使用新的方法签名 loadRoutes(routesConfig)。')
131
+ }
132
+ }
133
+ /** ************* 兼容 version < v0.6.1 *****************/
134
+
135
+ // 应用配置
136
+ const { router, store, i18n } = appOptions
137
+
138
+ // 如果 routesConfig 有值,则更新到本地,否则从本地获取
139
+ if (routesConfig) {
140
+ store.commit('account/setRoutesConfig', routesConfig)
141
+ } else {
142
+ routesConfig = store.getters['account/routesConfig']
143
+ }
144
+ // 如果开启了异步路由,则加载异步路由配置
145
+ const asyncRoutes = store.state.setting.asyncRoutes
146
+ if (asyncRoutes) {
147
+ if (routesConfig && routesConfig.length > 0) {
148
+ const routes = parseRoutes(routesConfig, appRouterMap.routerMap)
149
+ const finalRoutes = mergeRoutes(basicOptions.routes, routes)
150
+ formatRoutes(finalRoutes)
151
+ router.options = { ...router.options, routes: finalRoutes }
152
+ router.matcher = new Router({ ...router.options, routes: [] }).matcher
153
+ router.addRoutes(finalRoutes)
154
+ }
155
+ }
156
+ // 提取路由国际化数据
157
+ mergeI18nFromRoutes(i18n, router.options.routes)
158
+ // 初始化Admin后台菜单数据
159
+ const rootRoute = router.options.routes.find(item => item.path === '/')
160
+ const menuRoutes = rootRoute && rootRoute.children
161
+ if (menuRoutes) {
162
+ store.commit('setting/setMenuData', menuRoutes)
163
+ }
164
+ }
165
+
166
+ /**
167
+ * 合并路由
168
+ * @param target {Route[]}
169
+ * @param source {Route[]}
170
+ * @returns {Route[]}
171
+ */
172
+ function mergeRoutes (target, source) {
173
+ const routesMap = {}
174
+ // eslint-disable-next-line no-return-assign
175
+ target.forEach(item => routesMap[item.path] = item)
176
+ // eslint-disable-next-line no-return-assign
177
+ source.forEach(item => routesMap[item.path] = item)
178
+ return Object.values(routesMap)
179
+ }
180
+
181
+ /**
182
+ * 深度合并路由
183
+ * @param target {Route[]}
184
+ * @param source {Route[]}
185
+ * @returns {Route[]}
186
+ */
187
+ function deepMergeRoutes (target, source) {
188
+ // 映射路由数组
189
+ const mapRoutes = routes => {
190
+ const routesMap = {}
191
+ routes.forEach(item => {
192
+ routesMap[item.path] = {
193
+ ...item,
194
+ children: item.children ? mapRoutes(item.children) : undefined
195
+ }
196
+ })
197
+ return routesMap
198
+ }
199
+ const tarMap = mapRoutes(target)
200
+ const srcMap = mapRoutes(source)
201
+
202
+ // 合并路由
203
+ const merge = deepMerge(tarMap, srcMap)
204
+
205
+ // 转换为 routes 数组
206
+ const parseRoutesMap = routesMap => {
207
+ return Object.values(routesMap).map(item => {
208
+ if (item.children) {
209
+ item.children = parseRoutesMap(item.children)
210
+ } else {
211
+ delete item.children
212
+ }
213
+ return item
214
+ })
215
+ }
216
+ return parseRoutesMap(merge)
217
+ }
218
+
219
+ /**
220
+ * 格式化路由
221
+ * @param routes 路由配置
222
+ */
223
+ function formatRoutes (routes) {
224
+ routes.forEach(route => {
225
+ const { path } = route
226
+ if (!path.startsWith('/') && path !== '*') {
227
+ route.path = '/' + path
228
+ }
229
+ })
230
+ formatAuthority(routes)
231
+ }
232
+
233
+ /**
234
+ * 格式化路由的权限配置
235
+ * @param routes 路由
236
+ * @param pAuthorities 父级路由权限配置集合
237
+ */
238
+ function formatAuthority (routes, pAuthorities = []) {
239
+ routes.forEach(route => {
240
+ const meta = route.meta
241
+ const defaultAuthority = pAuthorities[pAuthorities.length - 1] || { permission: '*' }
242
+ if (meta) {
243
+ let authority = {}
244
+ if (!meta.authority) {
245
+ authority = defaultAuthority
246
+ } else if (typeof meta.authority === 'string') {
247
+ authority.permission = meta.authority
248
+ } else if (typeof meta.authority === 'object') {
249
+ authority = meta.authority
250
+ const { role } = authority
251
+ if (typeof role === 'string') {
252
+ authority.role = [role]
253
+ }
254
+ if (!authority.permission && !authority.role) {
255
+ authority = defaultAuthority
256
+ }
257
+ }
258
+ meta.authority = authority
259
+ } else {
260
+ const authority = defaultAuthority
261
+ route.meta = { authority }
262
+ }
263
+ route.meta.pAuthorities = pAuthorities
264
+ if (route.children) {
265
+ formatAuthority(route.children, [...pAuthorities, route.meta.authority])
266
+ }
267
+ })
268
+ }
269
+
270
+ /**
271
+ * 从路由 path 解析 i18n key
272
+ * @param path
273
+ * @returns {*}
274
+ */
275
+ function getI18nKey (path) {
276
+ const keys = path.split('/').filter(item => !item.startsWith(':') && item != '')
277
+ keys.push('name')
278
+ return keys.join('.')
279
+ }
280
+
281
+ /**
282
+ * 加载导航守卫
283
+ * @param guards
284
+ * @param options
285
+ */
286
+ function loadGuards (guards, options) {
287
+ const { beforeEach, afterEach } = guards
288
+ const { router } = options
289
+ beforeEach.forEach(guard => {
290
+ if (guard && typeof guard === 'function') {
291
+ router.beforeEach((to, from, next) => guard(to, from, next, options))
292
+ }
293
+ })
294
+ afterEach.forEach(guard => {
295
+ if (guard && typeof guard === 'function') {
296
+ router.afterEach((to, from) => guard(to, from, options))
297
+ }
298
+ })
299
+ }
300
+
301
+ /**
302
+ * 资源服务路由转新路由
303
+ * @param func
304
+ */
305
+ function funcToRouter (func) {
306
+ const router = [{
307
+ router: 'root',
308
+ children: positionRouter(parsefunc(func))
309
+ }]
310
+ // 任何情况首位加入资源管理
311
+ const resourceManageMain = {
312
+ router: 'resourceManageMain',
313
+ position: 0,
314
+ icon: 'api',
315
+ name: '资源管理'
316
+ }
317
+ router[0].children.unshift(resourceManageMain)
318
+ return router
319
+ }
320
+
321
+ function parsefunc (func) {
322
+ const router = []
323
+ for (const row of func) {
324
+ const route = {
325
+ router: row.link,
326
+ meta: {
327
+ singlePage: row.navigate
328
+ },
329
+ position: row.position - 1,
330
+ icon: row.icon,
331
+ name: row.name
332
+ }
333
+ if (row.children && row.children.length > 0) {
334
+ route.children = parsefunc(row.children)
335
+ }
336
+ router.push(route)
337
+ }
338
+ return router
339
+ }
340
+
341
+ /**
342
+ * 资源服务路由排序
343
+ */
344
+ function positionRouter (r) {
345
+ let router = []
346
+ for (const row of r) {
347
+ router[row.position] = row
348
+ }
349
+ router = arrRemoveEmpty(router)
350
+ return router
351
+ }
352
+
353
+ /**
354
+ * 数组去空值
355
+ */
356
+ function arrRemoveEmpty (arr) {
357
+ for (var i = 0; i < arr.length; i++) {
358
+ if (arr[i] == '' || typeof (arr[i]) == 'undefined') {
359
+ arr.splice(i, 1)
360
+ i--
361
+ }
362
+ }
363
+ return arr
364
+ }
365
+
366
+ export { parseRoutes, loadRoutes, formatAuthority, getI18nKey, loadGuards, deepMergeRoutes, formatRoutes, setAppOptions, funcToRouter, setAppRouterMap }