auth.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. // pages/components/auth/auth.js
  2. const api = require('../../../config');
  3. const getReq = require('../../../config').getReq;
  4. let app = getApp();
  5. Component({
  6. /**
  7. * 组件的属性列表
  8. */
  9. properties: {
  10. },
  11. /**
  12. * 组件的初始数据
  13. */
  14. data: {
  15. phone_iv: '',
  16. phone_encryptedData: '',
  17. showAuthName:true,
  18. showAuthPhone:false,
  19. userInfoE:{},
  20. },
  21. /**
  22. * 组件的方法列表
  23. */
  24. methods: {
  25. userPhoneHandler: function(e) {
  26. this.phone_encryptedData = e.detail.encryptedData
  27. this.phone_iv = e.detail.iv
  28. this.wxauthen(this.userInfoE)
  29. },
  30. userInfoHandler(e)
  31. {
  32. if (e.detail.errMsg == "getUserInfo:ok")
  33. {
  34. app.globalData.userInfo = e.detail.userInfo;
  35. app.globalData.userInfo.nickname = e.detail.userInfo.nickName;
  36. this.userInfoE = e
  37. this.wxauthen(e)
  38. }
  39. },
  40. wxauthen: function (eInfo) {
  41. let userInfo = eInfo.detail.userInfo;
  42. if (app.globalData.userId.unionid) {
  43. userInfo = Object.assign({}, app.globalData.userId, app.globalData.userInfo);
  44. }
  45. else {
  46. let { encryptedData, iv, signature } = eInfo.detail
  47. userInfo = Object.assign({}, { encryptedData }, { signature }, { iv }, userInfo)
  48. }
  49. let phoneInfo = { iv: this.phone_iv, encryptedData: this.phone_encryptedData }
  50. let params = {
  51. user_info: userInfo,
  52. phone_info: phoneInfo,
  53. act: "login",
  54. op: "wxauthen",
  55. relay_id: app.globalData.relay_id
  56. }
  57. let self = this;
  58. getReq(app,params, function (res) {
  59. if (res.code == 200) {
  60. let datas = res.datas;
  61. app.member_id = datas.member_id
  62. if (datas.hasmobile == false) {
  63. self.setData({showAuthName:false,showAuthPhone:true})
  64. }
  65. else {
  66. self.triggerEvent('getAuth', {
  67. userInfo
  68. })
  69. }
  70. }
  71. else {
  72. app.relogin();
  73. wx.showToast({
  74. icon: 'none',
  75. title: '登陆遇到一点麻烦,请重试~~~',
  76. duration: 2000
  77. })
  78. }
  79. })
  80. }
  81. }
  82. })