asyncRouter.js
937 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/*
* @Description:
* @Autor: renchao
* @LastEditTime: 2023-05-11 16:31:01
*/
var Layout;
let ApiUrl = localStorage.getItem('ApiUrl')
Layout = r => require.ensure([], () => r(require(`@/layout1`)))
/**
* @description: filterAsyncRouter
* @param {*} routers
* @author: renchao
*/
export default function filterAsyncRouter (routers) {
routers.forEach(item => {
if (!item.children) {
delete item.children
} else {
item.children = filterAsyncRouter(item.children)
}
item.path = JSON.parse(item.metadata)?.path || '/'
if (!item.parentId) {
item.component = Layout
} else {
item.component = loadView(item.uri)
}
item.meta = {
title: item.name,
icon: item.icon
}
})
return routers
}
/**
* @description: loadView
* @param {*} view
* @author: renchao
*/
function loadView (view) {
return r => require.ensure([], () => r(require(`@/views${view}.vue`)))
}