// 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) $api.Login('POST', 'social/token', { code: 'MINI@' + att.code }).then(res => { console.log(res); if(res.code == 2){ wx.showToast({ title: '请先注册账号', icon: 'none', mask: true, duration: 1500, }) that.setData({ code:att.code, user:resT.userInfo, is_login:false, }) } }) }, fail: (res) => { wx.showToast({ title: '授权失败,请重试。', icon: 'none', mask: true, duration: 1500, }) } }) }, // 一键注册 获取手机号 getphonenumberFun(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', phone:'15608615712', code: code, nickName:user.nickName, avatar:user.avatarUrl, }, false).then(res => { wx.showToast({ title: '注册成功', icon: 'none', mask: true, duration: 1500, }) wx.setStorageSync('access_token', res.access_token); console.log(res); setTimeout(()=>{ wx.switchTab({ url:'/pages/index/index' }) },1500) }) }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { // var that = this; // // 查看是否授权 // wx.getSetting({ // success: function (res) { // console.log(res) // if (res.authSetting['scope.userInfo']) { // wx.getUserInfo({ // success: function (res) { // console.log(res) // //从数据库获取用户信息 // that.queryUsreInfo(); // //用户已经授权过 // // wx.switchTab({ // // url: '/pages/index/index' // // }) // } // }); // } // } // }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { } })