Commit 29507f68 authored by 张伯涛's avatar 张伯涛

登录和菜单栏问题

parent 14c38886
...@@ -13,7 +13,6 @@ const whiteList = ['/auth-redirect', '/bind', '/register', '/login', '/forgetPwd ...@@ -13,7 +13,6 @@ const whiteList = ['/auth-redirect', '/bind', '/register', '/login', '/forgetPwd
router.beforeEach((to, from, next) => { router.beforeEach((to, from, next) => {
NProgress.start() NProgress.start()
if (getToken()) { if (getToken()) {
/* has token*/ /* has token*/
if (to.path === '/login') { if (to.path === '/login') {
...@@ -25,9 +24,9 @@ router.beforeEach((to, from, next) => { ...@@ -25,9 +24,9 @@ router.beforeEach((to, from, next) => {
store.dispatch('GetInfo').then(res => { store.dispatch('GetInfo').then(res => {
// 判断用户是否有权限 有角色 // 判断用户是否有权限 有角色
if (res.roles && res.roles.length > 0 && res.permissions && res.permissions.length > 0) { if (res.data.roles && res.data.roles.length > 0 && res.data.permissions && res.data.permissions.length > 0) {
// 拉取user_info // 拉取user_info
const roles = res.roles const roles = res.data.roles
store.dispatch('GenerateRoutes', { roles }).then((routers) => { store.dispatch('GenerateRoutes', { roles }).then((routers) => {
// 判断用户是否有路由 // 判断用户是否有路由
if (routers.accessedRoutes && routers.accessedRoutes.length > 0 && routers.getRouters && routers.getRouters.length > 0) { if (routers.accessedRoutes && routers.accessedRoutes.length > 0 && routers.getRouters && routers.getRouters.length > 0) {
......
import { constantRoutes } from '@/router' import { constantRoutes } from '@/router'
import { getRouters } from '@/api/menu' import { getRouters } from '@/api/menu'
import { getInfo } from '@/api/login'
import Layout from '@/layout/index' import Layout from '@/layout/index'
const permission = { const permission = {
...@@ -18,8 +19,8 @@ const permission = { ...@@ -18,8 +19,8 @@ const permission = {
GenerateRoutes({ commit }) { GenerateRoutes({ commit }) {
return new Promise(resolve => { return new Promise(resolve => {
// 向后端请求路由数据 // 向后端请求路由数据
getRouters().then(res => { getInfo().then(res => {
const accessedRoutes = filterAsyncRouter(res.data) const accessedRoutes = filterAsyncRouter(res.data.menus)
console.log(accessedRoutes) console.log(accessedRoutes)
if (accessedRoutes[0]) { if (accessedRoutes[0]) {
const firstChild = getFirstChild(accessedRoutes[0]) const firstChild = getFirstChild(accessedRoutes[0])
...@@ -27,7 +28,7 @@ const permission = { ...@@ -27,7 +28,7 @@ const permission = {
accessedRoutes.push({ path: '/', redirect: firstChild, hidden: true }) accessedRoutes.push({ path: '/', redirect: firstChild, hidden: true })
commit('SET_ROUTES', accessedRoutes) commit('SET_ROUTES', accessedRoutes)
} }
const routers = { accessedRoutes: accessedRoutes, getRouters: res.data } const routers = { accessedRoutes: accessedRoutes, getRouters: res.data.menus }
resolve(routers) resolve(routers)
}) })
}) })
......
import { login, logout, getInfo } from '@/api/login' import { login, logout, getInfo } from '@/api/login'
import { getToken, setToken, removeToken } from '@/utils/auth' import { getToken, setToken, removeToken } from '@/utils/auth'
import Layout from '@/layout'
import { loadView } from '@/store/modules/permission'
const user = { const user = {
state: { state: {
...@@ -55,11 +57,11 @@ const user = { ...@@ -55,11 +57,11 @@ const user = {
GetInfo({ commit, state }) { GetInfo({ commit, state }) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
getInfo(state.token).then(res => { getInfo(state.token).then(res => {
const user = res.user const user = res.data.user
const avatar = user.avatar === null ? require('@/assets/image/profile.jpg') : user.avatar const avatar = user.avatar === null ? require('@/assets/image/profile.jpg') : user.avatar
if (res.roles && res.roles.length > 0) { // 验证返回的roles是否是一个非空数组 if (res.data.roles && res.data.roles.length > 0) { // 验证返回的roles是否是一个非空数组
commit('SET_ROLES', res.roles) commit('SET_ROLES', res.data.roles)
commit('SET_PERMISSIONS', res.permissions) commit('SET_PERMISSIONS', res.data.permissions)
} else { } else {
commit('SET_ROLES', ['ROLE_DEFAULT']) commit('SET_ROLES', ['ROLE_DEFAULT'])
} }
...@@ -72,7 +74,6 @@ const user = { ...@@ -72,7 +74,6 @@ const user = {
}) })
}) })
}, },
// 退出系统 // 退出系统
LogOut({ commit, state }) { LogOut({ commit, state }) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
......
...@@ -140,6 +140,7 @@ export default { ...@@ -140,6 +140,7 @@ export default {
.then(() => { .then(() => {
// window.location.href = `${this.reLocation}/#/` // window.location.href = `${this.reLocation}/#/`
// this.$router.push({ path: `http://main.court.com${this.redirect || "/"}` }); // this.$router.push({ path: `http://main.court.com${this.redirect || "/"}` });
this.loading = false
this.$router.push('/welcome') this.$router.push('/welcome')
}) })
.catch(() => { .catch(() => {
......
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