diff --git a/src/api/index.js b/src/api/index.js index 109add5..964b0be 100644 --- a/src/api/index.js +++ b/src/api/index.js @@ -23,7 +23,7 @@ instance.interceptors.response.use( (response) => { if (response.data.code === 401 || response.data.code === 403) { Message.error('登录失效,请重新登录') - store.commit('SignOut', true) + store.dispatch('SignOut', true) return response.data } else if (response.data.code === 1 && response.data.msg) { diff --git a/src/store/index.js b/src/store/index.js index fb94e52..0a90a82 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -13,9 +13,7 @@ export default new Vuex.Store({ mallName: '', mallList: [], activeDlgShow: false, - userInfo: {}, - routes: [], - addRoutes: [] + userInfo: {} }, mutations: { @@ -31,13 +29,16 @@ export default new Vuex.Store({ setMallList (state, mallList) { state.mallList = mallList }, - SignOut (state) { + logout (state) { state.token = '' - state.userInfo = {} + state.userInfo = {} + state.mallList = [] + state.mallName = '' + state.mallId = '' setTimeout(() => { router.push('/login') - }, 600) + }, 200) }, setUserInfo (state, userInfo) { @@ -58,7 +59,20 @@ export default new Vuex.Store({ } }) }) - } + }, + + SignOut (store, isClear) { + if (isClear) { + store.commit('logout') + return false + } + + request.post('/api/token/logout').then(res => { + if (res.code === 0) { + store.commit('logout') + } + }) + } }, getters: { diff --git a/src/view/Home.vue b/src/view/Home.vue index 3253857..3f23493 100644 --- a/src/view/Home.vue +++ b/src/view/Home.vue @@ -148,14 +148,12 @@ methods: { handleClick (e) { - if (e === 'phone') { - this.$router.push('changePhone') + if (e === 'logout') { + this.$store.dispatch('SignOut', false) } else if (e === 'pwd') { this.$router.push('changePwd') } else if (e === 'message') { this.$router.push('message') - } else { - this.$store.commit('SignOut', true) } }, handleClose() {