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.
 

141 lines
3.0 KiB

// pages/login/index.js
import user from "../../utils/https/user.js"
import https from "../../utils/https.js"
var app = getApp()
Page({
/**
* 页面的初始数据
*/
data: {
err:null,
canIUseGetUserProfile:false
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
if (wx.getUserProfile) {
this.setData({
canIUseGetUserProfile: true
})
}
},
cancel:function(){
wx.reLaunch({
url: '/pages/index/index',
})
},
getUserProfile:function(e){
wx.getUserProfile({
desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
success: (res) => {
this.getUserInfo(res,1)
}
})
},
getUserInfo:function(e,type){
let that = this;
if (e.detail && (!e.detail.userInfo)){
wx.reLaunch({
url: '/pages/index/index',
})
return;
}
wx.login({
success: function (r) {
let api;
if(type==1){
api = user._post("user/wxLogin_v2", { code: r.code, loginType: 3, arrayInfo: {
nickName:e.userInfo.nickName,
avatarUrl:e.userInfo.avatarUrl,
gender:e.userInfo.gender
}})
}
else {
api = user._post("user/wxLogin", { code: r.code, encryptedData: e.detail.encryptedData, iv: e.detail.iv, loginType: 3 })
}
api.then(r => {
console.log(r)
// return;
// r.data.isBind是false的时候去绑定手机号 该用户没有注册过
// 已经注册的用户返回userinfo
if (r.data.isBindMobile === 0) {
wx.redirectTo({
url: '/pages/user/bindtel/index?regToken=' + encodeURIComponent(r.data.openid),
})
}
else if(r.data && r.data.id && r.data.token){
https.set_logininfo(r);
wx.navigateBack({
delta:1
})
}
else {
console.log('看这里看这里看这里')
wx.reLaunch({
url:"/pages/index/index"
})
}
}).catch(err=>{
wx.reLaunch({
url:"/pages/index/index"
})
})
},
fail:function(){
wx.reLaunch({
url:"/pages/index/index"
})
}
})
console.log(e);
},
addClick:function(e){
let id = e.currentTarget?e.currentTarget.dataset.clickid:e;
wx.uma.trackEvent(id)
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
}
})