mobilePhone.vue
2.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<template>
<view class="container flex-items-plus flex-column">
<view class="login-logoBox">
<image class="login-logo" src="@/static/logo.png"></image>
</view>
<view class="loginTitle-text flex-column-plus flex-items font-color-666 fs26">
<label>为了给您提供更好的服务</label>
<label>我们需要您的授权哦~</label>
</view>
<view>
<button class="loginWxBut fs28 mar-top-100" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">微信手机号授权</button>
</view>
</view>
</template>
<script>
const NET = require('../../utils/request')
const API = require('../../config/api')
export default {
data() {
return {
avatarUrl:''
}
},
onLoad(options) {
this.avatarUrl = uni.getStorageSync('avatarUrl')
console.log(this.avatarUrl,8888)
},
onBackPress(options) {
this.back();
return true;
},
methods: {
back(){
uni.switchTab({
url: 'login'
});
},
getPhoneNumber(e){
if(e.detail.errMsg === "getPhoneNumber:ok"){
console.log(e)
const that = this
uni.login({
provider: 'weixin',
success: (res) => {
that.code = res.code
NET.request(API.GetSessionKey,{
code:that.code,
},'POST').then(res1 => {
NET.request(API.SetWxPhone,{
wechatOpenId:res1.data.wechatOpenId,
sessionKey:res1.data.sessionKey,
encryptedData:e.detail.encryptedData,
iv:e.detail.iv,
headImage:this.avatarUrl
},'POST').then(res2 => {
const item = res2.data
uni.setStorageSync('storage_key', item);
console.log(uni.getStorageSync('storage_key'))
setTimeout(function(){
uni.switchTab({
url:'../../pages/tabbar/user/index',
success() {
uni.hideLoading()
}
})
},1000)
}).catch(res => {
})
}).catch(err => {
console.log(err,22222)
})
},
fail: () => {
uni.showToast({
title: "微信登录授权失败",
icon: "none"
});
}
})
}else{
uni.showToast({
title: "获取手机授权失败",
icon: "none"
});
}
},
}
}
</script>
<style lang="scss">
.container {
.login-logoBox {
margin-top: 154upx;
.login-logo {
width: 250upx;
height: 250upx;
}
}
.loginTitle-text {
margin-top: 222upx;
}
.loginWxBut {
background-image: linear-gradient(135deg, #FFA100 10%, #FF7911 100%);
color: #FFFFFF;
height: 88upx;
width: 600upx;
text-align: center;
line-height: 88upx;
border-radius: 88upx;
margin-top: 49upx;
}
.loginBut {
background-color: #FFFFFF;
color: #C5AA7B;
height: 88upx;
width: 600upx;
text-align: center;
line-height: 88upx;
border-radius: 88upx;
border: 2upx solid #C5AA7B;
margin-top: 30upx;
}
.register-text {
color: #47A7EE;
}
}
</style>