wxbutton.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. // pages/components/wxbutton/wxbutton.js
  2. const api = require('../../../config');
  3. const getReq = require('../../../config').getReq;
  4. const ald = require('../../../utils/ald-stat.js')
  5. let app = getApp();
  6. Component({
  7. /**
  8. * 组件的属性列表
  9. */
  10. properties: {
  11. item_data: {
  12. type: Object
  13. }
  14. },
  15. /**
  16. * 组件的初始数据
  17. */
  18. data: {
  19. },
  20. created() {
  21. console.log(this.properties.item_data);
  22. },
  23. /**
  24. * 组件的方法列表
  25. */
  26. methods: {
  27. onGetUserInfo(e) {
  28. console.log('onGetUserInfo');
  29. if (e.detail.errMsg == "getUserInfo:ok") {
  30. wx.showLoading({title: '加载中'});
  31. app.globalData.userInfo = e.detail.userInfo;
  32. app.globalData.userInfo.nickname = e.detail.userInfo.nickName;
  33. this.wxauthen(e)
  34. }
  35. },
  36. wxauthen: function (eInfo) {
  37. let userInfo;
  38. if (app.globalData.userId.unionid) {
  39. userInfo = Object.assign({}, app.globalData.userId, app.globalData.userInfo);
  40. } else {
  41. userInfo = eInfo.detail.userInfo;
  42. let {
  43. encryptedData,
  44. iv,
  45. signature
  46. } = eInfo.detail
  47. userInfo = Object.assign({}, {
  48. encryptedData
  49. }, {
  50. signature
  51. }, {
  52. iv
  53. }, userInfo)
  54. }
  55. let params = {
  56. user_info: userInfo,
  57. act: "login",
  58. op: "wxauthen",
  59. relay_id: app.globalData.relay_id,
  60. channel: app.globalData.channel_num
  61. }
  62. let self = this;
  63. getReq(app, params, function (res) {
  64. if (res.code == 200) {
  65. let datas = res.datas;
  66. app.globalData.member_id = datas.member_id
  67. app.globalData.hasmobile = datas.hasmobile
  68. }
  69. self.triggerEvent('wxButtonEvent', { event_type: 'getUserInfo', authen: 'success' });
  70. wx.hideLoading()
  71. })
  72. }
  73. }
  74. })