import { post, } from '../../utils/http'; import { objToParam, } from '../../utils/util'; Page({ /** * 页面的初始数据 */ data: { userInfo: null, prePage: 0 }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { console.log(options) if(options.prePage) { this.setData({ prePage: options.prePage }) } }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { }, /** * 获取用户信息 */ getUserInfo(e) { wx.getUserProfile({ desc: 'desc', success: (res) => { this.setData({ userInfo: JSON.parse(res.rawData) }) console.log(JSON.parse(res.rawData)) } }) }, /** * 获取用户手机号 */ getPhoneNumber(e) { let that = this; wx.login({ success(res) { post('api/login', { js_code: res.code, avatar_url: that.data.userInfo.avatarUrl, nickname: that.data.userInfo.nickName, iv: e.detail.iv, encrypted_data: e.detail.encryptedData, wx_data: JSON.stringify(that.data.userInfo) }, (res) => { console.log(res) wx.setStorageSync('token', res.data.token); wx.setStorageSync('userInfo', res.data) wx.showToast({ title: res.msg, icon: 'none' }) setTimeout(() => { if(that.data.prePage == 1) { wx.navigateBack() } else { let sceneData = getApp().globalData.sceneData wx.reLaunch({ url: `/${sceneData.path}?${objToParam(sceneData.query)}`, }) // wx.switchTab({ // url: '/pages/home/home', // }) } }, 1500); }) } }) }, /** * 跳转去用户协议 */ goToAgree(e) { wx.navigateTo({ url: '/pages/agreement/agreement?agree=' + e.currentTarget.dataset.agree, }) } })