Browse Source

修改微信获取用户信息错误的问题

master
Gao xiaosong 3 years ago
parent
commit
7fd577d574
  1. 86
      pages/user/User/index.vue

86
pages/user/User/index.vue

@ -1,8 +1,8 @@
<template>
<view class="user">
<view v-if="$store.getters.token || userInfo.uid">
<view class="getUserBaseData header bg-color-red acea-row row-between-wrapper" v-if="!userInfo.avatar && !userInfo.nickname">
<button class="userDataBtn" v-if="canIUseGetUserProfile" @tap="getUserInfoProfile">授权并查看用户信息</button>
<view class="getUserBaseData header bg-color-red acea-row row-between-wrapper" v-if="$deviceType === 'routine' && !userInfo.avatar && !userInfo.nickname">
<button class="userDataBtn" v-if="weixin" @tap="getUserInfoProfile">授权并查看用户信息</button>
<button class="userDataBtn" v-else @getuserinfo="getUserInfo" open-type="getUserInfo">授权并查看用户信息</button>
</view>
<view class="header bg-color-red acea-row row-between-wrapper" v-else>
@ -131,13 +131,32 @@
</view>
</template>
<script>
import { mapState, mapGetters, mapMutations, mapActions } from 'vuex'
import { getUserInfo, getMenuUser, wxappAuth, bindingPhone, wxappBindingPhone, wxappGetUserInfo } from '@/api/user'
import { isWeixin, VUE_APP_RESOURCES_URL, parseQuery, getProvider } from '@/utils'
import {
mapState,
mapGetters,
mapMutations,
mapActions
} from 'vuex'
import {
getUserInfo,
getMenuUser,
wxappAuth,
bindingPhone,
wxappBindingPhone,
wxappGetUserInfo
} from '@/api/user'
import {
isWeixin,
VUE_APP_RESOURCES_URL,
parseQuery,
getProvider
} from '@/utils'
import SwitchWindow from '@/components/SwitchWindow'
import Authorization from '@/pages/authorization/index'
import cookie from '@/utils/store/cookie'
import { wechat, oAuth, } from '@/libs/wechat'
const NAME = 'User'
export default {
@ -149,16 +168,19 @@ export default {
props: {},
data: function() {
return {
canIUseGetUserProfile: false,
weixin: false,
MyMenus: [],
switchActive: false,
isWeixin: false,
}
},
computed: mapGetters(['userInfo']),
computed: {
...mapGetters(['userInfo']),
...mapState(['$deviceType'])
},
onLoad() {
if (wx.getUserProfile) {
this.canIUseGetUserProfile = true
if (this.$deviceType==='weixin') {
this.weixin = true
}
},
methods: {
@ -195,7 +217,7 @@ export default {
goPersonalData() {
this.$yrouter.push('/pages/user/PersonalData/index')
},
getPhoneNumber (e) {
getPhoneNumber(e) {
//
if (e.mp.detail.errMsg == 'getPhoneNumber:ok') {
uni.showLoading({
@ -292,43 +314,12 @@ export default {
},
//
getUserInfoProfile(data) {
wx.getUserProfile({
lang: 'zh_CN',
desc: '需要获取您的信息用来展示',
success: res => {
uni.showLoading({
title: '正在更新信息...',
duration: 2000,
})
getProvider()
.then(provider => { //
if (!provider) {
reject()
if (isWeixin()) {
let wechatInit = wechat()
if (wechatInit) {
await oAuth()
}
// code
uni.login({
provider: provider,
success: async loginRes => {
wxappGetUserInfo({
encryptedData: res.encryptedData,
iv: res.iv,
code: loginRes.code, // code
}).then(res => {
if (res.status === 200) {
this.userInfo.avatar = res.data.avatar
this.userInfo.nickname = res.data.nickname
} else {
uni.showLoading({
title: res.msg,
duration: 2000,
})
}
})
}
})
})
}
})
},
changeswitch(data) {
this.switchActive = data
@ -415,8 +406,8 @@ export default {
</script>
<style lang="less">
.getUserBaseData{
.userDataBtn{
.getUserBaseData {
.userDataBtn {
width: 80%;
height: 80rpx;
background: linear-gradient(to right, #f35447 0%, #ff8e3c 100%);
@ -428,6 +419,7 @@ export default {
color: rgba(255, 255, 255, 1);
}
}
.footer-line-height {
height: 1 * 100rpx;
}

Loading…
Cancel
Save