vue2-client 1.3.13 → 1.3.14

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 (96) hide show
  1. package/CHANGELOG.md +311 -308
  2. package/index.js +30 -30
  3. package/package.json +76 -76
  4. package/src/base-client/components/common/AddressSearchCombobox/AddressSearchCombobox.vue +225 -225
  5. package/src/base-client/components/common/CreateQuery/CreateQuery.vue +551 -551
  6. package/src/base-client/components/common/CreateQuery/CreateQueryItem.vue +777 -777
  7. package/src/base-client/components/common/CreateSimpleFormQuery/CreateSimpleFormQueryItem.vue +553 -553
  8. package/src/base-client/components/common/CustomColumnsDrawer/index.md +46 -46
  9. package/src/base-client/components/common/FormGroupQuery/FormGroupQuery.vue +165 -165
  10. package/src/base-client/components/common/JSONToTree/jsontotree.vue +275 -275
  11. package/src/base-client/components/common/Upload/Upload.vue +161 -161
  12. package/src/base-client/components/common/XAddForm/XAddForm.vue +353 -353
  13. package/src/base-client/components/common/XAddNativeForm/XAddNativeForm.vue +326 -326
  14. package/src/base-client/components/common/XCard/XCard.vue +64 -64
  15. package/src/base-client/components/common/XForm/XForm.vue +273 -273
  16. package/src/base-client/components/common/XForm/XFormItem.vue +389 -389
  17. package/src/base-client/components/common/XFormTable/XFormTable.vue +505 -505
  18. package/src/base-client/components/common/XFormTable/index.md +96 -96
  19. package/src/base-client/components/common/XTable/XTable.vue +278 -278
  20. package/src/base-client/components/system/LogDetailsView/LogDetailsView.vue +376 -376
  21. package/src/base-client/components/system/QueryParamsDetailsView/QueryParamsDetailsView.vue +281 -281
  22. package/src/base-client/components/ticket/TicketDetailsView/TicketDetailsView.vue +807 -807
  23. package/src/base-client/components/ticket/TicketDetailsView/index.md +29 -29
  24. package/src/base-client/components/ticket/TicketDetailsView/part/TicketDetailsFlow.vue +260 -260
  25. package/src/base-client/components/ticket/TicketSubmitSuccessView/TicketSubmitSuccessView.vue +532 -532
  26. package/src/base-client/components/ticket/TicketSubmitSuccessView/index.md +29 -29
  27. package/src/base-client/plugins/AppData.js +69 -69
  28. package/src/base-client/plugins/GetLoginInfoService.js +179 -179
  29. package/src/base-client/plugins/PagedList.js +177 -177
  30. package/src/base-client/plugins/compatible/LoginServiceOA.js +20 -20
  31. package/src/base-client/plugins/i18n-extend.js +32 -32
  32. package/src/components/Ellipsis/index.md +38 -38
  33. package/src/components/NumberInfo/index.md +43 -43
  34. package/src/components/STable/README.md +341 -341
  35. package/src/components/STable/index.js +318 -318
  36. package/src/components/Trend/index.md +45 -45
  37. package/src/components/checkbox/ColorCheckbox.vue +157 -157
  38. package/src/components/checkbox/ImgCheckbox.vue +163 -163
  39. package/src/components/exception/ExceptionPage.vue +70 -70
  40. package/src/components/form/FormRow.vue +52 -52
  41. package/src/components/index.js +36 -36
  42. package/src/components/menu/SideMenu.vue +62 -62
  43. package/src/components/menu/menu.js +273 -273
  44. package/src/components/setting/Setting.vue +235 -235
  45. package/src/components/table/StandardTable.vue +141 -141
  46. package/src/components/table/advance/ActionColumns.vue +158 -158
  47. package/src/components/table/advance/SearchArea.vue +355 -355
  48. package/src/components/tool/AStepItem.vue +60 -60
  49. package/src/components/tool/AvatarList.vue +68 -68
  50. package/src/components/tool/Drawer.vue +142 -142
  51. package/src/components/tool/TagSelect.vue +83 -83
  52. package/src/components/transition/PageToggleTransition.vue +97 -97
  53. package/src/config/replacer/resolve.config.js +67 -67
  54. package/src/layouts/AdminLayout.vue +174 -174
  55. package/src/layouts/header/AdminHeader.vue +104 -104
  56. package/src/layouts/header/HeaderNotice.vue +167 -167
  57. package/src/layouts/header/HeaderSearch.vue +67 -67
  58. package/src/layouts/header/InstitutionDetail.vue +181 -181
  59. package/src/layouts/tabs/TabsHead.vue +190 -190
  60. package/src/layouts/tabs/TabsView.vue +379 -379
  61. package/src/mock/goods/index.js +108 -108
  62. package/src/pages/CreateQueryPage.vue +65 -65
  63. package/src/pages/login/Login.vue +277 -277
  64. package/src/pages/report/ReportTable.js +124 -124
  65. package/src/pages/report/ReportTableHome.vue +28 -28
  66. package/src/pages/resourceManage/orgListManage.vue +98 -98
  67. package/src/pages/system/dictionary/index.vue +43 -43
  68. package/src/pages/system/file/index.vue +317 -317
  69. package/src/pages/system/queryParams/index.vue +43 -43
  70. package/src/pages/system/ticket/index.vue +461 -461
  71. package/src/pages/system/ticket/submitTicketSuccess.vue +206 -206
  72. package/src/router/async/config.async.js +27 -27
  73. package/src/router/async/router.map.js +56 -56
  74. package/src/router/index.js +27 -27
  75. package/src/services/api/DictionaryDetailsViewApi.js +6 -6
  76. package/src/services/api/LogDetailsViewApi.js +10 -10
  77. package/src/services/api/QueryParamsDetailsViewApi.js +6 -6
  78. package/src/services/api/TicketDetailsViewApi.js +34 -34
  79. package/src/services/api/common.js +58 -58
  80. package/src/services/api/commonTempTable.js +10 -10
  81. package/src/services/api/index.js +17 -17
  82. package/src/services/api/manage.js +8 -8
  83. package/src/store/mutation-types.js +2 -2
  84. package/src/theme/default/nprogress.less +76 -76
  85. package/src/theme/default/style.less +47 -47
  86. package/src/utils/colors.js +103 -103
  87. package/src/utils/excel/Blob.js +180 -180
  88. package/src/utils/excel/Export2Excel.js +141 -141
  89. package/src/utils/formatter.js +68 -68
  90. package/src/utils/i18n.js +80 -80
  91. package/src/utils/request.js +225 -225
  92. package/src/utils/routerUtil.js +358 -358
  93. package/src/utils/theme-color-replacer-extend.js +91 -91
  94. package/src/utils/themeUtil.js +100 -100
  95. package/src/utils/util.js +230 -230
  96. package/vue.config.js +99 -99
@@ -1,358 +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 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 }
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 }