|
@@ -21,7 +21,7 @@
|
|
|
<!-- #endif -->
|
|
|
<!-- #ifdef APP-PLUS -->
|
|
|
<button class="authorize-login" @click="getUserinfoApp">
|
|
|
- 登录5
|
|
|
+ 登录
|
|
|
</button>
|
|
|
<!-- #endif -->
|
|
|
<view @click="showAgreement = true" class="agreement">点击登录视为同意<text class="underline">平台服务协议</text></view>
|
|
@@ -204,9 +204,9 @@
|
|
|
data: wxLoginData
|
|
|
})
|
|
|
this.wxLoginData = wxLoginData
|
|
|
- this.getUserInfo()
|
|
|
+ this.getUserInfo(1)
|
|
|
},
|
|
|
- fail: () => {
|
|
|
+ fail: (error) => {
|
|
|
console.log(33333, error)
|
|
|
this.$refs.uTips.show({
|
|
|
title: '微信登录授权失败',
|
|
@@ -231,47 +231,52 @@
|
|
|
let that = this
|
|
|
console.log('app enter')
|
|
|
uni.login({
|
|
|
- // provider: 'weixin',
|
|
|
+ provider: 'weixin',
|
|
|
success: (res2) => {
|
|
|
console.log('res2', res2)
|
|
|
uni.getUserInfo({
|
|
|
provider: 'weixin',
|
|
|
success: (info) => {
|
|
|
- console.log('info')
|
|
|
- // uni.setStorage({
|
|
|
- // key: 'wxLoginData',
|
|
|
- // data: {
|
|
|
- // code: res2.code,
|
|
|
- // encryptedData: info.encryptedData,
|
|
|
- // iv: info.iv,
|
|
|
- // rawData: info.rawData,
|
|
|
- // signature: info.signature,
|
|
|
- // }
|
|
|
- // })
|
|
|
- // that.wxLoginData = uni.getStorageSync("wxLoginData")
|
|
|
- // console.log(1111111, that.wxLoginData && that.wxLoginData.rawData)
|
|
|
+ console.log('info',info)
|
|
|
+ uni.setStorage({
|
|
|
+ key: 'wxLoginData',
|
|
|
+ data: {
|
|
|
+ nickName: info.userInfo.nickName,
|
|
|
+ gender: info.userInfo.gender,
|
|
|
+ avatarUrl: info.userInfo.avatarUrl,
|
|
|
+ unionId: info.userInfo.unionId,
|
|
|
+ openId:info.userInfo.openId
|
|
|
+ // code: res2.code,
|
|
|
+ // encryptedData: info.encryptedData,
|
|
|
+ // iv: info.iv,
|
|
|
+ // rawData: info.rawData,
|
|
|
+ // signature: info.signature,
|
|
|
+ }
|
|
|
+ })
|
|
|
+ that.wxLoginData = uni.getStorageSync("wxLoginData")
|
|
|
+ console.log(1111111, that.wxLoginData)
|
|
|
// that.userNmae = JSON.parse(that.wxLoginData.rawData).nickName
|
|
|
- // that.getUserInfo()
|
|
|
- // this.$refs.uTips.show({
|
|
|
- // title: '获取角色信息成功',
|
|
|
- // type: 'success',
|
|
|
- // })
|
|
|
+ that.getUserInfo(0)
|
|
|
+ this.$refs.uTips.show({
|
|
|
+ title: '获取角色信息成功',
|
|
|
+ type: 'success',
|
|
|
+ })
|
|
|
},
|
|
|
fail: (error) => {
|
|
|
console.log(2222, error)
|
|
|
- // that.$refs.uTips.show({
|
|
|
- // title: '微信登录授权失败',
|
|
|
- // type: 'warning',
|
|
|
- // })
|
|
|
+ that.$refs.uTips.show({
|
|
|
+ title: '微信登录授权失败',
|
|
|
+ type: 'warning',
|
|
|
+ })
|
|
|
}
|
|
|
})
|
|
|
},
|
|
|
- fail: () => {
|
|
|
+ fail: (error) => {
|
|
|
console.log(33333, error)
|
|
|
- // that.$refs.uTips.show({
|
|
|
- // title: '微信登录授权失败',
|
|
|
- // type: 'warning',
|
|
|
- // })
|
|
|
+ that.$refs.uTips.show({
|
|
|
+ title: '微信登录授权失败',
|
|
|
+ type: 'warning',
|
|
|
+ })
|
|
|
}
|
|
|
})
|
|
|
// uni.getProvider({
|
|
@@ -294,28 +299,34 @@
|
|
|
},
|
|
|
//#endif
|
|
|
|
|
|
- // 发请求获取个人数据
|
|
|
- getUserInfo() {
|
|
|
+ // 发请求获取个人数据 envType:1小程序 0:app
|
|
|
+ getUserInfo(envType) {
|
|
|
+ console.log('发请求获取个人数据envType',envType)
|
|
|
NET.request(API.WxLogin, {
|
|
|
...this.wxLoginData,
|
|
|
// ...this.wxPhoneData,
|
|
|
}, 'POST').then(res => {
|
|
|
+ console.log('token',res)
|
|
|
uni.setStorage({
|
|
|
key: 'token',
|
|
|
data: res.data.token
|
|
|
})
|
|
|
+ console.log('缓存中wxLoginData',this.wxLoginData)
|
|
|
uni.setStorage({
|
|
|
key: 'userData',
|
|
|
data: {
|
|
|
- headImage: JSON.parse(this.wxLoginData.rawData).avatarUrl,
|
|
|
+ headImage: envType ? this.wxLoginData.rawData.avatarUrl : this.wxLoginData.avatarUrl,
|
|
|
userName: res.data.name,
|
|
|
userId: res.data.userId,
|
|
|
}
|
|
|
})
|
|
|
+ console.log('存个人信息')
|
|
|
uni.switchTab({
|
|
|
url: '/pages/index/index'
|
|
|
})
|
|
|
+ console.log('switchTab')
|
|
|
}).catch(error => {
|
|
|
+ console.log(44444, error)
|
|
|
this.$refs.uTips.show({
|
|
|
title: '微信登录授权失败',
|
|
|
type: 'warning',
|