Commit 867ac68b authored by 晓彤's avatar 晓彤

修改路由跳转问题

parent fde01b8d
......@@ -9448,6 +9448,11 @@
"path-key": "^2.0.0"
}
},
"nprogress": {
"version": "0.2.0",
"resolved": "https://registry.npmjs.org/nprogress/-/nprogress-0.2.0.tgz",
"integrity": "sha1-y480xTIT2JVyP8urkH6UIq28r7E="
},
"nth-check": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/nth-check/-/nth-check-1.0.2.tgz",
......
......@@ -18,6 +18,7 @@
"echarts": "^4.9.0",
"element-ui": "^2.13.2",
"less": "^3.11.1",
"nprogress": "^0.2.0",
"save": "^2.4.0",
"sortablejs": "^1.13.0",
"vue": "^2.5.2",
......
import Vue from 'vue'
// import store from '../store/store'
import Router from 'vue-router'
import Login from '../views/login/Login'
import Main from '../views/Main'
......@@ -211,20 +212,27 @@ const router = new Router({
]
})
// 判断用户是否登陆到系统
// router.beforeEach(function(to, from, next) {
// var token = window.sessionStorage.getItem('token')
// if (token) {
// if (to.path === '/login') {
// // 如果已经登陆,跳转到首页
// console.log('777', to.path)
// next()
// } else {
// console.log('888', to.path)
// // 如果没有登录,就跳转登录页面
// store.commit('user/RESET_USER')
// next()
// }
// }
// })
router.beforeEach(function(to, from, next) {
var token = window.sessionStorage.getItem('token')
if (token !== null) {
if (to.path === '/login') {
next('/main')
} else if (to.path === '/main') {
next()
} else {
var menuList = window.sessionStorage.getItem('menuList')
if (menuList.indexOf(to.path) > -1) {
next()
} else {
next('/main')
}
}
} else {
if (to.path === '/login') {
next()
} else {
next('/login')
}
}
})
export default router
......@@ -106,6 +106,10 @@ export default {
'permissionList',
resp.data.data.permissionCodeList
)
window.sessionStorage.setItem(
'menuList',
resp.data.data.menuList
)
this.menuList = resp.data.data.menuList
this.getNav()
})
......
......@@ -75,6 +75,7 @@ export default {
logout()
.then((resp) => {
this.$store.commit('user/RESET_USER')
window.sessionStorage.clear()
this.$router.push('/')
})
.catch((error) => {
......@@ -148,7 +149,7 @@ p[multiBtn] {
}
.el-dropdown-link {
cursor: pointer;
color:#606266;
color: #606266;
font-size: 16px;
}
.el-icon-arrow-down {
......
......@@ -58,9 +58,13 @@ export default {
// 调取登陆接口
login(this.loginForm)
.then((resp) => {
if (resp.data.data === false) {
this.$message.error('用户名或密码错误,请重新登陆!')
} else {
// 将token放到Application中
window.sessionStorage.setItem('token', resp.data.data.token)
this.$router.push('/main')
}
})
.catch((error) => {
this.$message({ type: 'error', message: error })
......
......@@ -121,7 +121,6 @@ export default {
// 获取权限列表
getPermissionList() {
getPermissionList().then((resp) => {
// console.log('9090', resp.data.data)
this.allPermissionList = resp.data.data
})
},
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment