wxbutton.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. app.globalData.userInfo = e.detail.userInfo;
  31. app.globalData.userInfo.nickname = e.detail.userInfo.nickName;
  32. this.wxauthen(e)
  33. }
  34. },
  35. wxauthen: function (eInfo) {
  36. let userInfo;
  37. if (app.globalData.userId.unionid) {
  38. userInfo = Object.assign({}, app.globalData.userId, app.globalData.userInfo);
  39. }
  40. else {
  41. userInfo = eInfo.detail.userInfo;
  42. let { encryptedData, iv, signature } = eInfo.detail
  43. userInfo = Object.assign({}, { encryptedData }, { signature }, { iv }, userInfo)
  44. }
  45. let params = {
  46. user_info: userInfo,
  47. act: "login",
  48. op: "wxauthen",
  49. relay_id: app.globalData.relay_id,
  50. channel: app.globalData.channel_num
  51. }
  52. let self = this;
  53. getReq(app, params, function (res) {
  54. if (res.code == 200) {
  55. let datas = res.datas;
  56. app.globalData.member_id = datas.member_id
  57. app.globalData.hasmobile = datas.hasmobile
  58. }
  59. app.navigateto("pages/home/home")
  60. })
  61. }
  62. }
  63. })