login.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. // pages/login/login.js
  2. const app = getApp();
  3. const api = app.api;
  4. import regeneratorRuntime from '../../utils/runtime'
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. showPopPhone:false,
  11. wxPhoneEncrypted:null,
  12. wxUserEncrypted:null
  13. },
  14. /**
  15. * 生命周期函数--监听页面加载
  16. */
  17. onLoad: function (options) {
  18. wx.removeStorageSync('loginInfo');
  19. },
  20. /**
  21. * 生命周期函数--监听页面初次渲染完成
  22. */
  23. onReady: function () {
  24. },
  25. async bindGetUserInfo(e) {
  26. const userInfo = await app.getToken();
  27. this.setData({
  28. showPopPhone:true
  29. })
  30. },
  31. closePhonePop(){
  32. this.setData({
  33. showPopPhone:false
  34. });
  35. },
  36. getPhoneNumber(e){
  37. console.log(e);
  38. const that = this;
  39. that.setData({
  40. wxPhoneEncrypted:{
  41. encryptedData: e.detail.encryptedData,
  42. ivStr: e.detail.iv
  43. }
  44. });
  45. wx.getUserInfo({
  46. success: function (res) {
  47. console.log('用户信息',res)
  48. const {encryptedData,iv} =res
  49. that.setData({
  50. wxUserEncrypted:{
  51. encryptedData,
  52. ivStr:iv
  53. }
  54. },()=>{
  55. that.saveData();
  56. });
  57. }
  58. });
  59. },
  60. async saveData(){
  61. const {wxUserEncrypted,wxPhoneEncrypted}=this.data;
  62. const userInfo = await app.getToken();
  63. app.post(api.updateWxUserInfo,{
  64. wxUserEncrypted,
  65. wxPhoneEncrypted
  66. },{needToken:false}).then(res=>{
  67. console.log('注册状态',res)
  68. wx.showToast({
  69. title:"注册成功",
  70. duration:2000,
  71. icon:"none"
  72. });
  73. wx.removeStorageSync('loginInfo')
  74. wx.navigateBack();
  75. });
  76. },
  77. bindBack: function(){
  78. wx.navigateBack();
  79. },
  80. /**
  81. * 生命周期函数--监听页面显示
  82. */
  83. onShow: function () {
  84. },
  85. /**
  86. * 生命周期函数--监听页面隐藏
  87. */
  88. onHide: function () {
  89. },
  90. /**
  91. * 生命周期函数--监听页面卸载
  92. */
  93. onUnload: function () {
  94. },
  95. /**
  96. * 页面相关事件处理函数--监听用户下拉动作
  97. */
  98. onPullDownRefresh: function () {
  99. },
  100. /**
  101. * 页面上拉触底事件的处理函数
  102. */
  103. onReachBottom: function () {
  104. }
  105. })