auth.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // pages/components/auth/auth.js
  2. const api = require('../../../config');
  3. let app = getApp();
  4. Component({
  5. /**
  6. * 组件的属性列表
  7. */
  8. properties: {
  9. },
  10. /**
  11. * 组件的初始数据
  12. */
  13. data: {
  14. },
  15. /**
  16. * 组件的方法列表
  17. */
  18. methods: {
  19. userInfoHandler(e) {
  20. let self = this
  21. if (e.detail.errMsg == "getUserInfo:ok") {
  22. app.globalData.userInfo = e.detail.userInfo;
  23. app.globalData.userInfo.nickname = e.detail.userInfo.nickName;
  24. let userInfo = Object.assign({}, app.globalData.userId, app.globalData.userInfo);
  25. wx.request({
  26. url: api.host,
  27. method: 'GET',
  28. data: {
  29. user_info: userInfo,
  30. act: "login",
  31. op: "wxauthen",
  32. client_type: "mini"
  33. },
  34. success: function (res) {
  35. wx.setStorageSync('session_id', res.data.datas.HPHPSESSID);
  36. if (res.statusCode == 200) {
  37. self.triggerEvent('getAuth', {
  38. userInfo
  39. })
  40. }
  41. else {
  42. wx.showToast({
  43. icon: 'none',
  44. title: '登陆失败',
  45. duration: 2000
  46. })
  47. }
  48. }
  49. })
  50. }
  51. }
  52. }
  53. })