接口获取用户信息部分
// get user info 用户信息
getInfo({ commit, state }) {
// return new Promise((resolve, reject) => {
// getInfo(state.token).then(response => {
// const { data } = response
// if (!data) {
// reject('Verification failed, please Login again.')
// }
// const { roles, name, avatar, introduction } = data
// // roles must be a non-empty array
// if (!roles || roles.length <= 0) {
// reject('getInfo: roles must be a non-null array!')
// }
// commit('SET_ROLES', roles)
// commit('SET_NAME', name)
// commit('SET_AVATAR', avatar)
// commit('SET_INTRODUCTION', introduction)
// resolve(data)
// }).catch(error => {
// reject(error)
// })
// })
return new Promise((resolve, reject) => {
const { data } = { // 这部分是伪造的假数据,真正请求的需要后端返回相应数据,(原带接口即可满足)
code: 20000,
data: {
roles: ["admin"],
introduction: "I am a super administrator",
avatar:
"https://dss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=1999921673,816131569&fm=26&gp=0.jpg", // 这个是用户头像的图片
name: "Super Admin"
}
};
if (!data) {
reject("Verification failed, please Login again.");
}
const { roles, name, avatar, introduction } = data;
if (!roles || roles.length <= 0) {
reject("getInfo: roles must be a non-null array!");
}
commit("SET_ROLES", roles);
commit("SET_NAME", name);
commit("SET_AVATAR", avatar);
commit("SET_INTRODUCTION", introduction);
resolve(data);
});
},