C端小程序
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

143 řádky
3.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. 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. that.globalData.parkVendor = res.data.parkVendor
  120. if (res.data.token != "undefined") {
  121. that.globalData.etcpToken = res.data.token
  122. }
  123. })
  124. },
  125. globalData: {
  126. // token
  127. token: null,
  128. // 渠道
  129. sceneAddress: null,
  130. // 二维码参数
  131. scene: null,
  132. // 支持智慧停车, 用户名下有车
  133. phone: null,
  134. supportCar: false,
  135. parkVendor: 1, // 1: ETCP, 2: TJD
  136. // ETCP token
  137. etcpToken: null,
  138. // 当前商场信息
  139. market: {
  140. name: "陕西大悦城"
  141. }
  142. }
  143. })