app.js 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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. var time = wx.getStorageSync('token_time');
  37. var timestamp = Date.parse(new Date());
  38. if (time <= timestamp / 1000) {
  39. console.log('token过期')
  40. wx.removeStorageSync('token_time')
  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. },
  72. globalData: {
  73. statusBarHeight: wx.getSystemInfoSync()['statusBarHeight'],
  74. windowHeight: wx.getSystemInfoSync()['windowHeight'],
  75. imgUrl: 'http://resource.bike.hanyiyun.com/',
  76. screenHeight: '',
  77. login: false,
  78. platform: '',
  79. version: '',
  80. req: true,
  81. id: 0,
  82. times: 60,
  83. invalid: false,
  84. compatible: '',
  85. title: '闪现出行', //全局修改此小程序名称
  86. logoUrl: '/img/shanxianLg.png', //logo图片路径 网络图片/本地图片 dejin.png shanxianLg.png yuzhouLg.png
  87. appid: 'wxd47b0ef6600fbe24', //小程序的appid
  88. merchant_id: 1,
  89. // url : 'http://api.weikemu.dev.hanyiyun.com/api', //威科姆测试域名
  90. // url : 'https://api.xiaobaichuxing.hanyiyun.com/api', //小白出行域名sa
  91. // url: 'https://api.bike.hanyiyun.com/api', //闪现出行域名
  92. // url : 'https://api.weilai.hanyiyun.com/api', //太比特测试域名
  93. // url : 'https://api.weilaibike.com/api', //线上域名
  94. url: 'https://api.bike.saas.yufengjiayun.com/api', //商户端域名
  95. // url:'http://dev.api.saas.yufengjiayun.com/api',//测试域名
  96. // url:'https://api.dev.saas.yufengjiayun.com/api',//支付宝测试域名
  97. 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
  98. },
  99. request(api, params, method, req1) {
  100. var that = this;
  101. if (req1 == false) return;
  102. if (req1) {
  103. that.globalData.req = false;
  104. }
  105. if (wx.getStorageSync('token') != '' || wx.getStorageSync('token') != undefined) {
  106. if (req1 == true || req1 == undefined) {
  107. return new Promise((resolve, reject) => {
  108. wx.request({
  109. url: this.globalData.url + api,
  110. data: params,
  111. header: {
  112. 'content-type': 'application/x-www-form-urlencoded',
  113. 'Cache-Control': 'no-cache',
  114. 'Authorization': wx.getStorageSync('token'),
  115. 'merchant-id': this.globalData.merchant_id
  116. },
  117. method: method,
  118. success: (res) => {
  119. resolve(res)
  120. // console.log(res)
  121. if (res.statusCode == 450) {
  122. return;
  123. }
  124. if (res.data.statusCode != 200 ) {
  125. if (res.data.message == '订单不存在或订单已结算') {
  126. if (this.globalData.compatible) {
  127. wx.reLaunch({
  128. url: '/pages/compatible/index/index',
  129. })
  130. } else {
  131. wx.reLaunch({
  132. url: '/pages/index/index',
  133. })
  134. }
  135. return false;
  136. } else if (res.data.message == '运动中不能关锁') {
  137. return false;
  138. }
  139. if (res.message != undefined) {
  140. wx.showToast({
  141. title: res.message,
  142. icon: 'none',
  143. duration: 3000,
  144. mask: true
  145. })
  146. } else if (res.data.message != undefined) {
  147. wx.showToast({
  148. title: res.data.message,
  149. icon: 'none',
  150. duration: 3000,
  151. mask: true
  152. })
  153. }
  154. } else if (res.statusCode != 200) {
  155. if (res.data.message == '订单不存在或订单已结算') {
  156. if (this.globalData.compatible) {
  157. wx.reLaunch({
  158. url: '/pages/compatible/index/index',
  159. })
  160. } else {
  161. wx.reLaunch({
  162. url: '/pages/index/index',
  163. })
  164. }
  165. return false;
  166. } else if (res.data.message == '运动中不能关锁') {
  167. return false;
  168. }
  169. if (res.message != undefined) {
  170. wx.showToast({
  171. title: res.message,
  172. icon: 'none',
  173. duration: 3000,
  174. mask: true
  175. })
  176. } else if (res.data.message != undefined) {
  177. wx.showToast({
  178. title: res.data.message,
  179. icon: 'none',
  180. duration: 3000,
  181. mask: true
  182. })
  183. }
  184. }
  185. if (res.statusCode == 401) {
  186. var timeout;
  187. wx.removeStorageSync('token')
  188. wx.removeStorageSync('token_time')
  189. that.globalData.invalid = true
  190. console.log(that.globalData.login)
  191. if (that.globalData.login) {
  192. return false;
  193. }
  194. if (that.globalData.login == false) {
  195. that.globalData.login = true
  196. wx.showToast({
  197. title: '登陆过期请重新登陆~',
  198. icon: 'none',
  199. duration: 1000,
  200. mask: true,
  201. success: function () {
  202. wx.reLaunch({
  203. url: '/pages/authentication/authentication',
  204. })
  205. }
  206. })
  207. timeout = setTimeout(function () {
  208. that.globalData.login = false
  209. if (that.globalData.login == false) {
  210. clearTimeout(timeout)
  211. }
  212. }, 3000)
  213. }
  214. } else if (res.statusCode == 404) {
  215. wx.navigateTo({
  216. url: '/pages/undefind/undefind',
  217. })
  218. }
  219. },
  220. fail: (err) => {
  221. wx.showToast({
  222. title: err,
  223. icon: 'none',
  224. mask: true
  225. });
  226. reject("请求失败")
  227. },
  228. complete: () => {
  229. that.globalData.req = true
  230. }
  231. })
  232. })
  233. }
  234. }
  235. },
  236. })