From 5ba93805c127439949cd3f5273efe97f67d2dd9c Mon Sep 17 00:00:00 2001
From: joylink_cuiweidong <364937672@qq.com>
Date: Mon, 23 Sep 2019 17:47:54 +0800
Subject: [PATCH] =?UTF-8?q?=E8=8F=9C=E5=8D=95=E6=A0=8F=E8=B0=83=E6=95=B4?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/layout/components/Logout.vue | 24 +++++-
src/permission.js | 11 ++-
src/router/index.js | 130 +++++++++++++++++++++++++------
src/store/modules/permission.js | 24 ++++--
src/store/modules/user.js | 13 +++-
src/utils/auth.js | 13 ++++
src/utils/login.js | 3 +-
src/views/login/index.vue | 6 +-
8 files changed, 184 insertions(+), 40 deletions(-)
diff --git a/src/layout/components/Logout.vue b/src/layout/components/Logout.vue
index 6638fef8d..2a7d1232f 100644
--- a/src/layout/components/Logout.vue
+++ b/src/layout/components/Logout.vue
@@ -7,6 +7,9 @@
+
+ {{ $t('router.selfPermission') }}
+
{{ $t('global.language') }}
@@ -19,8 +22,9 @@
diff --git a/src/permission.js b/src/permission.js
index a863cda63..feee8e475 100644
--- a/src/permission.js
+++ b/src/permission.js
@@ -3,9 +3,10 @@ import store from '@/store';
import router from './router';
import NProgress from 'nprogress'; // Progress 进度条
import 'nprogress/nprogress.css';// Progress 进度条样式
-import { admin } from './router';
+import { admin, userDesign} from './router';
import { getToken, getScreenToken, getPlanToken } from '@/utils/auth'; // 验权
import { LoginParams } from '@/utils/login';
+import { getSessionStorage } from '@/utils/auth';
function hasPermission(roles, permissionRoles) {
if (roles.indexOf(admin) >= 0) return true;
@@ -15,7 +16,7 @@ function hasPermission(roles, permissionRoles) {
const isDev = process.env.NODE_ENV === 'development';
-const whiteList = ['/login', '/login1', '/dp/login', '/dp/login1', '/plan/login', '/plan/login1']; // 不重定向白名单
+const whiteList = ['/login', '/login1', '/dp/login', '/dp/login1', '/plan/login', '/plan/login1', '/design/login1']; // 不重定向白名单
const loginPage = isDev ? whiteList[1] : whiteList[0];
@@ -52,11 +53,15 @@ function handleRoute(to, from, next, routeInfo) {
// 拉取用户信息
store.dispatch('GetInfo', routeInfo.getTokenInfo).then(res => {
// 根据roles权限生成可访问的路由表
+ // debugger;
const roles = res.roles;
-
+ if (getSessionStorage('design')) {
+ roles.push(userDesign);
+ }
store.dispatch('GenerateRoutes', { roles, clientId: routeInfo.clientId }).then(() => {
// 动态添加可访问路由表
router.addRoutes(store.getters.addRouters);
+ // router.addRoutes(asyncRouter1);
if (to.redirectedFrom) {
next({ path: to.redirectedFrom, replace: true });
} else {
diff --git a/src/router/index.js b/src/router/index.js
index 7a59299de..433aaac9b 100644
--- a/src/router/index.js
+++ b/src/router/index.js
@@ -11,6 +11,7 @@ import LoginNewScreen from '@/views/login/loginNewScreen';
import LoginScreen from '@/views/login/loginScreen';
import LoginNewPlan from '@/views/login/loginNewPlan';
import LoginPlan from '@/views/login/loginPlan';
+import LoginDesign from '@/views/login/loginDesign';
import Jlmap3dedit from '@/views/jlmap3d/edit/jlmap3dedit';
import Jlmap3d from '@/views/jlmap3d/drive/jl3ddrive';
@@ -70,6 +71,9 @@ import PlanMonitor from '@/views/planMonitor/index';
import PlanMonitorHome from '@/views/planMonitor/home';
import PlanMonitorDetail from '@/views/planMonitor/detail';
+// import DesignPlatform from '@/views/designPlatform/index';
+import DesignPlatformHome from '@/views/designPlatform/home';
+
import Replay from '@/views/replay/index';
import Package from '@/views/package/index';
import PackageDraft from '@/views/package/draft/ruleForm';
@@ -142,6 +146,7 @@ export const userLesson = '012'; // 教学系统
export const userSimulation = '013'; // 仿真系统
export const userScreen = '014'; // 大屏系统
export const userPlan = '015'; // 计划系统
+export const userDesign='016'; // 设计系统
export const UrlConfig = {
display: '/display',
@@ -193,6 +198,12 @@ export const UrlConfig = {
detail: '/plan/detail',
pay: '/plan/pay'
},
+ design: {
+ prefix: '/design'
+ // tool: '/design/tool',
+ // detail: '/plan/detail',
+ // pay: '/plan/pay'
+ },
replay: {
prefix: '/replay'
},
@@ -277,6 +288,12 @@ export const constantRoutes = [
component: LoginPlan,
hidden: true
},
+ // 密码登录
+ {
+ path: '/design/login1',
+ component: LoginDesign,
+ hidden: true
+ },
{
path: '/jlmap3d/edit',
component: Jlmap3dedit,
@@ -294,19 +311,22 @@ export const constantRoutes = [
hidden: true
},
- {
- path: '/',
- component: Layout,
- redirect: '/dashboard',
- children: [{
- path: 'dashboard',
- component: Dashboard,
- meta: {
- i18n: 'router.homePage',
- icon: 'dashboard'
- }
- }]
- },
+ // {
+ // path: '/',
+ // component: Layout,
+ // redirect: '/dashboard',
+ // meta: {
+ // roles: [admin, user]
+ // },
+ // children: [{
+ // path: 'dashboard',
+ // component: Dashboard,
+ // meta: {
+ // i18n: 'router.homePage',
+ // icon: 'dashboard'
+ // }
+ // }]
+ // },
{ path: '*', redirect: '/404', hidden: true }
];
@@ -317,13 +337,54 @@ export const asyncRouter = [
component: Layout,
redirect: '/dashboard',
hidden: true,
+ meta: {
+ roles: [admin, user]
+ },
children: [
{
path: 'dashboard',
- component: Dashboard1
+ component: Dashboard,
+ meta: {
+ i18n: 'router.homePage',
+ icon: 'dashboard'
+ }
}
]
},
+ {
+ path: '/design/home',
+ redirect: '/design/home/index',
+ component: Layout,
+ meta: {
+ roles: [admin, user, userDesign]
+ },
+ children: [
+ {
+ path: 'index',
+ component: DesignPlatformHome,
+ meta: {
+ i18n: 'router.homePage',
+ icon: 'design'
+ }
+ }
+ ]
+ },
+ // {
+ // path: '/',
+ // component: Layout,
+ // redirect: '/dashboard',
+ // meta: {
+ // roles: [admin, user]
+ // },
+ // children: [{
+ // path: 'dashboard',
+ // component: Dashboard,
+ // meta: {
+ // i18n: 'router.homePage',
+ // icon: 'dashboard'
+ // }
+ // }]
+ // },
{
path: '/display/:mode',
component: Display,
@@ -361,7 +422,7 @@ export const asyncRouter = [
path: '/map',
meta: {
i18n: 'router.mapManage',
- roles: [admin, mapCreater]
+ roles: [admin, mapCreater, userDesign]
},
component: Layout,
children: [
@@ -426,7 +487,7 @@ export const asyncRouter = [
component: Layout,
meta: {
i18n: 'router.lessaonManage',
- roles: [admin, lessonCreater]
+ roles: [admin, lessonCreater, userDesign]
},
children: [
{
@@ -485,7 +546,7 @@ export const asyncRouter = [
path: '/script',
component: Layout,
meta: {
- roles: [admin, lessonCreater, user]
+ roles: [admin, lessonCreater, user, userDesign]
},
children: [
{
@@ -515,6 +576,7 @@ export const asyncRouter = [
{
path: '/teach',
component: Layout,
+ hidden: true,
meta: {
roles: [admin, userLesson, user]
},
@@ -561,6 +623,7 @@ export const asyncRouter = [
{
path: '/exam',
component: Layout,
+ hidden: true,
meta: {
roles: [admin, userExam, user]
},
@@ -622,6 +685,7 @@ export const asyncRouter = [
},
{
path: '/demonstration',
+ hidden: true,
component: Layout,
meta: {
roles: [admin, userSimulation, user]
@@ -658,6 +722,7 @@ export const asyncRouter = [
},
{
path: '/dp',
+ hidden: true,
redirect: '/dp/home',
component: ScreenMonitor,
meta: {
@@ -696,7 +761,7 @@ export const asyncRouter = [
redirect: '/plan/home',
component: PlanMonitor,
meta: {
- roles: [admin, user]
+ roles: [admin, user, userDesign]
},
children: [
{
@@ -723,7 +788,7 @@ export const asyncRouter = [
path: '/replay',
component: Layout,
meta: {
- roles: [admin]
+ roles: [admin, userDesign]
},
children: [
{
@@ -741,6 +806,7 @@ export const asyncRouter = [
meta: {
roles: [admin, user]
},
+ hidden: true,
children: [
{
path: 'manage',
@@ -766,7 +832,7 @@ export const asyncRouter = [
component: Layout,
meta: {
i18n: 'router.pulishManage',
- roles: [admin]
+ roles: [admin, userDesign]
},
children: [
{
@@ -857,7 +923,7 @@ export const asyncRouter = [
component: Layout,
meta: {
i18n: 'router.orderAuthorityManage',
- roles: [admin]
+ roles: [admin, userDesign]
},
children: [
{
@@ -949,7 +1015,7 @@ export const asyncRouter = [
component: Layout,
meta: {
i18n: 'router.systemManage',
- roles: [admin]
+ roles: [admin, userDesign]
},
children: [
{
@@ -1011,6 +1077,26 @@ export const asyncRouter = [
}
]
}
+ // ,
+ // {
+ // path: '/design',
+ // redirect: '/design/home',
+ // component: Layout,
+ // hidden: true,
+ // meta: {
+ // roles: [admin, user]
+ // },
+ // children: [
+ // {
+ // path: 'home',
+ // component: DesignPlatformHome,
+ // meta: {
+ // i18n: 'router.homePage',
+ // icon: 'design'
+ // }
+ // }
+ // ]
+ // }
];
const createRouter = () => new Router({
diff --git a/src/store/modules/permission.js b/src/store/modules/permission.js
index cd75fad78..263502d1b 100644
--- a/src/store/modules/permission.js
+++ b/src/store/modules/permission.js
@@ -1,6 +1,7 @@
-import { asyncRouter, constantRoutes, user, userLesson, userExam, userSimulation, userScreen, userPlan, superAdmin, admin } from '@/router';
+import { asyncRouter, constantRoutes, user, userLesson, userExam, userSimulation, userScreen, userPlan, superAdmin, admin, userDesign } from '@/router';
import { PermissionType } from '@/utils/PermissionType';
import { UrlConfig } from '@/router/index';
+import { getSessionStorage } from '@/utils/auth';
function setHonePagePath(route, roles) {
if (roles && roles.length === 2 && roles.indexOf(user) >= 0 && (route.path === '/' || route.path === 'dashboard')) {
@@ -26,7 +27,16 @@ function setHonePagePath(route, roles) {
function hasPermission(roles, route, parentsRoles) {
setHonePagePath(route, roles);
if (route.meta && route.meta.roles) {
+ // debugger;
// 如果存在本级路由,则使用自己的roles过滤
+ if (getSessionStorage('design')&& route.meta.roles.indexOf(userDesign)===-1 ) {
+ route.hidden = true;
+ } else {
+ // debugger;
+ if (!getSessionStorage('design')&&route.meta.roles.indexOf(userDesign)>0) {
+ route.hidden = true;
+ }
+ }
return roles.some(role => route.meta.roles.indexOf(role) >= 0);
} else if (parentsRoles) {
// 如果没有本级路由,有父级路由,则使用父级路由过滤
@@ -91,13 +101,15 @@ const permission = {
// 生成其他权限路由
GenerateRoutes({ commit }, data) {
return new Promise(resolve => {
+ // debugger;
const { roles } = convertRouterRoles(data);
let accessedRouters;
- if (roles.indexOf(superAdmin) >= 0) {
- accessedRouters = asyncRouter;
- } else {
- accessedRouters = filterAsyncRouter(asyncRouter, roles);
- }
+ // if (roles.indexOf(superAdmin) >= 0) {
+ // accessedRouters = asyncRouter;
+ // } else {
+ // eslint-disable-next-line prefer-const
+ accessedRouters = filterAsyncRouter(asyncRouter, roles);
+ // }
commit('SET_ROUTERS', accessedRouters);
resolve();
diff --git a/src/store/modules/user.js b/src/store/modules/user.js
index 3297633a9..5412c5597 100644
--- a/src/store/modules/user.js
+++ b/src/store/modules/user.js
@@ -1,6 +1,6 @@
-import { setSessionStorage } from '@/utils/auth';
+import { setSessionStorage, removeSessionStorage } from '@/utils/auth';
import { login, logout, getInfo } from '@/api/login';
-import { getToken, setToken, removeToken, removeScreenToken, setScreenToken, getScreenToken, setPlanToken, getPlanToken, removePlanToken, handleToken, handleRemoveToken } from '@/utils/auth';
+import { getToken, setToken, removeToken, removeScreenToken, setScreenToken, getScreenToken, setPlanToken, setDesignToken, getPlanToken, removePlanToken, handleToken, handleRemoveToken } from '@/utils/auth';
import { getUserConfigInfo } from '@/api/management/user';
import { LoginParams } from '@/utils/login';
import { creatSubscribe, perpetualTopic } from '@/utils/stomp';
@@ -77,6 +77,14 @@ const user = {
const header = { group: '', 'X-Token': getPlanToken() };
creatSubscribe(perpetualTopic, header);
};
+ } else if (userInfo.type == 'design') {
+ params = Object.assign({ account: username, password }, LoginParams.Design);
+ execFc = (token) => {
+ setDesignToken(token);
+ commit('SET_TOKENPLAN', token);
+ const header = { group: '', 'X-Token': getPlanToken() };
+ creatSubscribe(perpetualTopic, header);
+ };
} else {
params = Object.assign({ account: username, password }, LoginParams.LianKeTang);
execFc = (token) => {
@@ -170,6 +178,7 @@ const user = {
commit('SET_TOKEN', '');
commit('SET_ROLES', []);
commit('SET_ID', '');
+ removeSessionStorage('design');
handleRemoveToken();
resolve();
}).catch(error => {
diff --git a/src/utils/auth.js b/src/utils/auth.js
index 0e120f462..8b97f45e2 100644
--- a/src/utils/auth.js
+++ b/src/utils/auth.js
@@ -7,6 +7,8 @@ const TokenScreenKey = 'Screen-Token';
const TokenPlanKey = 'Plan-Token';
+const TokenDesignKey='Admin-Token';
+
// 设置教学,实训,仿真系统token
export function getToken() {
return SessionStorage.getItem(TokenKey);
@@ -28,6 +30,17 @@ export function removeScreenToken() {
return SessionStorage.removeItem(TokenScreenKey);
}
+// 设置城市轨道交通设计平台token
+export function getDesignToken() {
+ return SessionStorage.getItem(TokenDesignKey);
+}
+export function setDesignToken(token) {
+ return SessionStorage.setItem(TokenDesignKey, token);
+}
+export function removeDesignToken() {
+ return SessionStorage.removeItem(TokenDesignKey);
+}
+
// 设置琏计划token
export function getPlanToken() {
return SessionStorage.getItem(TokenPlanKey);
diff --git a/src/utils/login.js b/src/utils/login.js
index cbb2a2270..6dad0c93f 100644
--- a/src/utils/login.js
+++ b/src/utils/login.js
@@ -4,5 +4,6 @@ export const LoginParams = {
LianKeTang: { clientId: '1', secret: 'joylink' }, // "琏课堂"
DaPing: { clientId: '2', secret: 'bigscreen' }, // "大屏系统"
LianJiHua: { clientId: '3', secret: 'linkplan' }, // "琏计划"
- Assistant: { clientId: '4', secret: 'linkassistant' } // "琏课堂助手"
+ Assistant: { clientId: '4', secret: 'linkassistant' }, // "琏课堂助手"
+ Design: { clientId: '1', secret: 'joylink' } // "城市轨道交通设计平台"
};
diff --git a/src/views/login/index.vue b/src/views/login/index.vue
index cffc7633a..2aed87609 100644
--- a/src/views/login/index.vue
+++ b/src/views/login/index.vue
@@ -33,7 +33,8 @@
- 琏课堂
+
+ 城市轨道交通实训平台
{{ tipsMsg }}
@@ -80,7 +81,8 @@ export default {
};
},
mounted() {
- document.title = '琏课堂';
+ // document.title = '琏课堂';
+ document.title = '城市轨道交通实训平台';
},
methods: {
showPwd() {