<view>
<button open-type="getUserInfo" @getuserinfo="wxGetUserInfo">登录</button>
</view>
<view>
<button open-type="getPhoneNumber" @getphonenumber="wxGetPhone">获取手机号</button>
</view>
wxGetPhone(e) {
console.log("phone", e);
if (!e.detail.code) {
uni.showToast({
title: '获取手机号失败',
icon: 'none'
})
return;
}
that.decryptPhone(e.detail.code);
},
decryptPhone(obj) {
var that = this;
this.$api.getPhone({code:obj})
.then(ss => {
if (ss.code == 200) {
console.log(ss)
} else {
uni.showToast({
title: '获取手机号失败,请重试',
icon: 'none'
})
}
})
.catch(ss => {
uni.showToast({
title: '获取手机号失败,请重试',
icon: 'none'
})
})
},
wxGetUserInfo(e) {
uni.showModal({
title: '温馨提示',
content: '亲,授权微信登录后才能正常使用小程序功能',
success(res) {
console.log(0)
console.log(res)
if (res.confirm) {
uni.getUserProfile({
desc: '获取你的昵称、头像、地区及性别',
success: res => {
console.log(res);
console.log(1);
},
fail: res => {
console.log(2);
console.log(res)
uni.showToast({
title: '您拒绝了请求,不能正常使用小程序',
icon: 'error',
duration: 2000
});
return;
}
});
} else if (res.cancel) {
console.log(3);
uni.showToast({
title: '您拒绝了请求,不能正常使用小程序',
icon: 'error',
duration: 2000
});
return;
}
}
});
},