app.js 5.6 KB

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