From 0476f25ebadae3e349771733d54ab2cc66817335 Mon Sep 17 00:00:00 2001 From: Pan Date: Mon, 15 May 2017 18:42:25 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9D=83=E9=99=90=E9=A1=B5=E9=9D=A2=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main.js | 8 ++++---- src/utils/fetch.js | 5 +---- src/views/error/401.vue | 6 +++++- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/main.js b/src/main.js index 1ef8e2d6..52468c9b 100644 --- a/src/main.js +++ b/src/main.js @@ -52,13 +52,13 @@ router.beforeEach((to, from, next) => { next({ path: '/' }); } else { if (to.meta && to.meta.role) { // 判断即将进入的页面是否需要权限 - if (store.getters.uid) { // 判断当前用户是否已拉去玩info信息 + if (store.getters.uid) { // 判断当前用户是否已拉取完info信息 if (hasPermission(store.getters.roles, to.meta.role)) { // 判断权限 next(); // 有权限 } else { - next('/401'); // 无权限 + next({ path: '/401', query: { noGoBack: true } }); // 无权限 } - } else { // 未拉去info信息 + } else { // 未拉取info信息 store.dispatch('GetInfo').then(() => { // 拉取info permission.init({ // 初始化权限 roles: store.getters.roles, @@ -67,7 +67,7 @@ router.beforeEach((to, from, next) => { if (hasPermission(store.getters.roles, to.meta.role)) { // 判断权限 next();// 有权限 } else { - next('/401');// 无权限 + next({ path: '/401', query: { noGoBack: true } }); // 无权限 } }).catch(err => { console.log(err); diff --git a/src/utils/fetch.js b/src/utils/fetch.js index 45761c8a..f72817ad 100644 --- a/src/utils/fetch.js +++ b/src/utils/fetch.js @@ -21,10 +21,7 @@ service.interceptors.request.use(config => { }) service.interceptors.response.use( - response => { - console.log(response) - return response; - }, + response => response, error => { console.log('err' + error);// for debug const code = error.response.data; diff --git a/src/views/error/401.vue b/src/views/error/401.vue index bac594b2..ff7ffa5e 100644 --- a/src/views/error/401.vue +++ b/src/views/error/401.vue @@ -39,7 +39,11 @@ }, methods: { back() { - this.$router.go(-1) + if (this.$route.query.noGoBack) { + this.$router.push({ path: '/dashboard' }); + } else { + this.$router.go(-1); + } } } };