路由权限生成调整逻辑
This commit is contained in:
parent
ce0c5c074c
commit
61c3650621
@ -6,9 +6,10 @@ 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 { LoginParams } from '@/utils/login';
|
||||
import { getSessionStorage } from '@/utils/auth';
|
||||
import localStore from 'storejs';
|
||||
import { loginInfo } from '@/scripts/ProjectConfig';
|
||||
|
||||
function hasPermission(roles, permissionRoles) {
|
||||
if (roles.indexOf(admin) >= 0) return true;
|
||||
@ -21,9 +22,7 @@ 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/];
|
||||
|
||||
function isDesignPage(toRoutePath) {
|
||||
return designPageRegex.some(item => {
|
||||
return item.test(toRoutePath);
|
||||
});
|
||||
return designPageRegex.some(item => item.test(toRoutePath) );
|
||||
}
|
||||
for (const val in PermissionParam) {
|
||||
whiteList.push(PermissionParam[val].whitePage);
|
||||
@ -34,49 +33,35 @@ const loginDesignPage = whiteList[1];
|
||||
// 获取路径数据
|
||||
function getRouteInfo(to) {
|
||||
let loginPath = '';
|
||||
let clientId = '';
|
||||
const toRoutePath = to.redirectedFrom || to.path;
|
||||
const current_session = getSessionStorage('project');
|
||||
for (const val in PermissionParam) {
|
||||
if (PermissionParam[val].reg.test(toRoutePath)) {
|
||||
loginPath = PermissionParam[val].whitePage;
|
||||
clientId = PermissionParam[val].clientId;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (whiteList.includes(toRoutePath)) {
|
||||
if (whiteList.includes(toRoutePath)) { // 登陆页面清空 token
|
||||
removeToken();
|
||||
}
|
||||
|
||||
if (isDesignPage(toRoutePath)) {
|
||||
const whitePage = PermissionParam[current_session] ? PermissionParam[current_session].whitePage : '';
|
||||
loginPath = whitePage || loginDesignPage;
|
||||
clientId = LoginParams.Design.clientId;
|
||||
loginPath = loginDesignPage;
|
||||
if (current_session && !current_session.startsWith('design')) {
|
||||
removeToken();
|
||||
}
|
||||
} else {
|
||||
const whitePage = PermissionParam[current_session] ? PermissionParam[current_session].whitePage : '';
|
||||
loginPath = whitePage || loginPage;
|
||||
clientId = null;
|
||||
if (current_session && current_session.startsWith('design')) {
|
||||
removeToken();
|
||||
}
|
||||
}
|
||||
|
||||
return { clientId, loginPath };
|
||||
return { loginPath };
|
||||
}
|
||||
|
||||
function handleRoute(to, from, next, routeInfo) {
|
||||
if (store.getters.roles.length === 0) {
|
||||
// 拉取用户信息
|
||||
store.dispatch('GetInfo', getToken()).then(res => {
|
||||
// 根据roles权限生成可访问的路由表
|
||||
const roles = res.roles;
|
||||
store.dispatch('GenerateRoutes', { roles, clientId: routeInfo.clientId }).then(() => {
|
||||
// 动态添加可访问路由表
|
||||
router.addRoutes(store.getters.addRouters);
|
||||
// router.addRoutes(asyncRouter1);
|
||||
store.dispatch('GenerateRoutes', { roles }).then(() => {
|
||||
router.addRoutes(store.getters.addRouters); // 动态添加可访问路由表
|
||||
if (to.redirectedFrom) {
|
||||
next({ path: to.redirectedFrom, replace: true });
|
||||
} else {
|
||||
@ -105,10 +90,12 @@ function handleRoute(to, from, next, routeInfo) {
|
||||
}
|
||||
|
||||
router.beforeEach((to, from, next) => {
|
||||
const project = getSessionStorage('project');
|
||||
document.title = loginInfo[project || 'login'].browserTitle || loginInfo[project || 'login'].title;
|
||||
|
||||
NProgress.start();
|
||||
const routeInfo = getRouteInfo(to);
|
||||
if (getToken()) {
|
||||
// 已登录
|
||||
if (to.path === routeInfo.loginPath) {
|
||||
// 登录页面不拦截
|
||||
next();
|
||||
@ -117,8 +104,6 @@ router.beforeEach((to, from, next) => {
|
||||
handleRoute(to, from, next, routeInfo);
|
||||
}
|
||||
} else {
|
||||
// 继电器使用
|
||||
// 未登录情况下
|
||||
if (whiteList.indexOf(to.path) !== -1) {
|
||||
// 在免登录白名单,直接进入
|
||||
next();
|
||||
|
@ -130,7 +130,7 @@ const JsxtApply = () => import('@/views/jsxt/apply/index');
|
||||
const RefereeList = () => import('@/views/jsxt/refereeList/index');
|
||||
const homeJsxt = () => import('@/views/jsxt/home/index');
|
||||
|
||||
import { loginInfo, GenerateRouteProjectList } from '@/scripts/ProjectConfig';
|
||||
import { GenerateRouteProjectList } from '@/scripts/ProjectConfig';
|
||||
import { getSessionStorage } from '@/utils/auth';
|
||||
|
||||
/**
|
||||
@ -157,22 +157,17 @@ export const mapCreater = '02'; // 地图创建权限
|
||||
export const lessonCreater = '03'; // 课程创建权限
|
||||
export const admin = '04'; // 管理员
|
||||
export const superAdmin = '05'; // 超级管理员
|
||||
export const referee = '07'; // 裁判员
|
||||
// export const referee = '07'; // 裁判员
|
||||
|
||||
export const userExam = '011'; // 考试系统
|
||||
export const userLesson = '012'; // 教学系统
|
||||
export const userSimulation = '013'; // 仿真系统
|
||||
export const userScreen = '014'; // 大屏系统
|
||||
export const userPlan = '015'; // 计划系统
|
||||
export const userTrainingPlatform = '016'; // 实训平台
|
||||
export const refereePlatform = '017';
|
||||
// const isDev = process.env.NODE_ENV === 'development';
|
||||
export const projectTrain = '011'; // 城市轨道项目
|
||||
export const projectXian = '012'; // 西安地铁项目
|
||||
export const projectXty = '013'; // 西铁院
|
||||
export const projectGzzb = '014'; // 贵州装备
|
||||
export const projectJsxt = '015'; // 竞赛系统
|
||||
|
||||
export const userTrainingPlatform = '016'; // 实训系统
|
||||
// export const refereePlatform = '017'; // 裁判系统
|
||||
|
||||
/**
|
||||
* constantRoutes
|
||||
* a base page that does not have permission requirements
|
||||
* all roles can be accessed
|
||||
*/
|
||||
export const constantRoutes = [
|
||||
// 实训平台登录
|
||||
{
|
||||
@ -249,6 +244,77 @@ GenerateRouteProjectList.forEach(item => {
|
||||
hidden: true
|
||||
});
|
||||
});
|
||||
// 公共路由不需要过滤 直接可以访问
|
||||
export const publicAsyncRoute = [
|
||||
{ // 全屏战场图
|
||||
path: '/display/:mode',
|
||||
component: Display,
|
||||
hidden: true
|
||||
},
|
||||
{
|
||||
path: '/displayNew/:mode',
|
||||
component: DisplayNew,
|
||||
hidden: true
|
||||
},
|
||||
{
|
||||
path: '/design/display/:mode',
|
||||
component: DesignDisplay,
|
||||
hidden: true
|
||||
},
|
||||
{
|
||||
path: '/design/displayNew/:mode',
|
||||
component: DesignDisplayNew,
|
||||
hidden: true
|
||||
},
|
||||
{ // 剧本编辑 战场图
|
||||
path: '/scriptDisplay/:mode',
|
||||
component: ScriptDisplay,
|
||||
hidden: true
|
||||
},
|
||||
{ // 剧本编辑 战场图
|
||||
path: '/scriptDisplayNew/:mode',
|
||||
component: ScriptDisplayNew,
|
||||
hidden: true
|
||||
},
|
||||
{
|
||||
path: '/displayBigScreen/:mapId',
|
||||
component: BigScreen,
|
||||
hidden: true
|
||||
},
|
||||
{ // 综合演练室
|
||||
path: '/trainroom',
|
||||
component: TrainRoom,
|
||||
hidden: true
|
||||
},
|
||||
{
|
||||
path: '/jointTraining',
|
||||
component: JointTraining,
|
||||
hidden: true
|
||||
},
|
||||
{
|
||||
path: '/jointTrainingNew',
|
||||
component: JointTrainingNew,
|
||||
hidden: true
|
||||
},
|
||||
{
|
||||
path: '/jlmap3d',
|
||||
component: Jlmap3d,
|
||||
hidden: true
|
||||
},
|
||||
{
|
||||
path: '/displayIscs/system',
|
||||
component: IscsSystem,
|
||||
hidden: true,
|
||||
children: [
|
||||
{
|
||||
path: 'config/:mode',
|
||||
component: IscsConfig,
|
||||
hidden: true
|
||||
}
|
||||
]
|
||||
}
|
||||
];
|
||||
// 城市轨道项目
|
||||
export const asyncRouter = [
|
||||
{ // 公共地图
|
||||
path: '/design',
|
||||
@ -363,136 +429,12 @@ export const asyncRouter = [
|
||||
}
|
||||
]
|
||||
},
|
||||
// { // 个人地图
|
||||
// path: '/design/userlist',
|
||||
// redirect: '/design/userlist/home',
|
||||
// component: Layout,
|
||||
// meta: {
|
||||
// roles: [admin]
|
||||
// },
|
||||
// children: [
|
||||
// {
|
||||
// path: '',
|
||||
// redirect: '/design/userlist/home',
|
||||
// component: DesignPlatformUser,
|
||||
// meta: {
|
||||
// i18n: 'router.designUserPage',
|
||||
// icon: 'design'
|
||||
// },
|
||||
// children: [
|
||||
// {
|
||||
// path: 'home',
|
||||
// component: DesignPlatformHome,
|
||||
// meta: {
|
||||
// }
|
||||
// },
|
||||
// { // 地图 绘制
|
||||
// path: 'map/draw/:mapId/:view',
|
||||
// component: Mapedit,
|
||||
// hidden: true
|
||||
// },
|
||||
// { // 运行图设计
|
||||
// path: 'runPlan/detail/:mapId',
|
||||
// component: PlanMonitorDetail,
|
||||
// hidden: true
|
||||
// }
|
||||
// ]
|
||||
// }
|
||||
// ]
|
||||
// },
|
||||
{ // 全屏战场图
|
||||
path: '/display/:mode',
|
||||
component: Display,
|
||||
meta: {
|
||||
},
|
||||
hidden: true
|
||||
},
|
||||
{
|
||||
path: '/displayNew/:mode',
|
||||
component: DisplayNew,
|
||||
meta: {
|
||||
},
|
||||
hidden: true
|
||||
},
|
||||
{
|
||||
path: '/design/display/:mode',
|
||||
component: DesignDisplay,
|
||||
meta: {
|
||||
},
|
||||
hidden: true
|
||||
},
|
||||
{
|
||||
path: '/design/displayNew/:mode',
|
||||
component: DesignDisplayNew,
|
||||
meta: {
|
||||
},
|
||||
hidden: true
|
||||
},
|
||||
{ // 剧本编辑 战场图
|
||||
path: '/scriptDisplay/:mode',
|
||||
component: ScriptDisplay,
|
||||
meta: {
|
||||
},
|
||||
hidden: true
|
||||
},
|
||||
{ // 剧本编辑 战场图
|
||||
path: '/scriptDisplayNew/:mode',
|
||||
component: ScriptDisplayNew,
|
||||
meta: {
|
||||
},
|
||||
hidden: true
|
||||
},
|
||||
{
|
||||
path: '/displayIscs/system',
|
||||
component: IscsSystem,
|
||||
meta: {
|
||||
},
|
||||
hidden: true,
|
||||
children: [
|
||||
{
|
||||
path: 'config/:mode',
|
||||
component: IscsConfig,
|
||||
hidden: true
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
path: '/displayBigScreen/:mapId',
|
||||
component: BigScreen,
|
||||
meta: {
|
||||
},
|
||||
hidden: true
|
||||
},
|
||||
{ // 综合演练室
|
||||
path: '/trainroom',
|
||||
component: TrainRoom,
|
||||
meta: {
|
||||
},
|
||||
hidden: true
|
||||
},
|
||||
{
|
||||
path: '/jointTraining',
|
||||
component: JointTraining,
|
||||
hidden: true
|
||||
},
|
||||
{
|
||||
path: '/jointTrainingNew',
|
||||
component: JointTrainingNew,
|
||||
hidden: true
|
||||
},
|
||||
{
|
||||
path: '/jlmap3d',
|
||||
component: Jlmap3d,
|
||||
meta: {
|
||||
},
|
||||
hidden: true
|
||||
},
|
||||
{ // 实训平台
|
||||
path: '/trainingPlatform',
|
||||
component: Layout,
|
||||
hidden: true,
|
||||
meta: {
|
||||
roles: [admin, userSimulation, user, userTrainingPlatform]
|
||||
roles: [admin, user, userTrainingPlatform]
|
||||
},
|
||||
children: [
|
||||
{
|
||||
@ -975,6 +917,7 @@ export const asyncRouter = [
|
||||
]
|
||||
}
|
||||
];
|
||||
|
||||
export const projectRoute = {
|
||||
designgzb: [
|
||||
{
|
||||
@ -999,6 +942,7 @@ export const projectRoute = {
|
||||
}
|
||||
]
|
||||
};
|
||||
// 竞赛系统
|
||||
export const JSXT = [
|
||||
{
|
||||
path: '/jsxt',
|
||||
@ -1006,7 +950,7 @@ export const JSXT = [
|
||||
component: Layout,
|
||||
meta: {
|
||||
i18n: 'router.competitionManage',
|
||||
roles: [user, userTrainingPlatform, referee]
|
||||
roles: [user, admin, userTrainingPlatform]
|
||||
},
|
||||
hidden: getSessionStorage('project') ? !getSessionStorage('project').endsWith('jsxt') && !window.document.location.pathname.includes('jsxt') : !window.document.location.pathname.includes('jsxt'),
|
||||
children: [
|
||||
@ -1058,7 +1002,7 @@ export const JSXT = [
|
||||
component: Layout,
|
||||
meta: {
|
||||
i18n: 'router.homeJsxt',
|
||||
roles: [user, referee, refereePlatform]
|
||||
roles: [user, admin]
|
||||
},
|
||||
hidden: getSessionStorage('project') ? !getSessionStorage('project').endsWith('refereeJsxt') && !window.document.location.pathname.includes('refereeJsxt') : !window.document.location.pathname.includes('refereeJsxt'),
|
||||
children: [
|
||||
@ -1078,7 +1022,7 @@ export const JSXT = [
|
||||
component: Layout,
|
||||
meta: {
|
||||
i18n: 'router.refereeJManage',
|
||||
roles: [referee, refereePlatform]
|
||||
roles: [user, admin]
|
||||
},
|
||||
hidden: getSessionStorage('project') ? !getSessionStorage('project').endsWith('refereeJsxt') && !window.document.location.pathname.includes('refereeJsxt') : !window.document.location.pathname.includes('refereeJsxt'),
|
||||
children: [
|
||||
@ -1102,12 +1046,6 @@ const createRouter = () => new Router({
|
||||
|
||||
const router = createRouter();
|
||||
|
||||
router.beforeEach((to, from, next) => {
|
||||
const project = getSessionStorage('project');
|
||||
document.title = loginInfo[project || 'login'].browserTitle || loginInfo[project || 'login'].title;
|
||||
next();
|
||||
});
|
||||
|
||||
// 兼容 vue-router在3.1.0版本以上的路由跳转使用的是 promise 的方式
|
||||
const originalPush = Router.prototype.push;
|
||||
Router.prototype.push = function push(location) {
|
||||
|
@ -136,13 +136,14 @@ export const lessonCreater = '03'; // 课程创建权限
|
||||
export const admin = '04'; // 管理员
|
||||
export const superAdmin = '05'; // 超级管理员
|
||||
|
||||
export const userExam = '011'; // 考试系统
|
||||
export const userLesson = '012'; // 教学系统
|
||||
export const userSimulation = '013'; // 仿真系统
|
||||
export const userScreen = '014'; // 大屏系统
|
||||
export const userPlan = '015'; // 计划系统
|
||||
export const userTrainingPlatform = '016'; // 实训平台
|
||||
// const isDev = process.env.NODE_ENV === 'development';
|
||||
export const projectTrain = '011'; // 城市轨道项目
|
||||
export const projectXian = '012'; // 西安地铁项目
|
||||
export const projectXty = '013'; // 西铁院
|
||||
export const projectGzzb = '014'; // 贵州装备
|
||||
export const projectJsxt = '015'; // 竞赛系统
|
||||
|
||||
export const userTrainingPlatform = '016'; // 实训系统
|
||||
export const refereePlatform = '017'; // 裁判系统
|
||||
|
||||
/**
|
||||
* constantRoutes
|
||||
@ -200,7 +201,77 @@ export const constantRoutes = [
|
||||
},
|
||||
{ path: '*', redirect: '/404', hidden: true }
|
||||
];
|
||||
// 公共路由不需要过滤 直接可以访问
|
||||
export const publicAsyncRoute = [
|
||||
{ // 全屏战场图
|
||||
path: '/display/:mode',
|
||||
component: Display,
|
||||
hidden: true
|
||||
},
|
||||
{
|
||||
path: '/displayNew/:mode',
|
||||
component: DisplayNew,
|
||||
hidden: true
|
||||
},
|
||||
{
|
||||
path: '/design/display/:mode',
|
||||
component: DesignDisplay,
|
||||
hidden: true
|
||||
},
|
||||
{ // 剧本编辑 战场图
|
||||
path: '/scriptDisplay/:mode',
|
||||
component: ScriptDisplay,
|
||||
hidden: true
|
||||
},
|
||||
{ // 剧本编辑 战场图
|
||||
path: '/scriptDisplayNew/:mode',
|
||||
component: ScriptDisplayNew,
|
||||
hidden: true
|
||||
},
|
||||
|
||||
{ // 综合演练室
|
||||
path: '/trainroom',
|
||||
component: TrainRoom,
|
||||
hidden: true
|
||||
},
|
||||
{
|
||||
path: '/jointTraining',
|
||||
component: JointTraining,
|
||||
hidden: true
|
||||
},
|
||||
{
|
||||
path: '/jointTrainingNew',
|
||||
component: JointTrainingNew,
|
||||
hidden: true
|
||||
},
|
||||
{
|
||||
path: '/jlmap3d',
|
||||
component: Jlmap3d,
|
||||
hidden: true
|
||||
},
|
||||
{ // 运行图编辑
|
||||
path: '/plan/usertool',
|
||||
component: PlanMonitorEditUserTool,
|
||||
hidden: true
|
||||
},
|
||||
{ // 运行图编辑
|
||||
path: '/plan/tool',
|
||||
component: PlanMonitorEditTool,
|
||||
hidden: true
|
||||
},
|
||||
{
|
||||
path: '/displayIscs/system',
|
||||
component: IscsSystem,
|
||||
hidden: true,
|
||||
children: [
|
||||
{
|
||||
path: 'config/:mode',
|
||||
component: IscsConfig,
|
||||
hidden: true
|
||||
}
|
||||
]
|
||||
}
|
||||
];
|
||||
export const asyncRouter = [
|
||||
{ // 公共地图
|
||||
path: '/design',
|
||||
@ -305,85 +376,12 @@ export const asyncRouter = [
|
||||
}
|
||||
]
|
||||
},
|
||||
{ // 全屏战场图
|
||||
path: '/display/:mode',
|
||||
component: Display,
|
||||
meta: {
|
||||
},
|
||||
hidden: true
|
||||
},
|
||||
{
|
||||
path: '/displayNew/:mode',
|
||||
component: DisplayNew,
|
||||
meta: {
|
||||
},
|
||||
hidden: true
|
||||
},
|
||||
{
|
||||
path: '/design/display/:mode',
|
||||
component: DesignDisplay,
|
||||
meta: {
|
||||
},
|
||||
hidden: true
|
||||
},
|
||||
{ // 剧本编辑 战场图
|
||||
path: '/scriptDisplay/:mode',
|
||||
component: ScriptDisplay,
|
||||
meta: {
|
||||
},
|
||||
hidden: true
|
||||
},
|
||||
{ // 剧本编辑 战场图
|
||||
path: '/scriptDisplayNew/:mode',
|
||||
component: ScriptDisplayNew,
|
||||
meta: {
|
||||
},
|
||||
hidden: true
|
||||
},
|
||||
{
|
||||
path: '/displayIscs/system',
|
||||
component: IscsSystem,
|
||||
meta: {
|
||||
},
|
||||
hidden: true,
|
||||
children: [
|
||||
{
|
||||
path: 'config/:mode',
|
||||
component: IscsConfig,
|
||||
hidden: true
|
||||
}
|
||||
]
|
||||
},
|
||||
{ // 综合演练室
|
||||
path: '/trainroom',
|
||||
component: TrainRoom,
|
||||
meta: {
|
||||
},
|
||||
hidden: true
|
||||
},
|
||||
{
|
||||
path: '/jointTraining',
|
||||
component: JointTraining,
|
||||
hidden: true
|
||||
},
|
||||
{
|
||||
path: '/jointTrainingNew',
|
||||
component: JointTrainingNew,
|
||||
hidden: true
|
||||
},
|
||||
{
|
||||
path: '/jlmap3d',
|
||||
component: Jlmap3d,
|
||||
meta: {
|
||||
},
|
||||
hidden: true
|
||||
},
|
||||
{ // 实训平台
|
||||
path: '/trainingPlatform',
|
||||
component: Layout,
|
||||
hidden: true,
|
||||
meta: {
|
||||
roles: [admin, userSimulation, user, userTrainingPlatform]
|
||||
roles: [admin, user, userTrainingPlatform]
|
||||
},
|
||||
children: [
|
||||
{
|
||||
@ -451,20 +449,6 @@ export const asyncRouter = [
|
||||
}
|
||||
]
|
||||
},
|
||||
{ // 运行图编辑
|
||||
path: '/plan/usertool',
|
||||
component: PlanMonitorEditUserTool,
|
||||
meta: {
|
||||
},
|
||||
hidden: true
|
||||
},
|
||||
{ // 运行图编辑
|
||||
path: '/plan/tool',
|
||||
component: PlanMonitorEditTool,
|
||||
meta: {
|
||||
},
|
||||
hidden: true
|
||||
},
|
||||
{ // 发布内容管理
|
||||
path: '/publish',
|
||||
component: Layout,
|
||||
@ -764,11 +748,11 @@ const createRouter = () => new VueRouter({
|
||||
|
||||
const router = createRouter();
|
||||
|
||||
router.beforeEach((to, from, next) => {
|
||||
const project = getSessionStorage('project');
|
||||
document.title = loginInfo[project || 'login'].title;
|
||||
next();
|
||||
});
|
||||
// router.beforeEach((to, from, next) => {
|
||||
// const project = getSessionStorage('project');
|
||||
// document.title = loginInfo[project || 'login'].title;
|
||||
// next();
|
||||
// });
|
||||
|
||||
// 兼容 vue-router在3.1.0版本以上的路由跳转使用的是 promise 的方式
|
||||
const originalPush = VueRouter.prototype.push;
|
||||
|
@ -104,44 +104,58 @@ export const goOtherPlatformMenu = { // 导航栏快速切换平台
|
||||
designxadt: '/xadt/login'
|
||||
};
|
||||
export const PermissionParam = { // 路径权限处理所需参数配置(跳转白名单&路径正则匹配&clientId)
|
||||
login: {
|
||||
systemType: '011'
|
||||
},
|
||||
design: {
|
||||
systemType: '011'
|
||||
},
|
||||
designxty: {
|
||||
whitePage: '/designxty/login',
|
||||
reg: /^\/designxty/,
|
||||
systemType: '013',
|
||||
clientId: LoginParams.Design.clientId
|
||||
},
|
||||
designgzb: {
|
||||
whitePage: '/designgzb/login',
|
||||
reg: /^\/designgzb/,
|
||||
systemType: '014',
|
||||
clientId: LoginParams.Design.clientId
|
||||
},
|
||||
designxadt: {
|
||||
whitePage: '/designxadt/login',
|
||||
reg: /^\/designxadt/,
|
||||
systemType: '012',
|
||||
clientId: LoginParams.Design.clientId
|
||||
},
|
||||
xty: {
|
||||
whitePage: '/xty/login',
|
||||
reg: /^\/xty/,
|
||||
systemType: '013',
|
||||
clientId: null
|
||||
},
|
||||
gzb: {
|
||||
whitePage: '/gzb/login',
|
||||
reg: /^\/gzb/,
|
||||
systemType: '014',
|
||||
clientId: null
|
||||
},
|
||||
xadt: {
|
||||
whitePage: '/xadt/login',
|
||||
reg: /^\/xadt/,
|
||||
systemType: '012',
|
||||
clientId: null
|
||||
},
|
||||
jsxt: {
|
||||
whitePage: '/jsxt/login',
|
||||
reg: /^\/jsxt/,
|
||||
systemType: '015',
|
||||
clientId: null
|
||||
},
|
||||
refereeJsxt: {
|
||||
whitePage: '/refereeJsxt/login',
|
||||
reg: /^\/refereeJsxt/,
|
||||
systemType: '015',
|
||||
clientId: LoginParams.Design.clientId
|
||||
}
|
||||
};
|
||||
|
@ -1,46 +1,23 @@
|
||||
import { asyncRouter, constantRoutes, user, userLesson, userExam, userSimulation, userScreen, userPlan, superAdmin, admin, userTrainingPlatform, JSXT, refereePlatform, projectRoute } from '@/router/index_APP_TARGET';
|
||||
import { PermissionType } from '@/utils/PermissionType';
|
||||
import { UrlConfig } from '@/scripts/ConstDic';
|
||||
import { publicAsyncRoute, asyncRouter, constantRoutes, user, projectTrain, projectXian, projectXty, projectGzzb, projectJsxt, superAdmin, admin, userTrainingPlatform, JSXT, projectRoute } from '@/router/index_APP_TARGET';
|
||||
import { PermissionParam } from '@/scripts/ProjectConfig';
|
||||
import { getSessionStorage } from '@/utils/auth';
|
||||
|
||||
function setHonePagePath(route, roles) {
|
||||
if (roles && roles.length === 2 && roles.indexOf(user) >= 0 && (route.path === '/' || route.path === 'dashboard')) {
|
||||
if (roles.indexOf(userLesson) >= 0) {
|
||||
route.redirect = `${UrlConfig.teach.home}`;
|
||||
} else if (roles.indexOf(userExam) >= 0) {
|
||||
route.redirect = `${UrlConfig.exam.home}`;
|
||||
} else if (roles.indexOf(userSimulation) >= 0) {
|
||||
route.redirect = `${UrlConfig.demonstration.home}`;
|
||||
} else if (roles.indexOf(userScreen) >= 0) {
|
||||
route.redirect = `${UrlConfig.dp.home}`;
|
||||
} else if (roles.indexOf(userPlan) >= 0) {
|
||||
route.redirect = `${UrlConfig.plan.home}`;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过meta.role判断是否与当前用户权限匹配
|
||||
* 通过meta.role判断是否与当前用户权限匹配及子系统生成
|
||||
* @param roles
|
||||
* @param route
|
||||
*/
|
||||
function hasPermission(roles, route, parentsRoles) {
|
||||
setHonePagePath(route, roles);
|
||||
if (!getSessionStorage('project')) {
|
||||
return false;
|
||||
}
|
||||
if (route.meta && route.meta.roles) {
|
||||
// 如果存在本级路由,则使用自己的roles过滤
|
||||
if (getSessionStorage('project').startsWith('design')) {
|
||||
if (getSessionStorage('project').startsWith('design') || getSessionStorage('project').startsWith('refereeJsxt')) {
|
||||
const result = roles.filter(role => route.meta.roles.indexOf(role) >= 0) || [];
|
||||
return result.length && route.meta.roles.indexOf(userTrainingPlatform) < 0;
|
||||
} else if (getSessionStorage('project').startsWith('refereeJsxt')) {
|
||||
const result = roles.filter(role => route.meta.roles.indexOf(role) >= 0) || [];
|
||||
return result.length && route.meta.roles.indexOf(refereePlatform) >= 0;
|
||||
} else {
|
||||
roles = roles.filter(function (role) {
|
||||
return route.meta.roles.indexOf(role) >= 0;
|
||||
});
|
||||
roles = roles.filter((role) => route.meta.roles.indexOf(role) >= 0);
|
||||
return roles.some(role => route.meta.roles.indexOf(role) >= 0) && route.meta.roles.indexOf(userTrainingPlatform) >= 0;
|
||||
}
|
||||
} else if (parentsRoles) {
|
||||
@ -53,22 +30,24 @@ function hasPermission(roles, route, parentsRoles) {
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据roles和系统类型重新设置权限列表
|
||||
* @param roles
|
||||
* @param type
|
||||
* 根据项目重置 路由
|
||||
* @param systemType 项目类型
|
||||
*/
|
||||
function convertRouterRoles({ roles, permissionType }) {
|
||||
if (roles && roles.indexOf(user) >= 0) {
|
||||
switch (permissionType) {
|
||||
case PermissionType.LESSON: roles.push(userLesson); break;
|
||||
case PermissionType.EXAM: roles.push(userExam); break;
|
||||
case PermissionType.SIMULATION: roles.push(userSimulation); break;
|
||||
case PermissionType.SCREEN: roles.push(userScreen); break;
|
||||
case PermissionType.PLAN: roles.push(userPlan); break;
|
||||
}
|
||||
function resetAsyncRouter({ systemType }) {
|
||||
console.log(systemType);
|
||||
let list = publicAsyncRoute;
|
||||
if (systemType == projectTrain) {
|
||||
list = [...list, ...asyncRouter];
|
||||
} else if (systemType == projectXian) {
|
||||
list = [...list, ...asyncRouter];
|
||||
} else if (systemType == projectXty) {
|
||||
list = [...list, ...asyncRouter];
|
||||
} else if (systemType == projectGzzb) {
|
||||
list = [...list, ...asyncRouter, ...projectRoute.designgzb];
|
||||
} else if (systemType == projectJsxt) {
|
||||
list = [...list, ...JSXT];
|
||||
}
|
||||
|
||||
return { roles };
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -78,9 +57,6 @@ function convertRouterRoles({ roles, permissionType }) {
|
||||
*/
|
||||
function filterAsyncRouter(asyncRouter, roles, parentsRoles) {
|
||||
return asyncRouter.filter(route => {
|
||||
if (route.name === '大屏系统' && roles.indexOf(admin) == -1 && roles.indexOf(userScreen) == -1) {
|
||||
route.hidden = true;
|
||||
}
|
||||
if (hasPermission(roles, route, parentsRoles)) {
|
||||
if (route.children && route.children.length) {
|
||||
route.children = filterAsyncRouter(route.children, roles, route.meta ? route.meta.roles : undefined);
|
||||
@ -106,18 +82,16 @@ const permission = {
|
||||
// 生成其他权限路由
|
||||
GenerateRoutes({ commit }, data) {
|
||||
return new Promise(resolve => {
|
||||
const { roles } = convertRouterRoles(data);
|
||||
if (roles.indexOf(superAdmin) >= 0 && roles.indexOf(admin) < 0) {
|
||||
const { roles } = data;
|
||||
if (roles.includes(superAdmin) && !roles.includes(admin)) { // 只拥有超级管理员 没有管理员权限
|
||||
roles.push(admin);
|
||||
}
|
||||
const proRoute = projectRoute[getSessionStorage('project')];
|
||||
let routeArr = [];
|
||||
if (proRoute && proRoute.constructor === Array) {
|
||||
routeArr = [...asyncRouter, ...JSXT, ...proRoute];
|
||||
} else {
|
||||
routeArr = [...asyncRouter, ...JSXT];
|
||||
if (roles.includes(admin) && !roles.includes(user)) { // 只拥有管理员 不拥有普通用户权限 则增加用户权限
|
||||
roles.push(user);
|
||||
}
|
||||
const accessedRouters = filterAsyncRouter(routeArr, roles);
|
||||
const routeList = resetAsyncRouter(PermissionParam[getSessionStorage('project')]);
|
||||
|
||||
const accessedRouters = filterAsyncRouter(routeList, roles);
|
||||
accessedRouters.forEach(route => {
|
||||
if (route.children && route.children.length == 0) {
|
||||
route.hidden = true;
|
||||
|
@ -2,10 +2,10 @@ export function getBaseUrl() {
|
||||
let BASE_API;
|
||||
if (process.env.NODE_ENV === 'development') {
|
||||
// BASE_API = 'https://joylink.club/jlcloud';
|
||||
// BASE_API = 'https://test.joylink.club/jlcloud';
|
||||
BASE_API = 'https://test.joylink.club/jlcloud';
|
||||
// BASE_API = 'http://192.168.3.5:9000'; // 袁琪
|
||||
// BASE_API = 'http://192.168.3.6:9000'; // 旭强
|
||||
BASE_API = 'http://192.168.3.41:9000'; // 张赛
|
||||
// BASE_API = 'http://192.168.3.41:9000'; // 张赛
|
||||
// BASE_API = 'http://192.168.3.82:9000'; // 杜康
|
||||
// BASE_API = 'http://192.168.3.41:9000'; // 张S赛
|
||||
// BASE_API = 'http://b29z135112.zicp.vip';
|
||||
|
Loading…
Reference in New Issue
Block a user