app.js 4.7 KB

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