/* * 手太欠 * 愿这世界都如故事里一样 美好而动人~ */ Page({ data: { typeLogin : '', // 登录来源 loading : false, // 加载 loginCode : '', // 微信登录code checked : false, //勾选协议 }, onLoad(options) { this.setData({ typeLogin : options.type }) }, onShow() { // 获取code this.gainCode(); }, /** * 隐私协议 */ empowerTap() { wx.showToast({ title: '请勾选用户隐私和服务协议', icon: "none" }) }, /** * 微信授权手机号码 */ userPhone(e){ // 获取code this.gainCode(); if(e.detail.errMsg == "getPhoneNumber:ok"){ this.setData({ loading: true }) let enData = e.detail.encryptedData, iv = e.detail.iv // 检查用户登录Code是否过期 wx.checkSession({ success: ()=>{ this.userLogin(iv,enData) }, fail: err=>{ this.setData({ loading: false }) // 登录过期重新获取code wx.login({ success: res=>{ this.setData({ loginCode: res.code }) // 登录 this.userLogin(iv,enData) } }) } }) }else{ wx.showToast({ title: '拒绝了登录授权', icon : 'none' }) } }, /** * 用户登录 */ userLogin(iv,enData){ wx.$api.auth.login({ code : this.data.loginCode, encryptedData : enData, iv : iv, invite : getApp().globalData.inviteText || '' }).then(res=>{ // 存储登录信息 wx.setStorage({ key : 'token', data : res.data.token_type + ' ' + res.data.access_token, success: () =>{ // 存储邀请码 wx.$api.user.userIndex().then(res => { wx.setStorage({ key : 'invite', data : res.data.invite }) if(this.data.typeLogin == "indexDemo") { wx.redirectTo({ url: '/pages/index/assess/assess' }) return } // 回到上一页 wx.navigateBack() }).catch(err => {}) } }) }).catch(err=>{}) }, /** * 获取code */ gainCode() { wx.login({ success: res => { this.setData({ loginCode : res.code }) } }) }, // 勾选协议 radioChange() { this.setData({ checked: !this.data.checked }) }, // 免责声明 seeSm(){ wx.showModal({ title: '免责声明', content: '本品不含任何除原料外的添加物,如使用中有任何问题,请遵医嘱。', showCancel:false, confirmText:'知道了' }) } })