调整路由校验权限流程

This commit is contained in:
zyy 2020-07-09 10:16:33 +08:00
parent 3693994526
commit 49ac7ba919
3 changed files with 76 additions and 77 deletions

View File

@ -4,10 +4,8 @@ import router from './router/index_APP_TARGET';
import {PermissionParam} from '@/scripts/ProjectConfig';
import NProgress from 'nprogress';
import 'nprogress/nprogress.css';
import { admin} from './router/index_APP_TARGET';
import { getToken, removeToken} from '@/utils/auth';
// import { LoginParams } from '@/utils/login';
import { getSessionStorage } from '@/utils/auth';
import { admin } from './router/index_APP_TARGET';
import { getToken, removeToken, getSessionStorage } from '@/utils/auth';
import localStore from 'storejs';
import { loginInfo } from '@/scripts/ProjectConfig';
@ -19,18 +17,18 @@ function hasPermission(roles, permissionRoles) {
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/, /^\/practiceDisplayNew/, /^\/bigSplitScreen/];
// const designPageRegex = [/^\/design/, /^\/scriptDisplay/, /^\/publish/, /^\/orderauthor/, /^\/system/, /^\/iscs/, /^\/display\/record/, /^\/display\/manage/, /^\/apply/, /^\/plan/, /^\/display\/plan/, /^\/displayNew\/record/, /^\/displayNew\/manage/, /^\/displayNew\/plan/, /^\/practiceDisplayNew/, /^\/bigSplitScreen/];
function isDesignPage(toRoutePath) {
return designPageRegex.some(item => item.test(toRoutePath) );
}
// function isDesignPage(toRoutePath) {
// return designPageRegex.some(item => item.test(toRoutePath) );
// }
for (const val in PermissionParam) {
if (PermissionParam[val].whitePage) {
if (PermissionParam[val].whitePage && !whiteList.includes(PermissionParam[val].whitePage)) {
whiteList.push(PermissionParam[val].whitePage);
}
}
const loginPage = whiteList[0];
const loginDesignPage = whiteList[1];
// const loginPage = whiteList[0];
// const loginDesignPage = whiteList[1];
// 获取路径数据
function getRouteInfo(to) {
@ -41,25 +39,26 @@ function getRouteInfo(to) {
removeToken();
}
if (isDesignPage(toRoutePath)) {
const whitePage = PermissionParam[current_session] ? PermissionParam[current_session].whitePage : '';
loginPath = whitePage || loginDesignPage;
} else {
const whitePage = PermissionParam[current_session] ? PermissionParam[current_session].whitePage : '';
loginPath = whitePage || loginPage;
if (to.query.projectDevice && to.query.type) {
loginPath = `${loginPath}&projectDevice=${to.query.projectDevice}&type=${to.query.type}`;
}
if (current_session && current_session == 'jsxt' || current_session && current_session == 'refereeJsxt') {
const raceId = getSessionStorage('raceId'); // 登陆时候保存 竞赛id
loginPath = `${loginPath}?raceId=${raceId}`;
}
// if (isDesignPage(toRoutePath)) {
// const whitePage = PermissionParam[current_session] ? PermissionParam[current_session].whitePage : '';
// loginPath = whitePage || loginDesignPage;
// } else {
// const whitePage = PermissionParam[current_session] ? PermissionParam[current_session].whitePage : '';
// loginPath = whitePage || loginPage;
// }
loginPath = PermissionParam[current_session] ? PermissionParam[current_session].whitePage : whiteList[0];
if (to.query.projectDevice && to.query.type) {
loginPath = `${loginPath}&projectDevice=${to.query.projectDevice}&type=${to.query.type}`;
}
if (current_session && current_session == 'jsxt' || current_session && current_session == 'refereeJsxt') {
const raceId = getSessionStorage('raceId'); // 登陆时候保存 竞赛id
loginPath = `${loginPath}?raceId=${raceId}`;
}
return { loginPath };
return loginPath;
}
function handleRoute(to, next, routeInfo) {
function handleRoute(to, next, loginPath) {
if (store.getters.roles.length === 0) {
store.dispatch('GetInfo', getToken()).then(res => {
// 根据roles权限生成可访问的路由表
@ -76,7 +75,7 @@ function handleRoute(to, next, routeInfo) {
}).catch(() => {
store.dispatch('FedLogOut').then(() => {
Vue.prototype.$messageBox('验证失败,请重新登录!');
next({ path: routeInfo.loginPath });
next({ path: loginPath });
});
});
} else {
@ -99,14 +98,14 @@ router.beforeEach((to, from, next) => {
document.title = loginInfo[project || 'login'].browserTitle || loginInfo[project || 'login'].title;
NProgress.start();
const routeInfo = getRouteInfo(to);
const loginPath = getRouteInfo(to);
if (getToken()) {
if (to.path === routeInfo.loginPath) {
if (to.path === loginPath) {
// 登录页面不拦截
next();
} else {
// 进入系统重新计算路由
handleRoute(to, next, routeInfo);
handleRoute(to, next, loginPath);
}
} else {
if (whiteList.indexOf(to.path) !== -1) {
@ -118,7 +117,7 @@ router.beforeEach((to, from, next) => {
next();
} else {
// 否则全部重定向到登录页
next(routeInfo.loginPath);
next(loginPath);
}
}
});

View File

@ -227,7 +227,7 @@ export const constantRoutes = [
hidden: true
},
{
path: '/gzzbxy/relay/:deviceid',
path: '/gzzbxy/relay/:deviceid', // 贵阳 继电器
component: Jlmap3dTrain,
hidden: true
},

View File

@ -8,7 +8,7 @@ import FaviconJyd from '@/assets/icon/favicon_jyd.png';
import Bottom_Jyd from '@/assets/icon/bottom_jyd.png';
import Link_Jyd from '@/assets/icon/link_jyd.png';
import FaviconTky from '@/assets/icon/favicon_tky.png';
import { LoginParams } from '@/utils/login';
// import { LoginParams } from '@/utils/login';
// title:页面title; loginPath:退出登录跳转路径; loginParam:登录接口参数project;loginTitle:登录页左上角titlelogoWidth登录页左上角logo宽度
// homeTitle:导航栏title(没有采用title); browserTitle:浏览器窗口titlebottomColumn底部栏描述bottomIcon底部栏Icon;linkIcon:浏览器窗口icon(没有采用ProjectIcon)
@ -224,96 +224,96 @@ export const goOtherPlatformMenu = { // 导航栏快速切换平台
};
export const PermissionParam = { // 路径权限处理所需参数配置(跳转白名单&路径正则匹配&clientId
hyd: {
// systemType: '011'
whitePage: '/login?project=hyd',
reg: /^\/hyd/,
systemType: '011',
clientId: null
// reg: /^\/hyd/,
systemType: '011'
// clientId: null
},
designhyd: {
// systemType: '011'
whitePage: '/design/login?project=hyd',
reg: /^\/designhyd/,
systemType: '011',
clientId: LoginParams.Design.clientId
// reg: /^\/designhyd/,
systemType: '011'
// clientId: LoginParams.Design.clientId
},
login: {
whitePage: '/login',
systemType: '011'
},
design: {
whitePage: '/design/login',
systemType: '011'
},
designxty: {
whitePage: '/design/login?project=xty',
reg: /^\/designxty/,
systemType: '013',
clientId: LoginParams.Design.clientId
// reg: /^\/designxty/,
systemType: '013'
// clientId: LoginParams.Design.clientId
},
designgzb: {
whitePage: '/design/login?project=gzb',
reg: /^\/designgzb/,
systemType: '014',
clientId: LoginParams.Design.clientId
// reg: /^\/designgzb/,
systemType: '014'
// clientId: LoginParams.Design.clientId
},
designxadt: {
whitePage: '/design/login?project=xadt',
reg: /^\/designxadt/,
systemType: '012',
clientId: LoginParams.Design.clientId
// reg: /^\/designxadt/,
systemType: '012'
// clientId: LoginParams.Design.clientId
},
designjyd: {
whitePage: '/design/login?project=jyd',
reg: /^\/designjyd/,
systemType: '017',
clientId: LoginParams.Design.clientId
// reg: /^\/designjyd/,
systemType: '017'
// clientId: LoginParams.Design.clientId
},
designtky: {
whitePage: '/design/login?project=tky',
reg: /^\/designtky/,
systemType: '018',
clientId: LoginParams.Design.clientId
// reg: /^\/designtky/,
systemType: '018'
// clientId: LoginParams.Design.clientId
},
xty: {
whitePage: '/login?project=xty',
reg: /^\/xty/,
systemType: '013',
clientId: null
// reg: /^\/xty/,
systemType: '013'
// clientId: null
},
gzb: {
whitePage: '/login?project=gzb',
reg: /^\/gzb/,
systemType: '014',
clientId: null
// reg: /^\/gzb/,
systemType: '014'
// clientId: null
},
xadt: {
whitePage: '/login?project=xadt',
reg: /^\/xadt/,
systemType: '012',
clientId: null
// reg: /^\/xadt/,
systemType: '012'
// clientId: null
},
jyd: {
whitePage: '/login?project=jyd',
reg: /^\/jyd/,
systemType: '017',
clientId: null
// reg: /^\/jyd/,
systemType: '017'
// clientId: null
},
tky: {
whitePage: '/login?project=tky',
reg: /^\/tky/,
systemType: '018',
clientId: null
// reg: /^\/tky/,
systemType: '018'
// clientId: null
},
jsxt: {
whitePage: '/jsxt/login',
reg: /^\/jsxt/,
systemType: '015',
clientId: null
// reg: /^\/jsxt/,
systemType: '015'
// clientId: null
},
refereeJsxt: {
whitePage: '/refereeJsxt/login',
reg: /^\/refereeJsxt/,
systemType: '015',
clientId: LoginParams.Design.clientId
// reg: /^\/refereeJsxt/,
systemType: '015'
// clientId: LoginParams.Design.clientId
}
};
export const ProjectList = [