C端小程序
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

141 行
3.2 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. that.globalData.sceneAddress = options.scene;
  8. that.getLocation()
  9. that.userLogin()
  10. },
  11. /**
  12. * 获取地址位置信息
  13. */
  14. getLocation: function() {
  15. wx.getLocation({
  16. type: 'wgs84',
  17. success: function(res) {
  18. console.log("getLocation", res);
  19. },
  20. fail: error => {
  21. console.log(error);
  22. }
  23. })
  24. },
  25. /**
  26. * 用户登录
  27. */
  28. userLogin: function() {
  29. var that = this;
  30. // 登录
  31. wx.login({
  32. success: ({
  33. code
  34. }) => {
  35. Http.post({
  36. url: config.api.login,
  37. data: {
  38. appId: config.weapp.AppId,
  39. code: code,
  40. sceneAddress: that.globalData.sceneAddress,
  41. }
  42. }).then(res => {
  43. console.log("req", res);
  44. that.globalData.token = res.data.token;
  45. Http.setToken(res.data.token)
  46. that.checkUserCarStatus()
  47. that.getUserInfo()
  48. if (that.couponChannelListCallback) {
  49. that.couponChannelListCallback(that.globalData.token);
  50. }
  51. if (that.couponListCallback) {
  52. that.couponListCallback(that.globalData.token);
  53. }
  54. return Http.post({
  55. url: config.api.checkUserStatus,
  56. data: {}
  57. })
  58. }).then(res => {}).catch(err => {
  59. console.log(err)
  60. if (err.code == 11004) {
  61. // 用户昵称未授权
  62. wx.redirectTo({
  63. url: '../getuserinfo/index',
  64. })
  65. }
  66. })
  67. }
  68. })
  69. },
  70. /**
  71. * 获取用户信息
  72. */
  73. getUserInfo: function() {
  74. // 获取用户信息
  75. wx.getSetting({
  76. success: res => {
  77. console.log('getSetting', res)
  78. if (res.authSetting['scope.userInfo']) {
  79. // 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
  80. wx.getUserInfo({
  81. success: res => {
  82. // 可以将 res 发送给后台解码出 unionId
  83. console.log('getUserInfo', res)
  84. }
  85. })
  86. }
  87. }
  88. })
  89. },
  90. /**
  91. * 检查用户是否有车
  92. */
  93. checkUserCarStatus: function() {
  94. var that = this
  95. Http.get({
  96. url: config.api.userCarCount,
  97. data: {}
  98. }).then(res => {
  99. if (res.data > 0) {
  100. // 用户名下有车
  101. that.globalData.phone = res.data.phone
  102. that.globalData.supportCar = true
  103. // 共同登录
  104. }
  105. })
  106. },
  107. /**
  108. * car共同登录
  109. */
  110. userCarLogin: function() {
  111. var that = this
  112. // 共同登录
  113. Http.post({
  114. url: config.api.carInit,
  115. data: {
  116. phone: this.globalData.phone
  117. }
  118. }).then(res => {
  119. if (res.data.token != "undefined") {
  120. that.globalData.etcpToken = res.data.token
  121. }
  122. })
  123. },
  124. globalData: {
  125. // token
  126. token: null,
  127. // 渠道
  128. sceneAddress: null,
  129. // 二维码参数
  130. scene: null,
  131. // 支持智慧停车, 用户名下有车
  132. phone: null,
  133. supportCar: false,
  134. // ETCP token
  135. etcpToken: null,
  136. // 当前商场信息
  137. market: {
  138. name: "陕西大悦城"
  139. }
  140. }
  141. })