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.
 

211 lines
5.1 KiB

// pages/auth/auth.js
const $api = require('../../utils/api').API;
Page({
/**
* 页面的初始数据
*/
data: {
agree: true,
user: false,//用户信息
code: false,
// 登录页面
is_login: true,
},
setAgree() {
let {
agree
} = this.data;
this.setData({
agree: !agree
})
},
// 一键登录
bindGetUserInfo: function (e) {
let {
agree
} = this.data;
if (agree === false) {
wx.showToast({
title: '请勾选隐私政策',
icon: 'none',
duration: 2000
})
return;
}
var that = this;
let att = false;
wx.login({
success: (eve) => {
console.log(eve)
att = eve;
}
})
wx.getUserProfile({
desc: '用户展示用户信息',
success: (resT) => {
console.log(resT)
this.setData({
user: resT.userInfo,
})
$api.Login('POST', 'social/token?' + 'code=MINI@' + att.code).then(res => {
if (res.code == 2) {
wx.showToast({
title: '请先注册账号',
icon: 'none',
mask: true,
duration: 1500,
})
that.setData({
code: att.code,
is_login: false,
})
} else {
wx.showToast({
title: '授权成功',
icon: 'none',
mask: true,
duration: 1500,
})
console.log(res.access_token)
wx.setStorageSync(
'access_token', res.access_token
)
wx.switchTab({
url: '/pages/look/look'
})
// setTimeout(() => {
// }, 1500)
}
})
},
fail: (res) => {
wx.showToast({
title: '授权失败,请重试。',
icon: 'none',
mask: true,
duration: 1500,
})
}
})
},
// 一键注册 获取手机号
getphonenumberFun(e) {
console.log(e);
let {
agree,
user,
code
} = this.data;
if (agree === false) {
wx.showToast({
title: '请勾选隐私政策',
icon: 'none',
duration: 2000
})
return;
}
console.log(e)
console.log(user)
$api.AJAX('POST', 'social/register-bind', {
state: 'MINI',
encryptedData: e.detail.encryptedData,
iv: e.detail.iv,
code: code,
nickName: user.nickName,
avatar: user.avatarUrl,
}, false).then(res => {
if (res.code == 1) {
wx.showToast({
title: res.msg,
icon: 'none',
mask: true,
duration: 1500,
})
return
}
wx.showToast({
title: '注册成功',
icon: 'none',
mask: true,
duration: 1500,
})
wx.setStorageSync('access_token', res.access_token);
wx.switchTab({
url: '/pages/look/look'
})
// console.log(res);
// setTimeout(() => {
// }, 1500)
})
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
let token = wx.getStorageSync('access_token')
console.log(token)
if (token && token != '') {
wx.switchTab({
url: "/pages/look/look",
})
}
;
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
}
})