fix(auth): 企微提醒卡片深链登录后回跳原目标
- 新增 shared/utils/redirect.ts 安全回跳校验(防开放重定向) - 路由守卫未登录跳转携带 redirect 完整深链,已登录访问登录页优先回跳 - 登录成功统一按 redirect 深链落地,支持企微卡片点击直达精益培训模块
This commit is contained in:
1 parent
f1beb6fefb
commit
1034435355
15 files changed
+656
-38
No files matched your search
@@ -2,7 +2,8 @@
|
||||
* app/router/guards.ts
|
||||
* 全局路由守卫:认证、权限、旧 URL 兼容、document.title。
|
||||
* 依赖:vue-router、config、auth.store、i18n、adminModulePath、isPublicPath、useMessage、contract-payment 权限常量。
|
||||
* 逻辑:beforeEach 做登录/管理员/功能权限校验;afterEach 将 meta.title(i18n key 或字面量)解析为浏览器标题。
|
||||
* 逻辑:beforeEach 做登录/管理员/功能权限校验,未登录跳登录页时携带 redirect 深链参数(登录后原样回跳);
|
||||
* afterEach 将 meta.title(i18n key 或字面量)解析为浏览器标题。
|
||||
*/
|
||||
import type { Router } from 'vue-router';
|
||||
import { config } from '@/config';
|
||||
@@ -11,6 +12,7 @@ import { useAuthStore } from '@/features/auth/stores/auth.store';
|
||||
import { CONTRACT_PAYMENT_ACCESS_PERMISSION } from '@/features/contract-payment/constants';
|
||||
import { isPublicPath } from '@/shared/constants/routes';
|
||||
import { useMessage } from '@/shared/composables/useMessage';
|
||||
import { resolveSafeRedirect } from '@/shared/utils/redirect';
|
||||
import i18n from '@/i18n';
|
||||
|
||||
/**
|
||||
@@ -57,7 +59,7 @@ function setupChunkLoadRecovery(router: Router): void {
|
||||
}
|
||||
|
||||
/**
|
||||
注册全局 beforeEach / afterEach:登录、管理员、功能权限与页面标题。
|
||||
* 注册全局 beforeEach / afterEach:登录、管理员、功能权限与页面标题。
|
||||
* 核心逻辑:requiresAdmin 仍静默回应用管理;requiresFeaturePermission 会提示后再跳转,避免用户以为入口损坏。
|
||||
* @param router - 应用根路由实例
|
||||
*/
|
||||
@@ -79,12 +81,15 @@ export function setupRouterGuards(router: Router): void {
|
||||
}
|
||||
|
||||
if (to.path === '/login' && auth.isLoggedIn) {
|
||||
next('/workspace/applications');
|
||||
// 已登录访问登录页:优先回跳 redirect 深链(如企微卡片点入),避免丢失原目标
|
||||
const redirect = resolveSafeRedirect(to.query.redirect);
|
||||
next(redirect || '/workspace/applications');
|
||||
return;
|
||||
}
|
||||
|
||||
if (!auth.isLoggedIn && !isPublicPath(to.path)) {
|
||||
next('/login');
|
||||
// 未登录:携带完整深链(含 query)跳登录页,登录成功后原样回跳,保证企微卡片“点击直达”
|
||||
next({ path: '/login', query: { redirect: to.fullPath } });
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user