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.

97 rivejä
2.3 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. Http.get({
  26. url: config.api.checkUserStatus,
  27. data: { }
  28. }).then(statusres => {
  29. if (statusres.code == 11004) {
  30. // 用户昵称未授权
  31. wx.redirectTo({
  32. url: '../getuserinfo/index',
  33. })
  34. }
  35. })
  36. })
  37. }
  38. })
  39. // setTimeout(() => {
  40. // this.globalData.market={
  41. // name:"陕西大悦城"
  42. // }
  43. // }, 1000);
  44. },
  45. /**
  46. * 获取地址位置信息
  47. */
  48. getLocation: function () {
  49. wx.getLocation({
  50. type: 'wgs84',
  51. success: function (res) {
  52. console.log("getLocation", res);
  53. },
  54. fail: error => {
  55. console.log(error);
  56. }
  57. })
  58. },
  59. /**
  60. * 获取用户信息
  61. */
  62. getUserInfo: function () {
  63. // 获取用户信息
  64. wx.getSetting({
  65. success: res => {
  66. if (res.authSetting['scope.userInfo']) {
  67. // 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
  68. wx.getUserInfo({
  69. success: res => {
  70. // 可以将 res 发送给后台解码出 unionId
  71. this.globalData.userInfo = res.userInfo
  72. // 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
  73. // 所以此处加入 callback 以防止这种情况
  74. if (this.userInfoReadyCallback) {
  75. this.userInfoReadyCallback(res)
  76. }
  77. }
  78. })
  79. }
  80. }
  81. })
  82. },
  83. globalData: {
  84. // token
  85. token: null,
  86. // 渠道
  87. sceneAddress: null,
  88. // 二维码参数
  89. scene: null,
  90. // 当前商场信息
  91. market: {
  92. name: "陕西大悦城"
  93. }
  94. }
  95. })