添加页面跳转登录效果 review by 黄敬囿
Showing
5 changed files
with
43 additions
and
2 deletions
@@ -15,7 +15,8 @@ import { Event } from '/login/utils/index.js'; | @@ -15,7 +15,8 @@ import { Event } from '/login/utils/index.js'; | ||
15 | import { wxLogin } from '/login/utils/login/login.js'; | 15 | import { wxLogin } from '/login/utils/login/login.js'; |
16 | import { appReport } from './libs/appReport.js'; | 16 | import { appReport } from './libs/appReport.js'; |
17 | 17 | ||
18 | -global.event = new Event(); | 18 | +const event = new Event(); |
19 | +global.event = event; | ||
19 | 20 | ||
20 | import { logEvent, | 21 | import { logEvent, |
21 | YB_LAUNCH_APP, | 22 | YB_LAUNCH_APP, |
@@ -100,6 +101,25 @@ App({ | @@ -100,6 +101,25 @@ App({ | ||
100 | }, 1000); | 101 | }, 1000); |
101 | this.mtainit(options); | 102 | this.mtainit(options); |
102 | await wxLogin(); | 103 | await wxLogin(); |
104 | + event.on('user-is-login', ({ logged, loginSuccess }) => { | ||
105 | + const userInfo = wx.getStorageSync('userInfo'); | ||
106 | + console.log(userInfo); | ||
107 | + if (userInfo && userInfo.uid && userInfo.session_key) { | ||
108 | + this.globalData.userInfo = userInfo; | ||
109 | + if (logged) { | ||
110 | + logged(userInfo); | ||
111 | + } | ||
112 | + } else { | ||
113 | + event.once('user-login-success', (userInfo) => { | ||
114 | + if (loginSuccess) { | ||
115 | + loginSuccess(userInfo); | ||
116 | + } | ||
117 | + }); | ||
118 | + wx.navigateTo({ | ||
119 | + url: '/login/login-page/login-page', | ||
120 | + }) | ||
121 | + } | ||
122 | + }); | ||
103 | }, | 123 | }, |
104 | 124 | ||
105 | //当应用程序进入前台显示状态时触发 | 125 | //当应用程序进入前台显示状态时触发 |
@@ -306,3 +306,10 @@ const _onceWrap = (target, type, listener) => { | @@ -306,3 +306,10 @@ const _onceWrap = (target, type, listener) => { | ||
306 | state.wrapFn = wrapped; | 306 | state.wrapFn = wrapped; |
307 | return wrapped; | 307 | return wrapped; |
308 | } | 308 | } |
309 | + | ||
310 | +function arrayClone(arr, n) { | ||
311 | + var copy = new Array(n); | ||
312 | + for (var i = 0; i < n; ++i) | ||
313 | + copy[i] = arr[i]; | ||
314 | + return copy; | ||
315 | +} |
@@ -94,6 +94,7 @@ const wechatUnionIdIsBind = async (union_id, userInfo) => { | @@ -94,6 +94,7 @@ const wechatUnionIdIsBind = async (union_id, userInfo) => { | ||
94 | login.sendWeChatUserData(uid, userInfo.nickName, userInfo.avatarUrl).catch(error => {}); | 94 | login.sendWeChatUserData(uid, userInfo.nickName, userInfo.avatarUrl).catch(error => {}); |
95 | // 触发事件登录成功 | 95 | // 触发事件登录成功 |
96 | event.emit('wechat-login-success', newUserInfo); | 96 | event.emit('wechat-login-success', newUserInfo); |
97 | + event.emit('user-login-success', newUserInfo); | ||
97 | } else { | 98 | } else { |
98 | // 修改按钮状态, 获取手机号绑定手机号 | 99 | // 修改按钮状态, 获取手机号绑定手机号 |
99 | event.emit('wechat-login-change-status', { openType: 'getPhoneNumber' }); | 100 | event.emit('wechat-login-change-status', { openType: 'getPhoneNumber' }); |
@@ -231,6 +231,19 @@ Page(Object.assign({ | @@ -231,6 +231,19 @@ Page(Object.assign({ | ||
231 | 231 | ||
232 | }, | 232 | }, |
233 | 233 | ||
234 | + goLogin() { | ||
235 | + const event = global.event; | ||
236 | + event.emit('user-is-login', { logged: this.logged, loginSuccess: this.loginSuccess }); | ||
237 | + }, | ||
238 | + | ||
239 | + logged() { | ||
240 | + | ||
241 | + }, | ||
242 | + | ||
243 | + loginSuccess() { | ||
244 | + | ||
245 | + }, | ||
246 | + | ||
234 | _getGroupList() { | 247 | _getGroupList() { |
235 | this.commonService.getGroupList({ | 248 | this.commonService.getGroupList({ |
236 | limit: 20, | 249 | limit: 20, |
@@ -42,7 +42,7 @@ | @@ -42,7 +42,7 @@ | ||
42 | </view> | 42 | </view> |
43 | 43 | ||
44 | <block wx:if="{{product.status === 2}}"> | 44 | <block wx:if="{{product.status === 2}}"> |
45 | - <button class="action-item confirm" open-type="{{!hasUnionID ? 'getUserInfo':'getPhoneNumber'}}" bindgetphonenumber="getPhoneNumber" bindgetuserinfo='getUserInfo'>0元参加抽奖</button> | 45 | + <button class="action-item confirm" bindtap="goLogin">0元参加抽奖</button> |
46 | </block> | 46 | </block> |
47 | 47 | ||
48 | <block wx:else> | 48 | <block wx:else> |
-
Please register or login to post a comment