login.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. // pages/login/login.js
  2. import {
  3. getOpenidSessionKey
  4. } from '../../utils/httpUtil';
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. index: undefined,
  11. canIUseGetUserProfile: false
  12. },
  13. /**
  14. * 生命周期函数--监听页面加载
  15. */
  16. onLoad: function (options) {
  17. if (options.index) {
  18. this.setData({
  19. index: options.index
  20. })
  21. }
  22. if (wx.getUserProfile) {
  23. this.setData({
  24. canIUseGetUserProfile: true
  25. })
  26. }
  27. },
  28. getUserProfile: function (e) {
  29. wx.getUserProfile({
  30. desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
  31. success: (res) => {
  32. console.log('getUserProfile',res);
  33. getOpenidSessionKey((res) => {
  34. console.log('getUserProfilegetUserProfile',res)
  35. wx.showToast({
  36. title: '登录成功',
  37. icon: 'fail',
  38. duration: 1000,
  39. success: () => {
  40. const pages = getCurrentPages();
  41. const prevPage = pages[pages.length - 2];
  42. prevPage.setData({
  43. fromLoginIndex: this.data.index, // 有id就塞到第一位
  44. }, () => {
  45. wx.navigateBack({
  46. delta: 1
  47. })
  48. })
  49. }
  50. })
  51. }, (error) => {
  52. wx.showToast({
  53. title: '登录失败',
  54. icon: 'fail',
  55. duration: 1000,
  56. success: () => {
  57. wx.navigateBack()
  58. }
  59. })
  60. });
  61. }
  62. })
  63. },
  64. impower: function (e) {
  65. console.log(e)
  66. var myEventDetail = {} // detail对象,提供给事件监听函数
  67. var myEventOption = {} // 触发事件的选项
  68. getOpenidSessionKey((res) => {
  69. console.log(res)
  70. wx.showToast({
  71. title: '登录成功',
  72. icon: 'fail',
  73. duration: 1000,
  74. success: () => {
  75. const pages = getCurrentPages();
  76. const prevPage = pages[pages.length - 2];
  77. prevPage.setData({
  78. fromLoginIndex: this.data.index, // 有id就塞到第一位
  79. }, () => {
  80. wx.navigateBack({
  81. delta: 1
  82. })
  83. })
  84. }
  85. })
  86. }, (error) => {
  87. wx.showToast({
  88. title: '登录失败',
  89. icon: 'fail',
  90. duration: 1000,
  91. success: () => {
  92. wx.navigateBack()
  93. }
  94. })
  95. });
  96. },
  97. touchMove: function () {
  98. return false
  99. },
  100. /**
  101. * 生命周期函数--监听页面初次渲染完成
  102. */
  103. onReady: function () {
  104. },
  105. /**
  106. * 生命周期函数--监听页面显示
  107. */
  108. onShow: function () {
  109. },
  110. /**
  111. * 生命周期函数--监听页面隐藏
  112. */
  113. onHide: function () {
  114. },
  115. /**
  116. * 生命周期函数--监听页面卸载
  117. */
  118. onUnload: function () {
  119. },
  120. /**
  121. * 页面相关事件处理函数--监听用户下拉动作
  122. */
  123. onPullDownRefresh: function () {
  124. },
  125. /**
  126. * 页面上拉触底事件的处理函数
  127. */
  128. onReachBottom: function () {
  129. },
  130. /**
  131. * 用户点击右上角分享
  132. */
  133. onShareAppMessage: function () {
  134. }
  135. })