修复 getUserProfile

pull/1/MERGE
stivepeim 2021-05-06 10:04:18 +08:00
parent 5e6d4b5a77
commit 95031bc483
3 changed files with 24 additions and 12 deletions

View File

@ -24,8 +24,9 @@ class Routine
getUserInfo(){ getUserInfo(){
let that = this , code = this.getUserCode(); let that = this , code = this.getUserCode();
return new Promise( (resolve,reject) => { return new Promise( (resolve,reject) => {
uni.getUserInfo({ uni.getUserProfile({
lang: 'zh_CN', lang: 'zh_CN',
desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
success(user) { success(user) {
if(code) user.code = code; if(code) user.code = code;
resolve({userInfo:user,islogin:false}); resolve({userInfo:user,islogin:false});
@ -118,15 +119,12 @@ class Routine
authUserInfo(code,data) authUserInfo(code,data)
{ {
console.log('code:',code);
console.log('data:',data);
return new Promise((resolve, reject)=>{ return new Promise((resolve, reject)=>{
login(code,data).then(res=>{ login(code,data).then(res=>{
if(res.data.type==='login'){ if(res.data.type==='login'){
// let time = res.data.expiresTime - Cache.time(); // let time = res.data.expiresTime - Cache.time();
store.commit('UPDATE_USERINFO', res.data.user); store.commit('UPDATE_USERINFO', res.data.user);
store.commit('LOGIN', {token:res.data.token}); store.commit('LOGIN', {token:res.data.token});
store.commit('SETUID', res.data.user.uid);
// Cache.set(EXPIRES_TIME,res.data.expiresTime,time); // Cache.set(EXPIRES_TIME,res.data.expiresTime,time);
Cache.set(USER_INFO,res.data.user); Cache.set(USER_INFO,res.data.user);
} }

View File

@ -158,16 +158,12 @@
provider: 'apple', provider: 'apple',
timeout: 10000, timeout: 10000,
success(loginRes) { success(loginRes) {
console.log(loginRes, 'loginRes') uni.getUserProfile({
uni.getUserInfo({
provider: 'apple', provider: 'apple',
success: function(infoRes) { success: function(infoRes) {
console.log(infoRes.userInfo, 'yyyy') console.log(infoRes.userInfo, 'yyyy')
self.appleUserInfo = infoRes.userInfo self.appleUserInfo = infoRes.userInfo
self.appleLoginApi() self.appleLoginApi()
console.log(self.$store);
console.log(infoRes.userInfo);
}, },
fail() { fail() {
uni.showToast({ uni.showToast({
@ -247,10 +243,9 @@
provider: 'weixin', provider: 'weixin',
success: function(loginRes) { success: function(loginRes) {
// //
uni.getUserInfo({ uni.getUserProfile({
provider: 'weixin', provider: 'weixin',
success: function(infoRes) { success: function(infoRes) {
console.log(infoRes.userInfo, 'yyyy')
self.appUserInfo = infoRes.userInfo self.appUserInfo = infoRes.userInfo
self.wxLoginApi() self.wxLoginApi()

View File

@ -21,7 +21,7 @@
<button hover-class="none" @click="wechatLogin" class="bg-green btn1">微信登录</button> <button hover-class="none" @click="wechatLogin" class="bg-green btn1">微信登录</button>
<!-- #endif --> <!-- #endif -->
<!-- #ifdef MP --> <!-- #ifdef MP -->
<button hover-class="none" open-type="getUserInfo" @getuserinfo="setUserInfo" class="bg-green btn1">微信登录</button> <button hover-class="none" @tap="getUserProfile" class="bg-green btn1">微信登录</button>
<!-- #endif --> <!-- #endif -->
<!-- <button hover-class="none" @click="isUp = true" class="btn2">手机号登录</button> --> <!-- <button hover-class="none" @click="isUp = true" class="btn2">手机号登录</button> -->
</view> </view>
@ -238,6 +238,25 @@
}) })
}); });
}, },
getUserProfile() {
let self = this;
uni.showLoading({
title: '正在登录中'
});
Routine.getUserProfile()
.then(res => {
Routine.getCode()
.then(code => {
self.getWxUser(code, res);
})
.catch(res => {
uni.hideLoading();
});
})
.catch(res => {
uni.hideLoading();
});
},
setUserInfo(e) { setUserInfo(e) {
uni.showLoading({ uni.showLoading({
title: '正在登录中' title: '正在登录中'