index.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. // pages/login/index.js
  2. var app = getApp();
  3. var api = require('../../utils/api.js');
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. },
  10. /**
  11. * 生命周期函数--监听页面加载
  12. */
  13. onLoad: function (options) {
  14. var we_chat_user = wx.getStorageSync('we_chat_user')
  15. if (we_chat_user) {
  16. wx.redirectTo({
  17. url: '/pages/bind-phone/index',
  18. })
  19. }
  20. },
  21. bindGetUserInfo: function (e) {
  22. if(e.detail.errMsg == 'getUserInfo:ok') {
  23. wx.showLoading({
  24. title: '登录中',
  25. })
  26. console.log(wx.getStorageSync('we_chat_user_id'))
  27. wx.request({
  28. url: api.updateUserInfoUrl,
  29. method: 'POST',
  30. data: {
  31. id: wx.getStorageSync('we_chat_user_id'),
  32. iv: e.detail.iv,
  33. encryptedData: e.detail.encryptedData
  34. },
  35. success: info => {
  36. console.log(info)
  37. if (info.data.status == 'success') {
  38. wx.setStorageSync('we_chat_user', info.data.data);
  39. wx.redirectTo({
  40. url: '/pages/bind-phone/index',
  41. })
  42. }
  43. },
  44. complete: res => {
  45. wx.hideLoading()
  46. }
  47. });
  48. }
  49. },
  50. /**
  51. * 生命周期函数--监听页面初次渲染完成
  52. */
  53. onReady: function () {
  54. },
  55. /**
  56. * 生命周期函数--监听页面显示
  57. */
  58. onShow: function () {
  59. },
  60. /**
  61. * 生命周期函数--监听页面隐藏
  62. */
  63. onHide: function () {
  64. },
  65. /**
  66. * 生命周期函数--监听页面卸载
  67. */
  68. onUnload: function () {
  69. },
  70. /**
  71. * 页面相关事件处理函数--监听用户下拉动作
  72. */
  73. onPullDownRefresh: function () {
  74. },
  75. /**
  76. * 页面上拉触底事件的处理函数
  77. */
  78. onReachBottom: function () {
  79. },
  80. /**
  81. * 用户点击右上角分享
  82. */
  83. onShareAppMessage: function () {
  84. }
  85. })