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.

96 line
2.3 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. Http.post({
  27. url: config.api.checkUserStatus,
  28. data: {} //
  29. }).then(
  30. function(res) {
  31. },
  32. function(error) {
  33. console.log(error)
  34. if (error.code == 11004) {
  35. // 用户昵称未授权
  36. wx.redirectTo({
  37. url: '../getuserinfo/index',
  38. })
  39. }
  40. })
  41. })
  42. }
  43. })
  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. })