app.js 4.4 KB

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