From ae808e9d4c308db3f990a426b6bc696698457bfd Mon Sep 17 00:00:00 2001 From: tianfeng <769204422@qq.com> Date: Fri, 5 Sep 2025 12:11:47 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=B7=B3=E8=BD=AC=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/router/index.js | 4 ++- src/utils/routeGuard.js | 16 ++++-------- src/views/LoadingView.vue | 54 +++++++++++++++++++++++++++++++++++++-- 3 files changed, 60 insertions(+), 14 deletions(-) diff --git a/src/router/index.js b/src/router/index.js index 86adb46..90d065c 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -6,7 +6,9 @@ const router = createRouter({ routes: [ { path: "/", - redirect: "/loading", // 默认跳转到加载页面 + name: "root", + component: () => import("../views/LoadingView.vue"), + meta: { requiresAuth: false, isPublic: true }, }, { path: "/loading", diff --git a/src/utils/routeGuard.js b/src/utils/routeGuard.js index 726d85b..30f385e 100644 --- a/src/utils/routeGuard.js +++ b/src/utils/routeGuard.js @@ -396,17 +396,11 @@ class RouteGuard { */ isPublicPage(path) { const publicPages = [ - PAGES.APPLY, // 申请页面 - 重要:申请页面不需要权限检查 - PAGES.NOT_APP, // 错误页面 - APP连接失败时的页面 - "/404", // 404页面 - "/error", // 通用错误页面 - - // "/admin-center", //管理员中心(临时配置) - "/item-distribution", //赠送页面(临时配置) - "/recharge", //支付前页面(临时配置) - "/recharge-standard", //标准支付页面(临时配置) - "/recharge-freight-agent", //金币代理支付页面(临时配置) - ]; + PAGES.APPLY, // 申请页面 - 重要:申请页面不需要权限检查 + PAGES.NOT_APP, // 错误页面 - APP连接失败时的页面 + '/404', // 404页面 + '/error' // 通用错误页面 + ] return publicPages.includes(path); } diff --git a/src/views/LoadingView.vue b/src/views/LoadingView.vue index df48c41..b74e67d 100644 --- a/src/views/LoadingView.vue +++ b/src/views/LoadingView.vue @@ -53,6 +53,31 @@ import {getDefaultPage} from "@/utils/permissionManager.js"; const router = useRouter() +// 检查是否应该执行重定向 +const checkShouldRedirect = () => { + const currentRoute = router.currentRoute.value + const currentPath = currentRoute.path + const routeName = currentRoute.name + + console.log('Checking redirect conditions:', { + path: currentPath, + name: routeName, + url: window.location.href + }) + + // 只有当访问根路径或loading页面时,才执行自动跳转 + const isRootAccess = currentPath === '/' || routeName === 'root' + const isLoadingAccess = currentPath === '/loading' || routeName === 'loading' + + console.log('Redirect decision:', { + isRootAccess, + isLoadingAccess, + shouldRedirect: isRootAccess || isLoadingAccess + }) + + return isRootAccess || isLoadingAccess +} + // 响应式数据 const loadingText = ref('Initializing...') const subText = ref('Setting up your experience') @@ -73,6 +98,14 @@ let stepTimeout = null // 开始加载流程 const startLoading = async () => { try { + // 检查是否应该执行自动跳转 + const shouldRedirect = checkShouldRedirect() + + if (!shouldRedirect) { + console.log('User accessed specific path directly, not performing redirect') + return + } + // 如果在APP环境中,进行连接 if (isInApp()) { await connectToApp() @@ -160,9 +193,26 @@ const waitForLoadingComplete = () => { // 跳转到目标页面 const navigateToTargetPage = async () => { try { - router.replace(getDefaultPage()) + // 获取当前路由信息 + const currentRoute = router.currentRoute.value + const currentPath = currentRoute.path + const routeName = currentRoute.name + + console.log('Current path:', currentPath) + console.log('Route name:', routeName) + + // 只有当访问根路径 ("/") 或者 loading 页面时,才跳转到默认页面 + // 其他所有具体路径都不应该被重定向 + if (currentPath === '/' || routeName === 'root' || currentPath === '/loading' || routeName === 'loading') { + console.log('Navigating to default page from root or loading') + router.replace(getDefaultPage()) + } else { + console.log('User accessed specific path, not redirecting:', currentPath) + // 如果用户直接访问了具体路径,不进行任何跳转 + return + } } catch (error) { - console.error('Failed to get team entry:', error) + console.error('Failed to get default page:', error) // 出错时跳转到申请页面 router.replace('/apply') }