fix: url router
parent
49aa7f645c
commit
0732077adf
|
@ -45,7 +45,9 @@ export function usePermission() {
|
|||
resetRouter()
|
||||
const routes = await permissionStore.buildRoutesAction()
|
||||
routes.forEach((route) => {
|
||||
try {
|
||||
router.addRoute(route as unknown as RouteRecordRaw)
|
||||
} catch (e) {}
|
||||
})
|
||||
permissionStore.setLastBuildMenuTime()
|
||||
closeAll()
|
||||
|
|
|
@ -8,7 +8,6 @@ import { isUrl } from '@/utils/is'
|
|||
|
||||
export type LayoutMapKey = 'LAYOUT'
|
||||
const IFRAME = () => import('@/views/base/iframe/FrameBlank.vue')
|
||||
const URL_HASH_TAB = `__AGWE4H__HASH__TAG__PWHRG__`
|
||||
const LayoutMap = new Map<string, () => Promise<typeof import('*.vue')>>()
|
||||
|
||||
LayoutMap.set('LAYOUT', LAYOUT)
|
||||
|
@ -21,18 +20,6 @@ function asyncImportRoute(routes: AppRouteRecordRaw[] | undefined) {
|
|||
dynamicViewsModules = dynamicViewsModules || import.meta.glob('../../views/**/*.{vue,tsx}')
|
||||
if (!routes) return
|
||||
routes.forEach((item) => {
|
||||
if (/^\/?http(s)?/.test(item.component as string)) {
|
||||
item.component = item.component.substring(1, item.component.length)
|
||||
}
|
||||
if (/^http(s)?/.test(item.component as string)) {
|
||||
if (item.meta?.internalOrExternal) {
|
||||
item.path = item.component
|
||||
item.path = item.path.replace('#', URL_HASH_TAB)
|
||||
} else {
|
||||
item.meta.frameSrc = item.component
|
||||
}
|
||||
delete item.component
|
||||
}
|
||||
if (!item.component && item.meta?.frameSrc) {
|
||||
item.component = 'IFRAME'
|
||||
}
|
||||
|
@ -94,27 +81,20 @@ export function transformObjToRoute<T = AppRouteModule>(routeList: AppRouteModul
|
|||
} else if (!route.children) {
|
||||
route.component = route.component as string
|
||||
}
|
||||
|
||||
// if (isUrl(route.path)) {
|
||||
// route.component = 'LAYOUT'
|
||||
// const path = route.path
|
||||
// route.path = '/' + route.name
|
||||
// route.redirect = path
|
||||
// }
|
||||
if (isUrl(route.path)) {
|
||||
route.component = 'IFRAME'
|
||||
const path = route.path
|
||||
route.path = '/' + route.name
|
||||
const childRoute = [
|
||||
{
|
||||
path: path,
|
||||
name: route.name,
|
||||
component: 'IFRAME',
|
||||
sort: route.sort,
|
||||
meta: {
|
||||
title: route.name,
|
||||
icon: route.icon
|
||||
}
|
||||
}
|
||||
]
|
||||
route.children = childRoute
|
||||
route.component = 'IFrame'
|
||||
// const path = route.path
|
||||
// route.path = '/' + route.name
|
||||
// route.redirect = path
|
||||
}
|
||||
const component = route.component as string
|
||||
if (component && !isUrl(route.path)) {
|
||||
if (component) {
|
||||
const meta = route.meta || {}
|
||||
meta.hideMenu = !route.visible
|
||||
meta.orderNo = route.sort
|
||||
|
@ -125,8 +105,8 @@ export function transformObjToRoute<T = AppRouteModule>(routeList: AppRouteModul
|
|||
route.component = LayoutMap.get('LAYOUT'.toUpperCase())
|
||||
} else if (component.toUpperCase() === 'IFRAME') {
|
||||
route.component = LayoutMap.get('IFRAME'.toUpperCase())
|
||||
meta.frameSrc = route.path
|
||||
route.path = '/' + route.name
|
||||
// meta.frameSrc = route.path
|
||||
// route.path = '/' + route.name
|
||||
} else {
|
||||
//处理顶级非目录路由
|
||||
meta.single = true
|
||||
|
|
|
@ -236,6 +236,7 @@ export const usePermissionStore = defineStore('app-permission', {
|
|||
routeList = routeList.filter(routeRemoveIgnoreFilter)
|
||||
routeList = flatMultiLevelRoutes(routeList)
|
||||
routes = [PAGE_NOT_FOUND_ROUTE, dashboard, ...routeList, about]
|
||||
console.info(routes)
|
||||
break
|
||||
}
|
||||
|
||||
|
|
|
@ -141,7 +141,9 @@ export const useUserStore = defineStore('app-user', {
|
|||
if (!permissionStore.isDynamicAddedRoute) {
|
||||
const routes = await permissionStore.buildRoutesAction()
|
||||
routes.forEach((route) => {
|
||||
try {
|
||||
router.addRoute(route as unknown as RouteRecordRaw)
|
||||
} catch (e) {}
|
||||
})
|
||||
router.addRoute(PAGE_NOT_FOUND_ROUTE as unknown as RouteRecordRaw)
|
||||
permissionStore.setDynamicAddedRoute(true)
|
||||
|
|
Loading…
Reference in New Issue