西铁院调整

This commit is contained in:
fan 2019-10-29 15:06:15 +08:00
parent 27317bf24a
commit a6b0caab34
4 changed files with 1060 additions and 1047 deletions

View File

@ -10,9 +10,9 @@ import { getSessionStorage } from '@/utils/auth';
import localStore from 'storejs';
function hasPermission(roles, permissionRoles) {
if (roles.indexOf(admin) >= 0) return true;
if (!permissionRoles) return true;
return roles.some(role => permissionRoles.indexOf(role) >= 0);
if (roles.indexOf(admin) >= 0) return true;
if (!permissionRoles) return true;
return roles.some(role => permissionRoles.indexOf(role) >= 0);
}
const whiteList = ['/login', '/design/login', '/xty/login', '/designxty/login']; // 不重定向白名单
@ -27,106 +27,106 @@ const loginDesignXtyPage = whiteList[3];
// 获取路径数据
function getRouteInfo(to) {
let loginPath = '/';
let getTokenInfo = () => { };
let clientId = '';
const toRoutePath = to.redirectedFrom || to.path;
if (/^\/designxty/.test(toRoutePath)) {
loginPath = loginDesignXtyPage;
getTokenInfo = getDesignToken;
clientId = LoginParams.Design.clientId;
} else if (/^\/design/.test(toRoutePath) || /^\/scriptDisplay/.test(toRoutePath) || /^\/publish/.test(toRoutePath) || /^\/orderauthor/.test(toRoutePath) || /^\/system/.test(toRoutePath)|| /^\/display\/record/.test(toRoutePath) || /^\/display\/manage/.test(toRoutePath) || /^\/apply/.test(toRoutePath)) {
loginPath = getSessionStorage('project')==='designxty'?loginDesignXtyPage:loginDesignPage;
getTokenInfo = getDesignToken;
clientId = LoginParams.Design.clientId;
} else if (/^\/plan/.test(toRoutePath) || /^\/display\/plan/.test(toRoutePath)) {
if (getSessionStorage('project').startsWith('design')) {
loginPath = getSessionStorage('project')==='designxty'?loginDesignXtyPage:loginDesignPage;
getTokenInfo = getDesignToken;
clientId = LoginParams.Design.clientId;
} else {
loginPath = getSessionStorage('project')==='xty'?loginXtyPage:loginPage;
getTokenInfo = getToken;
clientId = null;
}
} else if ( /^\/xty/.test(toRoutePath)) {
loginPath = loginXtyPage;
getTokenInfo = getToken;
clientId = null;
} else {
loginPath = getSessionStorage('project')==='xty'?loginXtyPage:loginPage;
getTokenInfo = getToken;
clientId = null;
}
let loginPath = '/';
let getTokenInfo = () => { };
let clientId = '';
const toRoutePath = to.redirectedFrom || to.path;
if (/^\/designxty/.test(toRoutePath)) {
loginPath = loginDesignXtyPage;
getTokenInfo = getDesignToken;
clientId = LoginParams.Design.clientId;
} else if (/^\/design/.test(toRoutePath) || /^\/scriptDisplay/.test(toRoutePath) || /^\/publish/.test(toRoutePath) || /^\/orderauthor/.test(toRoutePath) || /^\/system/.test(toRoutePath) || /^\/display\/record/.test(toRoutePath) || /^\/display\/manage/.test(toRoutePath) || /^\/apply/.test(toRoutePath)) {
loginPath = getSessionStorage('project') === 'designxty' ? loginDesignXtyPage : loginDesignPage;
getTokenInfo = getDesignToken;
clientId = LoginParams.Design.clientId;
} else if (/^\/plan/.test(toRoutePath) || /^\/display\/plan/.test(toRoutePath)) {
if (getSessionStorage('project').startsWith('design')) {
loginPath = getSessionStorage('project') === 'designxty' ? loginDesignXtyPage : loginDesignPage;
getTokenInfo = getDesignToken;
clientId = LoginParams.Design.clientId;
} else {
loginPath = getSessionStorage('project') === 'xty' ? loginXtyPage : loginPage;
getTokenInfo = getToken;
clientId = null;
}
} else if ( /^\/xty/.test(toRoutePath)) {
loginPath = loginXtyPage;
getTokenInfo = getToken;
clientId = null;
} else {
loginPath = getSessionStorage('project') === 'xty' ? loginXtyPage : loginPage;
getTokenInfo = getToken;
clientId = null;
}
return { clientId, loginPath, getTokenInfo };
return { clientId, loginPath, getTokenInfo };
}
function handleRoute(to, from, next, routeInfo) {
if (store.getters.roles.length === 0) {
// 拉取用户信息
store.dispatch('GetInfo', routeInfo.getTokenInfo).then(res => {
// 根据roles权限生成可访问的路由表
const roles = res.roles;
if (getSessionStorage('project').startsWith('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 {
next({ ...to, replace: true });
}
});
if (store.getters.roles.length === 0) {
// 拉取用户信息
store.dispatch('GetInfo', routeInfo.getTokenInfo).then(res => {
// 根据roles权限生成可访问的路由表
const roles = res.roles;
if (getSessionStorage('project').startsWith('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 {
next({ ...to, replace: true });
}
});
}).catch(() => {
store.dispatch('FedLogOut', routeInfo.clientId).then(() => {
Vue.prototype.$messageBox('验证失败,请重新登录!');
next({ path: routeInfo.loginPath });
});
});
} else {
// 除没有动态改变权限的需求可直接next() 删下方权限判断
if (hasPermission(store.getters.roles, to.meta.roles)) {
if (to.path==='/404' && to.redirectedFrom==='/') {
next(localStore.get('trainingPlatformRoute'+store.getters.id) ||'/trainingPlatform');
} else {
next();
}
} else {
next({ path: '/401', replace: true, query: { noGoBack: true } });
}
}
}).catch(() => {
store.dispatch('FedLogOut', routeInfo.clientId).then(() => {
Vue.prototype.$messageBox('验证失败,请重新登录!');
next({ path: routeInfo.loginPath });
});
});
} else {
// 除没有动态改变权限的需求可直接next() 删下方权限判断
if (hasPermission(store.getters.roles, to.meta.roles)) {
if (to.path === '/404' && to.redirectedFrom === '/') {
next(localStore.get('trainingPlatformRoute' + store.getters.id) || '/trainingPlatform');
} else {
next();
}
} else {
next({ path: '/401', replace: true, query: { noGoBack: true } });
}
}
}
router.beforeEach((to, from, next) => {
NProgress.start();
const routeInfo = getRouteInfo(to);
if (routeInfo.getTokenInfo()) {
// 已登录
if (to.path === routeInfo.loginPath) {
// 登录页面不拦截
next();
} else {
// 进入系统重新计算路由
handleRoute(to, from, next, routeInfo);
}
} else {
// 未登录情况下
if (whiteList.indexOf(to.path) !== -1) {
// 在免登录白名单,直接进入
next();
} else {
// 否则全部重定向到登录页
next(routeInfo.loginPath);
}
}
NProgress.start();
const routeInfo = getRouteInfo(to);
if (routeInfo.getTokenInfo()) {
// 已登录
if (to.path === routeInfo.loginPath) {
// 登录页面不拦截
next();
} else {
// 进入系统重新计算路由
handleRoute(to, from, next, routeInfo);
}
} else {
// 未登录情况下
if (whiteList.indexOf(to.path) !== -1) {
// 在免登录白名单,直接进入
next();
} else {
// 否则全部重定向到登录页
next(routeInfo.loginPath);
}
}
});
router.afterEach(() => {
// 结束Progress
NProgress.done();
// 结束Progress
NProgress.done();
});

File diff suppressed because it is too large Load Diff

View File

@ -171,6 +171,7 @@ export default {
} else {
res = await getTrainingSystemList(filterSelect);
}
this.$emit('goRoutePath', res.data);
res.data && res.data.forEach(item =>{
item.key = item.id + item.type;
item.children && item.children.forEach(childrenItem => {

View File

@ -2,7 +2,7 @@
<div class="app-wrapper">
<el-scrollbar wrap-class="scrollbar-wrapper">
<div v-show="listShow" class="examList" :style="{width: widthLeft+'px'}">
<demon-list ref="demonList" :height="height" />
<demon-list ref="demonList" :height="height" @goRoutePath="goRoutePath" />
</div>
<drap-left :width-left="widthLeft" @drapWidth="drapWidth" />
<transition>
@ -21,58 +21,61 @@ import localStore from 'storejs';
import { getSessionStorage, setSessionStorage } from '@/utils/auth';
export default {
name: 'TrainingPlatform',
components: {
demonList,
drapLeft
},
data() {
return {
listShow: true,
widthLeft: 450,
productList: []
};
},
computed: {
...mapGetters([
'lessonbar'
]),
height() {
return this.$store.state.app.height - 50;
},
width() {
return this.$store.state.app.width;
},
userId() {
return this.$store.state.user.id;
}
},
watch: {
'lessonbar.opened': function (val) {
this.listShow = val;
}
},
mounted() {
const againEnter = getSessionStorage('againEnter') || null;
if (!againEnter) {
launchFullscreen();
const path = localStore.get('trainingPlatformRoute'+ this.userId);
if (path && path.startsWith('/trainingPlatform')) {
this.$router.push(path);
}
setSessionStorage('againEnter', true);
}
this.widthLeft = Number(localStore.get('LeftWidth'))?Number(localStore.get('LeftWidth')):450;
},
methods: {
refresh() {
this.$refs && this.$refs.demonList && this.$refs.demonList.refresh();
},
drapWidth(width) {
this.widthLeft = Number(width);
}
}
name: 'TrainingPlatform',
components: {
demonList,
drapLeft
},
data() {
return {
listShow: true,
widthLeft: 450,
productList: []
};
},
computed: {
...mapGetters([
'lessonbar'
]),
height() {
return this.$store.state.app.height - 50;
},
width() {
return this.$store.state.app.width;
},
userId() {
return this.$store.state.user.id;
}
},
watch: {
'lessonbar.opened': function (val) {
this.listShow = val;
}
},
mounted() {
this.widthLeft = Number(localStore.get('LeftWidth')) ? Number(localStore.get('LeftWidth')) : 450;
},
methods: {
refresh() {
this.$refs && this.$refs.demonList && this.$refs.demonList.refresh();
},
drapWidth(width) {
this.widthLeft = Number(width);
},
goRoutePath(data) {
const againEnter = getSessionStorage('againEnter') || null;
if (!againEnter) {
launchFullscreen();
const path = localStore.get('trainingPlatformRoute' + this.userId);
if (path && path.startsWith('/trainingPlatform')) {
this.$router.push(path);
} else if (data && data[0]) {
this.$router.push(`/trainingPlatform/permission/${data[0].id}`);
}
setSessionStorage('againEnter', true);
}
}
}
};
</script>
<style rel="stylesheet/scss" lang="scss" scoped>