const url = require('../../utils/url.js') var call = require("../../utils/net.js") var app = getApp() Page({ /** * 页面的初始数据 */ data: { avatarUrl: '', nickName: '', showContact: false }, //登录/注册 bindGetUserInfo(e) { console.log(e) // app.globalData.userInfo = e.detail.userInfo if (e.detail.errMsg == 'getUserInfo:ok') { this.setData({ avatarUrl: e.detail.userInfo.avatarUrl, nickName: e.detail.userInfo.nickName }) let reqData = { 'signature': e.detail.signature, 'rawData': e.detail.rawData } wx.login({ success(res) { if (res.code) { let code = res.code reqData['code'] = code call.request(url.host + url.login, { code: res.code}, res => { //console.log(res.data) wx.setStorageSync('userId', res.data.data); //将userIdEnc存入本地缓存 if(res.data.code==200){ call.request(url.host + url.getuserinfo, reqData, res => { console.log(res) }, res => { console.log(res) }) }else{ wx.showToast({ icon: 'none', title: res.data.msg, }) } }, res => { console.log(res) }) } else { console.log('登录失败!' + res.errMsg) } } }) } else if (e.detail.errMsg == 'getUserInfo:fail auth deny') { wx.showToast({ icon: 'none', title: '授权失败!', }) } }, //获取手机号 getPhoneNumber(e) { //console.log(e) let iv = e.detail.iv let encryptedData = e.detail.encryptedData let reqData = { 'iv': iv, 'encryptedData': encryptedData } wx.login({ success(res) { if (res.code) { let code = res.code reqData['code'] = code call.request(url.host + url.login, { code: res.code }, res => { //console.log(res) if (res.data.code == 200) { call.request(url.host + url.getPhone, reqData, res => { console.log(res) }, res => { console.log(res) }) } else { wx.showToast({ icon: 'none', title: res.data.msg, }) } }, res => { console.log(res) }) } else { console.log('登录失败!' + res.errMsg) } } }) }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { var that = this; }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { var that = this; if (typeof this.getTabBar === 'function' && this.getTabBar()) { this.getTabBar().setData({ selected: 1 }) } //查看是否授权 wx.getSetting({ success(res) { if (res.authSetting['scope.userInfo']) { // 已经授权,可以直接调用 getUserInfo 获取头像昵称 wx.getUserInfo({ success: function (res) { //console.log(res.userInfo) that.setData({ avatarUrl: res.userInfo.avatarUrl, nickName: res.userInfo.nickName }) } }) } } }) }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { }, //咨询客服 call: function () { this.setData({ showContact: true }) }, })