app.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. //app.js
  2. App({
  3. onLaunch: function () {
  4. console.log(wx.getStorageSync("token"))
  5. if (wx.getStorageSync("token") == '' || wx.getStorageSync("token") == undefined) {
  6. wx.reLaunch({
  7. url: '/pages/login/index',
  8. })
  9. } else {
  10. wx.reLaunch({
  11. url: '/pages/guanlian/guanlian',
  12. })
  13. }
  14. },
  15. globalData: {
  16. userInfo: null,
  17. // url:'https://bike.hanyiyun.com/app-api/', //域名
  18. url:'https://bike.saas.yufengjiayun.com/app-api/',
  19. title:'闪现出行',//项目名称
  20. },
  21. request(api, params, method) {
  22. if (true) {
  23. return new Promise((resolve, reject) => {
  24. wx.request({
  25. url: this.globalData.url + api,
  26. data: params,
  27. header: {
  28. 'content-type': 'application/x-www-form-urlencoded',
  29. 'Authorization': wx.getStorageSync('token'),
  30. },
  31. method: method,
  32. success: (res) => {
  33. resolve(res)
  34. // console.log(res)
  35. if (res.statusCode == 401) {
  36. wx.removeStorageSync('token')
  37. wx.showToast({
  38. title: '登陆过期请重新登陆~',
  39. icon: 'none',
  40. mask: true,
  41. success: function () {
  42. wx.redirectTo({
  43. url: '../login/index',
  44. })
  45. }
  46. })
  47. }
  48. },
  49. fail: (err) => {
  50. wx.showToast({
  51. title: err,
  52. icon: 'none',
  53. mask: true
  54. });
  55. reject("请求失败")
  56. }
  57. })
  58. })
  59. }
  60. },
  61. })