微信小程序登录问题处理

master
Chopper 2021-05-21 15:52:09 +08:00
parent f2118d5c8a
commit cf00156008
1 changed files with 44 additions and 34 deletions

View File

@ -1,7 +1,6 @@
<template> <template>
<view class="container"> <view class="container">
<u-modal v-model="showWxAuth" :title="projectName+'商城'" :show-confirm-button="false"> <u-modal v-model="phoneAuthPopup" :title="projectName+'商城'" :show-confirm-button="false">
<div class="tips"> <div class="tips">
为了更好地用户体验需要您授权手机号 为了更好地用户体验需要您授权手机号
</div> </div>
@ -13,15 +12,14 @@
<div class="box"> <div class="box">
<view class="logo-info"> <view class="logo-info">
<text class="title">欢迎进入{{ projectName }}商城</text> <text class="title">欢迎进入{{ projectName }}商城</text>
</view> </view>
<view class="small-tips"> <view class="small-tips">
<view>为您提供优质服务,{{ projectName }}需要获取以下信息</view> <view>为您提供优质服务,{{ projectName }}需要获取以下信息</view>
<view>您的公开信息昵称头像</view> <view>您的公开信息昵称头像</view>
</view> </view>
<view class="btns"> <view class="btns">
<button type="primary" open-type="getUserInfo" class="btn-auth" <button type="primary" bindtap="getUserProfile" @click="getUserProfile()"
@getuserinfo="hidenWxAuth()">确认微信授权</button> class="btn-auth">确认微信授权</button>
</view> </view>
</div> </div>
</view> </view>
@ -40,9 +38,8 @@
export default { export default {
data() { data() {
return { return {
show: true, //
// phoneAuthPopup: false,
showWxAuth: false,
// //
projectName: "LiLi", projectName: "LiLi",
//sessionkey //sessionkey
@ -53,40 +50,54 @@
image: '', image: '',
}; };
}, },
//codecode
components: {}, mounted() {
props: {}, let that = this;
//code
uni.login({
success: (res) => {
that.code = res.code;
},
});
},
methods: { methods: {
hidenWxAuth() { //
this.showWxAuth = true; getUserProfile(e) {
let that = this; let that = this;
//------Login--------- // 使wx.getUserProfile
uni.login({ uni.getUserProfile({
success: (res) => { desc: '用于完善会员资料', //
that.code = res.code; success: (res) => {
uni.getUserInfo({ that.nickName = res.userInfo.nickName;
provider: "weixin", that.image = res.userInfo.avatarUrl;
success: function(infoRes) { //
that.nickName = infoRes.userInfo.nickName; this.phoneAuthPopup = true;
that.image = infoRes.userInfo.avatarUrl; },
}, fail: (res) => {
}); that.nickName = "微信用户";
}, that.image =
}); "https://thirdwx.qlogo.cn/mmopen/vi_32/POgEwh4mIHO4nibH0KlMECNjjGxQUq24ZEaGT4poC6icRiccVGKSyXwibcPq4BWmiaIGuG1icwxaQX6grC9VemZoJ8rg/132";
//
this.phoneAuthPopup = true;
}
})
}, },
//
getPhoneNumber(e) { getPhoneNumber(e) {
let that = this;
let iv = e.detail.iv; let iv = e.detail.iv;
let encryptedData = e.detail.encryptedData; let encryptedData = e.detail.encryptedData;
if (!e.detail.encryptedData) { if (!e.detail.encryptedData) {
uni.showToast({ uni.showToast({
title: "请授予手机号码获取权限!", title: "请授予手机号码权限,手机号码会和会员系统用户绑定",
icon: "none", icon: "none",
}); });
return; return;
} }
let code = this.code;
let image = this.image; let code = this.code;
let image = this.image;
let nickName = this.nickName; let nickName = this.nickName;
mpAutoLogin({ mpAutoLogin({
encryptedData, encryptedData,
@ -115,7 +126,6 @@
}); });
}, },
}, },
}; };