diff --git a/src/permission.js b/src/permission.js index 029dc5a..5d7ede3 100644 --- a/src/permission.js +++ b/src/permission.js @@ -13,7 +13,7 @@ import { governmentGetInfo } from "@/api/login/index"; NProgress.configure({ showSpinner: false }); -const whiteList = ["/login", "/entLogin", "/register"]; // 白名单路径 +const whiteList = ["/login", "/entLogin", "/register"]; const isWhiteList = (path) => { return whiteList.some((pattern) => isPathMatch(pattern, path)); @@ -25,14 +25,15 @@ router.beforeEach((to, from, next) => { } NProgress.start(); - const search = window.location.search || window.location.hash.split("?")[1] || ""; + const search = + window.location.search || window.location.hash.split("?")[1] || ""; const params = new URLSearchParams(search); const userToken = params.get("userToken"); const signature = params.get("signature"); const timespan = params.get("timespan"); // ============================= - // 🔑 新增:处理 clienttoken 登录逻辑 + // 🔑 新增:处理 clienttoken 登录企业单点登录逻辑 // ============================= if (window.location.href.includes("clienttoken=")) { const reg = /[?&]clienttoken=([^]+)/; @@ -41,21 +42,25 @@ router.beforeEach((to, from, next) => { if (clienttoken) { // 清除 clienttoken 避免死循环 - let modifiedUrl = window.location.href.replace(/[?&]clienttoken=[^]+/, ''); - if (modifiedUrl.endsWith('?') || modifiedUrl.endsWith('&')) { - modifiedUrl = modifiedUrl.slice(0, -1); // 去掉末尾多余的符号 + let modifiedUrl = window.location.href.replace( + /[?&]clienttoken=[^]+/, + "" + ); + if (modifiedUrl.endsWith("?") || modifiedUrl.endsWith("&")) { + modifiedUrl = modifiedUrl.slice(0, -1); } // 如果 roles 还未加载,则拉取用户信息 if (store.getters.roles.length === 0) { isRelogin.show = true; - store.dispatch("SingleSignOnGetInfo", { clientToken: clienttoken }) + store + .dispatch("SingleSignOnGetInfo", { clientToken: clienttoken }) .then(() => { isRelogin.show = false; // 清除 URL 中的 clienttoken 并刷新页面 - window.history.replaceState({}, '', modifiedUrl); + window.history.replaceState({}, "", modifiedUrl); // 获取用户权限并生成路由 return store.dispatch("GenerateRoutes"); @@ -68,11 +73,12 @@ router.beforeEach((to, from, next) => { // console.error("单点登录失败:", err); store.dispatch("LogOut").then(() => { // Message.error("单点登录失败,请重试"); - window.location.href = "https://qytt.sipac.gov.cn/ecobrainportal/index.html"; + window.location.href = + "https://qytt.sipac.gov.cn/ecobrainportal/index.html"; }); }); - return; + return; } } } @@ -85,7 +91,7 @@ router.beforeEach((to, from, next) => { return; } - if (userToken && signature && timespan && to.path !== "/login") { + if (userToken && signature && timespan && !isPathMatch("/login", to.path)) { next({ path: "/login", query: { userToken, signature, timespan }, @@ -150,30 +156,34 @@ router.beforeEach((to, from, next) => { // ============================= // 🔐 原始本地登录逻辑 // ============================= - const token = getToken(); - if (token) { + if (getToken()) { to.meta.title && store.dispatch("settings/setTitle", to.meta.title); - if (to.path === "/login") { + /* has token*/ + if (to.path === "/entLogin") { next({ path: "/" }); NProgress.done(); - } else if (isWhiteList(to.path)) { - next(); + } else if (whiteList.indexOf(to.path) !== -1) { + next({ path: "/" }); + NProgress.done(); + // next(); } else { if (store.getters.roles.length === 0) { isRelogin.show = true; + // 判断当前用户是否已拉取完user_info信息 store .dispatch("GetInfo") .then(() => { isRelogin.show = false; store.dispatch("GenerateRoutes").then((accessRoutes) => { - router.addRoutes(accessRoutes); - next({ ...to, replace: true }); + // 根据roles权限生成可访问的路由表 + router.addRoutes(accessRoutes); + next({ ...to, replace: true }); }); }) .catch((err) => { store.dispatch("LogOut").then(() => { Message.error(err); - next("/"); + next({ path: "/" }); }); }); } else { @@ -181,14 +191,16 @@ router.beforeEach((to, from, next) => { } } } else { - if (isWhiteList(to.path)) { + // 没有token + if (whiteList.indexOf(to.path) !== -1) { + // 在免登录白名单,直接进入 next(); } else { - next(`/login?redirect=${encodeURIComponent(to.fullPath)}`); + next(`/entLogin?redirect=${encodeURIComponent(to.fullPath)}`); + NProgress.done(); } } }); - router.afterEach(() => { NProgress.done(); -}); \ No newline at end of file +}); diff --git a/src/router/index.js b/src/router/index.js index 0777c10..92ffe87 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -48,6 +48,11 @@ export const constantRoutes = [ // 测试 component: () => import("@/views/login_v1"), hidden: true, + }, + { + path: "/entLogin", + component: () => import("@/views/entLogin"), + hidden: true, }, { path: "/login_v2", diff --git a/src/views/tongjifenxi/index.vue b/src/views/Home/index.vue similarity index 100% rename from src/views/tongjifenxi/index.vue rename to src/views/Home/index.vue diff --git a/src/views/compilation/handbook/index.vue b/src/views/compilation/handbook/index.vue index 3234361..9cc8b6e 100644 --- a/src/views/compilation/handbook/index.vue +++ b/src/views/compilation/handbook/index.vue @@ -50,7 +50,6 @@