From 76f4017470a2d5af8b0d17d16dc9ec9aeba650c4 Mon Sep 17 00:00:00 2001 From: Pan Date: Wed, 25 Oct 2017 17:12:36 +0800 Subject: [PATCH] fix: fix getUserInfo by cookie bug --- src/mock/login.js | 2 +- src/permission.js | 2 ++ src/store/modules/user.js | 3 +++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/mock/login.js b/src/mock/login.js index 00ce9bde..5b00b503 100644 --- a/src/mock/login.js +++ b/src/mock/login.js @@ -34,7 +34,7 @@ export default { if (userMap[token]) { return userMap[token] } else { - return Promise.reject('error') + return false } }, logout: () => 'success' diff --git a/src/permission.js b/src/permission.js index b7ce9b6c..2fcc4c9c 100644 --- a/src/permission.js +++ b/src/permission.js @@ -3,6 +3,7 @@ import store from './store' import NProgress from 'nprogress' // Progress 进度条 import 'nprogress/nprogress.css'// Progress 进度条样式 import { getToken } from '@/utils/auth' // 验权 +import { Message } from 'element-ui' // permissiom judge function hasPermission(roles, permissionRoles) { @@ -29,6 +30,7 @@ router.beforeEach((to, from, next) => { }) }).catch(() => { store.dispatch('FedLogOut').then(() => { + Message.error('验证失败,请重新登录') next({ path: '/login' }) }) }) diff --git a/src/store/modules/user.js b/src/store/modules/user.js index 9c706978..0ac425e1 100644 --- a/src/store/modules/user.js +++ b/src/store/modules/user.js @@ -63,6 +63,9 @@ const user = { GetUserInfo({ commit, state }) { return new Promise((resolve, reject) => { getUserInfo(state.token).then(response => { + if (!response.data) { // 由于mockjs 不支持自定义状态码只能这样hack + reject('error') + } const data = response.data commit('SET_ROLES', data.role) commit('SET_NAME', data.name)