修改微信获取用户信息错误的问题
This commit is contained in:
@ -1,8 +1,8 @@
|
|||||||
<template>
|
<template>
|
||||||
<view class="user">
|
<view class="user">
|
||||||
<view v-if="$store.getters.token || userInfo.uid">
|
<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">
|
<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="canIUseGetUserProfile" @tap="getUserInfoProfile">授权并查看用户信息</button>
|
<button class="userDataBtn" v-if="weixin" @tap="getUserInfoProfile">授权并查看用户信息</button>
|
||||||
<button class="userDataBtn" v-else @getuserinfo="getUserInfo" open-type="getUserInfo">授权并查看用户信息</button>
|
<button class="userDataBtn" v-else @getuserinfo="getUserInfo" open-type="getUserInfo">授权并查看用户信息</button>
|
||||||
</view>
|
</view>
|
||||||
<view class="header bg-color-red acea-row row-between-wrapper" v-else>
|
<view class="header bg-color-red acea-row row-between-wrapper" v-else>
|
||||||
@ -131,13 +131,32 @@
|
|||||||
</view>
|
</view>
|
||||||
</template>
|
</template>
|
||||||
<script>
|
<script>
|
||||||
import { mapState, mapGetters, mapMutations, mapActions } from 'vuex'
|
import {
|
||||||
import { getUserInfo, getMenuUser, wxappAuth, bindingPhone, wxappBindingPhone, wxappGetUserInfo } from '@/api/user'
|
mapState,
|
||||||
import { isWeixin, VUE_APP_RESOURCES_URL, parseQuery, getProvider } from '@/utils'
|
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 SwitchWindow from '@/components/SwitchWindow'
|
||||||
import Authorization from '@/pages/authorization/index'
|
import Authorization from '@/pages/authorization/index'
|
||||||
import cookie from '@/utils/store/cookie'
|
import cookie from '@/utils/store/cookie'
|
||||||
|
|
||||||
|
import { wechat, oAuth, } from '@/libs/wechat'
|
||||||
|
|
||||||
const NAME = 'User'
|
const NAME = 'User'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
@ -149,16 +168,19 @@ export default {
|
|||||||
props: {},
|
props: {},
|
||||||
data: function() {
|
data: function() {
|
||||||
return {
|
return {
|
||||||
canIUseGetUserProfile: false,
|
weixin: false,
|
||||||
MyMenus: [],
|
MyMenus: [],
|
||||||
switchActive: false,
|
switchActive: false,
|
||||||
isWeixin: false,
|
isWeixin: false,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: mapGetters(['userInfo']),
|
computed: {
|
||||||
|
...mapGetters(['userInfo']),
|
||||||
|
...mapState(['$deviceType'])
|
||||||
|
},
|
||||||
onLoad() {
|
onLoad() {
|
||||||
if (wx.getUserProfile) {
|
if (this.$deviceType==='weixin') {
|
||||||
this.canIUseGetUserProfile = true
|
this.weixin = true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
@ -292,43 +314,12 @@ export default {
|
|||||||
},
|
},
|
||||||
// 申请获取用户信息
|
// 申请获取用户信息
|
||||||
getUserInfoProfile(data) {
|
getUserInfoProfile(data) {
|
||||||
wx.getUserProfile({
|
if (isWeixin()) {
|
||||||
lang: 'zh_CN',
|
let wechatInit = wechat()
|
||||||
desc: '需要获取您的信息用来展示',
|
if (wechatInit) {
|
||||||
success: res => {
|
await oAuth()
|
||||||
uni.showLoading({
|
|
||||||
title: '正在更新信息...',
|
|
||||||
duration: 2000,
|
|
||||||
})
|
|
||||||
getProvider()
|
|
||||||
.then(provider => { // 环境提供商
|
|
||||||
if (!provider) {
|
|
||||||
reject()
|
|
||||||
}
|
}
|
||||||
// 获取开发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) {
|
changeswitch(data) {
|
||||||
this.switchActive = data
|
this.switchActive = data
|
||||||
@ -428,6 +419,7 @@ export default {
|
|||||||
color: rgba(255, 255, 255, 1);
|
color: rgba(255, 255, 255, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.footer-line-height {
|
.footer-line-height {
|
||||||
height: 1 * 100rpx;
|
height: 1 * 100rpx;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user