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
182 lines
4.2 KiB
// pages/login/index.js
|
|
import user from "../../utils/https/user.js"
|
|
import https from "../../utils/https.js"
|
|
import util from '../../utils/util'
|
|
var app = getApp()
|
|
Page({
|
|
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
err:null,
|
|
canIUseGetUserProfile:false,
|
|
event: '',
|
|
|
|
isApproval: false
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
onLoad: function (options) {
|
|
if (wx.getUserProfile) {
|
|
this.setData({
|
|
canIUseGetUserProfile: true
|
|
})
|
|
}
|
|
if(wx.getStorageSync('login_from')){
|
|
util.pagePoint({
|
|
event:wx.getStorageSync('login_from')
|
|
},1)
|
|
}
|
|
|
|
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()
|
|
},
|
|
cancel:function(){
|
|
util.pagePoint({event:this.data.event+'cancel'},1)
|
|
wx.reLaunch({
|
|
url: '/pages/index/index',
|
|
})
|
|
},
|
|
getUserProfile:function(e){
|
|
if (!this.data.isApproval) {
|
|
wx.showToast({
|
|
title: '请先阅读并同意相关协议',
|
|
icon: "none"
|
|
});
|
|
return
|
|
}
|
|
|
|
|
|
wx.getUserProfile({
|
|
desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
|
|
success: (res) => {
|
|
this.getUserInfo(res,1)
|
|
}
|
|
})
|
|
},
|
|
getUserInfo:function(e,type){
|
|
if (!this.data.isApproval) {
|
|
wx.showToast({
|
|
title: '请先阅读并同意相关协议',
|
|
icon: "none"
|
|
});
|
|
return
|
|
}
|
|
|
|
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)
|
|
},
|
|
changeIsApproval:function (e) {
|
|
this.setData({isApproval: !this.data.isApproval})
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
*/
|
|
onReady: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面显示
|
|
*/
|
|
onShow: function () {
|
|
util.pagePoint({
|
|
event:'login_view'
|
|
},1)
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面隐藏
|
|
*/
|
|
onHide: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面卸载
|
|
*/
|
|
onUnload: function () {
|
|
wx.removeStorageSync('login_from')
|
|
},
|
|
|
|
/**
|
|
* 页面相关事件处理函数--监听用户下拉动作
|
|
*/
|
|
onPullDownRefresh: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 页面上拉触底事件的处理函数
|
|
*/
|
|
onReachBottom: function () {
|
|
|
|
}
|
|
})
|