This commit is contained in:
2026-04-25 20:48:08 +08:00
parent 138a0dc288
commit 02e63dd25a
11 changed files with 226 additions and 378 deletions

View File

@@ -1,6 +1,6 @@
import { isCurrentOrigin, isPortalDomainConfigReady, isSubPortal, mainPortalOrigin, subPortalOrigin } from '@/constants/portal'
import { useUserStore } from '@/stores/user'
import { createRouter, createWebHistory } from 'vue-router'
import { isCurrentOrigin, isPortalDomainConfigReady, isSubPortal, mainPortalOrigin, subPortalOrigin } from '@/constants/portal'
import { statisticsRoutes } from './modules/statistics'
// 路由配置
@@ -61,13 +61,13 @@ const routes = [
path: 'login',
name: 'SubLogin',
component: () => import('@/pages/sub-portal/SubLogin.vue'),
meta: { title: '子账号登录' }
meta: { title: '登录' }
},
{
path: 'register',
name: 'SubRegister',
component: () => import('@/pages/sub-portal/SubRegister.vue'),
meta: { title: '子账号注册' }
meta: { title: '注册' }
},
{
path: 'reset',
@@ -440,13 +440,10 @@ router.beforeEach(async (to, from, next) => {
return
}
// 登录态下强制要求主/子域配置完整,避免混域运行
if (userStore.isLoggedIn && !isPortalDomainConfigReady) {
if (import.meta.env.PROD) {
userStore.logout()
next(loginPathByRoute)
return
}
// 登录态下若未配置主/子域名,降级为单域运行(不强制登出)
// 否则会出现“登录成功后立即被清会话”的问题。
if (userStore.isLoggedIn && !isPortalDomainConfigReady && import.meta.env.PROD) {
console.warn('[router] 未配置主/子域名,当前以单域模式运行,跳过域名隔离跳转')
}
// 域名隔离:子账号登录态必须在子账号专属域名
@@ -467,7 +464,7 @@ router.beforeEach(async (to, from, next) => {
// 已登录用户访问认证页面,按账号类型重定向到对应首页
if (isAuthRoute && userStore.isLoggedIn) {
next(userStore.accountKind === 'subordinate' ? '/subscriptions' : '/dashboard')
next(userStore.accountKind === 'subordinate' ? '/subscriptions' : '/products')
return
}