app.js 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. App({
  2. onLaunch: function () {
  3. // 登录
  4. var that = this;
  5. wx.getSystemInfo({
  6. success: res => {
  7. console.log(res)
  8. var system = res.system.trim().split(/\s+/)[1];
  9. var intNumber = system.substring(0, system.indexOf("."));
  10. if (res.platform == 'ios' && intNumber < 13 || res.SDKVersion < '2.1.0') {
  11. console.log('低版本')
  12. that.globalData.compatible = true;
  13. wx.reLaunch({
  14. url: '/pages/compatible/index/index',
  15. })
  16. }
  17. that.globalData.platform = res.platform
  18. that.globalData.version = res.version
  19. console.log(res.safeArea.bottom)
  20. console.log('手机信息res' + res.model)
  21. if (res.model == 'iPhone X' || res.model == 'iPhone XR' || res.model == 'iPhone XS Max') {
  22. that.globalData.screenHeight = 'xSeries'
  23. } else if (res.safeArea.bottom >= 780) {
  24. that.globalData.screenHeight = 'xSeries'
  25. }
  26. }
  27. })
  28. if (wx.getStorageSync('midTimes') != '') {
  29. var time = wx.getStorageSync('midTimes');
  30. var timestamp = Date.parse(new Date()) / 1000;
  31. if (time <= timestamp) {
  32. console.log('midtimes过期')
  33. wx.setStorageSync('midTimes', '')
  34. }
  35. }
  36. if (wx.canIUse('getUpdateManager')) {
  37. const updateManager = wx.getUpdateManager()
  38. updateManager.onCheckForUpdate(function (res) {
  39. if (res.hasUpdate) {
  40. updateManager.onUpdateReady(function () {
  41. wx.showModal({
  42. title: '更新提示',
  43. content: '新版本已经准备好,是否重启应用?',
  44. success: function (res) {
  45. if (res.confirm) {
  46. updateManager.applyUpdate()
  47. }
  48. }
  49. })
  50. })
  51. updateManager.onUpdateFailed(function () {
  52. wx.showModal({
  53. title: '已经有新版本了哟~',
  54. content: '新版本已经上线啦~,请您删除当前小程序,重新搜索打开哟~'
  55. })
  56. })
  57. }
  58. })
  59. } else {
  60. wx.showModal({
  61. title: '提示',
  62. content: '当前微信版本过低,无法使用该功能,请升级到最新微信版本后重试。'
  63. })
  64. }
  65. },
  66. globalData: {
  67. statusBarHeight: wx.getSystemInfoSync()['statusBarHeight'],
  68. windowHeight: wx.getSystemInfoSync()['windowHeight'],
  69. imgUrl: 'http://resource.bike.hanyiyun.com/',
  70. screenHeight: '',
  71. login: false,
  72. platform: '',
  73. version: '',
  74. req: true,
  75. id: 0,
  76. times: 60,
  77. invalid: false,
  78. compatible: '',
  79. //闪现出行
  80. // title: '闪现出行', //全局修改此小程序名称
  81. // logoUrl: '/img/shanxianLg.png', //logo图片路径 网络图片/本地图片 dejin.png shanxianLg.png yuzhouLg.png dingding.png xuezi.png
  82. // appid: 'wxd47b0ef6600fbe24', //小程序的appid
  83. // merchant_id: 1, //商户ID
  84. // url: 'https://api.bike.saas.yufengjiayun.com/api', //叮叮出行
  85. // mapKey: 'C3YBZ-SLSKU-TYWVP-2NEUJ-JNDO3-KCFBH' //地图key值 德劲:PM2BZ-CS7L3-MPR35-3A5GW-HGW66-QLBXA ,闪现出行:C3YBZ-SLSKU-TYWVP-2NEUJ-JNDO3-KCFBH,禹州闪现出行 GTLBZ-F6BKO-5EDWH-SDHIX-K2ART-O2FRQ ,叮叮:IQYBZ-IKIW5-R6CII-QMV47-OAJJE-OAFBP ,学子:JQIBZ-RQTLX-7EL4B-T67UE-6PGKQ-FPFMD
  86. // 华智出行
  87. title: '华智出行', //全局修改此小程序名称
  88. logoUrl: '/img/huazhi.png', //logo图片路径 网络图片/本地图片 dejin.png shanxianLg.png yuzhouLg.png dingding.png xuezi.png
  89. appid: 'wxd60ff0c8471a5a0d', //小程序的appid
  90. merchant_id: 7, //商户ID
  91. url: 'https://api.bike.saas.yufengjiayun.com/api', //叮叮出行
  92. mapKey: 'C3YBZ-SLSKU-TYWVP-2NEUJ-JNDO3-KCFBH'
  93. // url : 'http://api.weikemu.dev.hanyiyun.com/api', //威科姆测试域名
  94. // url : 'https://api.xiaobaichuxing.hanyiyun.com/api', //小白出行域名sa
  95. // url: 'https://api.bike.hanyiyun.com/api', //闪现出行域名
  96. // url : 'https://api.weilai.hanyiyun.com/api', //太比特测试域名
  97. // url : 'https://api.weilaibike.com/api', //线上域名
  98. // url: 'https://api.bike.saas.yufengjiayun.com/api', //商户端域名
  99. // url:'http://dev.api.saas.yufengjiayun.com/api',//测试域名
  100. // url:'https://api.dev.saas.yufengjiayun.com/api',//支付宝测试域名
  101. },
  102. request(api, params, method, req1) {
  103. var that = this;
  104. if (req1 == false) return;
  105. if (req1) {
  106. that.globalData.req = false;
  107. }
  108. if (wx.getStorageSync('token') != '' || wx.getStorageSync('token') != undefined) {
  109. if (req1 == true || req1 == undefined) {
  110. return new Promise((resolve, reject) => {
  111. wx.request({
  112. url: this.globalData.url + api,
  113. data: params,
  114. header: {
  115. 'content-type': 'application/x-www-form-urlencoded',
  116. 'Cache-Control': 'no-cache',
  117. 'Authorization': wx.getStorageSync('token'),
  118. 'merchant-id': this.globalData.merchant_id
  119. },
  120. method: method,
  121. success: (res) => {
  122. resolve(res)
  123. // console.log(res)
  124. if (res.statusCode == 450) {
  125. return;
  126. }
  127. if (res.data.statusCode != 200) {
  128. if (res.data.message == '订单不存在或订单已结算') {
  129. if (this.globalData.compatible) {
  130. wx.reLaunch({
  131. url: '/pages/compatible/index/index',
  132. })
  133. } else {
  134. wx.reLaunch({
  135. url: '/pages/index/index',
  136. })
  137. }
  138. return false;
  139. } else if (res.data.message == '运动中不能关锁') {
  140. return false;
  141. }
  142. if (res.message != undefined) {
  143. wx.showToast({
  144. title: res.message,
  145. icon: 'none',
  146. duration: 3000,
  147. mask: true
  148. })
  149. } else if (res.data.message != undefined) {
  150. wx.showToast({
  151. title: res.data.message,
  152. icon: 'none',
  153. duration: 3000,
  154. mask: true
  155. })
  156. }
  157. } else if (res.statusCode != 200) {
  158. if (res.data.message == '订单不存在或订单已结算') {
  159. if (this.globalData.compatible) {
  160. wx.reLaunch({
  161. url: '/pages/compatible/index/index',
  162. })
  163. } else {
  164. wx.reLaunch({
  165. url: '/pages/index/index',
  166. })
  167. }
  168. return false;
  169. } else if (res.data.message == '运动中不能关锁') {
  170. return false;
  171. }
  172. if (res.message != undefined) {
  173. wx.showToast({
  174. title: res.message,
  175. icon: 'none',
  176. duration: 3000,
  177. mask: true
  178. })
  179. } else if (res.data.message != undefined) {
  180. wx.showToast({
  181. title: res.data.message,
  182. icon: 'none',
  183. duration: 3000,
  184. mask: true
  185. })
  186. }
  187. }
  188. if (res.statusCode == 401) {
  189. var timeout;
  190. wx.removeStorageSync('token')
  191. that.globalData.invalid = true
  192. console.log(that.globalData.login)
  193. if (that.globalData.login) {
  194. return false;
  195. }
  196. if (that.globalData.login == false) {
  197. that.globalData.login = true
  198. wx.showToast({
  199. title: '登陆过期请重新登陆~',
  200. icon: 'none',
  201. duration: 1000,
  202. mask: true,
  203. success: function () {
  204. wx.reLaunch({
  205. url: '/pages/authentication/authentication',
  206. })
  207. }
  208. })
  209. timeout = setTimeout(function () {
  210. that.globalData.login = false
  211. if (that.globalData.login == false) {
  212. clearTimeout(timeout)
  213. }
  214. }, 3000)
  215. }
  216. } else if (res.statusCode == 404) {
  217. wx.navigateTo({
  218. url: '/pages/undefind/undefind',
  219. })
  220. }
  221. },
  222. fail: (err) => {
  223. wx.showToast({
  224. title: err,
  225. icon: 'none',
  226. mask: true
  227. });
  228. reject("请求失败")
  229. },
  230. complete: () => {
  231. that.globalData.req = true
  232. }
  233. })
  234. })
  235. }
  236. }
  237. },
  238. })