|
@@ -38,7 +38,7 @@ export default {
|
|
data() {
|
|
data() {
|
|
return {
|
|
return {
|
|
invitationCode: '', //获取用户登录的邀请码
|
|
invitationCode: '', //获取用户登录的邀请码
|
|
- loginMessage: '' ,//登录信息反馈
|
|
|
|
|
|
+ loginMessage: '' //登录信息反馈
|
|
}
|
|
}
|
|
},
|
|
},
|
|
onLoad(option) {},
|
|
onLoad(option) {},
|
|
@@ -48,45 +48,64 @@ export default {
|
|
isCodeEmpty() {
|
|
isCodeEmpty() {
|
|
return this.invitationCode.trim().length < 6
|
|
return this.invitationCode.trim().length < 6
|
|
},
|
|
},
|
|
- hasError(){
|
|
|
|
- return this.loginMessage.length>0
|
|
|
|
|
|
+ hasError() {
|
|
|
|
+ return this.loginMessage.length > 0
|
|
}
|
|
}
|
|
},
|
|
},
|
|
methods: {
|
|
methods: {
|
|
- ...mapMutations(['login']),
|
|
|
|
|
|
+ ...mapMutations(['login', 'wxLogin']),
|
|
|
|
+ getUserProfile() {
|
|
|
|
+ const _that = this
|
|
|
|
+ // 可以通过 wx.getSetting 先查询一下用户是否授权了 "scope.record" 这个 scope
|
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
|
+ wx.getUserProfile({
|
|
|
|
+ desc: '用于完善会员资料',
|
|
|
|
+ success(res) {
|
|
|
|
+ // 更新用户信息
|
|
|
|
+ _that.wxLogin(res.userInfo)
|
|
|
|
+ uni.setStorageSync('profileFlag', true)
|
|
|
|
+ resolve(res.userInfo)
|
|
|
|
+ },
|
|
|
|
+ fail() {
|
|
|
|
+ _that.$util.msg('授权失败', 2000)
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ })
|
|
|
|
+ },
|
|
// 登录
|
|
// 登录
|
|
- goLogin() {
|
|
|
|
- // 获取用户微信信息
|
|
|
|
- wx.getUserInfo({
|
|
|
|
- success: res => {
|
|
|
|
- this.isUserInfo = false
|
|
|
|
- this.userInfo = res.userInfo
|
|
|
|
- // 验证邀请码
|
|
|
|
- this.UserService.userInvitation({
|
|
|
|
- invitationCode: this.invitationCode,
|
|
|
|
- nickName: res.userInfo.nickName,
|
|
|
|
- openid: uni.getStorageSync('openid')
|
|
|
|
- })
|
|
|
|
- .then(response => {
|
|
|
|
- console.log(response)
|
|
|
|
- // 保存用户信息
|
|
|
|
- this.login(response.data)
|
|
|
|
- this.$store.commit('updateStatus', response.data)
|
|
|
|
- // 登录成功提示
|
|
|
|
- this.$util.msg('登录成功', 1500, false, 'success')
|
|
|
|
- setTimeout(() => {
|
|
|
|
- this.$api.navigateTo(`/pages/index/index`)
|
|
|
|
- }, 1500)
|
|
|
|
- })
|
|
|
|
- .catch(error => {
|
|
|
|
- this.loginMessage = error.msg
|
|
|
|
- this.isUserInfo = false
|
|
|
|
- setTimeout(()=>{
|
|
|
|
- this.loginMessage = ''
|
|
|
|
- },2000)
|
|
|
|
- })
|
|
|
|
- }
|
|
|
|
|
|
+ async goLogin() {
|
|
|
|
+ const _that = this
|
|
|
|
+ let wechatUserInfo = uni.getStorageSync('wechatUserInfo')
|
|
|
|
+ let profileFlag = uni.getStorageSync('profileFlag')
|
|
|
|
+ console.log(profileFlag);
|
|
|
|
+ if (!profileFlag) {
|
|
|
|
+ wechatUserInfo = await this.getUserProfile()
|
|
|
|
+ }
|
|
|
|
+ // 验证邀请码
|
|
|
|
+ console.log(this.isWxAuthorize)
|
|
|
|
+ this.UserService.userInvitation({
|
|
|
|
+ invitationCode: this.invitationCode,
|
|
|
|
+ nickName: wechatUserInfo.nickName,
|
|
|
|
+ openid: uni.getStorageSync('openid')
|
|
})
|
|
})
|
|
|
|
+ .then(response => {
|
|
|
|
+ console.log(response)
|
|
|
|
+ // 保存用户信息
|
|
|
|
+ _that.login(response.data)
|
|
|
|
+ _that.$store.commit('updateStatus', response.data)
|
|
|
|
+ // 登录成功提示
|
|
|
|
+ _that.$util.msg('登录成功', 1500, false, 'success')
|
|
|
|
+ setTimeout(() => {
|
|
|
|
+ _that.$api.navigateTo(`/pages/index/index`)
|
|
|
|
+ }, 1500)
|
|
|
|
+ })
|
|
|
|
+ .catch(error => {
|
|
|
|
+ _that.loginMessage = error.msg
|
|
|
|
+ _that.isUserInfo = false
|
|
|
|
+ setTimeout(() => {
|
|
|
|
+ _that.loginMessage = ''
|
|
|
|
+ }, 2000)
|
|
|
|
+ })
|
|
},
|
|
},
|
|
// 输入框输入介绍
|
|
// 输入框输入介绍
|
|
vcodeInput(val) {
|
|
vcodeInput(val) {
|