| | |
| | | let pendingLoading = false |
| | | let routeInitFailed = false |
| | | let routeInitInProgress = false |
| | | let pendingRouteLocation = null |
| | | function getPendingLoading() { |
| | | return pendingLoading |
| | | } |
| | |
| | | function resetRouteInitState() { |
| | | routeInitFailed = false |
| | | routeInitInProgress = false |
| | | pendingRouteLocation = null |
| | | } |
| | | function createRouteLocation(route) { |
| | | return { |
| | | path: route.path, |
| | | query: route.query, |
| | | hash: route.hash, |
| | | replace: true |
| | | } |
| | | } |
| | | function queuePendingRoute(route) { |
| | | pendingRouteLocation = createRouteLocation(route) |
| | | } |
| | | function consumePendingRoute() { |
| | | const queuedRoute = pendingRouteLocation |
| | | pendingRouteLocation = null |
| | | return queuedRoute |
| | | } |
| | | function setupBeforeEachGuard(router) { |
| | | routeRegistry = new RouteRegistry(router) |
| | |
| | | } |
| | | if (!routeRegistry?.isRegistered() && userStore.isLogin) { |
| | | if (routeInitInProgress) { |
| | | queuePendingRoute(to) |
| | | next(false) |
| | | return |
| | | } |
| | |
| | | menuStore.addRemoveRouteFns(routeRegistry?.getRemoveRouteFns() || []) |
| | | IframeRouteManager.getInstance().save() |
| | | useWorktabStore().validateWorktabs(router) |
| | | if (isStaticRoute(to.path)) { |
| | | const targetLocation = consumePendingRoute() || createRouteLocation(to) |
| | | if (isStaticRoute(targetLocation.path)) { |
| | | routeInitInProgress = false |
| | | next({ |
| | | path: to.path, |
| | | query: to.query, |
| | | hash: to.hash, |
| | | replace: true |
| | | }) |
| | | next(targetLocation) |
| | | return |
| | | } |
| | | const { homePath } = useCommon() |
| | | const { path: validatedPath, hasPermission } = RoutePermissionValidator.validatePath( |
| | | to.path, |
| | | targetLocation.path, |
| | | menuList, |
| | | homePath.value || '/' |
| | | ) |
| | | routeInitInProgress = false |
| | | if (!hasPermission) { |
| | | closeLoading() |
| | | console.warn(`[RouteGuard] 用户无权限访问路径: ${to.path},已跳转到首页`) |
| | | console.warn(`[RouteGuard] 用户无权限访问路径: ${targetLocation.path},已跳转到首页`) |
| | | next({ |
| | | path: validatedPath, |
| | | replace: true |
| | | }) |
| | | } else { |
| | | next({ |
| | | path: to.path, |
| | | query: to.query, |
| | | hash: to.hash, |
| | | ...targetLocation, |
| | | path: validatedPath, |
| | | replace: true |
| | | }) |
| | | } |