做统一认证登录

This commit is contained in:
2026-09-19 21:44:04 +08:00
parent 1a4471e34d
commit fa281363fb
78 changed files with 8127 additions and 1442 deletions
+14 -1
View File
@@ -1,5 +1,6 @@
import { createRouter, createWebHashHistory } from "vue-router";
import { convertMenusToRoutes } from "./dynamicRoutes";
import { isSSOEnabled, redirectToAuthorize } from "@/utils/authClient";
// 静态子路由:需要在 Main 框架内显示的页面
const staticMainChildren = [
@@ -146,6 +147,13 @@ const staticRoutes = [
component: () => import("@/views/login/forget.vue"),
meta: { requiresAuth: false }
},
// 统一认证中心回跳页(接收 code 换取令牌,页面自身不展示业务内容)
{
path: "/auth/callback",
name: "AuthCallback",
component: () => import("@/views/auth/callback.vue"),
meta: { requiresAuth: false }
},
{
path: "/home",
name: "Home",
@@ -304,7 +312,7 @@ function findFirstValidRoute(routes) {
router.beforeEach(async (to, from, next) => {
const token = localStorage.getItem("token");
const publicPaths = ["/login", "/register", "/forget"];
const publicPaths = ["/login", "/register", "/forget", "/auth/callback"];
if (publicPaths.includes(to.path)) {
if (token) {
@@ -319,6 +327,11 @@ router.beforeEach(async (to, from, next) => {
}
if (!token) {
// 统一认证模式:跳认证中心登录(未开启时走原有本地登录页)
if (isSSOEnabled()) {
await redirectToAuthorize();
return;
}
next({ path: "/login", query: { redirect: to.path } });
return;
}