|
|
|
@ -1,9 +1,10 @@
|
|
|
|
|
import { login, logout, getInfo } from '@/api/login'
|
|
|
|
|
import { getToken, setToken, removeToken } from '@/utils/auth'
|
|
|
|
|
import { login, logout, getInfo, refreshToken } from '@/api/login'
|
|
|
|
|
import { getToken, getRefreshToken, setToken, setRefreshToken, setExpiresIn, removeToken } from '@/utils/auth'
|
|
|
|
|
|
|
|
|
|
const user = {
|
|
|
|
|
state: {
|
|
|
|
|
token: getToken(),
|
|
|
|
|
refresh_token: getRefreshToken(),
|
|
|
|
|
name: '',
|
|
|
|
|
avatar: '',
|
|
|
|
|
roles: [],
|
|
|
|
@ -14,6 +15,12 @@ const user = {
|
|
|
|
|
SET_TOKEN: (state, token) => {
|
|
|
|
|
state.token = token
|
|
|
|
|
},
|
|
|
|
|
SET_EXPIRES_IN: (state, time) => {
|
|
|
|
|
state.expires_in = time
|
|
|
|
|
},
|
|
|
|
|
SET_REFRESH_TOKEN: (state, token) => {
|
|
|
|
|
state.refresh_token = token
|
|
|
|
|
},
|
|
|
|
|
SET_NAME: (state, name) => {
|
|
|
|
|
state.name = name
|
|
|
|
|
},
|
|
|
|
@ -39,6 +46,10 @@ const user = {
|
|
|
|
|
login(username, password, code, uuid).then(res => {
|
|
|
|
|
setToken(res.access_token)
|
|
|
|
|
commit('SET_TOKEN', res.access_token)
|
|
|
|
|
setRefreshToken(res.refresh_token)
|
|
|
|
|
commit('SET_REFRESH_TOKEN', res.refresh_token)
|
|
|
|
|
setExpiresIn(res.expires_in)
|
|
|
|
|
commit('SET_EXPIRES_IN', res.expires_in)
|
|
|
|
|
resolve()
|
|
|
|
|
}).catch(error => {
|
|
|
|
|
reject(error)
|
|
|
|
@ -67,6 +78,23 @@ const user = {
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// 刷新token
|
|
|
|
|
RefreshToken({commit, state}) {
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
refreshToken(state.refresh_token).then(res => {
|
|
|
|
|
setToken(res.access_token)
|
|
|
|
|
commit('SET_TOKEN', res.access_token)
|
|
|
|
|
setRefreshToken(res.refresh_token)
|
|
|
|
|
commit('SET_REFRESH_TOKEN', res.refresh_token)
|
|
|
|
|
setExpiresIn(res.expires_in)
|
|
|
|
|
commit('SET_EXPIRES_IN', res.expires_in)
|
|
|
|
|
resolve()
|
|
|
|
|
}).catch(error => {
|
|
|
|
|
reject(error)
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// 退出系统
|
|
|
|
|
LogOut({ commit, state }) {
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|