auth.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. },
  16. /**
  17. * 组件的方法列表
  18. */
  19. methods: {
  20. userInfoHandler(e) {
  21. let self = this
  22. if (e.detail.errMsg == "getUserInfo:ok") {
  23. app.globalData.userInfo = e.detail.userInfo;
  24. app.globalData.userInfo.nickname = e.detail.userInfo.nickName;
  25. let userInfo = app.globalData.userInfo;
  26. if (app.globalData.userId.unionid) {
  27. userInfo = Object.assign({}, app.globalData.userId, app.globalData.userInfo);
  28. }
  29. else {
  30. let { encryptedData, iv, signature } = e.detail
  31. userInfo = Object.assign({}, { encryptedData }, { signature }, { iv }, userInfo)
  32. }
  33. let params = {
  34. user_info: userInfo,
  35. act: "login",
  36. op: "wxauthen"
  37. }
  38. getReq(params, function (res) {
  39. if (res.code == 200) {
  40. self.triggerEvent('getAuth', {
  41. userInfo
  42. })
  43. }
  44. else {
  45. wx.showToast({
  46. icon: 'none',
  47. title: '登陆失败',
  48. duration: 2000
  49. })
  50. }
  51. })
  52. }
  53. }
  54. }
  55. })