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.

102 line
2.6 KiB

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