Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

104 righe
2.3 KiB

  1. // pages/getuserinfo/index.js
  2. const config = require('../../config/config.js')
  3. const Http = require('../../utils/http.js')
  4. const HttpBasics = require('../../utils/HttpBasics.js')
  5. const Common = require('../../common/common.js')
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. canIUse: wx.canIUse("button.open-type.getPhoneNumber"),
  12. openId: '',
  13. session_key: '',
  14. backToLogin: false
  15. },
  16. /**
  17. * 生命周期函数--监听页面加载
  18. */
  19. onLoad: function (options) {
  20. var that = this;
  21. var openId = wx.getStorageSync("openId");
  22. var session_key = wx.getStorageSync("session_key");
  23. if (openId) {
  24. that.setData({
  25. openId: openId
  26. });
  27. }
  28. if (options.path == 'login') {
  29. that.setData({
  30. backToLogin: true
  31. });
  32. console.log(that.data.backToLogin, 'backToLogin');
  33. }
  34. if (session_key) {
  35. that.setData({
  36. session_key: session_key
  37. });
  38. }
  39. Common.getMallIcon()
  40. .then(data => {
  41. this.setData({
  42. logo: data.data.mallImgUrl ? data.data.mallImgUrl : '../../static/images/logo.png'
  43. })
  44. })
  45. },
  46. backHome: function () {
  47. wx.redirectTo({
  48. url: '/pages/index/index'
  49. })
  50. },
  51. getPhoneNumber(e) {
  52. console.log(e)
  53. var that = this;
  54. var iv = e.detail.iv;
  55. var encryptedData = e.detail.encryptedData;
  56. const data = {
  57. encryptedData: encryptedData,
  58. iv: iv,
  59. openId: that.data.openId,
  60. appId: config.weapp.appId,
  61. session_key: that.data.session_key,
  62. }
  63. HttpBasics.post({
  64. url: config.api.getUserPhoneForBuser,
  65. data
  66. }).then(res => {
  67. console.log(res)
  68. if (that.data.backToLogin) {
  69. wx.showToast({
  70. title: '授权成功!请重新登录',
  71. icon: 'none',
  72. duration: 2000,
  73. });
  74. setTimeout(() => {
  75. wx.redirectTo({
  76. url: '/pages/index/index',
  77. })
  78. }, 2000);
  79. return
  80. }
  81. wx.switchTab({
  82. url: '/pages/main/main'
  83. })
  84. wx.showToast({
  85. title: '授权成功!',
  86. icon: 'success',
  87. duration: 2000,
  88. mask: false
  89. });
  90. }).catch(err => {
  91. console.log(err, 'err');
  92. wx.showToast({
  93. title: err.message,
  94. icon: 'none',
  95. duration: 5000
  96. });
  97. })
  98. }
  99. })