@/api/user#getUserInfo JavaScript Examples
The following examples show how to use
@/api/user#getUserInfo.
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 vue-admin-better-template with Mozilla Public License 2.0 | 5 votes |
actions = {
setPermissions({ commit }, permissions) {
commit('setPermissions', permissions)
},
async login({ commit }, userInfo) {
const { data } = await login(userInfo)
const accessToken = data[tokenName]
if (accessToken) {
commit('setAccessToken', accessToken)
const hour = new Date().getHours()
const thisTime =
hour < 8
? '早上好'
: hour <= 11
? '上午好'
: hour <= 13
? '中午好'
: hour < 18
? '下午好'
: '晚上好'
Vue.prototype.$baseNotify(`欢迎登录${title}`, `${thisTime}!`)
} else {
Vue.prototype.$baseMessage(
`登录接口异常,未正确返回${tokenName}...`,
'error'
)
}
},
async getUserInfo({ commit, state }) {
const { data } = await getUserInfo(state.accessToken)
if (!data) {
Vue.prototype.$baseMessage('验证失败,请重新登录...', 'error')
return false
}
let { permissions, username, avatar } = data
if (permissions && username && Array.isArray(permissions)) {
commit('setPermissions', permissions)
commit('setUsername', username)
commit('setAvatar', avatar)
return permissions
} else {
Vue.prototype.$baseMessage('用户信息接口异常', 'error')
return false
}
},
async logout({ dispatch }) {
await logout(state.accessToken)
await dispatch('resetAccessToken')
await resetRouter()
},
resetAccessToken({ commit }) {
commit('setPermissions', [])
commit('setAccessToken', '')
removeAccessToken()
},
}
Example #2
Source File: user.js From san-admin with MIT License | 5 votes |
user = {
initData: data => ({
userInfo: null,
roles: []
}),
action: {
['user:updateUserInfo'](userInfo) {
return builder().set('user.userInfo', userInfo);
},
['user:updateRoles'](roles) {
return builder().set('user.roles', roles);
},
['user:getUserInfo'](data, {dispatch}) {
return new Promise((resolve, reject) => {
getUserInfo().then(res => {
const result = res.result;
if (result.role && result.role.permissions.length > 0) {
const role = result.role;
role.permissions = result.role.permissions;
role.permissions.map(per => {
if (per.actionEntitySet != null && per.actionEntitySet.length > 0) {
const action = per.actionEntitySet.map(action => {
return action.action;
});
per.actionList = action;
}
});
role.permissionList = role.permissions.map((permission) => {
return permission.permissionId;
});
dispatch('user:updateUserInfo', result);
dispatch('user:updateRoles', result.role);
} else {
reject(new Error('getInfo: roles must be a non-null array !'));
}
resolve(res);
}).catch(error => {
reject(error);
});
});
}
}
}