@/api/user#get_user_info JavaScript Examples
The following examples show how to use
@/api/user#get_user_info.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: user.js From vue3-element-admin with MIT License | 5 votes |
actions = {
// user login
login({ commit }, userInfo) {
return new Promise((resolve, reject) => {
user_login(userInfo)
.then((res) => {
console.log(11, res)
if (res.token) {
commit('SET_TOKEN', res.token)
commit('SET_ROLES', res.role)
commit('SET_NAME', res.username)
commit('SET_AVATAR', res.avatar)
commit('SET_INTRODUCTION', res.introduction)
ElMessage({
type: 'success',
message: res.message
})
} else {
ElMessage({
type: 'error',
message: res.message
})
}
resolve(res)
})
.catch((error) => {
reject(error)
})
})
},
// user logout
logout({ commit, state, dispatch }) {
return new Promise((resolve, reject) => {
user_logout(state.token)
.then((res) => {
commit('SET_TOKEN', '')
commit('SET_ROLES', '')
commit('SET_NAME', '')
commit('SET_AVATAR', '')
dispatch('tagsView/delAllViews', null, { root: true })
resolve(res)
})
.catch((error) => {
reject(error)
})
})
},
// get user info
getInfo({ commit, state }) {
return new Promise((resolve, reject) => {
get_user_info(state.token)
.then((res) => {
if (!res) {
reject('Verification failed, please Login again.')
}
const { roles, name, avatar, introduction } = res
// roles must be a non-empty array
if (!roles || roles.length <= 0) {
reject('getInfo: roles must be a non-null array!')
}
commit('SET_NAME', name)
commit('SET_ROLES', roles)
commit('SET_AVATAR', avatar)
commit('SET_INTRODUCTION', introduction)
resolve(res)
})
.catch((error) => {
reject(error)
})
})
}
}