fix: 优化小程序登录
parent
53917d32c0
commit
82810eb179
|
@ -92,64 +92,74 @@
|
||||||
|
|
||||||
|
|
||||||
//获取用户信息
|
//获取用户信息
|
||||||
async getUserProfile(e) {
|
getUserProfile(e) {
|
||||||
let that = this;
|
let that = this;
|
||||||
//获取code
|
//获取code
|
||||||
await uni.login({
|
uni.login({
|
||||||
success: (res) => {
|
success: (res) => {
|
||||||
|
if(res.errMsg == "login:ok") {
|
||||||
|
that.code = res.code
|
||||||
|
} else {
|
||||||
|
uni.showToast({
|
||||||
|
title: "系统异常,请联系管理员!"
|
||||||
|
})
|
||||||
|
}
|
||||||
that.code = res.code;
|
that.code = res.code;
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
// 推荐使用wx.getUserProfile获取用户信息,开发者每次通过该接口获取用户个人信息均需用户确认
|
if (this.code) {
|
||||||
await uni.getUserProfile({
|
// 推荐使用wx.getUserProfile获取用户信息,开发者每次通过该接口获取用户个人信息均需用户确认
|
||||||
desc: "用于完善会员资料", // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
|
uni.getUserProfile({
|
||||||
success: (res) => {
|
desc: "用于完善会员资料", // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
|
||||||
that.nickName = res.userInfo.nickName;
|
success: (res) => {
|
||||||
that.image = res.userInfo.avatarUrl;
|
that.nickName = res.userInfo.nickName;
|
||||||
|
that.image = res.userInfo.avatarUrl;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据公有的配置设置登录方式
|
* 根据公有的配置设置登录方式
|
||||||
*/
|
*/
|
||||||
if(this.configs.enableFetchMobileLogin){
|
if(this.configs.enableFetchMobileLogin){
|
||||||
this.phoneAuthPopup = true;
|
this.phoneAuthPopup = true;
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
let iv = res.iv;
|
let iv = res.iv;
|
||||||
let encryptedData = res.encryptedData;
|
let encryptedData = res.encryptedData;
|
||||||
|
|
||||||
let code = this.code;
|
let code = this.code;
|
||||||
let image = this.image;
|
let image = this.image;
|
||||||
let nickName = this.nickName;
|
let nickName = this.nickName;
|
||||||
mpAutoLogin({
|
mpAutoLogin({
|
||||||
encryptedData,
|
encryptedData,
|
||||||
iv,
|
iv,
|
||||||
code,
|
code,
|
||||||
image,
|
image,
|
||||||
nickName,
|
nickName,
|
||||||
}).then((apiRes) => {
|
}).then((apiRes) => {
|
||||||
storage.setAccessToken(apiRes.data.result.accessToken);
|
storage.setAccessToken(apiRes.data.result.accessToken);
|
||||||
storage.setRefreshToken(apiRes.data.result.refreshToken);
|
storage.setRefreshToken(apiRes.data.result.refreshToken);
|
||||||
// 登录成功
|
// 登录成功
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
title: "登录成功!",
|
title: "登录成功!",
|
||||||
icon: "none",
|
icon: "none",
|
||||||
});
|
});
|
||||||
//获取用户信息
|
//获取用户信息
|
||||||
getUserInfo().then((user) => {
|
getUserInfo().then((user) => {
|
||||||
storage.setUserInfo(user.data.result);
|
storage.setUserInfo(user.data.result);
|
||||||
storage.setHasLogin(true);
|
storage.setHasLogin(true);
|
||||||
|
|
||||||
uni.navigateBack({
|
uni.navigateBack({
|
||||||
delta: 1,
|
delta: 1,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
fail: (res) => {
|
fail: (res) => {
|
||||||
|
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
},
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
|
|
||||||
//获取手机号授权
|
//获取手机号授权
|
||||||
|
|
Loading…
Reference in New Issue