|
@@ -7,21 +7,22 @@ import {
|
|
|
removeToken
|
|
|
} from '@/uitls/auth'
|
|
|
import store from '../store';
|
|
|
+
|
|
|
import {
|
|
|
Message
|
|
|
} from 'element-ui'
|
|
|
+
|
|
|
NProgress.configure({
|
|
|
showSpinner: false
|
|
|
})
|
|
|
-const baseUrl = ['/', '/401', '/404', '/ui', '/loginRegister/login', '/work', '/message', '/work/space/project',
|
|
|
- '/iot/device/detail', '/work/operation/week/detail', '/work/staging/user'
|
|
|
-];
|
|
|
|
|
|
-const testBaseUrl = (path) => { //判断公共路由
|
|
|
- let nowBaseUrl = ['/loginRegister/login'].filter((item) => {
|
|
|
- return (item == path && item != '/')
|
|
|
- })
|
|
|
- return nowBaseUrl.length == 0;
|
|
|
+const baseUrl = ['/work', '/message'];
|
|
|
+const noTokenUrl = ['/', '/401', '/404', '/loginRegister/login'];
|
|
|
+
|
|
|
+const testBaseUrl = path => { //判断公共路由
|
|
|
+ return baseUrl.filter((item) => {
|
|
|
+ return item == path
|
|
|
+ }).length;
|
|
|
}
|
|
|
/* 消息提示 */
|
|
|
const tip = (msg, type) => {
|
|
@@ -32,7 +33,7 @@ const tip = (msg, type) => {
|
|
|
duration: 2000
|
|
|
});
|
|
|
}
|
|
|
-const testComment = (path) => { //判断权限路由
|
|
|
+const testComment = path => { //判断权限路由
|
|
|
let comment = getComment() ? JSON.parse(getComment()) : [];
|
|
|
let nowComment = comment.concat(baseUrl).filter((item) => {
|
|
|
return item == path
|
|
@@ -43,18 +44,13 @@ const testComment = (path) => { //判断权限路由
|
|
|
router.beforeEach((to, from, next) => {
|
|
|
if (getToken() && !(store.getters && store.getters.user && store.getters.user.userId) && !sessionStorage
|
|
|
.getItem('store')) removeToken();
|
|
|
- if (to.path.indexOf('website') === -1) {
|
|
|
+ if (noTokenUrl.filter(node => node === to.path).length === 0) {
|
|
|
/* 判断是否登录 */
|
|
|
- if (!getToken() && testBaseUrl(to.path)) return next('/loginRegister/login');
|
|
|
+ if (!getToken() && to.path != '/loginRegister/login') return next('/loginRegister/login');
|
|
|
/* 判断路由是否存在 */
|
|
|
if (to.matched.length === 0) return next('/404');
|
|
|
/* 判断是否有权限 */
|
|
|
if (testComment(to.path)) return next('/401');
|
|
|
- /* 无项目时跳转项目列表页面 */
|
|
|
- if (getToken() && localStorage.getItem('projectId') == 0 && to.path !== '/work/space/project') {
|
|
|
- tip('暂无项目,请先添加项目');
|
|
|
- return next('/work/space/project');
|
|
|
- }
|
|
|
}
|
|
|
NProgress.start();
|
|
|
next();
|