vue2-client 1.4.32 → 1.4.34

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