Skip to content

Commit

Permalink
feat: logout basic logic
Browse files Browse the repository at this point in the history
  • Loading branch information
lbwa committed Oct 9, 2018
1 parent 944f985 commit 5c134ac
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
13 changes: 11 additions & 2 deletions src/components/App/Header/UserInfo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
<i class="el-icon-tickets"></i>
<span slot="title">{{text.userCenter}}</span>
</el-menu-item>
<el-menu-item index="/logout">
<el-menu-item
index="/logout"
@click="logout($router.replace.bind($router))"
>
<i class="el-icon-circle-close-outline"></i>
<span slot="title">{{text.logout}}</span>
</el-menu-item>
Expand All @@ -28,7 +31,7 @@
</template>

<script>
import { mapState } from 'vuex'
import { mapState, mapActions } from 'vuex'
export default {
data () {
Expand All @@ -48,6 +51,12 @@ export default {
...mapState('login', [
'userInfo'
])
},
methods: {
...mapActions('login', [
'logout'
])
}
}
</script>
Expand Down
14 changes: 13 additions & 1 deletion src/store/modules/login/actions.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { pushLogin, fetchUserInfo } from 'SERVICES'
import { setTokenToLocal } from 'AUTH'
import { setTokenToLocal, removeToken } from 'AUTH'
import { dynamicRoutes } from 'ROUTER/routes'
import types from './mutations/types'
import { Notification } from 'element-ui'
Expand Down Expand Up @@ -62,6 +62,18 @@ export default {
: filterRoutes(dynamicRoutes, role)

commit(types.SET_ROUTES, globalRoutes)
},
logout ({ commit }, replace) {
commit(types.SET_USER_INFO, {})
commit(types.SET_USERNAME, '')
commit(types.SET_ROLE, [])
commit(types.SET_TOKEN, '')
removeToken()
replace('/')
Notification.success({
title: 'Success',
message: '用户已注销'
})
}
}

Expand Down

0 comments on commit 5c134ac

Please sign in to comment.