vue2-client 1.2.37-2 → 1.2.40

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