Jacob
4 天以前 bf50dc43351d1a9781a84faf775913e813ea6ecb
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
<template>
   <view class="login_page" v-if="isShow">
       <view class="login_bg"></view>
       <view class="login_box animated" :class="{ slideInUp: isShow }">
           <image class="head" src="https://ossacmall.bluedeer.com.cn/app/static/images/app_logo2.png"></image>
           <view class="title">很高兴遇见您,欢迎您的到来!</view>
           <view class="input_box">
               <view class="input_label">*手机号</view>
               <view class="input">{{ mobile }}</view><button class="input_btn" open-type="getPhoneNumber"
                   @getphonenumber="getphonenumber">手机号快捷登录</button>
           </view>
           <view class="submit" @click="submit">确认授权</view>
           <view class="cancel" @click="skip">暂时跳过</view>
       </view>
   </view>
</template>
<script>
   const app = getApp();
   import {
       silenceBindingSpread
   } from "@/utils";
   import Routine from '@/libs/routine';
   import {
       bindUserPhone,
       decryptPhone,
       getLogo
   } from '@/api/public';
   export default {
       name: 'loginPhone',
       data() {
           return {
               logoUrl: '',
               isShow: false,
               mobile: '',
               info: {},
               isUpdating:false
           }
       },
       mounted() {},
       methods: {
           getphonenumber(e) {
               console.log(e);
               if(e.detail&&e.detail.errMsg.indexOf('fail')>=0){
                   return false;
               }
               let that = this;
               this.info = e;
               uni.showLoading();
               Routine.getCode()
                   .then(code => {
                       console.log(code);
                       that.decryptPhone(this.info.detail.encryptedData, this.info.detail.iv, code);
                   })
                   .catch(error => {
                       uni.hideLoading();
                   });
           },
           decryptPhone(encryptedData, iv, code) {
               let that = this;
               uni.showLoading();
               decryptPhone({
                       encryptedData: encryptedData,
                       iv: iv,
                       code: code,
                       key: that.authKey,
                       type: 'routine'
                   })
                   .then(res => {
                       uni.hideLoading();
                       that.$set(that, 'mobile', res.message);
                   })
                   .catch(res => {
                       uni.hideLoading();
                   });
           },
           // 小程序获取手机号码回调
           getUserPhoneNumber(encryptedData, iv, code) {
               let that = this;
               uni.showLoading();
               bindUserPhone({
                       encryptedData: encryptedData,
                       iv: iv,
                       code: code,
                       key: that.authKey,
                       type: 'routine'
                   })
                   .then(res => {
                       uni.hideLoading();
                       that.$store.commit('UPDATE_LOGINSTATUS', res.data);
                       silenceBindingSpread();
                       that.getUserInfo();
                   })
                   .catch(e => {
                       console.log(e);
                       uni.hideLoading();
                   });
           },
           getUserInfo: function() {
               let that = this;
               Routine.getLastUserInfo()
                   .then(userInfo => {
                       uni.showLoading();
                       console.log("获取用户信息:", userInfo);
                       uni.$emit('registerSuccess', {});
                       uni.hideLoading();
                       that.$parent.$refs.loginInfo.show();
                       that.hide();
                   })
                   .catch(error => {
                       console.error("获取用户信息错误:", error);
                       // 处理错误情况
                   });
 
           },
           submit() {
               let that = this;
               if (!that.info.detail) {
                   uni.showToast({
                       title: '请先获取手机号',
                       icon: 'none'
                   });
                   return false;
               }
               if(that.isUpdating){
                   return false;
               }
               that.isUpdating=true;
               Routine.getCode()
                   .then(code => {
                       that.isUpdating=false;
                       this.getUserPhoneNumber(this.info.detail ? this.info.detail.encryptedData : '', this.info
                           .detail ? this.info.detail.iv : '', code);
                   })
                   .catch(error => {
                       that.isUpdating=false;
                       uni.hideLoading();
                   });
           },
 
 
           show() {
               let that = this;
               that.authKey = app.globalData.authKey;
               this.isShow = true;
           },
           skip() {
               let pages = getCurrentPages(),
                   currPage = pages[pages.length - 1];
               if (currPage.route.indexOf('pages/zone/') >= 0 ||
                   currPage.route.indexOf('pages/users/user_get_coupon/index') >= 0
               ) {
                   uni.switchTab({
                       'url': '/pages/index/index'
                   })
               }
               if (
                   currPage.route.indexOf('pages/users/user_vip/index') >= 0 ||
                   currPage.route.indexOf('pages/users/user_goods_collection/index') >= 0 ||
                   currPage.route.indexOf('pages/users/user_address/index') >= 0 ||
                   currPage.route.indexOf('pages/users/user_address_list/index') >= 0 ||
                   currPage.route.indexOf('pages/users/order_list/index') >= 0
               ) {
                   uni.switchTab({
                       'url': '/pages/user/index'
                   })
               }
               this.hide();
           },
           hide() {
               this.isShow = false;
           }
       }
   }
</script>
 
<style lang="scss" scoped>
   .login_page {
       position: fixed;
       left: 0;
       top: 0;
       width: 100%;
       height: 100%;
       z-index: 9999;
   }
 
   .login_bg {
       width: 100%;
       height: 100%;
       background: rgba(0, 0, 0, .7);
   }
 
   .login_box {
       width: 100%;
       box-sizing: border-box;
       padding: 290rpx 60rpx 60rpx 60rpx;
       position: absolute;
       left: 0;
       bottom: 0;
       background: url("https://ossacmall.bluedeer.com.cn/app/static/images/login_top2.png") center top/100% auto no-repeat;
       background-color: #FFE20E;
       border-radius: 40rpx 40rpx 0 0;
 
       .head {
           width: 80rpx;
           height: 80rpx;
           left: 45rpx;
           top: 50rpx;
           position: absolute;
           border: 1rpx solid #F5F5F5;
           border-radius: 50%;
       }
 
       .title {
           font-size: 34rpx;
           line-height: 60rpx;
           position: absolute;
           left: 144rpx;
           top: 60rpx;
           color: #ffffff;
       }
 
       .input_box {
           padding-left: 110rpx;
           padding-right: 250rpx;
           position: relative;
           font-size: 30rpx;
           height: 133rpx;
           line-height: 133rpx;
           color: #000000;
           border-bottom: 2rpx solid #000000;
 
           .input_label {
               position: absolute;
               left: 0;
               top: 0;
           }
 
           .input {
               width: 100%;
               height: 100%;
               text-align: center;
           }
 
           .input_btn {
               position: absolute;
               right: 0;
               top: 50%;
               margin-top: -29rpx;
               width: max-content;
               font-size: 31rpx;
               line-height: 57rpx;
               text-align: center;
               background-color: unset;
               color: #016DCC;
           }
       }
 
       .private {
           padding-left: 50rpx;
           font-size: 25rpx;
           color: #000000;
           position: relative;
           margin-top: 40rpx;
 
           .private_icon {
               width: 90rpx;
               height: 90rpx;
               position: absolute;
               left: -22rpx;
               top: 50%;
               margin-top: -45rpx;
 
               &:before {
                   content: '';
                   display: block;
                   position: absolute;
                   width: 35rpx;
                   height: 35rpx;
                   box-shadow: inset 0 0 0 1rpx #000;
                   border-radius: 50%;
                   left: 50%;
                   top: 50%;
                   margin-left: -18rpx;
                   margin-top: -18rpx;
               }
 
               &.active:after {
                   content: '';
                   display: block;
                   position: absolute;
                   width: 18rpx;
                   height: 18rpx;
                   background-color: #000000;
                   border-radius: 50%;
                   left: 50%;
                   top: 50%;
                   margin-left: -9rpx;
                   margin-top: -9rpx;
               }
           }
 
           .private_btn {
               display: inline-block;
               border-bottom: 1rpx solid #000000;
           }
       }
 
       .submit {
           margin-top: 96rpx;
           font-size: 30rpx;
           line-height: 84rpx;
           text-align: center;
           color: #ffffff;
           border-radius: 8rpx;
           background: #016DCC;
       }
 
       .cancel {
           font-size: 30rpx;
           width: max-content;
           margin: 24rpx auto 0 auto;
           color: #000000;
       }
   }
 
   .animated {
       animation-duration: .4s
   }
</style>