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.

182 lines
4.2 KiB

5 years ago
// pages/login/index.js
import user from "../../utils/https/user.js"
import https from "../../utils/https.js"
4 years ago
import util from '../../utils/util'
5 years ago
var app = getApp()
Page({
/**
* 页面的初始数据
*/
data: {
5 years ago
err:null,
4 years ago
canIUseGetUserProfile:false,
event: '',
isApproval: false
5 years ago
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
5 years ago
if (wx.getUserProfile) {
this.setData({
canIUseGetUserProfile: true
})
}
4 years ago
if(wx.getStorageSync('login_from')){
util.pagePoint({
event:wx.getStorageSync('login_from')
},1)
}
4 years ago
let page = getCurrentPages().reverse().find(item=>item.route && item.route.indexOf('login/index')==-1);
if(page && page.route && app.globalData.loginPageEvent[page.route]){
this.setData({
event:app.globalData.loginPageEvent[page.route]
})
util.pagePoint({event:app.globalData.loginPageEvent[page.route]+'enter'},1)
}
console.log()
5 years ago
},
cancel:function(){
4 years ago
util.pagePoint({event:this.data.event+'cancel'},1)
11 months ago
wx.switchTab({
5 years ago
url: '/pages/index/index',
})
5 years ago
},
5 years ago
getUserProfile:function(e){
if (!this.data.isApproval) {
wx.showToast({
title: '请先阅读并同意相关协议',
icon: "none"
});
return
}
5 years ago
wx.getUserProfile({
desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
success: (res) => {
this.getUserInfo(res,1)
}
})
},
getUserInfo:function(e,type){
if (!this.data.isApproval) {
wx.showToast({
title: '请先阅读并同意相关协议',
icon: "none"
});
return
}
5 years ago
let that = this;
5 years ago
if (e.detail && (!e.detail.userInfo)){
11 months ago
wx.switchTab({
5 years ago
url: '/pages/index/index',
})
return;
}
wx.login({
success: function (r) {
5 years ago
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 => {
5 years ago
console.log(r)
// return;
// r.data.isBind是false的时候去绑定手机号 该用户没有注册过
// 已经注册的用户返回userinfo
5 years ago
if (r.data.isBindMobile === 0) {
5 years ago
wx.redirectTo({
5 years ago
url: '/pages/user/bindtel/index?regToken=' + encodeURIComponent(r.data.openid),
5 years ago
})
}
else if(r.data && r.data.id && r.data.token){
https.set_logininfo(r);
wx.navigateBack({
delta:1
})
}
else {
console.log('看这里看这里看这里')
11 months ago
wx.switchTab({
5 years ago
url:"/pages/index/index"
})
}
}).catch(err=>{
11 months ago
wx.switchTab({
5 years ago
url:"/pages/index/index"
})
})
},
fail:function(){
11 months ago
wx.switchTab({
5 years ago
url:"/pages/index/index"
})
}
})
console.log(e);
},
addClick:function(e){
let id = e.currentTarget?e.currentTarget.dataset.clickid:e;
wx.uma.trackEvent(id)
},
changeIsApproval:function (e) {
this.setData({isApproval: !this.data.isApproval})
},
5 years ago
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
4 years ago
util.pagePoint({
event:'login_view'
},1)
5 years ago
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
4 years ago
wx.removeStorageSync('login_from')
5 years ago
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
}
})