|
|
@ -1,9 +1,10 @@
|
|
|
|
import { login, logout, getInfo } from '@/api/login'
|
|
|
|
import { login, logout, getInfo, refreshToken } from '@/api/login'
|
|
|
|
import { getToken, setToken, removeToken } from '@/utils/auth'
|
|
|
|
import { getToken, getRefreshToken, setToken, setRefreshToken, setExpiresIn, removeToken } from '@/utils/auth'
|
|
|
|
|
|
|
|
|
|
|
|
const user = {
|
|
|
|
const user = {
|
|
|
|
state: {
|
|
|
|
state: {
|
|
|
|
token: getToken(),
|
|
|
|
token: getToken(),
|
|
|
|
|
|
|
|
refresh_token: getRefreshToken(),
|
|
|
|
name: '',
|
|
|
|
name: '',
|
|
|
|
avatar: '',
|
|
|
|
avatar: '',
|
|
|
|
roles: [],
|
|
|
|
roles: [],
|
|
|
@ -14,6 +15,12 @@ const user = {
|
|
|
|
SET_TOKEN: (state, token) => {
|
|
|
|
SET_TOKEN: (state, token) => {
|
|
|
|
state.token = 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) => {
|
|
|
|
SET_NAME: (state, name) => {
|
|
|
|
state.name = name
|
|
|
|
state.name = name
|
|
|
|
},
|
|
|
|
},
|
|
|
@ -39,6 +46,10 @@ const user = {
|
|
|
|
login(username, password, code, uuid).then(res => {
|
|
|
|
login(username, password, code, uuid).then(res => {
|
|
|
|
setToken(res.access_token)
|
|
|
|
setToken(res.access_token)
|
|
|
|
commit('SET_TOKEN', 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()
|
|
|
|
resolve()
|
|
|
|
}).catch(error => {
|
|
|
|
}).catch(error => {
|
|
|
|
reject(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 }) {
|
|
|
|
LogOut({ commit, state }) {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|