2022-06-19 13:02:12 +08:00
|
|
|
const viewModules = import.meta.glob('../view/**/*.vue')
|
|
|
|
|
const pluginModules = import.meta.glob('../plugin/**/*.vue')
|
2021-09-03 19:20:08 +08:00
|
|
|
|
2019-09-08 23:22:49 +08:00
|
|
|
export const asyncRouterHandle = (asyncRouter) => {
|
2021-09-21 17:55:18 +08:00
|
|
|
asyncRouter.forEach(item => {
|
2023-07-11 22:04:03 +08:00
|
|
|
if (item.component && typeof item.component === 'string') {
|
2022-06-19 13:02:12 +08:00
|
|
|
if (item.component.split('/')[0] === 'view') {
|
|
|
|
|
item.component = dynamicImport(viewModules, item.component)
|
|
|
|
|
} else if (item.component.split('/')[0] === 'plugin') {
|
|
|
|
|
item.component = dynamicImport(pluginModules, item.component)
|
|
|
|
|
}
|
2021-06-02 14:11:45 +08:00
|
|
|
}
|
|
|
|
|
if (item.children) {
|
|
|
|
|
asyncRouterHandle(item.children)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
2021-09-03 19:20:08 +08:00
|
|
|
|
|
|
|
|
function dynamicImport(
|
|
|
|
|
dynamicViewsModules,
|
|
|
|
|
component
|
|
|
|
|
) {
|
|
|
|
|
const keys = Object.keys(dynamicViewsModules)
|
|
|
|
|
const matchKeys = keys.filter((key) => {
|
2021-09-04 16:21:21 +08:00
|
|
|
const k = key.replace('../', '')
|
2021-09-03 19:20:08 +08:00
|
|
|
return k === component
|
|
|
|
|
})
|
|
|
|
|
const matchKey = matchKeys[0]
|
2021-09-04 16:21:21 +08:00
|
|
|
|
2021-09-03 19:20:08 +08:00
|
|
|
return dynamicViewsModules[matchKey]
|
|
|
|
|
}
|