|
@@ -47,6 +47,9 @@ export const useUserStore = defineStore('user-store', {
|
|
|
setAvatar(avatar: string) {
|
|
|
this.avatar = avatar;
|
|
|
},
|
|
|
+ setUsername(username: string) {
|
|
|
+ this.username = username;
|
|
|
+ },
|
|
|
setUserInfo(info: any) {
|
|
|
this.info = info;
|
|
|
},
|
|
@@ -55,10 +58,7 @@ export const useUserStore = defineStore('user-store', {
|
|
|
try {
|
|
|
const { data } = await userLogin(userInfo);
|
|
|
console.log(data, 'data');
|
|
|
- const userToken =
|
|
|
- data.authentication.token_type +
|
|
|
- ' ' +
|
|
|
- data.authentication.access_token;
|
|
|
+ const userToken = data.token_type + ' ' + data.access_token;
|
|
|
const ex = 7 * 24 * 60 * 60 * 1000;
|
|
|
storage.set(ACCESS_TOKEN, userToken, ex);
|
|
|
// storage.get(IM_TOKEN, data.imToken);
|
|
@@ -73,25 +73,18 @@ export const useUserStore = defineStore('user-store', {
|
|
|
|
|
|
// 获取用户信息
|
|
|
async getInfo() {
|
|
|
- // const that = this;
|
|
|
return new Promise((resolve, reject) => {
|
|
|
- // .then(res => {
|
|
|
- // const result = res.data;
|
|
|
- // this..setUserInfo(result);
|
|
|
- // that.setAvatar(result.account.avatar);
|
|
|
- // resolve(res);
|
|
|
- // })
|
|
|
- // .catch(error => {
|
|
|
- // reject(error);
|
|
|
- // });
|
|
|
- try {
|
|
|
- // getUserInfo().then((res: any) => {
|
|
|
- // console.log(res, 'res');
|
|
|
- // });
|
|
|
- resolve(true);
|
|
|
- } catch {
|
|
|
- reject();
|
|
|
- }
|
|
|
+ getUserInfo()
|
|
|
+ .then((res: any) => {
|
|
|
+ const result = res.data;
|
|
|
+ this.setUserInfo(result);
|
|
|
+ this.setAvatar(result.account.avatar);
|
|
|
+ this.setUsername(result.nickname);
|
|
|
+ resolve(true);
|
|
|
+ })
|
|
|
+ .catch((error: any) => {
|
|
|
+ reject(error);
|
|
|
+ });
|
|
|
});
|
|
|
},
|
|
|
|