From 09abc2fbe13f88e3ff486a187fefc901506937e1 Mon Sep 17 00:00:00 2001 From: fan <18706759286@163.com> Date: Thu, 16 Apr 2020 17:11:46 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E5=85=A8=E9=83=A8=E6=8F=90=E5=87=BA=E5=88=B0ProjectConfig?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/permission.js | 65 +++++++--------------- src/scripts/ProjectConfig.js | 44 ++++++++++++++- src/views/login/index.vue | 4 +- src/views/system/systemGenerate/create.vue | 5 +- 4 files changed, 65 insertions(+), 53 deletions(-) diff --git a/src/permission.js b/src/permission.js index be1e8f186..3d3c9b496 100644 --- a/src/permission.js +++ b/src/permission.js @@ -1,6 +1,7 @@ import Vue from 'vue'; import store from '@/store/index_APP_TARGET'; import router from './router/index_APP_TARGET'; +import {PermissionParam} from '@/scripts/ProjectConfig'; import NProgress from 'nprogress'; import { admin} from './router/index_APP_TARGET'; import { getToken, removeToken} from '@/utils/auth'; @@ -14,7 +15,7 @@ function hasPermission(roles, permissionRoles) { return roles.some(role => permissionRoles.indexOf(role) >= 0); } -const whiteList = ['/login', '/design/login', '/xty/login', '/designxty/login', '/gzb/login', '/designgzb/login', '/gzzbxy/relay', '/xadt/login', '/designxadt/login']; // 不重定向白名单 +const whiteList = ['/login', '/design/login', '/gzzbxy/relay']; // 不重定向白名单 const designPageRegex = [/^\/design/, /^\/scriptDisplay/, /^\/publish/, /^\/orderauthor/, /^\/system/, /^\/iscs/, /^\/display\/record/, /^\/display\/manage/, /^\/apply/, /^\/plan/, /^\/display\/plan/, /^\/displayNew\/record/, /^\/displayNew\/manage/, /^\/displayNew\/plan/]; @@ -23,61 +24,35 @@ function isDesignPage(toRoutePath) { return item.test(toRoutePath); }); } - +for (const val in PermissionParam) { + whiteList.push(PermissionParam[val].whitePage); +} const loginPage = whiteList[0]; const loginDesignPage = whiteList[1]; -const loginXtyPage = whiteList[2]; -const loginDesignXtyPage = whiteList[3]; -const loginGzbPage = whiteList[4]; -const loginDesignGzbPage = whiteList[5]; -const loginXasPage = whiteList[7]; -const loginDesignXasPage = whiteList[8]; -const loginDesignPageMenu = { - design: loginDesignPage, - designxty: loginDesignXtyPage, - designgzb: loginDesignGzbPage, - designhyd: loginDesignPage, - designxadt: loginDesignXasPage -}; -const loginPageMenu = { - login: loginPage, - xty: loginXtyPage, - gzb: loginGzbPage, - hyd: loginPage, - xadt: loginXasPage -}; + // 获取路径数据 function getRouteInfo(to) { - let loginPath = '/login'; + let loginPath = ''; let clientId = ''; const toRoutePath = to.redirectedFrom || to.path; const current_session = getSessionStorage('project'); - if (/^\/designxty/.test(toRoutePath)) { - loginPath = loginDesignXtyPage; - clientId = LoginParams.Design.clientId; - } else if (/^\/designxadt/.test(toRoutePath)) { - loginPath = loginDesignXasPage; - clientId = LoginParams.Design.clientId; - } else if (/^\/designgzb/.test(toRoutePath)) { - loginPath = loginDesignGzbPage; - clientId = LoginParams.Design.clientId; - } else if (isDesignPage(toRoutePath)) { - loginPath = loginDesignPageMenu[current_session] || loginDesignPage; + for (const val in PermissionParam) { + if (PermissionParam[val].reg.test(toRoutePath)) { + loginPath = PermissionParam[val].whitePage; + clientId = PermissionParam[val].clientId; + break; + } + } + if (isDesignPage(toRoutePath)) { + const whitePage = PermissionParam[current_session] ? PermissionParam[current_session].whitePage : ''; + loginPath = whitePage || loginDesignPage; clientId = LoginParams.Design.clientId; if (current_session && !current_session.startsWith('design')) { removeToken(); } - } else if ( /^\/xty/.test(toRoutePath)) { - loginPath = loginXtyPage; - clientId = null; - } else if ( /^\/gzb/.test(toRoutePath)) { - loginPath = loginGzbPage; - clientId = null; - } else if ( /^\/xadt/.test(toRoutePath)) { - loginPath = loginXasPage; - clientId = null; } else { - loginPath = loginPageMenu[current_session] || loginPath; + const whitePage = PermissionParam[current_session] ? PermissionParam[current_session].whitePage : ''; + loginPath = whitePage || loginPage; clientId = null; if (current_session && current_session.startsWith('design')) { removeToken(); @@ -143,7 +118,7 @@ router.beforeEach((to, from, next) => { if (whiteList.indexOf(to.path) !== -1) { // 在免登录白名单,直接进入 next(); - } else if (to.path.substr(0, 13) == whiteList[6]) { + } else if (to.path.substr(0, 13) == whiteList[2]) { next(); } else { // 否则全部重定向到登录页 diff --git a/src/scripts/ProjectConfig.js b/src/scripts/ProjectConfig.js index a3c4f0461..43ad16fd3 100644 --- a/src/scripts/ProjectConfig.js +++ b/src/scripts/ProjectConfig.js @@ -4,8 +4,9 @@ import FaviconXty from '@/assets/icon/favicon_xty.png'; import FaviconGzb from '@/assets/icon/favicon_gzb.png'; import FaviconHyd from '@/assets/icon/favicon_hyd.png'; import FaviconXadt from '@/assets/icon/favicon_xas.png'; +import { LoginParams } from '@/utils/login'; -export const loginInfo = { +export const loginInfo = { // 页面title & 退出登录跳转路径 xty: { title: '西安铁路职业技术学院城市轨道交通实训平台', loginPath: '/xty/login' @@ -73,8 +74,8 @@ export const ProjectCode = { }; export const GetMapListByProjectList = ['xty', 'designxty', 'gzb', 'designgzb', 'xadt', 'designxadt']; // 实训设计平台通过项目code获取地图列表的项目 export const CaseHideProjectList = ['hyd', 'designhyd']; // 案例展示隐藏的项目 -export const GenerateRouteProjectList = ['xty', 'designxty', 'gzb', 'designgzb', 'xadt', 'designxadt'];// 需要在公共路由中生成登录页面的项目 -export const goOtherPlatformMenu = { +export const GenerateRouteProjectList = ['xty', 'designxty', 'gzb', 'designgzb', 'xadt', 'designxadt'];// 需要在公共路由中生成登录页面的项目&登录页样式 +export const goOtherPlatformMenu = { // 导航栏快速切换平台 login: '/design/login', design: '/login', xty: '/designxty/login', @@ -86,3 +87,40 @@ export const goOtherPlatformMenu = { xadt: '/designxadt/login', designxadt: '/xadt/login' }; +export const PermissionParam = { // 路径权限处理所需参数配置(跳转白名单&路径正则匹配&clientId) + designxty: { + whitePage: '/designxty/login', + reg: /^\/designxty/, + clientId: LoginParams.Design.clientId + }, + designgzb: { + whitePage: '/designgzb/login', + reg: /^\/designgzb/, + clientId: LoginParams.Design.clientId + }, + designxadt: { + whitePage: '/designxadt/login', + reg: /^\/designxadt/, + clientId: LoginParams.Design.clientId + }, + xty: { + whitePage: '/xty/login', + reg: /^\/xty/, + clientId: null + }, + gzb: { + whitePage: '/gzb/login', + reg: /^\/gzb/, + clientId: null + }, + xadt: { + whitePage: '/xadt/login', + reg: /^\/xadt/, + clientId: null + } +}; +export const ProjectList = [ + {value:'xty', label:'西铁院'}, + {value: 'gzb', label: '贵州装备'}, + {value: 'xadt', label: '西安地铁'} +]; diff --git a/src/views/login/index.vue b/src/views/login/index.vue index 73e8c2cbc..9b16d630d 100644 --- a/src/views/login/index.vue +++ b/src/views/login/index.vue @@ -103,7 +103,7 @@ import { getLoginWmurl, checkLoginStatus } from '@/api/login'; import { LoginParams } from '@/utils/login'; import bgImg from '@/assets/bg1.jpg'; import { UrlConfig } from '@/scripts/ConstDic'; -import { loginInfo, ProjectIcon} from '@/scripts/ProjectConfig'; +import { loginInfo, ProjectIcon, GenerateRouteProjectList} from '@/scripts/ProjectConfig'; import { removeToken } from '@/utils/auth'; import LangStorage from '@/utils/lang'; import FloatPart from './floatPart'; @@ -167,7 +167,7 @@ export default { }, isProject() { const projectName = this.$route.path.split('/')[1]; - return projectName.endsWith('xty') || projectName.endsWith('gzb') || projectName.endsWith('hyd') || projectName.endsWith('xadt'); + return GenerateRouteProjectList.includes(projectName); }, logoImg() { const projectName = this.$route.path.split('/')[1]; diff --git a/src/views/system/systemGenerate/create.vue b/src/views/system/systemGenerate/create.vue index 21d7b898b..d469e0b3e 100644 --- a/src/views/system/systemGenerate/create.vue +++ b/src/views/system/systemGenerate/create.vue @@ -11,6 +11,7 @@