af-mobile-client-vue3 1.1.8 → 1.1.10
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/.env +6 -6
- package/.env.development +4 -4
- package/.env.envoiceShow +6 -6
- package/.env.production +6 -6
- package/.husky/commit-msg +1 -1
- package/.husky/pre-commit +1 -1
- package/.vscode/settings.json +61 -61
- package/mock/modules/user.mock.ts +152 -152
- package/package.json +1 -1
- package/public/favicon.svg +4 -4
- package/public/safari-pinned-tab.svg +32 -32
- package/scripts/verifyCommit.js +19 -19
- package/src/App.vue +43 -43
- package/src/api/user/index.ts +40 -40
- package/src/bootstrap.ts +18 -18
- package/src/components/core/NavBar/index.vue +12 -12
- package/src/components/core/Tabbar/index.vue +38 -38
- package/src/components/core/XGridDropOption/index.vue +151 -151
- package/src/components/core/XMultiSelect/index.vue +183 -183
- package/src/components/data/XCellDetail/index.vue +106 -106
- package/src/components/data/XFormItem/index.vue +105 -107
- package/src/components/data/XOlMap/XLocationPicker/index.vue +7 -9
- package/src/components/data/XOlMap/index.vue +103 -96
- package/src/components/data/XReportForm/XReportFormJsonRender.vue +220 -220
- package/src/components/data/XReportForm/index.vue +1079 -1079
- package/src/components/data/XReportGrid/XAddReport/index.ts +1 -1
- package/src/components/data/XReportGrid/XReportDrawer/index.ts +1 -1
- package/src/components/data/XSignature/index.vue +285 -285
- package/src/components/data/XTag/index.vue +10 -10
- package/src/components/layout/NormalDataLayout/index.vue +70 -70
- package/src/components/layout/TabBarLayout/index.vue +40 -40
- package/src/components.d.ts +53 -53
- package/src/env.d.ts +16 -16
- package/src/font-style/font.css +3 -3
- package/src/hooks/useCommon.ts +9 -9
- package/src/layout/PageLayout.vue +4 -5
- package/src/layout/SingleLayout.vue +4 -5
- package/src/locales/en-US.json +25 -25
- package/src/locales/zh-CN.json +25 -25
- package/src/plugins/AppData.ts +38 -38
- package/src/router/guards.ts +59 -59
- package/src/router/index.ts +61 -61
- package/src/router/invoiceRoutes.ts +33 -33
- package/src/services/api/common.ts +109 -109
- package/src/services/api/manage.ts +8 -8
- package/src/services/api/search.ts +16 -16
- package/src/services/restTools.ts +56 -56
- package/src/services/v3Api.ts +11 -11
- package/src/stores/modules/routeCache.ts +22 -0
- package/src/stores/modules/setting.ts +52 -52
- package/src/stores/mutation-type.ts +7 -7
- package/src/utils/authority-utils.ts +84 -84
- package/src/utils/crypto.ts +39 -39
- package/src/utils/i18n.ts +41 -41
- package/src/utils/indexedDB.ts +180 -180
- package/src/utils/mobileUtil.ts +26 -26
- package/src/utils/routerUtil.ts +271 -271
- package/src/utils/runEvalFunction.ts +13 -13
- package/src/utils/wechatUtil.ts +9 -9
- package/src/views/common/LoadError.vue +64 -64
- package/src/views/common/NotFound.vue +68 -68
- package/src/views/component/EvaluateRecordView/index.vue +40 -40
- package/src/views/component/XCellDetailView/index.vue +217 -217
- package/src/views/component/XCellListView/index.vue +2 -2
- package/src/views/component/XOlMapView/XLocationPicker/index.vue +0 -2
- package/src/views/component/XOlMapView/index.vue +3 -5
- package/src/views/component/XReportFormIframeView/index.vue +47 -47
- package/src/views/component/XReportFormView/index.vue +13 -13
- package/src/views/component/XSignatureView/index.vue +50 -50
- package/src/views/component/menu.vue +117 -117
- package/src/views/component/notice.vue +46 -46
- package/src/views/component/topNav.vue +36 -36
- package/src/views/invoiceShow/index.vue +61 -61
- package/src/views/user/login/ForgetPasswordForm.vue +94 -94
- package/src/views/user/login/LoginTitle.vue +68 -68
- package/src/views/user/login/index.vue +22 -22
- package/src/views/user/my/index.vue +230 -230
- package/src/vue-router.d.ts +9 -9
- package/tsconfig.json +43 -43
- package/src/stores/modules/cachedView.ts +0 -31
package/src/utils/routerUtil.ts
CHANGED
|
@@ -1,271 +1,271 @@
|
|
|
1
|
-
import type { RouteRecordRaw } from 'vue-router'
|
|
2
|
-
import router from '@af-mobile-client-vue3/router'
|
|
3
|
-
import routes from '@af-mobile-client-vue3/router/routes'
|
|
4
|
-
import useUserStore from '@af-mobile-client-vue3/stores/modules/user.js'
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* 根据 路由配置 和 路由组件注册 解析路由
|
|
8
|
-
* @param routesConfig 路由配置
|
|
9
|
-
* @param routerMap 本地路由组件注册配置
|
|
10
|
-
*/
|
|
11
|
-
function parseRoutes(routesConfig, routerMap) {
|
|
12
|
-
const routes = []
|
|
13
|
-
routesConfig.forEach((item) => {
|
|
14
|
-
// 获取注册在 routerMap 中的 router,初始化 routeCfg
|
|
15
|
-
let router: any
|
|
16
|
-
let routeCfg: any
|
|
17
|
-
if (typeof item === 'string') {
|
|
18
|
-
router = routerMap[item]
|
|
19
|
-
routeCfg = { path: (router && router.path) || item, router: item }
|
|
20
|
-
}
|
|
21
|
-
else if (typeof item === 'object') {
|
|
22
|
-
// 当没有设置路由对象名或者设置的是blank路由对象时, 给空界面, path为名称
|
|
23
|
-
if (!item.router || item.router === 'blank') {
|
|
24
|
-
router = routerMap.blank
|
|
25
|
-
item.path = encodeURI(item.name)
|
|
26
|
-
}
|
|
27
|
-
else {
|
|
28
|
-
router = routerMap[item.router]
|
|
29
|
-
}
|
|
30
|
-
// 查看是否是单页面
|
|
31
|
-
if (item.meta && item.meta.singlePage) {
|
|
32
|
-
router = routerMap.singlePage
|
|
33
|
-
item.path = encodeURI(item.name)
|
|
34
|
-
}
|
|
35
|
-
// 当没在动态路由对象中找到时, 不添加到路由
|
|
36
|
-
// if (!router) return
|
|
37
|
-
routeCfg = item
|
|
38
|
-
}
|
|
39
|
-
if (!router) {
|
|
40
|
-
console.warn(`can't find register for router ${routeCfg.router}, please register it in advance.`)
|
|
41
|
-
router = typeof item === 'string' ? { path: item, name: item } : item
|
|
42
|
-
}
|
|
43
|
-
// 从 router 和 routeCfg 解析路由
|
|
44
|
-
const meta = {
|
|
45
|
-
authority: router.authority,
|
|
46
|
-
icon: router.icon,
|
|
47
|
-
page: router.page,
|
|
48
|
-
link: router.link,
|
|
49
|
-
params: router.params,
|
|
50
|
-
query: router.query,
|
|
51
|
-
...router.meta,
|
|
52
|
-
}
|
|
53
|
-
const cfgMeta = {
|
|
54
|
-
authority: routeCfg.authority,
|
|
55
|
-
icon: routeCfg.icon,
|
|
56
|
-
page: routeCfg.page,
|
|
57
|
-
link: routeCfg.link,
|
|
58
|
-
params: routeCfg.params,
|
|
59
|
-
query: routeCfg.query,
|
|
60
|
-
...routeCfg.meta,
|
|
61
|
-
}
|
|
62
|
-
Object.keys(cfgMeta).forEach((key) => {
|
|
63
|
-
if (cfgMeta[key] === undefined || cfgMeta[key] === null || cfgMeta[key] === '')
|
|
64
|
-
delete cfgMeta[key]
|
|
65
|
-
})
|
|
66
|
-
Object.assign(meta, cfgMeta)
|
|
67
|
-
const route = {
|
|
68
|
-
path: routeCfg.path || router.path || routeCfg.router,
|
|
69
|
-
name: routeCfg.name || router.name,
|
|
70
|
-
component: router.component || router,
|
|
71
|
-
redirect: routeCfg.redirect || router.redirect,
|
|
72
|
-
meta: { ...meta, authority: meta.authority || '*' },
|
|
73
|
-
beforeEnter: undefined,
|
|
74
|
-
children: undefined,
|
|
75
|
-
}
|
|
76
|
-
if (router.beforeEnter)
|
|
77
|
-
route.beforeEnter = router.beforeEnter
|
|
78
|
-
|
|
79
|
-
if (routeCfg.invisible || router.invisible)
|
|
80
|
-
route.meta.invisible = true
|
|
81
|
-
|
|
82
|
-
if (routeCfg.children && routeCfg.children.length > 0)
|
|
83
|
-
route.children = parseRoutes(routeCfg.children, routerMap)
|
|
84
|
-
|
|
85
|
-
// 当没有子并且自己时blank(空界面)时, 不添加到路由
|
|
86
|
-
if (route.component.name === 'blank' && route.children && route.children.length <= 0)
|
|
87
|
-
return
|
|
88
|
-
routes.push(route)
|
|
89
|
-
})
|
|
90
|
-
return routes
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* 加载路由
|
|
95
|
-
* @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}]}]} 路由配置
|
|
96
|
-
*/
|
|
97
|
-
function loadRoutes(routesConfig?: any) {
|
|
98
|
-
// 如果 routesConfig 有值,则更新到本地,否则从本地获取
|
|
99
|
-
if (routesConfig)
|
|
100
|
-
useUserStore().setRoutesConfig(routesConfig)
|
|
101
|
-
else
|
|
102
|
-
routesConfig = useUserStore().getRoutesConfig()
|
|
103
|
-
|
|
104
|
-
if (routesConfig && routesConfig.length > 0) {
|
|
105
|
-
const newRoutes = parseRoutes(routesConfig, routes)
|
|
106
|
-
// 设置路由首页
|
|
107
|
-
newRoutes[0].redirect = '/'
|
|
108
|
-
const finalRoutes = mergeRoutes(routes, newRoutes)
|
|
109
|
-
formatRoutes(finalRoutes)
|
|
110
|
-
finalRoutes.forEach((row) => {
|
|
111
|
-
router.addRoute(row)
|
|
112
|
-
})
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* 合并路由
|
|
118
|
-
* @param target
|
|
119
|
-
* @param source
|
|
120
|
-
*/
|
|
121
|
-
function mergeRoutes(target: Array<RouteRecordRaw>, source: Array<RouteRecordRaw>) {
|
|
122
|
-
const routesMap: RouteRecordRaw = {} as RouteRecordRaw
|
|
123
|
-
|
|
124
|
-
target.forEach(item => routesMap[item.path] = item)
|
|
125
|
-
|
|
126
|
-
source.forEach(item => routesMap[item.path] = item)
|
|
127
|
-
return Object.values(routesMap)
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* 格式化路由
|
|
132
|
-
* @param routes 路由配置
|
|
133
|
-
*/
|
|
134
|
-
function formatRoutes(routes) {
|
|
135
|
-
routes.forEach((route) => {
|
|
136
|
-
const { path } = route
|
|
137
|
-
if (!path.startsWith('/') && path !== '*')
|
|
138
|
-
route.path = `/${path}`
|
|
139
|
-
})
|
|
140
|
-
formatAuthority(routes)
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* 格式化路由的权限配置
|
|
145
|
-
* @param routes 路由
|
|
146
|
-
* @param pAuthorities 父级路由权限配置集合
|
|
147
|
-
*/
|
|
148
|
-
function formatAuthority(routes, pAuthorities = []) {
|
|
149
|
-
routes.forEach((route) => {
|
|
150
|
-
const meta = route.meta
|
|
151
|
-
const defaultAuthority = pAuthorities[pAuthorities.length - 1] || { permission: '*' }
|
|
152
|
-
if (meta) {
|
|
153
|
-
let authority: any = {}
|
|
154
|
-
if (!meta.authority) {
|
|
155
|
-
authority = defaultAuthority
|
|
156
|
-
}
|
|
157
|
-
else if (typeof meta.authority === 'string' || Array.isArray(meta.authority)) {
|
|
158
|
-
authority.permission = meta.authority
|
|
159
|
-
}
|
|
160
|
-
else if (typeof meta.authority === 'object') {
|
|
161
|
-
authority = meta.authority
|
|
162
|
-
const { role } = authority
|
|
163
|
-
if (typeof role === 'string')
|
|
164
|
-
authority.role = [role]
|
|
165
|
-
|
|
166
|
-
if (!authority.permission && !authority.role)
|
|
167
|
-
authority = defaultAuthority
|
|
168
|
-
}
|
|
169
|
-
meta.authority = authority
|
|
170
|
-
}
|
|
171
|
-
else {
|
|
172
|
-
const authority = defaultAuthority
|
|
173
|
-
route.meta = { authority }
|
|
174
|
-
}
|
|
175
|
-
route.meta.pAuthorities = pAuthorities
|
|
176
|
-
if (route.children)
|
|
177
|
-
formatAuthority(route.children, [...pAuthorities, route.meta.authority])
|
|
178
|
-
})
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
/**
|
|
182
|
-
* 加载导航守卫
|
|
183
|
-
* @param guards
|
|
184
|
-
*/
|
|
185
|
-
function loadGuards(guards, _router) {
|
|
186
|
-
const { beforeEach, afterEach } = guards
|
|
187
|
-
beforeEach.forEach((guard) => {
|
|
188
|
-
if (guard && typeof guard === 'function')
|
|
189
|
-
_router.beforeEach((to, from, next) => guard(to, from, next))
|
|
190
|
-
})
|
|
191
|
-
afterEach.forEach((guard) => {
|
|
192
|
-
if (guard && typeof guard === 'function')
|
|
193
|
-
_router.afterEach((to, from) => guard(to, from))
|
|
194
|
-
})
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
/**
|
|
198
|
-
* 资源服务路由转新路由
|
|
199
|
-
* @param func
|
|
200
|
-
*/
|
|
201
|
-
function funcToRouter(func) {
|
|
202
|
-
return [{
|
|
203
|
-
router: 'root',
|
|
204
|
-
children: positionRouter(parsefunc(func)),
|
|
205
|
-
}]
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
function parsefunc(func) {
|
|
209
|
-
const tree = []
|
|
210
|
-
for (const row of func) {
|
|
211
|
-
const route = {
|
|
212
|
-
router: row.link,
|
|
213
|
-
meta: {
|
|
214
|
-
singlePage: row.navigate,
|
|
215
|
-
},
|
|
216
|
-
position: row.position - 1,
|
|
217
|
-
icon: row.icon,
|
|
218
|
-
name: row.name,
|
|
219
|
-
params: undefined,
|
|
220
|
-
children: undefined,
|
|
221
|
-
}
|
|
222
|
-
if (row.link.includes('$')) {
|
|
223
|
-
route.router = row.link.split('$')[1]
|
|
224
|
-
route.params = row.link.split('$')[0]
|
|
225
|
-
}
|
|
226
|
-
if (row.children && row.children.length > 0)
|
|
227
|
-
route.children = parsefunc(row.children)
|
|
228
|
-
|
|
229
|
-
tree.push(route)
|
|
230
|
-
}
|
|
231
|
-
// 如果是 microapp 作为子应用路由应该是平铺的 树状结构由父项目处理
|
|
232
|
-
if (window.__MICRO_APP_ENVIRONMENT__)
|
|
233
|
-
return flattenTree(tree)
|
|
234
|
-
|
|
235
|
-
return tree
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
function flattenTree(tree) {
|
|
239
|
-
let flat = []
|
|
240
|
-
for (const node of tree) {
|
|
241
|
-
const { children, ...rest } = node
|
|
242
|
-
flat.push(rest)
|
|
243
|
-
if (children && children.length > 0)
|
|
244
|
-
flat = flat.concat(flattenTree(children))
|
|
245
|
-
}
|
|
246
|
-
return flat
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
/**
|
|
250
|
-
* 资源服务路由排序
|
|
251
|
-
*/
|
|
252
|
-
function positionRouter(r) {
|
|
253
|
-
let router = r.sort((a, b) => a.position - b.position)
|
|
254
|
-
router = arrRemoveEmpty(router)
|
|
255
|
-
return router
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
/**
|
|
259
|
-
* 数组去空值
|
|
260
|
-
*/
|
|
261
|
-
function arrRemoveEmpty(arr) {
|
|
262
|
-
for (let i = 0; i < arr.length; i++) {
|
|
263
|
-
if (arr[i] === '' || typeof (arr[i]) == 'undefined') {
|
|
264
|
-
arr.splice(i, 1)
|
|
265
|
-
i--
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
return arr
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
export { formatAuthority, formatRoutes, funcToRouter, loadGuards, loadRoutes, parseRoutes }
|
|
1
|
+
import type { RouteRecordRaw } from 'vue-router'
|
|
2
|
+
import router from '@af-mobile-client-vue3/router'
|
|
3
|
+
import routes from '@af-mobile-client-vue3/router/routes'
|
|
4
|
+
import useUserStore from '@af-mobile-client-vue3/stores/modules/user.js'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* 根据 路由配置 和 路由组件注册 解析路由
|
|
8
|
+
* @param routesConfig 路由配置
|
|
9
|
+
* @param routerMap 本地路由组件注册配置
|
|
10
|
+
*/
|
|
11
|
+
function parseRoutes(routesConfig, routerMap) {
|
|
12
|
+
const routes = []
|
|
13
|
+
routesConfig.forEach((item) => {
|
|
14
|
+
// 获取注册在 routerMap 中的 router,初始化 routeCfg
|
|
15
|
+
let router: any
|
|
16
|
+
let routeCfg: any
|
|
17
|
+
if (typeof item === 'string') {
|
|
18
|
+
router = routerMap[item]
|
|
19
|
+
routeCfg = { path: (router && router.path) || item, router: item }
|
|
20
|
+
}
|
|
21
|
+
else if (typeof item === 'object') {
|
|
22
|
+
// 当没有设置路由对象名或者设置的是blank路由对象时, 给空界面, path为名称
|
|
23
|
+
if (!item.router || item.router === 'blank') {
|
|
24
|
+
router = routerMap.blank
|
|
25
|
+
item.path = encodeURI(item.name)
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
router = routerMap[item.router]
|
|
29
|
+
}
|
|
30
|
+
// 查看是否是单页面
|
|
31
|
+
if (item.meta && item.meta.singlePage) {
|
|
32
|
+
router = routerMap.singlePage
|
|
33
|
+
item.path = encodeURI(item.name)
|
|
34
|
+
}
|
|
35
|
+
// 当没在动态路由对象中找到时, 不添加到路由
|
|
36
|
+
// if (!router) return
|
|
37
|
+
routeCfg = item
|
|
38
|
+
}
|
|
39
|
+
if (!router) {
|
|
40
|
+
console.warn(`can't find register for router ${routeCfg.router}, please register it in advance.`)
|
|
41
|
+
router = typeof item === 'string' ? { path: item, name: item } : item
|
|
42
|
+
}
|
|
43
|
+
// 从 router 和 routeCfg 解析路由
|
|
44
|
+
const meta = {
|
|
45
|
+
authority: router.authority,
|
|
46
|
+
icon: router.icon,
|
|
47
|
+
page: router.page,
|
|
48
|
+
link: router.link,
|
|
49
|
+
params: router.params,
|
|
50
|
+
query: router.query,
|
|
51
|
+
...router.meta,
|
|
52
|
+
}
|
|
53
|
+
const cfgMeta = {
|
|
54
|
+
authority: routeCfg.authority,
|
|
55
|
+
icon: routeCfg.icon,
|
|
56
|
+
page: routeCfg.page,
|
|
57
|
+
link: routeCfg.link,
|
|
58
|
+
params: routeCfg.params,
|
|
59
|
+
query: routeCfg.query,
|
|
60
|
+
...routeCfg.meta,
|
|
61
|
+
}
|
|
62
|
+
Object.keys(cfgMeta).forEach((key) => {
|
|
63
|
+
if (cfgMeta[key] === undefined || cfgMeta[key] === null || cfgMeta[key] === '')
|
|
64
|
+
delete cfgMeta[key]
|
|
65
|
+
})
|
|
66
|
+
Object.assign(meta, cfgMeta)
|
|
67
|
+
const route = {
|
|
68
|
+
path: routeCfg.path || router.path || routeCfg.router,
|
|
69
|
+
name: routeCfg.name || router.name,
|
|
70
|
+
component: router.component || router,
|
|
71
|
+
redirect: routeCfg.redirect || router.redirect,
|
|
72
|
+
meta: { ...meta, authority: meta.authority || '*' },
|
|
73
|
+
beforeEnter: undefined,
|
|
74
|
+
children: undefined,
|
|
75
|
+
}
|
|
76
|
+
if (router.beforeEnter)
|
|
77
|
+
route.beforeEnter = router.beforeEnter
|
|
78
|
+
|
|
79
|
+
if (routeCfg.invisible || router.invisible)
|
|
80
|
+
route.meta.invisible = true
|
|
81
|
+
|
|
82
|
+
if (routeCfg.children && routeCfg.children.length > 0)
|
|
83
|
+
route.children = parseRoutes(routeCfg.children, routerMap)
|
|
84
|
+
|
|
85
|
+
// 当没有子并且自己时blank(空界面)时, 不添加到路由
|
|
86
|
+
if (route.component.name === 'blank' && route.children && route.children.length <= 0)
|
|
87
|
+
return
|
|
88
|
+
routes.push(route)
|
|
89
|
+
})
|
|
90
|
+
return routes
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* 加载路由
|
|
95
|
+
* @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}]}]} 路由配置
|
|
96
|
+
*/
|
|
97
|
+
function loadRoutes(routesConfig?: any) {
|
|
98
|
+
// 如果 routesConfig 有值,则更新到本地,否则从本地获取
|
|
99
|
+
if (routesConfig)
|
|
100
|
+
useUserStore().setRoutesConfig(routesConfig)
|
|
101
|
+
else
|
|
102
|
+
routesConfig = useUserStore().getRoutesConfig()
|
|
103
|
+
|
|
104
|
+
if (routesConfig && routesConfig.length > 0) {
|
|
105
|
+
const newRoutes = parseRoutes(routesConfig, routes)
|
|
106
|
+
// 设置路由首页
|
|
107
|
+
newRoutes[0].redirect = '/'
|
|
108
|
+
const finalRoutes = mergeRoutes(routes, newRoutes)
|
|
109
|
+
formatRoutes(finalRoutes)
|
|
110
|
+
finalRoutes.forEach((row) => {
|
|
111
|
+
router.addRoute(row)
|
|
112
|
+
})
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* 合并路由
|
|
118
|
+
* @param target
|
|
119
|
+
* @param source
|
|
120
|
+
*/
|
|
121
|
+
function mergeRoutes(target: Array<RouteRecordRaw>, source: Array<RouteRecordRaw>) {
|
|
122
|
+
const routesMap: RouteRecordRaw = {} as RouteRecordRaw
|
|
123
|
+
|
|
124
|
+
target.forEach(item => routesMap[item.path] = item)
|
|
125
|
+
|
|
126
|
+
source.forEach(item => routesMap[item.path] = item)
|
|
127
|
+
return Object.values(routesMap)
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* 格式化路由
|
|
132
|
+
* @param routes 路由配置
|
|
133
|
+
*/
|
|
134
|
+
function formatRoutes(routes) {
|
|
135
|
+
routes.forEach((route) => {
|
|
136
|
+
const { path } = route
|
|
137
|
+
if (!path.startsWith('/') && path !== '*')
|
|
138
|
+
route.path = `/${path}`
|
|
139
|
+
})
|
|
140
|
+
formatAuthority(routes)
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* 格式化路由的权限配置
|
|
145
|
+
* @param routes 路由
|
|
146
|
+
* @param pAuthorities 父级路由权限配置集合
|
|
147
|
+
*/
|
|
148
|
+
function formatAuthority(routes, pAuthorities = []) {
|
|
149
|
+
routes.forEach((route) => {
|
|
150
|
+
const meta = route.meta
|
|
151
|
+
const defaultAuthority = pAuthorities[pAuthorities.length - 1] || { permission: '*' }
|
|
152
|
+
if (meta) {
|
|
153
|
+
let authority: any = {}
|
|
154
|
+
if (!meta.authority) {
|
|
155
|
+
authority = defaultAuthority
|
|
156
|
+
}
|
|
157
|
+
else if (typeof meta.authority === 'string' || Array.isArray(meta.authority)) {
|
|
158
|
+
authority.permission = meta.authority
|
|
159
|
+
}
|
|
160
|
+
else if (typeof meta.authority === 'object') {
|
|
161
|
+
authority = meta.authority
|
|
162
|
+
const { role } = authority
|
|
163
|
+
if (typeof role === 'string')
|
|
164
|
+
authority.role = [role]
|
|
165
|
+
|
|
166
|
+
if (!authority.permission && !authority.role)
|
|
167
|
+
authority = defaultAuthority
|
|
168
|
+
}
|
|
169
|
+
meta.authority = authority
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
const authority = defaultAuthority
|
|
173
|
+
route.meta = { authority }
|
|
174
|
+
}
|
|
175
|
+
route.meta.pAuthorities = pAuthorities
|
|
176
|
+
if (route.children)
|
|
177
|
+
formatAuthority(route.children, [...pAuthorities, route.meta.authority])
|
|
178
|
+
})
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* 加载导航守卫
|
|
183
|
+
* @param guards
|
|
184
|
+
*/
|
|
185
|
+
function loadGuards(guards, _router) {
|
|
186
|
+
const { beforeEach, afterEach } = guards
|
|
187
|
+
beforeEach.forEach((guard) => {
|
|
188
|
+
if (guard && typeof guard === 'function')
|
|
189
|
+
_router.beforeEach((to, from, next) => guard(to, from, next))
|
|
190
|
+
})
|
|
191
|
+
afterEach.forEach((guard) => {
|
|
192
|
+
if (guard && typeof guard === 'function')
|
|
193
|
+
_router.afterEach((to, from) => guard(to, from))
|
|
194
|
+
})
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* 资源服务路由转新路由
|
|
199
|
+
* @param func
|
|
200
|
+
*/
|
|
201
|
+
function funcToRouter(func) {
|
|
202
|
+
return [{
|
|
203
|
+
router: 'root',
|
|
204
|
+
children: positionRouter(parsefunc(func)),
|
|
205
|
+
}]
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
function parsefunc(func) {
|
|
209
|
+
const tree = []
|
|
210
|
+
for (const row of func) {
|
|
211
|
+
const route = {
|
|
212
|
+
router: row.link,
|
|
213
|
+
meta: {
|
|
214
|
+
singlePage: row.navigate,
|
|
215
|
+
},
|
|
216
|
+
position: row.position - 1,
|
|
217
|
+
icon: row.icon,
|
|
218
|
+
name: row.name,
|
|
219
|
+
params: undefined,
|
|
220
|
+
children: undefined,
|
|
221
|
+
}
|
|
222
|
+
if (row.link.includes('$')) {
|
|
223
|
+
route.router = row.link.split('$')[1]
|
|
224
|
+
route.params = row.link.split('$')[0]
|
|
225
|
+
}
|
|
226
|
+
if (row.children && row.children.length > 0)
|
|
227
|
+
route.children = parsefunc(row.children)
|
|
228
|
+
|
|
229
|
+
tree.push(route)
|
|
230
|
+
}
|
|
231
|
+
// 如果是 microapp 作为子应用路由应该是平铺的 树状结构由父项目处理
|
|
232
|
+
if (window.__MICRO_APP_ENVIRONMENT__)
|
|
233
|
+
return flattenTree(tree)
|
|
234
|
+
|
|
235
|
+
return tree
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
function flattenTree(tree) {
|
|
239
|
+
let flat = []
|
|
240
|
+
for (const node of tree) {
|
|
241
|
+
const { children, ...rest } = node
|
|
242
|
+
flat.push(rest)
|
|
243
|
+
if (children && children.length > 0)
|
|
244
|
+
flat = flat.concat(flattenTree(children))
|
|
245
|
+
}
|
|
246
|
+
return flat
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* 资源服务路由排序
|
|
251
|
+
*/
|
|
252
|
+
function positionRouter(r) {
|
|
253
|
+
let router = r.sort((a, b) => a.position - b.position)
|
|
254
|
+
router = arrRemoveEmpty(router)
|
|
255
|
+
return router
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* 数组去空值
|
|
260
|
+
*/
|
|
261
|
+
function arrRemoveEmpty(arr) {
|
|
262
|
+
for (let i = 0; i < arr.length; i++) {
|
|
263
|
+
if (arr[i] === '' || typeof (arr[i]) == 'undefined') {
|
|
264
|
+
arr.splice(i, 1)
|
|
265
|
+
i--
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
return arr
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
export { formatAuthority, formatRoutes, funcToRouter, loadGuards, loadRoutes, parseRoutes }
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
export function executeStrFunction(funcString, args) {
|
|
2
|
-
// 使用 eval 执行传入的函数字符串
|
|
3
|
-
// eslint-disable-next-line no-eval
|
|
4
|
-
return eval(`(${funcString})`)(...args)
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export function executeStrFunctionByContext(context, fnStr, args) {
|
|
8
|
-
// 使用 new Function 创建函数,并绑定 context 作为 this
|
|
9
|
-
// eslint-disable-next-line no-new-func
|
|
10
|
-
const fn = new Function(`return (${fnStr});`)()
|
|
11
|
-
// 使用 bind 绑定 context,并立即调用
|
|
12
|
-
return fn.bind(context)(...args)
|
|
13
|
-
}
|
|
1
|
+
export function executeStrFunction(funcString, args) {
|
|
2
|
+
// 使用 eval 执行传入的函数字符串
|
|
3
|
+
// eslint-disable-next-line no-eval
|
|
4
|
+
return eval(`(${funcString})`)(...args)
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export function executeStrFunctionByContext(context, fnStr, args) {
|
|
8
|
+
// 使用 new Function 创建函数,并绑定 context 作为 this
|
|
9
|
+
// eslint-disable-next-line no-new-func
|
|
10
|
+
const fn = new Function(`return (${fnStr});`)()
|
|
11
|
+
// 使用 bind 绑定 context,并立即调用
|
|
12
|
+
return fn.bind(context)(...args)
|
|
13
|
+
}
|
package/src/utils/wechatUtil.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 判断是否是微信环境
|
|
3
|
-
*/
|
|
4
|
-
function isWechat() {
|
|
5
|
-
const ua = window.navigator.userAgent.toLowerCase()
|
|
6
|
-
return ua.includes('micromessenger')
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export { isWechat }
|
|
1
|
+
/**
|
|
2
|
+
* 判断是否是微信环境
|
|
3
|
+
*/
|
|
4
|
+
function isWechat() {
|
|
5
|
+
const ua = window.navigator.userAgent.toLowerCase()
|
|
6
|
+
return ua.includes('micromessenger')
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export { isWechat }
|