C端小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

100 line
2.5 KiB

  1. let config = require('./config/config.js')
  2. const Http = require("./utils/HttpBasics");
  3. App({
  4. data: {},
  5. onLaunch: function(options) {
  6. var that = this;
  7. this.globalData.sceneAddress = options.scene;
  8. this.getLocation()
  9. this.getUserInfo()
  10. // 登录
  11. wx.login({
  12. success: ({
  13. code
  14. }) => {
  15. Http.post({
  16. url: config.api.login,
  17. data: {
  18. appId: config.weapp.AppId,
  19. code: code,
  20. sceneAddress: this.globalData.sceneAddress,
  21. }
  22. }).then(res => {
  23. // console.log("req",res);
  24. this.globalData.token = res.data.token;
  25. Http.setToken(res.data.token)
  26. if (that.couponChannelListCallback) {
  27. that.couponChannelListCallback(res.data.token);
  28. }
  29. if (that.couponListCallback) {
  30. that.couponListCallback(res.data.token);
  31. }
  32. return Http.post({
  33. url: config.api.checkUserStatus,
  34. data: {}
  35. })
  36. }).then(res => {
  37. }).catch(err => {
  38. console.log(err)
  39. if (err.code == 11004) {
  40. // 用户昵称未授权
  41. wx.redirectTo({
  42. url: '../getuserinfo/index',
  43. })
  44. }
  45. })
  46. }
  47. })
  48. },
  49. /**
  50. * 获取地址位置信息
  51. */
  52. getLocation: function() {
  53. wx.getLocation({
  54. type: 'wgs84',
  55. success: function(res) {
  56. console.log("getLocation", res);
  57. },
  58. fail: error => {
  59. console.log(error);
  60. }
  61. })
  62. },
  63. /**
  64. * 获取用户信息
  65. */
  66. getUserInfo: function() {
  67. // 获取用户信息
  68. wx.getSetting({
  69. success: res => {
  70. if (res.authSetting['scope.userInfo']) {
  71. // 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
  72. wx.getUserInfo({
  73. success: res => {
  74. // 可以将 res 发送给后台解码出 unionId
  75. this.globalData.userInfo = res.userInfo
  76. // 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
  77. // 所以此处加入 callback 以防止这种情况
  78. if (this.userInfoReadyCallback) {
  79. this.userInfoReadyCallback(res)
  80. }
  81. }
  82. })
  83. }
  84. }
  85. })
  86. },
  87. globalData: {
  88. // token
  89. token: null,
  90. // 渠道
  91. sceneAddress: null,
  92. // 二维码参数
  93. scene: null,
  94. // 当前商场信息
  95. market: {
  96. name: "陕西大悦城"
  97. }
  98. }
  99. })