You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							131 lines
						
					
					
						
							3.1 KiB
						
					
					
				
			
		
		
		
			
			
			
				
					
				
				
					
				
			
		
		
	
	
							131 lines
						
					
					
						
							3.1 KiB
						
					
					
				| // pages/weChatAuth/index.js | |
| import { store } from '../../utils/store.js' | |
| import { UserModel } from '../../models/user.js' | |
| let userModel = new UserModel() | |
| import { AuthModel } from '../../models/auth.js' | |
| let authModel = new AuthModel() | |
| 
 | |
| 
 | |
| Page({ | |
| 
 | |
|   /** | |
|    * 页面的初始数据 | |
|    */ | |
|   data: { | |
|     canIUse: wx.canIUse('button.open-type.getUserInfo'), | |
|     nickName: '', | |
|     avatarUrl: '', | |
|     userInfo: { | |
|       type: Object, | |
|       value: {} | |
|     }, | |
|     type:1 | |
|   }, | |
| 
 | |
|   /** | |
|    * 生命周期函数--监听页面加载 | |
|    */ | |
|   onLoad: function (options) { | |
|     this.setData({ | |
|       type:options.type | |
|     }) | |
|   }, | |
| 
 | |
|   /** | |
|    * 生命周期函数--监听页面显示 | |
|    */ | |
|   onShow: function () { | |
| 
 | |
|   }, | |
| 
 | |
|   // 授权登录 | |
|   bindGetUserInfo(e) { | |
|     //console.log(e.detail.userInfo) | |
|     if (e.detail.userInfo) { | |
|       let avatarUrl = e.detail.userInfo.avatarUrl | |
|       let nickName = e.detail.userInfo.nickName | |
|       store.saveUserInfo({ | |
|         nickName: nickName, | |
|         avatarUrl: avatarUrl, | |
|         phone: '' | |
|       }) | |
|       this.sendUserInfo(e.detail.userInfo) | |
|     } | |
|   }, | |
| 
 | |
|   // 上传用户信息 | |
|   sendUserInfo(weChatInfo) { | |
|     userModel.sendUserInfo(weChatInfo, res => { | |
|       this.getUserInfo() | |
|     }) | |
|   }, | |
| 
 | |
|   // 获取用户信息 | |
|   getUserInfo() { | |
|     userModel.getUserInfo(res => { | |
|       console.log(res) | |
|       let nickName = res.result.nickName | |
|       let avatarUrl = res.result.avatarUrl | |
| 
 | |
|       if (nickName && avatarUrl) { | |
|         //console.log('已授权') | |
|         this.setData({ | |
|           userInfo: res.result, | |
|           avatarUrl: res.result.avatarUrl, | |
|           nickName: res.result.nickName, | |
|           reAuth: true, | |
|           isAuth: false | |
|         }, () => { | |
|           if (store.hasPhone()) { | |
|             //console.log('已经绑定手机号码') | |
|           } else { | |
|             //console.log('未绑定手机号码') | |
|             wx.showModal({ | |
|               title: '温馨提示', | |
|               content: '是否前往验证手机号码?', | |
|               success(res) { | |
|                 if (res.confirm) { | |
|                   wx.redirectTo({ | |
|                     // url: '/pages/register/index', | |
|                     url: '/pages/weChatAuth/index?type=2', | |
|                   }) | |
|                 } else if (res.cancel) { | |
|                   wx.switchTab({ | |
|                     url: '/pages/home/index', | |
|                   }) | |
|                 } | |
|               } | |
|             }) | |
|           } | |
|         }) | |
|         store.saveUserInfo({ | |
|           nickName: res.result.nickName, | |
|           avatarUrl: res.result.avatarUrl, | |
|           phone: res.result.phone || '' | |
|         }) | |
|       } else { | |
|         //console.log('未授权') | |
|         this.setData({ | |
|           isAuth: true | |
|         }) | |
|       } | |
|     }) | |
|   }, | |
|   bindGetPhoneNumber(e){ | |
|     // var user = UserModel; | |
|     if (e.detail.encryptedData){ | |
|       console.log(e); | |
|       let data = {} | |
|       // data.nickName = this.data.nickName; | |
|       // data.avatarUrl = this.data.avatarUrl; | |
|       data.encryptedData = e.detail.encryptedData; | |
|       data.iv = e.detail.iv; | |
|       // data.session = app.globalData.session; | |
|       userModel.wxRegister(data,res => { | |
|           wx.reLaunch({ | |
|             url: '/pages/home/index', | |
|           }) | |
|       }); | |
|     } | |
|   } | |
| }) |