App.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <script>
  2. var token = ''
  3. if (uni.getStorageSync('token')) {
  4. token = uni.getStorageSync('token')
  5. }
  6. export default {
  7. globalData: {
  8. statusBarHeight: uni.getSystemInfoSync()['statusBarHeight'],
  9. windowHeight: uni.getSystemInfoSync()['windowHeight'],
  10. },
  11. systemInfo: {},
  12. onLaunch: function() {
  13. // console.log('App Launch');
  14. // uni.getStorageSync('token');
  15. console.log(token);
  16. var that = this;
  17. uni.getSystemInfo({
  18. success: res => {
  19. // console.log(res.safeArea.bottom)
  20. console.log('手机信息res' + res.model)
  21. res.lang = res.language.indexOf('zh') !== -1 ? 'zh' : 'en';
  22. that.systemInfo = res;
  23. }
  24. })
  25. },
  26. onShow: function() {
  27. console.log('App Show');
  28. },
  29. onHide: function() {
  30. console.log('App Hide');
  31. },
  32. methods: {
  33. request(api, params, method) {
  34. var that = this;
  35. var merchant_id = 0;
  36. return new Promise((resolve, reject) => {
  37. uni.request({
  38. url: 'http://bike.saas.yufengjiayun.com/app-api/' + api,
  39. // url:'http://dev.saas.yufengjiayun.com/app-api/'+api,
  40. data: params,
  41. header: {
  42. 'content-type': 'application/x-www-form-urlencoded',
  43. 'Authorization': 'bearer' + ' ' + uni.getStorageSync('token').token,
  44. 'type': 'app',
  45. 'merchant-id': merchant_id
  46. },
  47. method: method,
  48. success: (res) => {
  49. resolve(res)
  50. // console.log(res)
  51. if (res.statusCode == 450) {
  52. return;
  53. }
  54. if (res.data.statusCode != 200) {
  55. if (res.message != undefined) {
  56. uni.showToast({
  57. title: res.message,
  58. icon: 'none',
  59. duration: 3000,
  60. mask: true
  61. })
  62. } else if (res.data.message != undefined) {
  63. uni.showToast({
  64. title: res.data.message,
  65. icon: 'none',
  66. duration: 3000,
  67. mask: true
  68. })
  69. }
  70. } else if (res.statusCode != 200) {
  71. if (res.message != undefined) {
  72. uni.showToast({
  73. title: res.message,
  74. icon: 'none',
  75. duration: 3000,
  76. mask: true
  77. })
  78. } else if (res.data.message != undefined) {
  79. uni.showToast({
  80. title: res.data.message,
  81. icon: 'none',
  82. duration: 3000,
  83. mask: true
  84. })
  85. }
  86. }
  87. if (res.statusCode == 401) {
  88. uni.removeStorageSync('token')
  89. uni.showToast({
  90. title: '登陆过期请重新登陆~',
  91. icon: 'none',
  92. mask: true,
  93. success: function() {
  94. uni.redirectTo({
  95. url: '/pages/login/login',
  96. })
  97. }
  98. })
  99. }
  100. },
  101. fail: (err) => {
  102. console.log(err)
  103. uni.showToast({
  104. title: '请求超时请重试',
  105. icon: 'none',
  106. mask: true
  107. });
  108. reject(err)
  109. }
  110. })
  111. })
  112. },
  113. }
  114. };
  115. </script>
  116. <style>
  117. /* 解决头条小程序组件内引入字体不生效的问题 */
  118. /* #ifdef MP-TOUTIAO */
  119. @font-face {
  120. font-family: uniicons;
  121. src: url('/static/uni.ttf');
  122. }
  123. /* #endif */
  124. </style>