|
@@ -67,28 +67,23 @@ export default {
|
|
|
agreed: false,
|
|
agreed: false,
|
|
|
nickname: '',
|
|
nickname: '',
|
|
|
avatar: '',
|
|
avatar: '',
|
|
|
- redirectUrl: '',
|
|
|
|
|
- loginCode: ''
|
|
|
|
|
- }
|
|
|
|
|
- },
|
|
|
|
|
- onLoad(options) {
|
|
|
|
|
- // 处理邀请码
|
|
|
|
|
- if (options.inviteCode) {
|
|
|
|
|
- uni.setStorageSync('inviteCode', options.inviteCode)
|
|
|
|
|
- uni.setStorageSync('inviteType', options.inviteType || 'family')
|
|
|
|
|
- }
|
|
|
|
|
- // 存储登录后跳转地址
|
|
|
|
|
- if (options.redirect) {
|
|
|
|
|
- this.redirectUrl = decodeURIComponent(options.redirect)
|
|
|
|
|
- }
|
|
|
|
|
- // 预获取微信登录code(有效期5分钟,用户操作通常在时限内)
|
|
|
|
|
- var self = this
|
|
|
|
|
- uni.login({
|
|
|
|
|
- provider: 'weixin',
|
|
|
|
|
- success: function(res) { self.loginCode = res.code },
|
|
|
|
|
- fail: function() {}
|
|
|
|
|
- })
|
|
|
|
|
|
|
+ redirectUrl: ''
|
|
|
|
|
+ },
|
|
|
},
|
|
},
|
|
|
|
|
+ onLoad(options) {
|
|
|
|
|
+ // 处理邀请码
|
|
|
|
|
+ if (options.inviteCode) {
|
|
|
|
|
+ uni.setStorageSync('inviteCode', options.inviteCode)
|
|
|
|
|
+ uni.setStorageSync('inviteType', options.inviteType || 'family')
|
|
|
|
|
+ }
|
|
|
|
|
+ // 存储登录后跳转地址
|
|
|
|
|
+ if (options.redirect) {
|
|
|
|
|
+ this.redirectUrl = decodeURIComponent(options.redirect)
|
|
|
|
|
+ }
|
|
|
|
|
+ // 注意:不在 onLoad 预取 login code —— 微信 code 一次性有效(5分钟且用过即废),
|
|
|
|
|
+ // 预取后如果用户隔几分钟再点击授权,code 已失效会报 invalid code (40029)。
|
|
|
|
|
+ // 正确做法:getPhoneNumber 中用户点击授权时实时获取。
|
|
|
|
|
+ },
|
|
|
methods: {
|
|
methods: {
|
|
|
handleImageError(e) {
|
|
handleImageError(e) {
|
|
|
console.log('Logo 加载失败,使用默认显示')
|
|
console.log('Logo 加载失败,使用默认显示')
|
|
@@ -121,16 +116,26 @@ export default {
|
|
|
}
|
|
}
|
|
|
var self = this
|
|
var self = this
|
|
|
self.loading = true
|
|
self.loading = true
|
|
|
- if (!self.loginCode) {
|
|
|
|
|
- uni.showToast({ title: '网络异常,请重试', icon: 'none' })
|
|
|
|
|
- self.loading = false
|
|
|
|
|
- return
|
|
|
|
|
- }
|
|
|
|
|
- wechatPhoneLogin({ code: self.loginCode, phoneCode: e.detail.code }).then(function(res) {
|
|
|
|
|
- self.completeLogin(res.data)
|
|
|
|
|
- }).catch(function(err) {
|
|
|
|
|
- uni.showToast({ title: err.message || '登录失败', icon: 'none' })
|
|
|
|
|
- self.loading = false
|
|
|
|
|
|
|
+ // 点击授权时实时获取 login code(微信 code 一次性有效,不能复用旧 code)
|
|
|
|
|
+ uni.login({
|
|
|
|
|
+ provider: 'weixin',
|
|
|
|
|
+ success: function(loginRes) {
|
|
|
|
|
+ if (!loginRes.code) {
|
|
|
|
|
+ uni.showToast({ title: '网络异常,请重试', icon: 'none' })
|
|
|
|
|
+ self.loading = false
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+ wechatPhoneLogin({ code: loginRes.code, phoneCode: e.detail.code }).then(function(res) {
|
|
|
|
|
+ self.completeLogin(res.data)
|
|
|
|
|
+ }).catch(function(err) {
|
|
|
|
|
+ uni.showToast({ title: err.message || '登录失败', icon: 'none' })
|
|
|
|
|
+ self.loading = false
|
|
|
|
|
+ })
|
|
|
|
|
+ },
|
|
|
|
|
+ fail: function() {
|
|
|
|
|
+ uni.showToast({ title: '网络异常,请重试', icon: 'none' })
|
|
|
|
|
+ self.loading = false
|
|
|
|
|
+ }
|
|
|
})
|
|
})
|
|
|
},
|
|
},
|
|
|
completeLogin: function(data) {
|
|
completeLogin: function(data) {
|