auth.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. // console.log(e.detail.errMsg)
  27. // console.log(e.detail.iv)
  28. // console.log(e.detail.encryptedData)
  29. this.phone_encryptedData = e.detail.encryptedData
  30. this.phone_iv = e.detail.iv
  31. this.wxauthen(this.userInfoE)
  32. },
  33. userInfoHandler(e)
  34. {
  35. if (e.detail.errMsg == "getUserInfo:ok")
  36. {
  37. app.globalData.userInfo = e.detail.userInfo;
  38. app.globalData.userInfo.nickname = e.detail.userInfo.nickName;
  39. this.userInfoE = e
  40. this.wxauthen(e)
  41. }
  42. },
  43. wxauthen: function (eInfo) {
  44. let userInfo = eInfo.detail.userInfo;
  45. if (app.globalData.userId.unionid) {
  46. userInfo = Object.assign({}, app.globalData.userId, app.globalData.userInfo);
  47. }
  48. else {
  49. let { encryptedData, iv, signature } = e.detail
  50. userInfo = Object.assign({}, { encryptedData }, { signature }, { iv }, userInfo)
  51. }
  52. let phoneInfo = { iv: this.phone_iv, encryptedData: this.phone_encryptedData }
  53. let params = {
  54. user_info: userInfo,
  55. phone_info: phoneInfo,
  56. act: "login",
  57. op: "wxauthen"
  58. }
  59. let self = this;
  60. getReq(app,params, function (res) {
  61. if (res.code == 200) {
  62. let datas = res.datas;
  63. app.member_id = datas.member_id
  64. if (datas.hasmobile == false) {
  65. self.setData({showAuthName:false,showAuthPhone:true})
  66. }
  67. else {
  68. self.triggerEvent('getAuth', {
  69. userInfo
  70. })
  71. }
  72. }
  73. else {
  74. app.relogin();
  75. wx.showToast({
  76. icon: 'none',
  77. title: '登陆遇到一点麻烦,请重试~~~',
  78. duration: 2000
  79. })
  80. }
  81. })
  82. }
  83. }
  84. })