From 98f0335e581fa19075091bf34ab485c0025817a3 Mon Sep 17 00:00:00 2001 From: yanfeiyong <2060201549@qq.com> Date: Tue, 27 May 2025 14:34:48 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E7=8E=AF=E5=A2=83=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/permission.js | 58 +-- src/router/index.js | 5 + src/views/{tongjifenxi => Home}/index.vue | 0 src/views/compilation/handbook/index.vue | 105 +++++- src/views/compilation/handbook/yulan.vue | 60 --- .../{onecailiao => monolithic}/index.vue | 0 .../components/ProjectDetails/Months.vue | 4 +- src/views/entLogin.vue | 357 ++++++++++++++++++ src/views/index.vue | 2 +- src/views/login_v1.vue | 4 +- src/views/manage-add/index.vue | 4 +- src/views/manage-info/index.vue | 4 +- src/views/manage/index.vue | 1 + src/views/models/badlist/index.vue | 1 + 14 files changed, 495 insertions(+), 110 deletions(-) rename src/views/{tongjifenxi => Home}/index.vue (100%) delete mode 100644 src/views/compilation/handbook/yulan.vue rename src/views/compilation/{onecailiao => monolithic}/index.vue (100%) create mode 100644 src/views/entLogin.vue 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 @@