app.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. var http = require("/utils/config.js");
  2. import touch from '/utils/touch.js'//新加
  3. App({
  4. onLaunch: function () {
  5. // 登录
  6. // console.log(http)
  7. var that = this;
  8. wx.getSystemInfo({
  9. success: res => {
  10. // console.log(res.safeArea.bottom)
  11. console.log('手机信息res' + res.model)
  12. if (res.model == 'iPhone X' || res.model == 'iPhone XR' || res.model == 'iPhone XS Max') {
  13. that.globalData.screenHeight = 'xSeries'
  14. } else if (res.safeArea.bottom >= 750) {
  15. that.globalData.screenHeight = 'xSeries'
  16. }
  17. }
  18. })
  19. if (wx.canIUse('getUpdateManager')) {
  20. const updateManager = wx.getUpdateManager()
  21. updateManager.onCheckForUpdate(function (res) {
  22. if (res.hasUpdate) {
  23. updateManager.onUpdateReady(function () {
  24. wx.showModal({
  25. title: '更新提示',
  26. content: '新版本已经准备好,是否重启应用?',
  27. success: function (res) {
  28. if (res.confirm) {
  29. updateManager.applyUpdate()
  30. }
  31. }
  32. })
  33. })
  34. updateManager.onUpdateFailed(function () {
  35. wx.showModal({
  36. title: '已经有新版本了哟~',
  37. content: '新版本已经上线啦~,请您删除当前小程序,重新搜索打开哟~'
  38. })
  39. })
  40. }
  41. })
  42. } else {
  43. wx.showModal({
  44. title: '提示',
  45. content: '当前微信版本过低,无法使用该功能,请升级到最新微信版本后重试。'
  46. })
  47. }
  48. if (wx.getStorageSync('token')) {
  49. }
  50. },
  51. globalData: {
  52. statusBarHeight: wx.getSystemInfoSync()['statusBarHeight'],
  53. windowHeight: wx.getSystemInfoSync()['windowHeight'],
  54. localUrl: http.url,
  55. screenHeight: '',
  56. login: false,
  57. swichChecked:false,
  58. userInfo: null
  59. },
  60. touch: new touch(), //实例化这个touch对象
  61. request(api, params, method) {
  62. var that = this;
  63. if (true) {
  64. return new Promise((resolve, reject) => {
  65. wx.request({
  66. url: this.globalData.localUrl + api,
  67. data: params,
  68. header: {
  69. 'content-type': 'application/x-www-form-urlencoded',
  70. 'Authorization': 'bearer' + ' ' + wx.getStorageSync('token'),
  71. },
  72. method: method,
  73. success: (res) => {
  74. resolve(res)
  75. // console.log(res)
  76. if (res.statusCode == 450) {
  77. return;
  78. }
  79. if (res.data.statusCode != 200) {
  80. if (res.data.message == '订单不存在或订单已结算') {
  81. wx.redirectTo({
  82. url: '/pages/index/index',
  83. })
  84. return false;
  85. } else if (res.data.message == '运动中不能关锁') {
  86. return false;
  87. }
  88. if (res.message != undefined) {
  89. wx.showToast({
  90. title: res.message,
  91. icon: 'none',
  92. duration: 3000,
  93. mask: true
  94. })
  95. } else if (res.data.message != undefined) {
  96. wx.showToast({
  97. title: res.data.message,
  98. icon: 'none',
  99. duration: 3000,
  100. mask: true
  101. })
  102. }
  103. } else if (res.statusCode != 200) {
  104. if (res.data.message == '订单不存在或订单已结算') {
  105. wx.redirectTo({
  106. url: '/pages/index/index',
  107. })
  108. return false;
  109. } else if (res.data.message == '运动中不能关锁') {
  110. return false;
  111. }
  112. if (res.message != undefined) {
  113. wx.showToast({
  114. title: res.message,
  115. icon: 'none',
  116. duration: 3000,
  117. mask: true
  118. })
  119. } else if (res.data.message != undefined) {
  120. wx.showToast({
  121. title: res.data.message,
  122. icon: 'none',
  123. duration: 3000,
  124. mask: true
  125. })
  126. }
  127. }
  128. if (res.statusCode == 401) {
  129. wx.removeStorageSync('token')
  130. wx.showToast({
  131. title: '登陆过期请重新登陆~',
  132. icon: 'none',
  133. mask: true,
  134. success: function () {
  135. wx.redirectTo({
  136. url: '../login/login',
  137. })
  138. }
  139. })
  140. }
  141. },
  142. fail: (err) => {
  143. wx.showToast({
  144. title: err,
  145. icon: 'none',
  146. mask: true
  147. });
  148. reject("请求失败")
  149. }
  150. })
  151. })
  152. }
  153. },
  154. })