123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201 |
- 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
- })
- },
- })
|