在我开发算盘记账APP小程序的过程中,遇到了UNIAPP开发微信小程序微信登录反映特别慢的问题。经反复查找原因,原来是因为微信登录界面代码的uni.login中包含了uni.getUserProfile,这样会造成拉出登录窗体失败,严重时点击几十次才会有反映。后经反复想找原因,测试效果,改成在uni.getUserProfile的流程包含uni.login,将二者的包含关系反一下,点击一下成就能拉出窗体,反应很快。小程序与APP的微信授权登录流程有所不同,下步再作说明。代码结构如下,测试好用,欢迎参考:
//改变运行顺序的微信登录
login_xcx(){
var that = this;
//新版登录方式
uni.getUserProfile({
desc: '登录',
success: (res) => {
console.log(res.userInfo);
that.userInfo = res.userInfo;
uni.login({
provider: 'weixin',
success: function(loginRes) {
let code = loginRes.code;
console.log("code=", code)
try {
uni.request({
url: 'https://www.',
data: {
code: code,
nickname: that.userInfo.nickName,
img: that.userInfo.avatarUrl
},
method: 'get',
header: {
'content-type': 'application/json'
},
success: (res) => {
console.log("返回的Openid结果=>", res)
that.wx_unionid = res.data.wx_unionid
console.log("wx_unionid结果=>", res.data.wx_unionid)
//返回的基本信息做本地缓存
let data = res.data;
if (data.ec === 0) {
//提示:有该用户,请输入密码
uni.showToast({
icon: 'none',
position: 'top',
title: '开始记账吧',
});
//存用户信息
//uni.setStorage({
uni.setStorage({
key: 'userInfo',
data: data.data,
success: function() {
console.log(
'success'
);
}
});
uni.reLaunch({ //信息更新成功后跳转到小程序首页
url: ''
});
}else if (data.ec === -1) {
//提示:有该用户,请输入密码
uni.showToast({
icon: 'none',
position: 'top',
title: ' ',
});
console.log(that.userInfo)
uni.reLaunch({
url: ' '
});
}
},
fail: (res) => {
console.log(
"获取wxOpenid失败")
uni.hideLoading();
},
});
} catch (e) {}
}
});
},
fail: (res) => {
console.log(res);
},
});
},
本文暂时没有评论,来添加一个吧(●'◡'●)