vue2-client 1.3.1 → 1.3.2

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