|
@@ -25,6 +25,13 @@ const mutations = {
|
|
|
},
|
|
|
SET_ROLES: (state, roles) => {
|
|
|
state.roles = roles
|
|
|
+ },
|
|
|
+ // 退出登录逻辑直接放在 mutations 中
|
|
|
+ LOGOUT(state) {
|
|
|
+ state.token = ''
|
|
|
+ state.roles = []
|
|
|
+ removeToken()
|
|
|
+ resetRouter()
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -36,7 +43,7 @@ const actions = {
|
|
|
login({ username: username.trim(), password: password, type: type, captcha: captcha.trim() }).then(response => {
|
|
|
const { data } = response
|
|
|
commit('SET_TOKEN', data.token)
|
|
|
- setToken(data.token)
|
|
|
+ setToken(data.token,data.exp)
|
|
|
resolve(response)
|
|
|
}).catch(error => {
|
|
|
reject(error)
|
|
@@ -73,24 +80,24 @@ const actions = {
|
|
|
},
|
|
|
|
|
|
// 用户退出
|
|
|
- logout({ commit, state, dispatch }) {
|
|
|
- return new Promise((resolve, reject) => {
|
|
|
- logout(state.token).then(() => {
|
|
|
- commit('SET_TOKEN', '')
|
|
|
- commit('SET_ROLES', [])
|
|
|
- removeToken()
|
|
|
- resetRouter()
|
|
|
-
|
|
|
- // reset visited views and cached views
|
|
|
- // to fixed https://github.com/PanJiaChen/vue-element-admin/issues/2485
|
|
|
- dispatch('tagsView/delAllViews', null, { root: true })
|
|
|
-
|
|
|
- resolve()
|
|
|
- }).catch(error => {
|
|
|
- reject(error)
|
|
|
- })
|
|
|
- })
|
|
|
- },
|
|
|
+ // logout({ commit, state, dispatch }) {
|
|
|
+ // return new Promise((resolve, reject) => {
|
|
|
+ // logout(state.token).then(() => {
|
|
|
+ // commit('SET_TOKEN', '')
|
|
|
+ // commit('SET_ROLES', [])
|
|
|
+ // removeToken()
|
|
|
+ // resetRouter()
|
|
|
+
|
|
|
+ // // 重置已经访问过的视图
|
|
|
+ // // to fixed https://github.com/PanJiaChen/vue-element-admin/issues/2485
|
|
|
+ // dispatch('tagsView/delAllViews', null, { root: true })
|
|
|
+
|
|
|
+ // resolve()
|
|
|
+ // }).catch(error => {
|
|
|
+ // reject(error)
|
|
|
+ // })
|
|
|
+ // })
|
|
|
+ // },
|
|
|
|
|
|
// 清理token
|
|
|
resetToken({ commit }) {
|
|
@@ -102,7 +109,7 @@ const actions = {
|
|
|
})
|
|
|
},
|
|
|
|
|
|
- // 当用户切换时,我们都是退出去再重新进,所以这个暂时用不到
|
|
|
+ // 用户切换时重置路由
|
|
|
async changeRoles({ commit, dispatch }, role) {
|
|
|
const token = role + '-token'
|
|
|
|