login.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. // pages/login/login.js
  2. const api = require('../../config.js');
  3. const getReq = require('../../config.js').getReq;
  4. let app = getApp();
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. url: ''
  11. },
  12. /**
  13. * 生命周期函数--监听页面加载
  14. */
  15. onLoad: function (options) {
  16. let url = options.url || ''
  17. this.setData({
  18. url
  19. })
  20. },
  21. /**
  22. * 生命周期函数--监听页面初次渲染完成
  23. */
  24. onReady: function () {
  25. },
  26. /**
  27. * 生命周期函数--监听页面显示
  28. */
  29. onShow: function () {
  30. },
  31. /**
  32. * 生命周期函数--监听页面隐藏
  33. */
  34. onHide: function () {
  35. },
  36. /**
  37. * 生命周期函数--监听页面卸载
  38. */
  39. onUnload: function () {
  40. },
  41. /**
  42. * 页面相关事件处理函数--监听用户下拉动作
  43. */
  44. onPullDownRefresh: function () {
  45. },
  46. /**
  47. * 页面上拉触底事件的处理函数
  48. */
  49. onReachBottom: function () {
  50. },
  51. userInfoHandler(e) {
  52. let self = this
  53. if (e.detail.errMsg == "getUserInfo:ok") {
  54. app.globalData.userInfo = e.detail.userInfo;
  55. app.globalData.userInfo.nickname = e.detail.userInfo.nickName;
  56. let userInfo = app.globalData.userInfo;
  57. if (app.globalData.userId.unionid) {
  58. userInfo = Object.assign({}, app.globalData.userId, app.globalData.userInfo);
  59. }
  60. else {
  61. let { encryptedData, iv, signature } = e.detail
  62. userInfo = Object.assign({}, { encryptedData }, { signature }, { iv }, userInfo)
  63. }
  64. let params = {
  65. user_info: userInfo,
  66. act: "login",
  67. op: "wxauthen",
  68. relay_id: app.globalData.relay_id,
  69. channel: app.globalData.channel_num
  70. }
  71. getReq(app,params, function (res) {
  72. if (res.code == 200) {
  73. app.globalData.backLogin = true;
  74. app.globalData.member_id = datas.member_id
  75. app.globalData.hasmobile = datas.hasmobile
  76. wx.navigateBack();
  77. }
  78. else {
  79. wx.showToast({
  80. icon: 'none',
  81. title: '登陆失败',
  82. duration: 2000
  83. })
  84. }
  85. })
  86. }
  87. }
  88. })