fix: 优化小程序登录

master
misworga831 2023-08-10 14:19:23 +08:00
parent 53917d32c0
commit 82810eb179
1 changed files with 58 additions and 48 deletions

View File

@ -92,64 +92,74 @@
//
async getUserProfile(e) {
getUserProfile(e) {
let that = this;
//code
await uni.login({
uni.login({
success: (res) => {
if(res.errMsg == "login:ok") {
that.code = res.code
} else {
uni.showToast({
title: "系统异常,请联系管理员!"
})
}
that.code = res.code;
},
});
// 使wx.getUserProfile
await uni.getUserProfile({
desc: "用于完善会员资料", //
success: (res) => {
that.nickName = res.userInfo.nickName;
that.image = res.userInfo.avatarUrl;
/**
* 根据公有的配置设置登录方式
*/
if(this.configs.enableFetchMobileLogin){
this.phoneAuthPopup = true;
return false
}
let iv = res.iv;
let encryptedData = res.encryptedData;
if (this.code) {
// 使wx.getUserProfile
uni.getUserProfile({
desc: "用于完善会员资料", //
success: (res) => {
that.nickName = res.userInfo.nickName;
that.image = res.userInfo.avatarUrl;
let code = this.code;
let image = this.image;
let nickName = this.nickName;
mpAutoLogin({
encryptedData,
iv,
code,
image,
nickName,
}).then((apiRes) => {
storage.setAccessToken(apiRes.data.result.accessToken);
storage.setRefreshToken(apiRes.data.result.refreshToken);
//
uni.showToast({
title: "登录成功!",
icon: "none",
});
//
getUserInfo().then((user) => {
storage.setUserInfo(user.data.result);
storage.setHasLogin(true);
/**
* 根据公有的配置设置登录方式
*/
if(this.configs.enableFetchMobileLogin){
this.phoneAuthPopup = true;
return false
}
let iv = res.iv;
let encryptedData = res.encryptedData;
uni.navigateBack({
delta: 1,
});
});
});
},
fail: (res) => {
let code = this.code;
let image = this.image;
let nickName = this.nickName;
mpAutoLogin({
encryptedData,
iv,
code,
image,
nickName,
}).then((apiRes) => {
storage.setAccessToken(apiRes.data.result.accessToken);
storage.setRefreshToken(apiRes.data.result.refreshToken);
//
uni.showToast({
title: "登录成功!",
icon: "none",
});
//
getUserInfo().then((user) => {
storage.setUserInfo(user.data.result);
storage.setHasLogin(true);
uni.navigateBack({
delta: 1,
});
});
});
},
fail: (res) => {
},
});
}
},
});
},
//